Skip to content

Commit 313ad0a

Browse files
jcranmer-intelsys-ce-bb
authored andcommitted
Emit target extension types for SPIR-V friendly IR.
The ABI name mangling of target extension types is tweaked to be like a pointer-to-a-struct, which maintains somewhat better compatibility with the typed pointer representation for name mangling. Original commit: KhronosGroup/SPIRV-LLVM-Translator@15e0aa9
1 parent 4c82652 commit 313ad0a

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "llvm/ADT/StringExtras.h"
6060
#include "llvm/Analysis/LoopInfo.h"
6161
#include "llvm/BinaryFormat/Dwarf.h"
62+
#include "llvm/IR/AttributeMask.h"
6263
#include "llvm/IR/Constants.h"
6364
#include "llvm/IR/DerivedTypes.h"
6465
#include "llvm/IR/Dominators.h"
@@ -3179,6 +3180,8 @@ SPIRVToLLVM::SPIRVToLLVM(Module *LLVMModule, SPIRVModule *TheSPIRVModule)
31793180
assert(M && "Initialization without an LLVM module is not allowed");
31803181
initialize(*M);
31813182
Context = &M->getContext();
3183+
if (BM->getDesiredBIsRepresentation() == BIsRepresentation::SPIRVFriendlyIR)
3184+
UseTargetTypes = !Context->supportsTypedPointers();
31823185
DbgTran.reset(new SPIRVToLLVMDbgTran(TheSPIRVModule, LLVMModule, this));
31833186
}
31843187

llvm-spirv/lib/SPIRV/SPIRVUtil.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,11 +1352,14 @@ static SPIR::RefParamType transTypeDesc(Type *Ty,
13521352
}
13531353
if (auto *TargetTy = dyn_cast<TargetExtType>(Ty)) {
13541354
std::string FullName;
1355+
unsigned AS = 0;
13551356
{
13561357
raw_string_ostream OS(FullName);
13571358
StringRef Name = TargetTy->getName();
13581359
if (Name.consume_front(kSPIRVTypeName::PrefixAndDelim)) {
13591360
OS << "__spirv_" << Name;
1361+
AS = getOCLOpaqueTypeAddrSpace(
1362+
SPIRVOpaqueTypeOpCodeMap::map(Name.str()));
13601363
} else {
13611364
OS << Name;
13621365
}
@@ -1367,7 +1370,12 @@ static SPIR::RefParamType transTypeDesc(Type *Ty,
13671370
for (unsigned Param : TargetTy->int_params())
13681371
OS << "_" << Param;
13691372
}
1370-
return SPIR::RefParamType(new SPIR::UserDefinedType(FullName));
1373+
// Translate as if it's a pointer to the named struct.
1374+
auto *Inner = new SPIR::UserDefinedType(FullName);
1375+
auto *PT = new SPIR::PointerType(Inner);
1376+
PT->setAddressSpace(static_cast<SPIR::TypeAttributeEnum>(
1377+
AS + (unsigned)SPIR::ATTR_ADDR_SPACE_FIRST));
1378+
return SPIR::RefParamType(PT);
13711379
}
13721380

13731381
if (auto *TPT = dyn_cast<TypedPointerType>(Ty)) {

llvm-spirv/test/GroupAndSubgroupInstructions.spvasm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393
; CHECK-SPV-IR: declare spir_func i32 @_Z31__spirv_SubgroupShuffleXorINTELij(i32, i32) #[[#Attrs]]
9494
; CHECK-SPV-IR: declare spir_func i32 @_Z35__spirv_SubgroupBlockReadINTEL_RintPU3AS1Kj(ptr addrspace(1)) #[[#Attrs]]
9595
; CHECK-SPV-IR: declare spir_func void @_Z31__spirv_SubgroupBlockWriteINTELPU3AS1jj(ptr addrspace(1), i32) #[[#Attrs]]
96-
; CHECK-SPV-IR: declare spir_func i32 @_Z40__spirv_SubgroupImageBlockReadINTEL_RintPU3AS133__spirv_Image__void_1_0_0_0_0_0_2Dv2_i(ptr addrspace(1), <2 x i32>) #[[#Attrs]]
97-
; CHECK-SPV-IR: declare spir_func void @_Z36__spirv_SubgroupImageBlockWriteINTELPU3AS133__spirv_Image__void_1_0_0_0_0_0_2Dv2_ij(ptr addrspace(1), <2 x i32>, i32) #[[#Attrs]]
96+
; CHECK-SPV-IR: declare spir_func i32 @_Z40__spirv_SubgroupImageBlockReadINTEL_RintPU3AS133__spirv_Image__void_1_0_0_0_0_0_2Dv2_i(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 2), <2 x i32>) #[[#Attrs]]
97+
; CHECK-SPV-IR: declare spir_func void @_Z36__spirv_SubgroupImageBlockWriteINTELPU3AS133__spirv_Image__void_1_0_0_0_0_0_2Dv2_ij(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 2), <2 x i32>, i32) #[[#Attrs]]
9898

9999
; CHECK-COMMON: attributes #[[#Attrs]] =
100100
; CHECK-COMMON-SAME: convergent

llvm-spirv/test/constant-sampler-under-control-flow.spt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@
9898
; CHECK-LLVM: br i1 %[[cond]], label %[[br1:.*]], label %[[br0:.*]]
9999

100100
; CHECK-LLVM: [[br0]]:
101-
; CHECK-LLVM: %[[s0:.*]] = call ptr addrspace(2) @__translate_sampler_initializer(i32 23)
102-
; CHECK-LLVM: call spir_func ptr addrspace(1) @_Z20__spirv_SampledImagePU3AS133__spirv_Image__void_1_0_0_0_0_0_0PU3AS215__spirv_Sampler(ptr addrspace(1) %{{.*}}, ptr addrspace(2) %[[s0]])
101+
; CHECK-LLVM: %[[s0:.*]] = call target("spirv.Sampler") @__translate_sampler_initializer(i32 23)
102+
; CHECK-LLVM: call spir_func target("spirv.SampledImage", void, 1, 0, 0, 0, 0, 0, 0) @_Z20__spirv_SampledImagePU3AS133__spirv_Image__void_1_0_0_0_0_0_0PU3AS215__spirv_Sampler(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %{{.*}}, target("spirv.Sampler") %[[s0]])
103103

104104
; CHECK-LLVM: [[br1]]:
105-
; CHECK-LLVM: %[[s1:.*]] = call ptr addrspace(2) @__translate_sampler_initializer(i32 23)
106-
; CHECK-LLVM: call spir_func ptr addrspace(1) @_Z20__spirv_SampledImagePU3AS133__spirv_Image__void_1_0_0_0_0_0_0PU3AS215__spirv_Sampler(ptr addrspace(1) %{{.*}}, ptr addrspace(2) %[[s1]])
105+
; CHECK-LLVM: %[[s1:.*]] = call target("spirv.Sampler") @__translate_sampler_initializer(i32 23)
106+
; CHECK-LLVM: call spir_func target("spirv.SampledImage", void, 1, 0, 0, 0, 0, 0, 0) @_Z20__spirv_SampledImagePU3AS133__spirv_Image__void_1_0_0_0_0_0_0PU3AS215__spirv_Sampler(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %{{.*}}, target("spirv.Sampler") %[[s1]])

0 commit comments

Comments
 (0)