Skip to content

Commit 28690f3

Browse files
committed
--Added support for SPV_EXT_image_raw10_raw12 extension.
1 parent 147e615 commit 28690f3

File tree

7 files changed

+156
-1
lines changed

7 files changed

+156
-1
lines changed

llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,23 @@ static bool buildTernaryBitwiseFunctionINTELInst(
10791079
return true;
10801080
}
10811081

1082+
static bool buildImageChannelDataTypeInst(const SPIRV::IncomingCall *Call,
1083+
unsigned Opcode,
1084+
MachineIRBuilder &MIRBuilder,
1085+
SPIRVGlobalRegistry *GR) {
1086+
if (Call->isSpirvOp())
1087+
return buildOpFromWrapper(MIRBuilder, Opcode, Call,
1088+
GR->getSPIRVTypeID(Call->ReturnType));
1089+
1090+
auto MIB = MIRBuilder.buildInstr(Opcode)
1091+
.addDef(Call->ReturnRegister)
1092+
.addUse(GR->getSPIRVTypeID(Call->ReturnType));
1093+
for (unsigned i = 0; i < Call->Arguments.size(); ++i)
1094+
MIB.addUse(Call->Arguments[i]);
1095+
1096+
return true;
1097+
}
1098+
10821099
/// Helper function for building Intel's 2d block io instructions.
10831100
static bool build2DBlockIOINTELInst(const SPIRV::IncomingCall *Call,
10841101
unsigned Opcode,
@@ -2411,6 +2428,16 @@ generateTernaryBitwiseFunctionINTELInst(const SPIRV::IncomingCall *Call,
24112428
return buildTernaryBitwiseFunctionINTELInst(Call, Opcode, MIRBuilder, GR);
24122429
}
24132430

2431+
static bool generateImageChannelDataTypeInst(const SPIRV::IncomingCall *Call,
2432+
MachineIRBuilder &MIRBuilder,
2433+
SPIRVGlobalRegistry *GR) {
2434+
const SPIRV::DemangledBuiltin *Builtin = Call->Builtin;
2435+
unsigned Opcode =
2436+
SPIRV::lookupNativeBuiltin(Builtin->Name, Builtin->Set)->Opcode;
2437+
2438+
return buildImageChannelDataTypeInst(Call, Opcode, MIRBuilder, GR);
2439+
}
2440+
24142441
static bool generate2DBlockIOINTELInst(const SPIRV::IncomingCall *Call,
24152442
MachineIRBuilder &MIRBuilder,
24162443
SPIRVGlobalRegistry *GR) {
@@ -3061,6 +3088,8 @@ std::optional<bool> lowerBuiltin(const StringRef DemangledCall,
30613088
return generatePredicatedLoadStoreInst(Call.get(), MIRBuilder, GR);
30623089
case SPIRV::BlockingPipes:
30633090
return generateBlockingPipesInst(Call.get(), MIRBuilder, GR);
3091+
case SPIRV::ImageChannelDataTypes:
3092+
return generateImageChannelDataTypeInst(Call.get(), MIRBuilder, GR);
30643093
}
30653094
return false;
30663095
}

llvm/lib/Target/SPIRV/SPIRVBuiltins.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def Block2DLoadStore : BuiltinGroup;
7272
def Pipe : BuiltinGroup;
7373
def PredicatedLoadStore : BuiltinGroup;
7474
def BlockingPipes : BuiltinGroup;
75+
def ImageChannelDataTypes : BuiltinGroup;
7576

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

14811482
defm : DemangledNativeBuiltin<"get_image_num_samples", OpenCL_std, ImageMiscQuery, 1, 1, OpImageQuerySamples>;
14821483
defm : DemangledNativeBuiltin<"get_image_num_mip_levels", OpenCL_std, ImageMiscQuery, 1, 1, OpImageQueryLevels>;
1484+
defm : DemangledNativeBuiltin<"get_image_channel_data_type", OpenCL_std, ImageChannelDataTypes, 1, 1, OpImageQueryFormat>;
14831485

14841486
//===----------------------------------------------------------------------===//
14851487
// Class defining a "convert_destType<_sat><_roundingMode>" call record for

llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ static const std::map<std::string, SPIRV::Extension::Extension, std::less<>>
163163
{"SPV_INTEL_kernel_attributes",
164164
SPIRV::Extension::Extension::SPV_INTEL_kernel_attributes},
165165
{"SPV_ALTERA_blocking_pipes",
166-
SPIRV::Extension::Extension::SPV_ALTERA_blocking_pipes}};
166+
SPIRV::Extension::Extension::SPV_ALTERA_blocking_pipes},
167+
{"SPV_EXT_image_raw10_raw12",
168+
SPIRV::Extension::Extension::SPV_EXT_image_raw10_raw12}};
167169

168170
bool SPIRVExtensionsParser::parse(cl::Option &O, StringRef ArgName,
169171
StringRef ArgValue,

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,48 @@ void addInstrRequirements(const MachineInstr &MI,
15931593
}
15941594
break;
15951595
}
1596+
case SPIRV::OpImageQueryFormat: {
1597+
Register ResultReg = MI.getOperand(0).getReg();
1598+
const MachineRegisterInfo &MRI = MI.getMF()->getRegInfo();
1599+
static const unsigned CompareOps[] = {
1600+
SPIRV::OpIEqual, SPIRV::OpINotEqual,
1601+
SPIRV::OpUGreaterThan, SPIRV::OpUGreaterThanEqual,
1602+
SPIRV::OpULessThan, SPIRV::OpULessThanEqual,
1603+
SPIRV::OpSGreaterThan, SPIRV::OpSGreaterThanEqual,
1604+
SPIRV::OpSLessThan, SPIRV::OpSLessThanEqual};
1605+
1606+
auto CheckAndAddExtension = [&](int64_t ImmVal) {
1607+
if (ImmVal == 4323 || ImmVal == 4324) {
1608+
if (ST.canUseExtension(SPIRV::Extension::SPV_EXT_image_raw10_raw12))
1609+
Reqs.addExtension(SPIRV::Extension::SPV_EXT_image_raw10_raw12);
1610+
else
1611+
report_fatal_error("This requires the "
1612+
"SPV_EXT_image_raw10_raw12 extension");
1613+
}
1614+
};
1615+
1616+
for (MachineInstr &UseInst : MRI.use_instructions(ResultReg)) {
1617+
unsigned Opc = UseInst.getOpcode();
1618+
1619+
if (Opc == SPIRV::OpSwitch) {
1620+
for (const MachineOperand &Op : UseInst.operands())
1621+
if (Op.isImm())
1622+
CheckAndAddExtension(Op.getImm());
1623+
} else if (llvm::is_contained(CompareOps, Opc)) {
1624+
for (unsigned i = 1; i < UseInst.getNumOperands(); ++i) {
1625+
Register UseReg = UseInst.getOperand(i).getReg();
1626+
MachineInstr *ConstInst = MRI.getVRegDef(UseReg);
1627+
if (ConstInst && ConstInst->getOpcode() == SPIRV::OpConstantI) {
1628+
int64_t ImmVal = ConstInst->getOperand(2).getImm();
1629+
if (ImmVal)
1630+
CheckAndAddExtension(ImmVal);
1631+
}
1632+
}
1633+
}
1634+
}
1635+
break;
1636+
}
1637+
15961638
case SPIRV::OpGroupNonUniformShuffle:
15971639
case SPIRV::OpGroupNonUniformShuffleXor:
15981640
Reqs.addCapability(SPIRV::Capability::GroupNonUniformShuffle);

llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ defm SPV_KHR_maximal_reconvergence : ExtensionOperand<128, [EnvVulkan]>;
390390
defm SPV_INTEL_bfloat16_arithmetic
391391
: ExtensionOperand<129, [EnvVulkan, EnvOpenCL]>;
392392
defm SPV_INTEL_16bit_atomics : ExtensionOperand<130, [EnvVulkan, EnvOpenCL]>;
393+
defm SPV_EXT_image_raw10_raw12 :ExtensionOperand<131, [EnvOpenCL, EnvVulkan]>;
393394

394395
//===----------------------------------------------------------------------===//
395396
// Multiclass used to define Capabilities enum values and at the same time
@@ -1110,6 +1111,8 @@ defm HalfFloat : ImageChannelDataTypeOperand<13, [Kernel]>;
11101111
defm Float : ImageChannelDataTypeOperand<14, [Kernel]>;
11111112
defm UnormInt24 : ImageChannelDataTypeOperand<15, [Kernel]>;
11121113
defm UnormInt101010_2 : ImageChannelDataTypeOperand<16, [Kernel]>;
1114+
defm UnsignedIntRaw10EXT : ImageChannelDataTypeOperand<17, [Kernel]>;
1115+
defm UnsignedIntRaw12EXT : ImageChannelDataTypeOperand<18, [Kernel]>;
11131116

11141117
//===----------------------------------------------------------------------===//
11151118
// Multiclass used to define ImageOperand enum values and at the same time
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown --spirv-ext=+SPV_EXT_image_raw10_raw12 %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_EXT_image_raw10_raw12 -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK-NOT: OpExtension "SPV_EXT_image_raw10_raw12"
5+
6+
define dso_local spir_kernel void @test_raw1012(ptr addrspace(1) noundef writeonly align 4 captures(none) %dst, i32 noundef %value) {
7+
entry:
8+
switch i32 %value, label %sw.epilog [
9+
i32 4323, label %sw.epilog.sink.split
10+
i32 4324, label %sw.bb1
11+
]
12+
13+
sw.bb1:
14+
br label %sw.epilog.sink.split
15+
16+
sw.epilog.sink.split:
17+
%.sink = phi i32 [ 12, %sw.bb1 ], [ 10, %entry ]
18+
store i32 %.sink, ptr addrspace(1) %dst, align 4
19+
br label %sw.epilog
20+
21+
sw.epilog:
22+
%0 = add i32 %value, -4323
23+
%or.cond = icmp ult i32 %0, 2
24+
br i1 %or.cond, label %if.then, label %if.end
25+
26+
if.then:
27+
store i32 1012, ptr addrspace(1) %dst, align 4
28+
br label %if.end
29+
30+
if.end:
31+
ret void
32+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown --spirv-ext=+SPV_EXT_image_raw10_raw12 %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s --spirv-ext=+SPV_EXT_image_raw10_raw12 -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK: OpExtension "SPV_EXT_image_raw10_raw12"
5+
6+
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) {
7+
entry:
8+
%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)
9+
switch i32 %call, label %sw.epilog [
10+
i32 4304, label %sw.epilog.sink.split
11+
i32 4323, label %sw.bb1
12+
i32 4324, label %sw.bb2
13+
]
14+
15+
sw.bb1:
16+
br label %sw.epilog.sink.split
17+
18+
sw.bb2:
19+
br label %sw.epilog.sink.split
20+
21+
sw.epilog.sink.split:
22+
%.sink = phi i32 [ 12, %sw.bb2 ], [ 10, %sw.bb1 ], [ 8, %entry ]
23+
store i32 %.sink, ptr addrspace(1) %dst, align 4
24+
br label %sw.epilog
25+
26+
sw.epilog:
27+
%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)
28+
%cmp = icmp eq i32 %call3, 4323
29+
br i1 %cmp, label %if.end7.sink.split, label %if.else
30+
31+
if.else:
32+
%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)
33+
%cmp5 = icmp eq i32 %call4, 4324
34+
br i1 %cmp5, label %if.end7.sink.split, label %if.end7
35+
36+
if.end7.sink.split:
37+
%.sink14 = phi i32 [ 1010, %sw.epilog ], [ 1212, %if.else ]
38+
store i32 %.sink14, ptr addrspace(1) %dst, align 4
39+
br label %if.end7
40+
41+
if.end7:
42+
ret void
43+
}
44+
45+
declare spir_func i32 @_Z27get_image_channel_data_type14ocl_image2d_ro(target("spirv.Image", void, 1, 0, 0, 0, 0, 0, 0))

0 commit comments

Comments
 (0)