[clang] [llvm] [HLSL] Implementation of dot intrinsic (PR #81190)
Chris B via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 23 13:58:51 PST 2024
================
@@ -17959,6 +17964,52 @@ llvm::Value *CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned ICEArguments,
return Arg;
}
+Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
+ const CallExpr *E) {
+ if (!getLangOpts().HLSL)
+ return nullptr;
+
+ switch (BuiltinID) {
+ case Builtin::BI__builtin_hlsl_dot: {
+ Value *Op0 = EmitScalarExpr(E->getArg(0));
+ Value *Op1 = EmitScalarExpr(E->getArg(1));
+ llvm::Type *T0 = Op0->getType();
+ llvm::Type *T1 = Op1->getType();
+ if (!T0->isVectorTy() && !T1->isVectorTy()) {
+ if (T0->isFloatingPointTy()) {
+ return Builder.CreateFMul(Op0, Op1, "dx.dot");
+ }
+
+ if (T0->isIntegerTy()) {
+ return Builder.CreateMul(Op0, Op1, "dx.dot");
+ }
+ // Bools should have been promoted
+ assert(
+ false &&
+ "Dot product on a scalar is only supported on integers and floats.");
+ }
+ // A VectorSplat should have happened
+ assert(T0->isVectorTy() && T1->isVectorTy() &&
+ "Dot product of vector and scalar is not supported.");
+
+ // A vector sext or sitofp should have happened
+ assert(T0->getScalarType() == T1->getScalarType() &&
+ "Dot product of vectors need the same element types.");
+
+ auto *VecTy0 = E->getArg(0)->getType()->getAs<VectorType>();
+ auto *VecTy1 = E->getArg(1)->getType()->getAs<VectorType>();
----------------
llvm-beanz wrote:
These declarations need `[[maybe_unused]]` to avoid producing warnings in non-assert builds.
https://github.com/llvm/llvm-project/pull/81190
More information about the cfe-commits
mailing list