[clang] [HLSL] Implement support for HLSL intrinsic - select (PR #107129)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 6 16:11:03 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 15fa3ba547bc3ee04af5c32b8f723a97e3feefd8 44685a3cf034a9e5d7166b93b8021724bd8fd146 --extensions h,cpp -- clang/lib/CodeGen/CGBuiltin.cpp clang/lib/CodeGen/CodeGenFunction.h clang/lib/Headers/hlsl/hlsl_intrinsics.h clang/lib/Sema/SemaHLSL.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 97e56b411b..79f09bfd0f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18521,7 +18521,7 @@ Intrinsic::ID getDotProductIntrinsic(CGHLSLRuntime &RT, QualType QT) {
Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
const CallExpr *E,
- ReturnValueSlot ReturnValue) {
+ ReturnValueSlot ReturnValue) {
if (!getLangOpts().HLSL)
return nullptr;
@@ -18711,17 +18711,21 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
case Builtin::BI__builtin_hlsl_select: {
Value *OpCond = EmitScalarExpr(E->getArg(0));
RValue RValTrue = EmitAnyExpr(E->getArg(1));
- Value *OpTrue = RValTrue.isScalar() ? RValTrue.getScalarVal()
- : RValTrue.getAggregatePointer(E->getArg(1)->getType(), *this);
+ Value *OpTrue =
+ RValTrue.isScalar()
+ ? RValTrue.getScalarVal()
+ : RValTrue.getAggregatePointer(E->getArg(1)->getType(), *this);
RValue RValFalse = EmitAnyExpr(E->getArg(2));
- Value *OpFalse = RValFalse.isScalar() ? RValFalse.getScalarVal()
- : RValFalse.getAggregatePointer(E->getArg(2)->getType(), *this);
-
- Value *SelectVal = Builder.CreateSelect(OpCond, OpTrue, OpFalse,
- "hlsl.select");
+ Value *OpFalse =
+ RValFalse.isScalar()
+ ? RValFalse.getScalarVal()
+ : RValFalse.getAggregatePointer(E->getArg(2)->getType(), *this);
+
+ Value *SelectVal =
+ Builder.CreateSelect(OpCond, OpTrue, OpFalse, "hlsl.select");
if (!RValTrue.isScalar())
Builder.CreateStore(SelectVal, ReturnValue.getAddress(),
- ReturnValue.isVolatile());
+ ReturnValue.isVolatile());
return SelectVal;
}
diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h
index 81a0b66618..35a5275e61 100644
--- a/clang/lib/CodeGen/CodeGenFunction.h
+++ b/clang/lib/CodeGen/CodeGenFunction.h
@@ -4701,7 +4701,7 @@ public:
llvm::Value *EmitPPCBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
llvm::Value *EmitAMDGPUBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
llvm::Value *EmitHLSLBuiltinExpr(unsigned BuiltinID, const CallExpr *E,
- ReturnValueSlot ReturnValue);
+ ReturnValueSlot ReturnValue);
llvm::Value *EmitScalarOrConstFoldImmArg(unsigned ICEArguments, unsigned Idx,
const CallExpr *E);
llvm::Value *EmitSystemZBuiltinExpr(unsigned BuiltinID, const CallExpr *E);
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 1cd4f085cb..f7e37511cb 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -1616,7 +1616,7 @@ double4 saturate(double4);
template <typename T>
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
T select(bool, T, T);
-
+
/// \fn vector<T,Sz> select(vector<bool,Sz> Conds, vector<T,Sz> TrueVals,
/// vector<T,Sz> FalseVals)
/// \brief ternary operator for vectors. All vectors must be the same size.
@@ -1628,7 +1628,7 @@ T select(bool, T, T);
template <typename T, int Sz>
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_select)
vector<T, Sz> select(vector<bool, Sz>, vector<T, Sz>, vector<T, Sz>);
-
+
//===----------------------------------------------------------------------===//
// sin builtins
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 62661aae31..49482fdfd0 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -1513,17 +1513,17 @@ void SetElementTypeAsReturnType(Sema *S, CallExpr *TheCall,
}
static bool CheckScalarOrVector(Sema *S, CallExpr *TheCall, QualType Scalar,
- unsigned ArgIndex) {
+ unsigned ArgIndex) {
assert(TheCall->getNumArgs() >= ArgIndex);
QualType ArgType = TheCall->getArg(ArgIndex)->getType();
auto *VTy = ArgType->getAs<VectorType>();
// not the scalar or vector<scalar>
if (!(S->Context.hasSameUnqualifiedType(ArgType, Scalar) ||
- (VTy && S->Context.hasSameUnqualifiedType(VTy->getElementType(),
- Scalar)))) {
+ (VTy &&
+ S->Context.hasSameUnqualifiedType(VTy->getElementType(), Scalar)))) {
S->Diag(TheCall->getArg(0)->getBeginLoc(),
- diag::err_typecheck_expect_scalar_or_vector)
- << ArgType << Scalar;
+ diag::err_typecheck_expect_scalar_or_vector)
+ << ArgType << Scalar;
return true;
}
return false;
@@ -1533,12 +1533,11 @@ static bool CheckBoolSelect(Sema *S, CallExpr *TheCall) {
assert(TheCall->getNumArgs() == 3);
Expr *Arg1 = TheCall->getArg(1);
Expr *Arg2 = TheCall->getArg(2);
- if(!S->Context.hasSameUnqualifiedType(Arg1->getType(),
- Arg2->getType())) {
+ if (!S->Context.hasSameUnqualifiedType(Arg1->getType(), Arg2->getType())) {
S->Diag(TheCall->getBeginLoc(),
- diag::err_typecheck_call_different_arg_types)
- << Arg1->getType() << Arg2->getType()
- << Arg1->getSourceRange() << Arg2->getSourceRange();
+ diag::err_typecheck_call_different_arg_types)
+ << Arg1->getType() << Arg2->getType() << Arg1->getSourceRange()
+ << Arg2->getSourceRange();
return true;
}
@@ -1551,27 +1550,24 @@ static bool CheckVectorSelect(Sema *S, CallExpr *TheCall) {
Expr *Arg1 = TheCall->getArg(1);
Expr *Arg2 = TheCall->getArg(2);
if (!Arg1->getType()->isVectorType()) {
- S->Diag(Arg1->getBeginLoc(),
- diag::err_builtin_non_vector_type)
- << "Second" << TheCall->getDirectCallee() << Arg1->getType()
- << Arg1->getSourceRange();
+ S->Diag(Arg1->getBeginLoc(), diag::err_builtin_non_vector_type)
+ << "Second" << TheCall->getDirectCallee() << Arg1->getType()
+ << Arg1->getSourceRange();
return true;
}
-
+
if (!Arg2->getType()->isVectorType()) {
- S->Diag(Arg2->getBeginLoc(),
- diag::err_builtin_non_vector_type)
- << "Third" << TheCall->getDirectCallee() << Arg2->getType()
- << Arg2->getSourceRange();
+ S->Diag(Arg2->getBeginLoc(), diag::err_builtin_non_vector_type)
+ << "Third" << TheCall->getDirectCallee() << Arg2->getType()
+ << Arg2->getSourceRange();
return true;
}
- if (!S->Context.hasSameUnqualifiedType(Arg1->getType(),
- Arg2->getType())) {
+ if (!S->Context.hasSameUnqualifiedType(Arg1->getType(), Arg2->getType())) {
S->Diag(TheCall->getBeginLoc(),
- diag::err_typecheck_call_different_arg_types)
- << Arg1->getType() << Arg2->getType()
- << Arg1->getSourceRange() << Arg2->getSourceRange();
+ diag::err_typecheck_call_different_arg_types)
+ << Arg1->getType() << Arg2->getType() << Arg1->getSourceRange()
+ << Arg2->getSourceRange();
return true;
}
@@ -1580,9 +1576,9 @@ static bool CheckVectorSelect(Sema *S, CallExpr *TheCall) {
if (TheCall->getArg(0)->getType()->getAs<VectorType>()->getNumElements() !=
Arg1->getType()->getAs<VectorType>()->getNumElements()) {
S->Diag(TheCall->getBeginLoc(),
- diag::err_typecheck_vector_lengths_not_equal)
- << TheCall->getArg(0)->getType() << Arg1->getType()
- << TheCall->getArg(0)->getSourceRange() << Arg1->getSourceRange();
+ diag::err_typecheck_vector_lengths_not_equal)
+ << TheCall->getArg(0)->getType() << Arg1->getType()
+ << TheCall->getArg(0)->getSourceRange() << Arg1->getSourceRange();
return true;
}
TheCall->setType(Arg1->getType());
@@ -1631,7 +1627,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
return true;
auto *VTy = ArgTy->getAs<VectorType>();
if (VTy && VTy->getElementType()->isBooleanType() &&
- CheckVectorSelect(&SemaRef, TheCall))
+ CheckVectorSelect(&SemaRef, TheCall))
return true;
break;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/107129
More information about the cfe-commits
mailing list