[clang] [llvm] Adding splitdouble HLSL function (PR #109331)
Farzon Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 9 09:45:48 PDT 2024
================
@@ -18901,6 +18901,160 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef<Value *>{Op0},
nullptr, "hlsl.radians");
}
+ // This should only be called when targeting DXIL
+ case Builtin::BI__builtin_hlsl_splitdouble: {
+
+ assert((E->getArg(0)->getType()->hasFloatingRepresentation() &&
+ E->getArg(1)->getType()->hasUnsignedIntegerRepresentation() &&
+ E->getArg(2)->getType()->hasUnsignedIntegerRepresentation()) &&
+ "asuint operands types mismatch");
+ Value *Op0 = EmitScalarExpr(E->getArg(0));
+ const auto *OutArg1 = dyn_cast<HLSLOutArgExpr>(E->getArg(1));
+ const auto *OutArg2 = dyn_cast<HLSLOutArgExpr>(E->getArg(2));
+
+ CallArgList Args;
+ auto [Op1BaseLValue, Op1TmpLValue] =
+ EmitHLSLOutArgExpr(OutArg1, Args, OutArg1->getType());
+ auto [Op2BaseLValue, Op2TmpLValue] =
+ EmitHLSLOutArgExpr(OutArg2, Args, OutArg2->getType());
+
+ if (CGM.getTarget().getTriple().isDXIL()) {
+
+ llvm::StructType *RetType = nullptr;
+
+ if (Op0->getType()->isVectorTy()) {
+ auto *Op0VecTy = E->getArg(0)->getType()->getAs<VectorType>();
+
+ llvm::VectorType *i32VecTy = llvm::VectorType::get(
+ Int32Ty, ElementCount::getFixed(Op0VecTy->getNumElements()));
+ RetType = llvm::StructType::get(i32VecTy, i32VecTy);
+ } else {
+ RetType = llvm::StructType::get(Int32Ty, Int32Ty);
+ }
+
+ CallInst *CI =
+ Builder.CreateIntrinsic(RetType, Intrinsic::dx_splitdouble, {Op0},
+ nullptr, "hlsl.splitdouble");
+
+ Value *Arg0 = Builder.CreateExtractValue(CI, 0);
+ Value *Arg1 = Builder.CreateExtractValue(CI, 1);
+
+ Builder.CreateStore(Arg0, Op1TmpLValue.getAddress());
+ auto *s = Builder.CreateStore(Arg1, Op2TmpLValue.getAddress());
+
+ EmitWritebacks(*this, Args);
+ return s;
+ }
+
+ assert(!CGM.getTarget().getTriple().isDXIL() &&
+ "For non-DXIL targets we generate the instructions");
+
+ if (!Op0->getType()->isVectorTy()) {
+ FixedVectorType *DestTy = FixedVectorType::get(Int32Ty, 2);
+ Value *Bitcast = Builder.CreateBitCast(Op0, DestTy);
+
+ Value *Arg0 = Builder.CreateExtractElement(Bitcast, 0.0);
+ Value *Arg1 = Builder.CreateExtractElement(Bitcast, 1.0);
+
+ Builder.CreateStore(Arg0, Op1TmpLValue.getAddress());
+ auto *s = Builder.CreateStore(Arg1, Op2TmpLValue.getAddress());
+
+ EmitWritebacks(*this, Args);
+ return s;
+ }
+
+ auto emitVectorCode =
+ [](Value *Op, CGBuilderTy *Builder,
+ FixedVectorType *DestTy) -> std::pair<Value *, Value *> {
+ Value *bitcast = Builder->CreateBitCast(Op, DestTy);
+
+ SmallVector<int> LowbitsIndex;
+ SmallVector<int> HighbitsIndex;
+
+ for (unsigned int idx = 0; idx < DestTy->getNumElements(); idx += 2) {
----------------
farzonl wrote:
The clang style is for variables to be capital. so this would be `Idx`. The line above would be `EmitVectorCode`.
https://github.com/llvm/llvm-project/pull/109331
More information about the cfe-commits
mailing list