Skip to content

Commit 8fd1d77

Browse files
Fznamznonvmaksimo
authored andcommitted
Fix names of some instructions in SPIR-V friendly IR
Remove double mangling for OpAll/OpAny and relational instructions. Add return type to name of function which corresponds to OpImageQuerySizeLod/OpImageQuerySize instructions.
1 parent c13723b commit 8fd1d77

File tree

7 files changed

+63
-13
lines changed

7 files changed

+63
-13
lines changed

llvm-spirv/lib/SPIRV/OCLUtil.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,9 +1305,11 @@ Instruction *mutateCallInstOCL(
13051305
Module *M, CallInst *CI,
13061306
std::function<std::string(CallInst *, std::vector<Value *> &, Type *&RetTy)>
13071307
ArgMutate,
1308-
std::function<Instruction *(CallInst *)> RetMutate, AttributeList *Attrs) {
1308+
std::function<Instruction *(CallInst *)> RetMutate, AttributeList *Attrs,
1309+
bool TakeFuncName) {
13091310
OCLBuiltinFuncMangleInfo BtnInfo(CI->getCalledFunction());
1310-
return mutateCallInst(M, CI, ArgMutate, RetMutate, &BtnInfo, Attrs);
1311+
return mutateCallInst(M, CI, ArgMutate, RetMutate, &BtnInfo, Attrs,
1312+
TakeFuncName);
13111313
}
13121314

13131315
static std::pair<StringRef, StringRef>

llvm-spirv/lib/SPIRV/OCLUtil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ Instruction *mutateCallInstOCL(
468468
std::function<std::string(CallInst *, std::vector<Value *> &, Type *&RetTy)>
469469
ArgMutate,
470470
std::function<Instruction *(CallInst *)> RetMutate,
471-
AttributeList *Attrs = nullptr);
471+
AttributeList *Attrs = nullptr, bool TakeFuncName = false);
472472

473473
/// Check if instruction is bitcast from spirv.ConstantSampler to spirv.Sampler
474474
bool isSamplerInitializer(Instruction *Inst);

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,6 +2386,13 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
23862386
BV->getName(), BB));
23872387
}
23882388

2389+
case OpImageQuerySize:
2390+
case OpImageQuerySizeLod: {
2391+
return mapValue(
2392+
BV, transSPIRVBuiltinFromInst(static_cast<SPIRVInstruction *>(BV), BB,
2393+
/*AddRetTypePostfix=*/true));
2394+
}
2395+
23892396
case OpBitReverse: {
23902397
auto *BR = static_cast<SPIRVUnary *>(BV);
23912398
auto Ty = transType(BV->getType());
@@ -3373,9 +3380,7 @@ Instruction *SPIRVToLLVM::transOCLBuiltinFromInst(SPIRVInstruction *BI,
33733380
return transBuiltinFromInst(FuncName, BI, BB);
33743381
}
33753382

3376-
Instruction *SPIRVToLLVM::transSPIRVBuiltinFromInst(SPIRVInstruction *BI,
3377-
BasicBlock *BB) {
3378-
assert(BB && "Invalid BB");
3383+
std::string getSPIRVFuncSuffix(SPIRVInstruction *BI) {
33793384
string Suffix = "";
33803385
if (BI->getOpCode() == OpCreatePipeFromPipeStorage) {
33813386
auto CPFPS = static_cast<SPIRVCreatePipeFromPipeStorage *>(BI);
@@ -3395,9 +3400,22 @@ Instruction *SPIRVToLLVM::transSPIRVBuiltinFromInst(SPIRVInstruction *BI,
33953400
break;
33963401
}
33973402
}
3403+
return Suffix;
3404+
}
33983405

3399-
return transBuiltinFromInst(getSPIRVFuncName(BI->getOpCode(), Suffix), BI,
3400-
BB);
3406+
Instruction *SPIRVToLLVM::transSPIRVBuiltinFromInst(SPIRVInstruction *BI,
3407+
BasicBlock *BB,
3408+
bool AddRetTypePostfix) {
3409+
assert(BB && "Invalid BB");
3410+
if (AddRetTypePostfix) {
3411+
const Type *RetTy =
3412+
BI->hasType() ? transType(BI->getType()) : Type::getVoidTy(*Context);
3413+
return transBuiltinFromInst(getSPIRVFuncName(BI->getOpCode(), RetTy) +
3414+
getSPIRVFuncSuffix(BI),
3415+
BI, BB);
3416+
}
3417+
return transBuiltinFromInst(
3418+
getSPIRVFuncName(BI->getOpCode(), getSPIRVFuncSuffix(BI)), BI, BB);
34013419
}
34023420

34033421
bool SPIRVToLLVM::translate() {
@@ -4475,13 +4493,13 @@ Instruction *SPIRVToLLVM::transOCLAllAny(SPIRVInstruction *I, BasicBlock *BB) {
44754493
CastInst::CreateSExtOrBitCast(OldArg, NewArgTy, "", CI);
44764494
Args[0] = NewArg;
44774495
RetTy = Int32Ty;
4478-
return CI->getCalledFunction()->getName().str();
4496+
return getSPIRVFuncName(I->getOpCode(), getSPIRVFuncSuffix(I));
44794497
},
44804498
[=](CallInst *NewCI) -> Instruction * {
44814499
return CastInst::CreateTruncOrBitCast(
44824500
NewCI, Type::getInt1Ty(*Context), "", NewCI->getNextNode());
44834501
},
4484-
&Attrs)));
4502+
&Attrs, /*TakeFuncName=*/true)));
44854503
}
44864504

44874505
Instruction *SPIRVToLLVM::transOCLRelational(SPIRVInstruction *I,
@@ -4508,7 +4526,7 @@ Instruction *SPIRVToLLVM::transOCLRelational(SPIRVInstruction *I,
45084526
IntTy,
45094527
cast<FixedVectorType>(CI->getType())->getNumElements());
45104528
}
4511-
return CI->getCalledFunction()->getName().str();
4529+
return getSPIRVFuncName(I->getOpCode(), getSPIRVFuncSuffix(I));
45124530
},
45134531
[=](CallInst *NewCI) -> Instruction * {
45144532
Type *RetTy = Type::getInt1Ty(*Context);
@@ -4519,7 +4537,7 @@ Instruction *SPIRVToLLVM::transOCLRelational(SPIRVInstruction *I,
45194537
return CastInst::CreateTruncOrBitCast(NewCI, RetTy, "",
45204538
NewCI->getNextNode());
45214539
},
4522-
&Attrs)));
4540+
&Attrs, /*TakeFuncName=*/true)));
45234541
}
45244542

45254543
std::unique_ptr<SPIRVModule> readSpirvModule(std::istream &IS,

llvm-spirv/lib/SPIRV/SPIRVReader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ class SPIRVToLLVM {
122122
Instruction *transBuiltinFromInst(const std::string &FuncName,
123123
SPIRVInstruction *BI, BasicBlock *BB);
124124
Instruction *transOCLBuiltinFromInst(SPIRVInstruction *BI, BasicBlock *BB);
125-
Instruction *transSPIRVBuiltinFromInst(SPIRVInstruction *BI, BasicBlock *BB);
125+
Instruction *transSPIRVBuiltinFromInst(SPIRVInstruction *BI, BasicBlock *BB,
126+
bool AddRetTypePostfix = false);
126127
void transOCLVectorLoadStore(std::string &UnmangledName,
127128
std::vector<SPIRVWord> &BArgs);
128129

llvm-spirv/test/relationals.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
33
; RUN: llvm-spirv %t.bc -o %t.spv
44
; RUN: spirv-val %t.spv
5+
; RUN: llvm-spirv %t.spv -r --spirv-target-env=SPV-IR -o %t.rev.bc
6+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-SPV-LLVM
57

68
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
79
target triple = "spir"
@@ -12,6 +14,18 @@ declare dso_local spir_func <4 x i8> @_Z16__spirv_IsFiniteIDv4_aDv4_fET_T0_(<4 x
1214
declare dso_local spir_func <4 x i8> @_Z16__spirv_IsNormalIDv4_aDv4_fET_T0_(<4 x float>)
1315
declare dso_local spir_func <4 x i8> @_Z18__spirv_SignBitSetIDv4_aDv4_fET_T0_(<4 x float>)
1416

17+
; CHECK-SPV-LLVM: call spir_func <4 x i32> @_Z13__spirv_IsNanDv4_f
18+
; CHECK-SPV-LLVM: call spir_func <4 x i32> @_Z13__spirv_IsInfDv4_f
19+
; CHECK-SPV-LLVM: call spir_func <4 x i32> @_Z16__spirv_IsFiniteDv4_f
20+
; CHECK-SPV-LLVM: call spir_func <4 x i32> @_Z16__spirv_IsNormalDv4_f
21+
; CHECK-SPV-LLVM: call spir_func <4 x i32> @_Z18__spirv_SignBitSetDv4_f
22+
23+
; CHECK-SPV-LLVM: declare spir_func <4 x i32> @_Z13__spirv_IsNanDv4_f(<4 x float>)
24+
; CHECK-SPV-LLVM: declare spir_func <4 x i32> @_Z13__spirv_IsInfDv4_f(<4 x float>)
25+
; CHECK-SPV-LLVM: declare spir_func <4 x i32> @_Z16__spirv_IsFiniteDv4_f(<4 x float>)
26+
; CHECK-SPV-LLVM: declare spir_func <4 x i32> @_Z16__spirv_IsNormalDv4_f(<4 x float>)
27+
; CHECK-SPV-LLVM: declare spir_func <4 x i32> @_Z18__spirv_SignBitSetDv4_f(<4 x float>)
28+
1529
; CHECK-SPIRV: {{[0-9]+}} TypeBool [[TBool:[0-9]+]]
1630
; CHECK-SPIRV: {{[0-9]+}} TypeVector [[TBoolVec:[0-9]+]] [[TBool]]
1731

llvm-spirv/test/transcoding/OpAllAny.ll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44
; RUN: llvm-spirv %t.bc -o %t.spv
55
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
66
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
7+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc --spirv-target-env=SPV-IR
8+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-SPV-LLVM
79

810
; CHECK-LLVM: call spir_func i32 @_Z3allDv2_i(
911
; CHECK-LLVM: call spir_func i32 @_Z3anyDv2_i(
1012

13+
; CHECK-SPV-LLVM: call spir_func i32 @_Z11__spirv_AllDv2_i(
14+
; CHECK-SPV-LLVM: call spir_func i32 @_Z11__spirv_AnyDv2_i(
15+
16+
; CHECK-SPV-LLVM: declare spir_func i32 @_Z11__spirv_AllDv2_i(<2 x i32>)
17+
; CHECK-SPV-LLVM: declare spir_func i32 @_Z11__spirv_AnyDv2_i(<2 x i32>)
18+
1119
; CHECK-SPIRV: 2 TypeBool [[BoolTypeID:[0-9]+]]
1220
; CHECK-SPIRV: 4 All [[BoolTypeID]]
1321
; CHECK-SPIRV: 4 Any [[BoolTypeID]]

llvm-spirv/test/transcoding/check_ro_qualifier.ll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
; RUN: llvm-spirv %t.bc -o %t.spv
33
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
44
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
5+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc --spirv-target-env=SPV-IR
6+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-SPV-LLVM
57

68
; CHECK-LLVM: opencl.image2d_array_ro_t = type opaque
79
; CHECK-LLVM: define spir_kernel void @sample_kernel(%opencl.image2d_array_ro_t addrspace(1)
@@ -14,6 +16,11 @@
1416
; CHECK-LLVM: declare spir_func <2 x i32> @_Z13get_image_dim20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)
1517
; CHECK-LLVM: declare spir_func i64 @_Z20get_image_array_size20ocl_image2d_array_ro(%opencl.image2d_array_ro_t addrspace(1)
1618

19+
; CHECK-SPV-LLVM: call spir_func <3 x i32> @_Z32__spirv_ImageQuerySizeLod_Ruint320ocl_image2d_array_roi(%opencl.image2d_array_ro_t addrspace(1)
20+
; CHECK-SPV-LLVM: call spir_func <3 x i64> @_Z33__spirv_ImageQuerySizeLod_Rulong320ocl_image2d_array_roi(%opencl.image2d_array_ro_t addrspace(1)
21+
; CHECK-SPV-LLVM: declare spir_func <3 x i32> @_Z32__spirv_ImageQuerySizeLod_Ruint320ocl_image2d_array_roi(%opencl.image2d_array_ro_t addrspace(1)
22+
; CHECK-SPV-LLVM: declare spir_func <3 x i64> @_Z33__spirv_ImageQuerySizeLod_Rulong320ocl_image2d_array_roi(%opencl.image2d_array_ro_t addrspace(1)
23+
1724
; CHECK-LLVM-DAG: [[AQ]] = !{!"read_only"}
1825
; CHECK-LLVM-DAG: [[TYPE]] = !{!"image2d_array_t"}
1926

0 commit comments

Comments
 (0)