|
20 | 20 | #include "llvm/IR/IntrinsicsDirectX.h"
|
21 | 21 | #include "llvm/IR/IntrinsicsSPIRV.h"
|
22 | 22 |
|
| 23 | +#include "clang/Basic/Builtins.h" |
23 | 24 | #include "clang/Basic/HLSLRuntime.h"
|
24 | 25 |
|
25 | 26 | #include "llvm/ADT/SmallVector.h"
|
|
29 | 30 | #include <optional>
|
30 | 31 | #include <vector>
|
31 | 32 |
|
32 |
| -// Define the function generator macro |
33 |
| -#define GENERATE_HLSL_INTRINSIC_FUNCTION(name) \ |
34 |
| - llvm::Intrinsic::ID get_hlsl_##name##_intrinsic() { \ |
35 |
| - llvm::Triple::ArchType Arch = getArch(); \ |
36 |
| - switch (Arch) { \ |
37 |
| - case llvm::Triple::dxil: \ |
38 |
| - return llvm::Intrinsic::dx_##name; \ |
39 |
| - case llvm::Triple::spirv: \ |
40 |
| - return llvm::Intrinsic::spv_##name; \ |
41 |
| - default: \ |
42 |
| - llvm_unreachable("Intrinsic " #name \ |
43 |
| - " not supported by target architecture"); \ |
44 |
| - } \ |
| 33 | +#define GENERATE_HLSL_INTRINSIC_BASE(IntrinsicPostfix) \ |
| 34 | + llvm::Triple::ArchType Arch = getArch(); \ |
| 35 | + switch (Arch) { \ |
| 36 | + case llvm::Triple::dxil: \ |
| 37 | + return llvm::Intrinsic::dx_##IntrinsicPostfix; \ |
| 38 | + case llvm::Triple::spirv: \ |
| 39 | + return llvm::Intrinsic::spv_##IntrinsicPostfix; \ |
| 40 | + default: \ |
| 41 | + llvm_unreachable("Intrinsic " #IntrinsicPostfix \ |
| 42 | + " not supported by target architecture"); \ |
| 43 | + } |
| 44 | + |
| 45 | +// A function generator macro for when there is no builtins or |
| 46 | +// when builtins are mapped to a set of intrinsics for different types. |
| 47 | +#define GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix) \ |
| 48 | + llvm::Intrinsic::ID get##FunctionName##Intrinsic() { \ |
| 49 | + GENERATE_HLSL_INTRINSIC_BASE(IntrinsicPostfix) \ |
| 50 | + } |
| 51 | + |
| 52 | +// A template function generator macro for when we have builtins. |
| 53 | +#define GENERATE_HLSL_INTRINSIC_TEMPLATE(BuiltinName, IntrinsicPostfix) \ |
| 54 | + template <> llvm::Intrinsic::ID getIntrinsic<Builtin::BI__##BuiltinName>() { \ |
| 55 | + GENERATE_HLSL_INTRINSIC_BASE(IntrinsicPostfix) \ |
45 | 56 | }
|
46 | 57 |
|
47 | 58 | namespace llvm {
|
@@ -69,9 +80,9 @@ class CGHLSLRuntime {
|
69 | 80 | //===----------------------------------------------------------------------===//
|
70 | 81 | // Start of reserved area for HLSL intrinsic getters.
|
71 | 82 | //===----------------------------------------------------------------------===//
|
72 |
| - |
73 |
| - GENERATE_HLSL_INTRINSIC_FUNCTION(all) |
74 |
| - GENERATE_HLSL_INTRINSIC_FUNCTION(thread_id) |
| 83 | + template <unsigned BI> llvm::Intrinsic::ID getIntrinsic(); |
| 84 | + GENERATE_HLSL_INTRINSIC_TEMPLATE(builtin_hlsl_elementwise_all, all) |
| 85 | + GENERATE_HLSL_INTRINSIC_FUNCTION(ThreadId, thread_id) |
75 | 86 |
|
76 | 87 | //===----------------------------------------------------------------------===//
|
77 | 88 | // End of reserved area for HLSL intrinsic getters.
|
|
0 commit comments