[clang] [llvm] Add length HLSL function to DirectX Backend (PR #101256)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 30 15:20:06 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff a6ef0864e9cf365a5cc4a3c39c9c749c49c87c1d 08110b735a908ad7387df72029e28ee133ec39d5 --extensions h,cpp -- clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CGHLSLRuntime.h clang/lib/Headers/hlsl/hlsl_intrinsics.h clang/lib/Sema/SemaHLSL.cpp llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a28073ca9c..9b0ab3d361 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18462,7 +18462,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
}
case Builtin::BI__builtin_hlsl_elementwise_length: {
Value *X = EmitScalarExpr(E->getArg(0));
-
+
if (!E->getArg(0)->getType()->hasFloatingRepresentation())
llvm_unreachable("length operand must have a float representation");
// if the operand is a scalar, we can use the fabs llvm intrinsic directly
@@ -18473,8 +18473,8 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
}
return Builder.CreateIntrinsic(
/*ReturnType=*/X->getType()->getScalarType(),
- CGM.getHLSLRuntime().getLengthIntrinsic(),
- ArrayRef<Value *>{X}, nullptr, "hlsl.length");
+ CGM.getHLSLRuntime().getLengthIntrinsic(), ArrayRef<Value *>{X},
+ nullptr, "hlsl.length");
}
case Builtin::BI__builtin_hlsl_elementwise_frac: {
Value *Op0 = EmitScalarExpr(E->getArg(0));
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 21ac25bba1..03e74ef35b 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -908,7 +908,6 @@ float3 lerp(float3, float3, float3);
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_lerp)
float4 lerp(float4, float4, float4);
-
//===----------------------------------------------------------------------===//
// length builtins
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 75be844227..183ff40c04 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -1083,19 +1083,18 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
if (SemaRef.checkArgCount(TheCall, 1))
return true;
if (SemaRef.PrepareBuiltinElementwiseMathOneArgCall(TheCall))
- return true;
+ return true;
ExprResult A = TheCall->getArg(0);
QualType ArgTyA = A.get()->getType();
QualType RetTy;
- if (auto *VTy = ArgTyA->getAs<VectorType>())
+ if (auto *VTy = ArgTyA->getAs<VectorType>())
RetTy = VTy->getElementType();
- else
+ else
RetTy = TheCall->getArg(0)->getType();
- TheCall->setType(RetTy);
-
+ TheCall->setType(RetTy);
if (CheckFloatOrHalfRepresentations(&SemaRef, TheCall))
return true;
diff --git a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
index 7ef5b9eae9..8c3dd54b9a 100644
--- a/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
+++ b/llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
@@ -181,17 +181,17 @@ static bool expandLengthIntrinsic(CallInst *Orig) {
}
Value *Result = Builder.CreateIntrinsic(
EltTy, Intrinsic::sqrt, ArrayRef<Value *>{Sum}, nullptr, "elt.sqrt");
-
- Orig->replaceAllUsesWith(Result);
+
+ Orig->replaceAllUsesWith(Result);
Orig->eraseFromParent();
- return true;
+ return true;
} else {
- Value *Result = Builder.CreateIntrinsic(
- EltTy, Intrinsic::fabs, ArrayRef<Value *>{Elt}, nullptr, "elt.abs");
- Orig->replaceAllUsesWith(Result);
- Orig->eraseFromParent();
- return true;
- }
+ Value *Result = Builder.CreateIntrinsic(
+ EltTy, Intrinsic::fabs, ArrayRef<Value *>{Elt}, nullptr, "elt.abs");
+ Orig->replaceAllUsesWith(Result);
+ Orig->eraseFromParent();
+ return true;
+ }
}
static bool expandLerpIntrinsic(CallInst *Orig) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/101256
More information about the llvm-commits
mailing list