Skip to content

Commit 3b57b64

Browse files
authored
[HLSL][SPIR-V] Add create.handle intrinsic (llvm#81038)
Add a SPIR-V target-specific intrinsic for creating handles, which is used for lowering HLSL resources types like RWBuffer. `llvm/lib/TargetParser/Triple.cpp`: SPIR-V intrinsics use "spv" as the target prefix, not "spirv". As far as I can tell, this is the first one that is used via the `CGBuiltin` codepath, which relies on `getArchTypePrefix`, so I've corrected it here. `clang/lib/Basic/Targets/SPIR.h`: When records are laid out in the lowering from AST to IR, they were incorrectly offset because these Pointer attributes were defaulting to 32. Related to llvm#81036
1 parent 35c4f02 commit 3b57b64

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

clang/lib/Basic/Targets/SPIR.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ class LLVM_LIBRARY_VISIBILITY SPIRVTargetInfo : public BaseSPIRVTargetInfo {
310310
assert(Triple.getEnvironment() >= llvm::Triple::Pixel &&
311311
Triple.getEnvironment() <= llvm::Triple::Amplification &&
312312
"Logical SPIR-V environment must be a valid shader stage.");
313+
PointerWidth = PointerAlign = 64;
313314

314315
// SPIR-V IDs are represented with a single 32-bit word.
315316
SizeType = TargetInfo::UnsignedInt;

clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s
2+
// RUN: %clang_cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s --check-prefix=CHECK-SPIRV
23

34
RWBuffer<float> Buf;
45

@@ -7,3 +8,6 @@ RWBuffer<float> Buf;
78

89
// CHECK: %[[HandleRes:[0-9]+]] = call ptr @llvm.dx.create.handle(i8 1)
910
// CHECK: store ptr %[[HandleRes]], ptr %h, align 4
11+
12+
// CHECK-SPIRV: %[[HandleRes:[0-9]+]] = call ptr @llvm.spv.create.handle(i8 1)
13+
// CHECK-SPIRV: store ptr %[[HandleRes]], ptr %h, align 8

llvm/include/llvm/IR/IntrinsicsSPIRV.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ let TargetPrefix = "spv" in {
3838
// Expect, Assume Intrinsics
3939
def int_spv_assume : Intrinsic<[], [llvm_i1_ty]>;
4040
def int_spv_expect : Intrinsic<[llvm_anyint_ty], [LLVMMatchType<0>, LLVMMatchType<0>]>;
41+
42+
// The following intrinsic(s) are mirrored from IntrinsicsDirectX.td for HLSL support.
43+
def int_spv_create_handle : ClangBuiltin<"__builtin_hlsl_create_handle">,
44+
Intrinsic<[ llvm_ptr_ty ], [llvm_i8_ty], [IntrWillReturn]>;
4145
}

llvm/lib/IR/Function.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "llvm/IR/IntrinsicsR600.h"
4545
#include "llvm/IR/IntrinsicsRISCV.h"
4646
#include "llvm/IR/IntrinsicsS390.h"
47+
#include "llvm/IR/IntrinsicsSPIRV.h"
4748
#include "llvm/IR/IntrinsicsVE.h"
4849
#include "llvm/IR/IntrinsicsWebAssembly.h"
4950
#include "llvm/IR/IntrinsicsX86.h"

llvm/lib/TargetParser/Triple.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ StringRef Triple::getArchTypePrefix(ArchType Kind) {
188188

189189
case spirv:
190190
case spirv32:
191-
case spirv64: return "spirv";
191+
case spirv64: return "spv";
192192

193193
case kalimba: return "kalimba";
194194
case lanai: return "lanai";

0 commit comments

Comments
 (0)