[clang] [HLSL] Implement HLSL Flat casting (excluding splat cases) (PR #118842)
Chris B via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 16 08:25:51 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
----------------
llvm-beanz wrote:
It's probably worth referencing https://github.com/llvm/llvm-project/issues/88060 in the comment.
https://github.com/llvm/llvm-project/pull/118842
More information about the cfe-commits
mailing list