[clang] Added HLSL or intrinsic function with respective semantic checks (PR #127899)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 19 13:26:41 PST 2025
https://github.com/metkarpoonam created https://github.com/llvm/llvm-project/pull/127899
None
>From 3ac4882e65c804c434bf6184559bdc6d9588683f Mon Sep 17 00:00:00 2001
From: Poonam Vilas Metkar <poonammetkar at microsoft.com>
Date: Wed, 19 Feb 2025 13:16:16 -0800
Subject: [PATCH] Added HLSL or intrinsic function with respective semantic
checks
---
clang/include/clang/Basic/Builtins.td | 8 +++++++-
clang/lib/Headers/hlsl/hlsl_intrinsics.h | 19 +++++++++++++++++++
clang/lib/Sema/SemaHLSL.cpp | 23 +++++++++++++++++++++++
3 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index 29939242596ba..d71d17d9e3e01 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -98,7 +98,7 @@ def AcoshF128 : Builtin {
}
def AsinF16F128 : Builtin, F16F128MathTemplate {
- let Spellings = ["__builtin_asin"];
+ let Spellings = ["__builtin_asin"];
let Attributes = [FunctionWithBuiltinPrefix, NoThrow,
ConstIgnoringErrnoAndExceptions];
let Prototype = "T(T)";
@@ -1238,6 +1238,7 @@ def NondetermenisticValue : Builtin {
let Prototype = "void(...)";
}
+
def ElementwiseAbs : Builtin {
let Spellings = ["__builtin_elementwise_abs"];
let Attributes = [NoThrow, Const, CustomTypeChecking];
@@ -4968,6 +4969,11 @@ def HLSLGroupMemoryBarrierWithGroupSync: LangBuiltin<"HLSL_LANG"> {
let Attributes = [NoThrow, Const];
let Prototype = "void()";
}
+def HLSLOr : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_or"];
+ let Attributes = [NoThrow, Const];
+ let Prototype = "void(...)";
+}
// Builtins for XRay.
def XRayCustomEvent : Builtin {
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d1f5fdff8b600..a3238c806262b 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -37,6 +37,25 @@ namespace hlsl {
#define _HLSL_16BIT_AVAILABILITY_STAGE(environment, version, stage)
#endif
+//===----------------------------------------------------------------------===//
+// or builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn T or(T x, T y)
+/// \brief Returns the bitwise OR of the two input values, \a x and \a y.
+/// \param x The first input value and y The second input value.
+///
+/// \returns The bitwise OR of the two input values.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool or (bool, bool);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool2 or (bool2, bool2);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool3 or (bool3, bool3);
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_or)
+bool4 or (bool4, bool4);
+
//===----------------------------------------------------------------------===//
// abs builtins
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 4abd870ad6aaa..28e121ae2b8cb 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2558,6 +2558,29 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
}
break;
}
+
+ case Builtin::BI__builtin_hlsl_or: {
+ if (SemaRef.checkArgCount(TheCall, 2))
+ return true;
+ if (CheckVectorElementCallArgs(&SemaRef, TheCall))
+ return true;
+
+ //Ensure input parameter type is bool
+ ExprResult A = TheCall->getArg(0);
+ QualType ArgTyA = A.get()->getType();
+ ExprResult B = TheCall->getArg(1);
+ QualType ArgTyB = B.get()->getType();
+ if (!ArgTyA->isBooleanType() || !ArgTyB->isBooleanType()) {
+ SemaRef.Diag(TheCall->getArg(0)->getBeginLoc(),
+ diag::err_typecheck_convert_incompatible)
+ << ArgTyA << SemaRef.Context.BoolTy << 1 << 0 << 0;
+ return true;
+ }
+ // Ensure input expr type is a scalar/vector and the same as the return type
+ if (CheckAnyScalarOrVector(&SemaRef, TheCall, 0))
+ return true;
+ break;
+ }
}
return false;
}
More information about the cfe-commits
mailing list