Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,8 +1217,9 @@ static void AddDotProductRequirements(const MachineInstr &MI,
}

void addInstrRequirements(const MachineInstr &MI,
SPIRV::RequirementHandler &Reqs,
SPIRV::ModuleAnalysisInfo &MAI,
const SPIRVSubtarget &ST) {
SPIRV::RequirementHandler &Reqs = MAI.Reqs;
switch (MI.getOpcode()) {
case SPIRV::OpMemoryModel: {
int64_t Addr = MI.getOperand(0).getImm();
Expand Down Expand Up @@ -1738,15 +1739,45 @@ void addInstrRequirements(const MachineInstr &MI,
break;
case SPIRV::OpConvertHandleToImageINTEL:
case SPIRV::OpConvertHandleToSamplerINTEL:
case SPIRV::OpConvertHandleToSampledImageINTEL:
case SPIRV::OpConvertHandleToSampledImageINTEL: {
if (!ST.canUseExtension(SPIRV::Extension::SPV_INTEL_bindless_images))
report_fatal_error("OpConvertHandleTo[Image/Sampler/SampledImage]INTEL "
"instructions require the following SPIR-V extension: "
"SPV_INTEL_bindless_images",
false);
SPIRVGlobalRegistry *GR = ST.getSPIRVGlobalRegistry();
SPIRV::AddressingModel::AddressingModel AddrModel = MAI.Addr;
SPIRVType *TyDef = GR->getSPIRVTypeForVReg(MI.getOperand(1).getReg());
if (MI.getOpcode() == SPIRV::OpConvertHandleToImageINTEL &&
TyDef->getOpcode() != SPIRV::OpTypeImage) {
report_fatal_error("Incorrect return type for the instruction "
"OpConvertHandleToImageINTEL",
false);
} else if (MI.getOpcode() == SPIRV::OpConvertHandleToSamplerINTEL &&
TyDef->getOpcode() != SPIRV::OpTypeSampler) {
report_fatal_error("Incorrect return type for the instruction "
"OpConvertHandleToSamplerINTEL",
false);
} else if (MI.getOpcode() == SPIRV::OpConvertHandleToSampledImageINTEL &&
TyDef->getOpcode() != SPIRV::OpTypeSampledImage) {
report_fatal_error("Incorrect return type for the instruction "
"OpConvertHandleToSampledImageINTEL",
false);
}
SPIRVType *SpvTy = GR->getSPIRVTypeForVReg(MI.getOperand(2).getReg());
unsigned Bitwidth = GR->getScalarOrVectorBitWidth(SpvTy);
if (!(Bitwidth == 32 && AddrModel == SPIRV::AddressingModel::Physical32) &&
!(Bitwidth == 64 && AddrModel == SPIRV::AddressingModel::Physical64)) {
report_fatal_error(
"Parameter value must be a 32-bit scalar in case of "
"Physical32 addressing model or a 64-bit scalar in case of "
"Physical64 addressing model",
false);
}
Reqs.addExtension(SPIRV::Extension::SPV_INTEL_bindless_images);
Reqs.addCapability(SPIRV::Capability::BindlessImagesINTEL);
break;
}
case SPIRV::OpSubgroup2DBlockLoadINTEL:
case SPIRV::OpSubgroup2DBlockLoadTransposeINTEL:
case SPIRV::OpSubgroup2DBlockLoadTransformINTEL:
Expand Down Expand Up @@ -1879,7 +1910,7 @@ static void collectReqs(const Module &M, SPIRV::ModuleAnalysisInfo &MAI,
continue;
for (const MachineBasicBlock &MBB : *MF)
for (const MachineInstr &MI : MBB)
addInstrRequirements(MI, MAI.Reqs, ST);
addInstrRequirements(MI, MAI, ST);
}
// Collect requirements for OpExecutionMode instructions.
auto Node = M.getNamedMetadata("spirv.ExecutionMode");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; RUN: not llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_bindless_images %s -o %t.spvt 2>&1 | FileCheck %s --check-prefix=CHECK-ERROR

; CHECK-ERROR: LLVM ERROR: Parameter value must be a 32-bit scalar in case of Physical32 addressing model or a 64-bit scalar in case of Physical64 addressing model

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
target triple = "spir64-unknown-unknown"

define spir_func void @foo(i32 %in) {
%img = call spir_func target("spirv.Image", i32, 2, 0, 0, 0, 0, 0, 0) @_Z33__spirv_ConvertHandleToImageINTELi(i32 %in)
%samp = call spir_func target("spirv.Sampler") @_Z35__spirv_ConvertHandleToSamplerINTELl(i64 42)
%sampImage = call spir_func target("spirv.SampledImage", i64, 1, 0, 0, 0, 0, 0, 0) @_Z40__spirv_ConvertHandleToSampledImageINTELl(i64 43)
ret void
}

declare spir_func target("spirv.Image", i32, 2, 0, 0, 0, 0, 0, 0) @_Z33__spirv_ConvertHandleToImageINTELi(i32)

declare spir_func target("spirv.Sampler") @_Z35__spirv_ConvertHandleToSamplerINTELl(i64)

declare spir_func target("spirv.SampledImage", i64, 1, 0, 0, 0, 0, 0, 0) @_Z40__spirv_ConvertHandleToSampledImageINTELl(i64)
Loading