[clang] [HLSL] add BuiltinsHLSL and set it up as target builtins. (PR #81902)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 15 10:54:03 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-directx
@llvm/pr-subscribers-hlsl
Author: Farzon Lotfi (farzonl)
<details>
<summary>Changes</summary>
1. This change moves hlsl specific builtins from Builtins.td to BuiltinsHLSL.td.
2. Adds changes to the build system to build BuiltinsHLSL.td.
3. Setups HLSL builtins as TargetBuiltins.
---
Full diff: https://github.com/llvm/llvm-project/pull/81902.diff
6 Files Affected:
- (modified) clang/include/clang/Basic/Builtins.td (-13)
- (added) clang/include/clang/Basic/BuiltinsHLSL.td (+21)
- (modified) clang/include/clang/Basic/CMakeLists.txt (+5-1)
- (modified) clang/include/clang/Basic/TargetBuiltins.h (+10)
- (modified) clang/lib/Basic/Targets/DirectX.cpp (+13)
- (modified) clang/lib/Basic/Targets/DirectX.h (+1-3)
``````````diff
diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index df74026c5d2d50..2943911b662191 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4511,19 +4511,6 @@ def GetDeviceSideMangledName : LangBuiltin<"CUDA_LANG"> {
let Prototype = "char const*(...)";
}
-// HLSL
-def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
- let Spellings = ["__builtin_hlsl_wave_active_count_bits"];
- let Attributes = [NoThrow, Const];
- let Prototype = "unsigned int(bool)";
-}
-
-def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
- let Spellings = ["__builtin_hlsl_create_handle"];
- let Attributes = [NoThrow, Const];
- let Prototype = "void*(unsigned char)";
-}
-
// Builtins for XRay.
def XRayCustomEvent : Builtin {
let Spellings = ["__xray_customevent"];
diff --git a/clang/include/clang/Basic/BuiltinsHLSL.td b/clang/include/clang/Basic/BuiltinsHLSL.td
new file mode 100644
index 00000000000000..98088f920a9940
--- /dev/null
+++ b/clang/include/clang/Basic/BuiltinsHLSL.td
@@ -0,0 +1,21 @@
+//===--- BuiltinsHLSL.td - HLSL Builtin function database ---------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+include "clang/Basic/BuiltinsBase.td"
+
+def HLSLWaveActiveCountBits : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_wave_active_count_bits"];
+ let Attributes = [NoThrow, Const];
+ let Prototype = "unsigned int(bool)";
+}
+
+def HLSLCreateHandle : LangBuiltin<"HLSL_LANG"> {
+ let Spellings = ["__builtin_hlsl_create_handle"];
+ let Attributes = [NoThrow, Const];
+ let Prototype = "void*(unsigned char)";
+}
diff --git a/clang/include/clang/Basic/CMakeLists.txt b/clang/include/clang/Basic/CMakeLists.txt
index 7785fb430c069b..01233eb44feffc 100644
--- a/clang/include/clang/Basic/CMakeLists.txt
+++ b/clang/include/clang/Basic/CMakeLists.txt
@@ -65,7 +65,11 @@ clang_tablegen(BuiltinsBPF.inc -gen-clang-builtins
SOURCE BuiltinsBPF.td
TARGET ClangBuiltinsBPF)
-clang_tablegen(BuiltinsRISCV.inc -gen-clang-builtins
+clang_tablegen(BuiltinsHLSL.inc -gen-clang-builtins
+ SOURCE BuiltinsHLSL.td
+ TARGET ClangBuiltinsHLSL)
+
+ clang_tablegen(BuiltinsRISCV.inc -gen-clang-builtins
SOURCE BuiltinsRISCV.td
TARGET ClangBuiltinsRISCV)
diff --git a/clang/include/clang/Basic/TargetBuiltins.h b/clang/include/clang/Basic/TargetBuiltins.h
index 4333830bf34f24..15cf111ae5e9e5 100644
--- a/clang/include/clang/Basic/TargetBuiltins.h
+++ b/clang/include/clang/Basic/TargetBuiltins.h
@@ -89,6 +89,16 @@ namespace clang {
};
}
+ /// HLSL builtins
+ namespace hlsl {
+ enum {
+ LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/BuiltinsHLSL.inc"
+ LastTSBuiltin
+ };
+ } // namespace hlsl
+
/// PPC builtins
namespace PPC {
enum {
diff --git a/clang/lib/Basic/Targets/DirectX.cpp b/clang/lib/Basic/Targets/DirectX.cpp
index 0dd27e6e93b33b..83cc049e5963aa 100644
--- a/clang/lib/Basic/Targets/DirectX.cpp
+++ b/clang/lib/Basic/Targets/DirectX.cpp
@@ -12,11 +12,24 @@
#include "DirectX.h"
#include "Targets.h"
+#include "clang/Basic/MacroBuilder.h"
+#include "clang/Basic/TargetBuiltins.h"
using namespace clang;
using namespace clang::targets;
+static constexpr Builtin::Info BuiltinInfo[] = {
+#define BUILTIN(ID, TYPE, ATTRS) \
+ {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
+#include "clang/Basic/BuiltinsHLSL.inc"
+};
+
void DirectXTargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
DefineStd(Builder, "DIRECTX", Opts);
}
+
+ArrayRef<Builtin::Info> DirectXTargetInfo::getTargetBuiltins() const {
+ return llvm::ArrayRef(BuiltinInfo,
+ clang::hlsl::LastTSBuiltin - Builtin::FirstTSBuiltin);
+}
diff --git a/clang/lib/Basic/Targets/DirectX.h b/clang/lib/Basic/Targets/DirectX.h
index acfcc8c47ba950..99c9522b0dd542 100644
--- a/clang/lib/Basic/Targets/DirectX.h
+++ b/clang/lib/Basic/Targets/DirectX.h
@@ -73,9 +73,7 @@ class LLVM_LIBRARY_VISIBILITY DirectXTargetInfo : public TargetInfo {
return Feature == "directx";
}
- ArrayRef<Builtin::Info> getTargetBuiltins() const override {
- return std::nullopt;
- }
+ ArrayRef<Builtin::Info> getTargetBuiltins() const override;
std::string_view getClobbers() const override { return ""; }
``````````
</details>
https://github.com/llvm/llvm-project/pull/81902
More information about the cfe-commits
mailing list