Skip to content

Commit 894f95b

Browse files
authored
[SPV-IR] Ignore SPIR-V linkage name for BuiltIn variable (#1180)
The BuiltIn variable/call name in SPV-IR should stick to "__spirv_BuiltIn*", no matter what the SPIR-V linkage name is. This is a regression of PR #1133. Signed-off-by: Yilong Guo <yilong.guo@intel.com>
1 parent d88af63 commit 894f95b

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

lib/SPIRV/SPIRVInternal.h

+2
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,8 @@ StringRef undecorateSPIRVFunction(StringRef S);
659659
/// and get the original name.
660660
bool isDecoratedSPIRVFunc(const Function *F, StringRef &UndecName);
661661

662+
std::string prefixSPIRVName(const std::string &S);
663+
662664
StringRef dePrefixSPIRVName(StringRef R, SmallVectorImpl<StringRef> &Postfix);
663665

664666
/// Get a canonical function name for a SPIR-V op code.

lib/SPIRV/SPIRVReader.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,11 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
14771477
Initializer = UndefValue::get(Ty);
14781478
} else
14791479
AddrSpace = SPIRSPIRVAddrSpaceMap::rmap(BS);
1480+
// Force SPIRV BuiltIn variable's name to be __spirv_BuiltInXXXX.
1481+
// No matter what BV's linkage name is.
1482+
SPIRVBuiltinVariableKind BVKind;
1483+
if (BVar->isBuiltin(&BVKind))
1484+
BV->setName(prefixSPIRVName(SPIRVBuiltInNameMap::map(BVKind)));
14801485
auto LVar = new GlobalVariable(*M, Ty, IsConst, LinkageTy,
14811486
/*Initializer=*/nullptr, BV->getName(), 0,
14821487
GlobalVariable::NotThreadLocal, AddrSpace);

test/ignore-builtin-linkage-name.spt

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
119734787 65536 393230 25 0
2+
2 Capability Addresses
3+
2 Capability Linkage
4+
2 Capability Kernel
5+
2 Capability Int64
6+
2 Capability GenericPointer
7+
5 ExtInstImport 1 "OpenCL.std"
8+
3 MemoryModel 2 2
9+
4 EntryPoint 6 8 "foo"
10+
3 Source 0 0
11+
8 Name 5 "__spirv_WorkgroupSize"
12+
4 Name 9 "entry"
13+
4 Name 13 "GroupID"
14+
3 Name 24 "mul"
15+
16+
4 Decorate 5 BuiltIn 25
17+
3 Decorate 5 Constant
18+
10 Decorate 5 LinkageAttributes "__spirv_WorkgroupSize" Import
19+
4 Decorate 13 Alignment 8
20+
4 Decorate 5 Alignment 32
21+
4 TypeInt 2 64 0
22+
5 Constant 2 10 3 0
23+
5 Constant 2 16 0 0
24+
5 Constant 2 20 2 0
25+
4 TypeVector 3 2 3
26+
4 TypePointer 4 5 3
27+
2 TypeVoid 6
28+
3 TypeFunction 7 6
29+
4 TypeArray 11 2 10
30+
4 TypePointer 12 7 11
31+
4 TypePointer 14 8 3
32+
4 TypePointer 17 8 2
33+
4 Variable 4 5 5
34+
35+
5 Function 6 8 0 7
36+
37+
2 Label 9
38+
4 Variable 12 13 7
39+
4 PtrCastToGeneric 14 15 5
40+
6 PtrAccessChain 17 18 15 16 16
41+
4 PtrCastToGeneric 14 19 5
42+
6 PtrAccessChain 17 21 19 16 20
43+
6 Load 2 22 18 2 32
44+
6 Load 2 23 21 2 8
45+
5 IMul 2 24 22 23
46+
1 Return
47+
48+
1 FunctionEnd
49+
50+
; RUN: llvm-spirv %s -to-binary -o %t.spv
51+
; RUN: spirv-val %t.spv
52+
; RUN: llvm-spirv -r %t.spv -spirv-target-env=SPV-IR -o - | llvm-dis | FileCheck %s -check-prefix=CHECK-LLVM
53+
54+
; CHECK-LLVM-NOT: __spirv_WorkgroupSize
55+
; CHECK-LLVM: __spirv_BuiltInWorkgroupSize

0 commit comments

Comments
 (0)