Skip to content

Commit 5b57d52

Browse files
fix for SPV_INTEL_function_pointers: result type of OpConstantFunctionPointerINTEL must be OpTypePointer with Storage Class operand equal to CodeSectionINTEL
1 parent 58c8d73 commit 5b57d52

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,9 +3292,6 @@ bool SPIRVInstructionSelector::selectGlobalValue(
32923292
PointerBaseType = GR.getOrCreateSPIRVType(
32933293
GVType, MIRBuilder, SPIRV::AccessQualifier::ReadWrite, false);
32943294
}
3295-
SPIRVType *ResType = GR.getOrCreateSPIRVPointerType(
3296-
PointerBaseType, I, TII,
3297-
addressSpaceToStorageClass(GV->getAddressSpace(), STI));
32983295

32993296
std::string GlobalIdent;
33003297
if (!GV->hasName()) {
@@ -3327,6 +3324,10 @@ bool SPIRVInstructionSelector::selectGlobalValue(
33273324
STI.canUseExtension(SPIRV::Extension::SPV_INTEL_function_pointers)
33283325
? dyn_cast<Function>(GV)
33293326
: nullptr;
3327+
SPIRVType *ResType = GR.getOrCreateSPIRVPointerType(
3328+
PointerBaseType, I, TII,
3329+
GVFun ? SPIRV::StorageClass::CodeSectionINTEL
3330+
: addressSpaceToStorageClass(GV->getAddressSpace(), STI));
33303331
if (GVFun) {
33313332
// References to a function via function pointers generate virtual
33323333
// registers without a definition. We will resolve it later, during
@@ -3378,6 +3379,9 @@ bool SPIRVInstructionSelector::selectGlobalValue(
33783379
? SPIRV::LinkageType::LinkOnceODR
33793380
: SPIRV::LinkageType::Export);
33803381

3382+
SPIRVType *ResType = GR.getOrCreateSPIRVPointerType(
3383+
PointerBaseType, I, TII,
3384+
addressSpaceToStorageClass(GV->getAddressSpace(), STI));
33813385
Register Reg = GR.buildGlobalVariable(ResVReg, ResType, GlobalIdent, GV,
33823386
Storage, Init, GlobalVar->isConstant(),
33833387
HasLnkTy, LnkType, MIRBuilder, true);

llvm/lib/Target/SPIRV/SPIRVUtils.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ addressSpaceToStorageClass(unsigned AddrSpace, const SPIRVSubtarget &STI) {
205205
: SPIRV::StorageClass::CrossWorkgroup;
206206
case 7:
207207
return SPIRV::StorageClass::Input;
208+
case 9:
209+
return SPIRV::StorageClass::CodeSectionINTEL;
208210
default:
209211
report_fatal_error("Unknown address space");
210212
}

llvm/lib/Target/SPIRV/SPIRVUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ storageClassToAddressSpace(SPIRV::StorageClass::StorageClass SC) {
166166
return 6;
167167
case SPIRV::StorageClass::Input:
168168
return 7;
169+
case SPIRV::StorageClass::CodeSectionINTEL:
170+
return 9;
169171
default:
170172
report_fatal_error("Unable to get address space id");
171173
}

llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_function_pointers/fp_const.ll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
; CHECK-DAG: %[[TyInt64:.*]] = OpTypeInt 64 0
1111
; CHECK-DAG: %[[TyFun:.*]] = OpTypeFunction %[[TyInt64]] %[[TyInt64]]
1212
; CHECK-DAG: %[[TyInt8:.*]] = OpTypeInt 8 0
13+
; CHECK-DAG: %[[TyPtrFunCodeSection:.*]] = OpTypePointer CodeSectionINTEL %[[TyFun]]
14+
; CHECK-DAG: %[[ConstFunFp:.*]] = OpConstantFunctionPointerINTEL %[[TyPtrFunCodeSection]] %[[DefFunFp:.*]]
1315
; CHECK-DAG: %[[TyPtrFun:.*]] = OpTypePointer Function %[[TyFun]]
14-
; CHECK-DAG: %[[ConstFunFp:.*]] = OpConstantFunctionPointerINTEL %[[TyPtrFun]] %[[DefFunFp:.*]]
1516
; CHECK-DAG: %[[TyPtrPtrFun:.*]] = OpTypePointer Function %[[TyPtrFun]]
1617
; CHECK-DAG: %[[TyPtrInt8:.*]] = OpTypePointer Function %[[TyInt8]]
1718
; CHECK-DAG: %[[TyPtrPtrInt8:.*]] = OpTypePointer Function %[[TyPtrInt8]]

0 commit comments

Comments
 (0)