Skip to content
Open
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
29 changes: 29 additions & 0 deletions llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,23 @@ static bool buildTernaryBitwiseFunctionINTELInst(
return true;
}

static bool buildImageChannelDataTypeInst(const SPIRV::IncomingCall *Call,
unsigned Opcode,
MachineIRBuilder &MIRBuilder,
SPIRVGlobalRegistry *GR) {
if (Call->isSpirvOp())
return buildOpFromWrapper(MIRBuilder, Opcode, Call,
GR->getSPIRVTypeID(Call->ReturnType));

auto MIB = MIRBuilder.buildInstr(Opcode)
.addDef(Call->ReturnRegister)
.addUse(GR->getSPIRVTypeID(Call->ReturnType));
for (unsigned i = 0; i < Call->Arguments.size(); ++i)
MIB.addUse(Call->Arguments[i]);

return true;
}

/// Helper function for building Intel's 2d block io instructions.
static bool build2DBlockIOINTELInst(const SPIRV::IncomingCall *Call,
unsigned Opcode,
Expand Down Expand Up @@ -2411,6 +2428,16 @@ generateTernaryBitwiseFunctionINTELInst(const SPIRV::IncomingCall *Call,
return buildTernaryBitwiseFunctionINTELInst(Call, Opcode, MIRBuilder, GR);
}

static bool generateImageChannelDataTypeInst(const SPIRV::IncomingCall *Call,
MachineIRBuilder &MIRBuilder,
SPIRVGlobalRegistry *GR) {
const SPIRV::DemangledBuiltin *Builtin = Call->Builtin;
unsigned Opcode =
SPIRV::lookupNativeBuiltin(Builtin->Name, Builtin->Set)->Opcode;

return buildImageChannelDataTypeInst(Call, Opcode, MIRBuilder, GR);
}

static bool generate2DBlockIOINTELInst(const SPIRV::IncomingCall *Call,
MachineIRBuilder &MIRBuilder,
SPIRVGlobalRegistry *GR) {
Expand Down Expand Up @@ -3061,6 +3088,8 @@ std::optional<bool> lowerBuiltin(const StringRef DemangledCall,
return generatePredicatedLoadStoreInst(Call.get(), MIRBuilder, GR);
case SPIRV::BlockingPipes:
return generateBlockingPipesInst(Call.get(), MIRBuilder, GR);
case SPIRV::ImageChannelDataTypes:
return generateImageChannelDataTypeInst(Call.get(), MIRBuilder, GR);
}
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/SPIRV/SPIRVBuiltins.td
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def Block2DLoadStore : BuiltinGroup;
def Pipe : BuiltinGroup;
def PredicatedLoadStore : BuiltinGroup;
def BlockingPipes : BuiltinGroup;
def ImageChannelDataTypes : BuiltinGroup;

//===----------------------------------------------------------------------===//
// Class defining a demangled builtin record. The information in the record
Expand Down Expand Up @@ -1480,6 +1481,7 @@ defm : DemangledImageQueryBuiltin<"get_image_array_size", OpenCL_std, 3>;

defm : DemangledNativeBuiltin<"get_image_num_samples", OpenCL_std, ImageMiscQuery, 1, 1, OpImageQuerySamples>;
defm : DemangledNativeBuiltin<"get_image_num_mip_levels", OpenCL_std, ImageMiscQuery, 1, 1, OpImageQueryLevels>;
defm : DemangledNativeBuiltin<"get_image_channel_data_type", OpenCL_std, ImageChannelDataTypes, 1, 1, OpImageQueryFormat>;

//===----------------------------------------------------------------------===//
// Class defining a "convert_destType<_sat><_roundingMode>" call record for
Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ static const std::map<std::string, SPIRV::Extension::Extension, std::less<>>
{"SPV_INTEL_kernel_attributes",
SPIRV::Extension::Extension::SPV_INTEL_kernel_attributes},
{"SPV_ALTERA_blocking_pipes",
SPIRV::Extension::Extension::SPV_ALTERA_blocking_pipes}};
SPIRV::Extension::Extension::SPV_ALTERA_blocking_pipes},
{"SPV_EXT_image_raw10_raw12",
SPIRV::Extension::Extension::SPV_EXT_image_raw10_raw12}};

bool SPIRVExtensionsParser::parse(cl::Option &O, StringRef ArgName,
StringRef ArgValue,
Expand Down
42 changes: 42 additions & 0 deletions llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1593,6 +1593,48 @@ void addInstrRequirements(const MachineInstr &MI,
}
break;
}
case SPIRV::OpImageQueryFormat: {
Register ResultReg = MI.getOperand(0).getReg();
const MachineRegisterInfo &MRI = MI.getMF()->getRegInfo();
static const unsigned CompareOps[] = {
SPIRV::OpIEqual, SPIRV::OpINotEqual,
SPIRV::OpUGreaterThan, SPIRV::OpUGreaterThanEqual,
SPIRV::OpULessThan, SPIRV::OpULessThanEqual,
SPIRV::OpSGreaterThan, SPIRV::OpSGreaterThanEqual,
SPIRV::OpSLessThan, SPIRV::OpSLessThanEqual};

auto CheckAndAddExtension = [&](int64_t ImmVal) {
if (ImmVal == 4323 || ImmVal == 4324) {
if (ST.canUseExtension(SPIRV::Extension::SPV_EXT_image_raw10_raw12))
Reqs.addExtension(SPIRV::Extension::SPV_EXT_image_raw10_raw12);
else
report_fatal_error("This requires the "
"SPV_EXT_image_raw10_raw12 extension");
}
};

for (MachineInstr &UseInst : MRI.use_instructions(ResultReg)) {
unsigned Opc = UseInst.getOpcode();

if (Opc == SPIRV::OpSwitch) {
for (const MachineOperand &Op : UseInst.operands())
if (Op.isImm())
CheckAndAddExtension(Op.getImm());
} else if (llvm::is_contained(CompareOps, Opc)) {
for (unsigned i = 1; i < UseInst.getNumOperands(); ++i) {
Register UseReg = UseInst.getOperand(i).getReg();
MachineInstr *ConstInst = MRI.getVRegDef(UseReg);
if (ConstInst && ConstInst->getOpcode() == SPIRV::OpConstantI) {
int64_t ImmVal = ConstInst->getOperand(2).getImm();
if (ImmVal)
CheckAndAddExtension(ImmVal);
}
}
}
}
break;
}

case SPIRV::OpGroupNonUniformShuffle:
case SPIRV::OpGroupNonUniformShuffleXor:
Reqs.addCapability(SPIRV::Capability::GroupNonUniformShuffle);
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ defm SPV_KHR_maximal_reconvergence : ExtensionOperand<128, [EnvVulkan]>;
defm SPV_INTEL_bfloat16_arithmetic
: ExtensionOperand<129, [EnvVulkan, EnvOpenCL]>;
defm SPV_INTEL_16bit_atomics : ExtensionOperand<130, [EnvVulkan, EnvOpenCL]>;
defm SPV_EXT_image_raw10_raw12 :ExtensionOperand<131, [EnvOpenCL, EnvVulkan]>;

//===----------------------------------------------------------------------===//
// Multiclass used to define Capabilities enum values and at the same time
Expand Down Expand Up @@ -1110,6 +1111,8 @@ defm HalfFloat : ImageChannelDataTypeOperand<13, [Kernel]>;
defm Float : ImageChannelDataTypeOperand<14, [Kernel]>;
defm UnormInt24 : ImageChannelDataTypeOperand<15, [Kernel]>;
defm UnormInt101010_2 : ImageChannelDataTypeOperand<16, [Kernel]>;
defm UnsignedIntRaw10EXT : ImageChannelDataTypeOperand<17, [Kernel]>;
defm UnsignedIntRaw12EXT : ImageChannelDataTypeOperand<18, [Kernel]>;

//===----------------------------------------------------------------------===//
// Multiclass used to define ImageOperand enum values and at the same time
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown --spirv-ext=+SPV_EXT_image_raw10_raw12 %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_EXT_image_raw10_raw12 -o - -filetype=obj | spirv-val %}

; CHECK-NOT: OpExtension "SPV_EXT_image_raw10_raw12"

define dso_local spir_kernel void @test_raw1012(ptr addrspace(1) noundef writeonly align 4 captures(none) %dst, i32 noundef %value) {
entry:
switch i32 %value, label %sw.epilog [
i32 4323, label %sw.epilog.sink.split
i32 4324, label %sw.bb1
]

sw.bb1:
br label %sw.epilog.sink.split

sw.epilog.sink.split:
%.sink = phi i32 [ 12, %sw.bb1 ], [ 10, %entry ]
store i32 %.sink, ptr addrspace(1) %dst, align 4
br label %sw.epilog

sw.epilog:
%0 = add i32 %value, -4323
%or.cond = icmp ult i32 %0, 2
br i1 %or.cond, label %if.then, label %if.end

if.then:
store i32 1012, ptr addrspace(1) %dst, align 4
br label %if.end

if.end:
ret void
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown --spirv-ext=+SPV_EXT_image_raw10_raw12 %s -o - | FileCheck %s
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_EXT_image_raw10_raw12 -o - -filetype=obj | spirv-val %}

; CHECK: OpExtension "SPV_EXT_image_raw10_raw12"

define dso_local spir_kernel void @test_raw1012(ptr addrspace(1) noundef writeonly align 4 captures(none) %dst, target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %img) {
entry:
%call = tail call spir_func i32 @_Z27get_image_channel_data_type14ocl_image2d_ro(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %img)
switch i32 %call, label %sw.epilog [
i32 4304, label %sw.epilog.sink.split
i32 4323, label %sw.bb1
i32 4324, label %sw.bb2
]

sw.bb1:
br label %sw.epilog.sink.split

sw.bb2:
br label %sw.epilog.sink.split

sw.epilog.sink.split:
%.sink = phi i32 [ 12, %sw.bb2 ], [ 10, %sw.bb1 ], [ 8, %entry ]
store i32 %.sink, ptr addrspace(1) %dst, align 4
br label %sw.epilog

sw.epilog:
%call3 = tail call spir_func i32 @_Z27get_image_channel_data_type14ocl_image2d_ro(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %img)
%cmp = icmp eq i32 %call3, 4323
br i1 %cmp, label %if.end7.sink.split, label %if.else

if.else:
%call4 = tail call spir_func i32 @_Z27get_image_channel_data_type14ocl_image2d_ro(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0) %img)
%cmp5 = icmp eq i32 %call4, 4324
br i1 %cmp5, label %if.end7.sink.split, label %if.end7

if.end7.sink.split:
%.sink14 = phi i32 [ 1010, %sw.epilog ], [ 1212, %if.else ]
store i32 %.sink14, ptr addrspace(1) %dst, align 4
br label %if.end7

if.end7:
ret void
}

declare spir_func i32 @_Z27get_image_channel_data_type14ocl_image2d_ro(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0))
Loading