Skip to content

Commit 1416ead

Browse files
add the test and the rest of the implememtation
1 parent 704d31b commit 1416ead

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,25 @@ static bool build2DBlockIOINTELInst(const SPIRV::IncomingCall *Call,
10961096
return true;
10971097
}
10981098

1099+
// Helper function for building Intel's predicated load/store instructions.
1100+
static bool buildPredicatedLoadStoreInst(const SPIRV::IncomingCall *Call,
1101+
unsigned Opcode,
1102+
MachineIRBuilder &MIRBuilder,
1103+
SPIRVGlobalRegistry *GR) {
1104+
// Generate SPIRV instruction accordingly.
1105+
if (Call->isSpirvOp())
1106+
return buildOpFromWrapper(MIRBuilder, Opcode, Call,
1107+
GR->getSPIRVTypeID(Call->ReturnType));
1108+
1109+
auto MIB = MIRBuilder.buildInstr(Opcode)
1110+
.addDef(Call->ReturnRegister)
1111+
.addUse(GR->getSPIRVTypeID(Call->ReturnType));
1112+
for (unsigned i = 0; i < Call->Arguments.size(); ++i)
1113+
MIB.addUse(Call->Arguments[i]);
1114+
1115+
return true;
1116+
}
1117+
10991118
static bool buildPipeInst(const SPIRV::IncomingCall *Call, unsigned Opcode,
11001119
unsigned Scope, MachineIRBuilder &MIRBuilder,
11011120
SPIRVGlobalRegistry *GR) {
@@ -2419,6 +2438,16 @@ static bool generatePipeInst(const SPIRV::IncomingCall *Call,
24192438
return buildPipeInst(Call, Opcode, Scope, MIRBuilder, GR);
24202439
}
24212440

2441+
static bool generatePredicatedLoadStoreInst(const SPIRV::IncomingCall *Call,
2442+
MachineIRBuilder &MIRBuilder,
2443+
SPIRVGlobalRegistry *GR) {
2444+
const SPIRV::DemangledBuiltin *Builtin = Call->Builtin;
2445+
unsigned Opcode =
2446+
SPIRV::lookupNativeBuiltin(Builtin->Name, Builtin->Set)->Opcode;
2447+
2448+
return buildPredicatedLoadStoreInst(Call, Opcode, MIRBuilder, GR);
2449+
}
2450+
24222451
static bool buildNDRange(const SPIRV::IncomingCall *Call,
24232452
MachineIRBuilder &MIRBuilder,
24242453
SPIRVGlobalRegistry *GR) {
@@ -3019,6 +3048,8 @@ std::optional<bool> lowerBuiltin(const StringRef DemangledCall,
30193048
return generate2DBlockIOINTELInst(Call.get(), MIRBuilder, GR);
30203049
case SPIRV::Pipe:
30213050
return generatePipeInst(Call.get(), MIRBuilder, GR);
3051+
case SPIRV::PredicatedLoadStore:
3052+
return generatePredicatedLoadStoreInst(Call.get(), MIRBuilder, GR);
30223053
}
30233054
return false;
30243055
}

llvm/lib/Target/SPIRV/SPIRVBuiltins.td

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def BindlessINTEL : BuiltinGroup;
7070
def TernaryBitwiseINTEL : BuiltinGroup;
7171
def Block2DLoadStore : BuiltinGroup;
7272
def Pipe : BuiltinGroup;
73-
def PredicatedIO : BuiltinGroup;
73+
def PredicatedLoadStore : BuiltinGroup;
7474

7575
//===----------------------------------------------------------------------===//
7676
// Class defining a demangled builtin record. The information in the record
@@ -754,8 +754,8 @@ defm : DemangledNativeBuiltin<"__spirv_Subgroup2DBlockPrefetchINTEL", OpenCL_std
754754
defm : DemangledNativeBuiltin<"__spirv_Subgroup2DBlockStoreINTEL", OpenCL_std, Block2DLoadStore, 10, 10, OpSubgroup2DBlockStoreINTEL>;
755755

756756
// SPV_INTEL_predicated_io builtin records
757-
defm : DemangledNativeBuiltin<"__spirv_PredicatedLoadINTEL", OpenCL_std, PredicatedIO, 3, 4, OpPredicatedLoadINTEL>;
758-
defm : DemangledNativeBuiltin<"__spirv_PredicatedStoreINTEL", OpenCL_std, PredicatedIO, 3, 4, OpPredicatedStoreINTEL>;
757+
defm : DemangledNativeBuiltin<"__spirv_PredicatedLoadINTEL", OpenCL_std, PredicatedLoadStore, 3, 4, OpPredicatedLoadINTEL>;
758+
defm : DemangledNativeBuiltin<"__spirv_PredicatedStoreINTEL", OpenCL_std, PredicatedLoadStore, 3, 4, OpPredicatedStoreINTEL>;
759759

760760
//===----------------------------------------------------------------------===//
761761
// Class defining a work/sub group builtin that should be translated into a

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,6 +2035,17 @@ void addInstrRequirements(const MachineInstr &MI,
20352035
// TODO: Add UntypedPointersKHR when implemented.
20362036
break;
20372037
}
2038+
case SPIRV::OpPredicatedLoadINTEL:
2039+
case SPIRV::OpPredicatedStoreINTEL: {
2040+
if (!ST.canUseExtension(SPIRV::Extension::SPV_INTEL_predicated_io))
2041+
report_fatal_error(
2042+
"OpPredicated[Load/Store]INTEL instructions require "
2043+
"the following SPIR-V extension: SPV_INTEL_predicated_io",
2044+
false);
2045+
Reqs.addExtension(SPIRV::Extension::SPV_INTEL_predicated_io);
2046+
Reqs.addCapability(SPIRV::Capability::PredicatedIOINTEL);
2047+
break;
2048+
}
20382049

20392050
default:
20402051
break;

0 commit comments

Comments
 (0)