[clang] [HLSL] Implement HLSL Flat casting (excluding splat cases) (PR #118842)
Ashley Coleman via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 15 12:46:35 PST 2025
================
@@ -2412,6 +2412,102 @@ bool SemaHLSL::CheckCompatibleParameterABI(FunctionDecl *New,
return HadError;
}
+// Generally follows PerformScalarCast, with cases reordered for
+// clarity of what types are supported
+bool SemaHLSL::CanPerformScalarCast(QualType SrcTy, QualType DestTy) {
+
+ if (SemaRef.getASTContext().hasSameUnqualifiedType(SrcTy, DestTy))
+ return true;
+
+ switch (Type::ScalarTypeKind SrcKind = SrcTy->getScalarTypeKind()) {
+ case Type::STK_Bool: // casting from bool is like casting from an integer
+ case Type::STK_Integral:
+ switch (DestTy->getScalarTypeKind()) {
+ case Type::STK_Bool:
+ case Type::STK_Integral:
+ case Type::STK_Floating:
+ return true;
+ case Type::STK_CPointer:
+ case Type::STK_ObjCObjectPointer:
+ case Type::STK_BlockPointer:
+ case Type::STK_MemberPointer:
+ llvm_unreachable("HLSL doesn't support pointers.");
+ case Type::STK_IntegralComplex:
+ case Type::STK_FloatingComplex:
+ llvm_unreachable("HLSL doesn't support complex types.");
+ case Type::STK_FixedPoint:
+ llvm_unreachable("HLSL doesn't support fixed point types.");
+ }
+ llvm_unreachable("Should have returned before this");
+
+ case Type::STK_Floating:
+ switch (DestTy->getScalarTypeKind()) {
+ case Type::STK_Floating:
+ case Type::STK_Bool:
+ case Type::STK_Integral:
+ return true;
+ case Type::STK_FloatingComplex:
+ case Type::STK_IntegralComplex:
+ llvm_unreachable("HLSL doesn't support complex types.");
+ case Type::STK_FixedPoint:
+ llvm_unreachable("HLSL doesn't support fixed point types.");
+ case Type::STK_CPointer:
+ case Type::STK_ObjCObjectPointer:
+ case Type::STK_BlockPointer:
+ case Type::STK_MemberPointer:
+ llvm_unreachable("HLSL doesn't support pointers.");
+ }
+ llvm_unreachable("Should have returned before this");
+
+ case Type::STK_MemberPointer:
+ case Type::STK_CPointer:
+ case Type::STK_BlockPointer:
+ case Type::STK_ObjCObjectPointer:
+ llvm_unreachable("HLSL doesn't support pointers.");
+
+ case Type::STK_FixedPoint:
+ llvm_unreachable("HLSL doesn't support fixed point types.");
+
+ case Type::STK_FloatingComplex:
+ case Type::STK_IntegralComplex:
+ llvm_unreachable("HLSL doesn't support complex types.");
+ }
+
+ llvm_unreachable("Unhandled scalar cast");
+}
+
+// Can we perform an HLSL Flattened cast?
+// TODO: update this code when matrices are added
----------------
V-FEXrt wrote:
idk if this is something llvm has, but other projects I've worked on will tie "future todos" like this to an issue somewhere so they are easier to find later.
If that's something llvm does then this todo would be good to associate with an issue
https://github.com/llvm/llvm-project/pull/118842
More information about the cfe-commits
mailing list