Skip to content

Commit 0b9225e

Browse files
committed
--Added support for the extension SPV_KHR_relaxed_extended_instruction
--Modified the SPIRVEmitNonSemanticDI.cpp file for forward referencing --Modified the test files to reflect the changes made in SPIRVEmitNonSemanticDI.cpp.
1 parent 2f0079c commit 0b9225e

File tree

12 files changed

+425
-171
lines changed

12 files changed

+425
-171
lines changed

llvm/docs/SPIRVUsage.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ Below is a list of supported SPIR-V extensions, sorted alphabetically by their e
245245
- Adds execution mode and capability to enable maximal reconvergence.
246246
* - ``SPV_ALTERA_blocking_pipes``
247247
- Adds new pipe read and write functions that have blocking semantics instead of the non-blocking semantics of the existing pipe read/write functions.
248+
* - `` SPV_KHR_relaxed_extended_instruction``
249+
- Adds the ability to have forward declaration in some specific non-semantic instructions.
248250

249251
SPIR-V representation in LLVM IR
250252
================================

llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVInstPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void SPIRVInstPrinter::printInst(const MCInst *MI, uint64_t Address,
110110
printOpDecorate(MI, OS);
111111
} else if (OpCode == SPIRV::OpExtInstImport) {
112112
recordOpExtInstImport(MI);
113-
} else if (OpCode == SPIRV::OpExtInst) {
113+
} else if (OpCode == SPIRV::OpExtInst || OpCode == SPIRV::OpExtInstWithForwardRefsKHR) {
114114
printOpExtInst(MI, OS);
115115
} else if (OpCode == SPIRV::UNKNOWN_type) {
116116
printUnknownType(MI, OS);

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_KHR_relaxed_extended_instruction",
168+
SPIRV::Extension::Extension::SPV_KHR_relaxed_extended_instruction}};
167169

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

llvm/lib/Target/SPIRV/SPIRVEmitNonSemanticDI.cpp

Lines changed: 379 additions & 157 deletions
Large diffs are not rendered by default.

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class SPIRVGlobalRegistry : public SPIRVIRMapping {
8484

8585
DenseMap<const Metadata *, Register> MDMap;
8686

87+
llvm::DenseSet<llvm::Register> PlaceholderRegs;
88+
8789
// Maps OpVariable and OpFunction-related v-regs to its LLVM IR definition.
8890
DenseMap<std::pair<const MachineFunction *, Register>, const Value *> Reg2GO;
8991

@@ -144,6 +146,18 @@ class SPIRVGlobalRegistry : public SPIRVIRMapping {
144146

145147
void addDebugValue(const Metadata *MD, Register Reg) { MDMap[MD] = Reg; }
146148

149+
void markAsForwardPlaceholder(llvm::Register Reg) {
150+
PlaceholderRegs.insert(Reg);
151+
}
152+
153+
bool isForwardPlaceholder(llvm::Register Reg) const {
154+
return PlaceholderRegs.count(Reg);
155+
}
156+
157+
void resolveForwardPlaceholder(llvm::Register Reg) {
158+
PlaceholderRegs.erase(Reg);
159+
}
160+
147161
// A registry of "assign type" records:
148162
// - Add a record.
149163
void addAssignPtrTypeInstr(Value *Val, CallInst *AssignPtrTyCI) {

llvm/lib/Target/SPIRV/SPIRVInstrInfo.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ def OpExtInstImport: Op<11, (outs ID:$res), (ins StringImm:$extInstsName, variab
148148
// perspective of the instruction selection pass
149149
def OpExtInst: Op<12, (outs ID:$res), (ins TYPE:$ty, i32imm:$set, Extension:$inst, variable_ops),
150150
"$res = OpExtInst $ty $set $inst">;
151+
def OpExtInstWithForwardRefsKHR: Op<4433, (outs ID:$res), (ins TYPE:$ty, i32imm:$set, Extension:$inst, variable_ops),
152+
"$res = OpExtInstWithForwardRefsKHR $ty $set $inst">;
151153
// 3.42.5 Mode-Setting Instructions
152154

153155
def OpMemoryModel: Op<14, (outs), (ins AddressingModel:$addr, MemoryModel:$mem),

llvm/lib/Target/SPIRV/SPIRVMCInstLower.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ void SPIRVMCInstLower::lower(const MachineInstr *MI, MCInst &OutMI,
5656
break;
5757
}
5858
case MachineOperand::MO_Immediate:
59-
if (MI->getOpcode() == SPIRV::OpExtInst && i == 2) {
59+
if ((MI->getOpcode() == SPIRV::OpExtInst ||
60+
MI->getOpcode() == SPIRV::OpExtInstWithForwardRefsKHR) &&
61+
i == 2) {
6062
MCRegister Reg = MAI->getExtInstSetReg(MO.getImm());
6163
MCOp = MCOperand::createReg(Reg);
6264
} else {

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ void SPIRVModuleAnalysis::processOtherInstrs(const Module &M) {
647647
const unsigned OpCode = MI.getOpcode();
648648
if (OpCode == SPIRV::OpString) {
649649
collectOtherInstr(MI, MAI, SPIRV::MB_DebugStrings, IS);
650-
} else if (OpCode == SPIRV::OpExtInst && MI.getOperand(2).isImm() &&
650+
} else if ((OpCode == SPIRV::OpExtInst|| OpCode == SPIRV::OpExtInstWithForwardRefsKHR) && MI.getOperand(2).isImm() &&
651651
MI.getOperand(2).getImm() ==
652652
SPIRV::InstructionSet::
653653
NonSemantic_Shader_DebugInfo_100) {
@@ -2087,6 +2087,16 @@ void addInstrRequirements(const MachineInstr &MI,
20872087
SPIRV::Capability::SubgroupMatrixMultiplyAccumulateINTEL);
20882088
break;
20892089
}
2090+
case SPIRV::OpExtInstWithForwardRefsKHR: {
2091+
if (!ST.canUseExtension(
2092+
SPIRV::Extension::SPV_KHR_relaxed_extended_instruction))
2093+
report_fatal_error("OpExtInstWithForwardRefsKHR instruction requires the "
2094+
"following SPIR-V "
2095+
"extension: SPV_KHR_relaxed_extended_instruction",
2096+
false);
2097+
Reqs.addExtension(SPIRV::Extension::SPV_KHR_relaxed_extended_instruction);
2098+
break;
2099+
}
20902100
case SPIRV::OpBitwiseFunctionINTEL: {
20912101
if (!ST.canUseExtension(
20922102
SPIRV::Extension::SPV_INTEL_ternary_bitwise_function))

llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td

Lines changed: 1 addition & 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_KHR_relaxed_extended_instruction : ExtensionOperand<131, [EnvVulkan, EnvOpenCL]>;
393394

394395
//===----------------------------------------------------------------------===//
395396
// Multiclass used to define Capabilities enum values and at the same time

llvm/test/CodeGen/SPIRV/debug-info/debug-function.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
; CHECK-MIR-DAG: [[type_void:%[0-9]+:type]] = OpTypeVoid
77
; CHECK-MIR-DAG: [[source:%[0-9]+:.*]] = OpExtInst [[type_void]], 3, 35, {{%[0-9]+:.*}}
88
; CHECK-MIR-DAG: [[compile_unit:%[0-9]+:.*]] = OpExtInst [[type_void]], 3, 1
9-
; CHECK-MIR-DAG: [[type_func:%[0-9]+:.*]] = OpExtInst [[type_void]], 3, 8, {{%[0-9]+:.*}}, [[type_void]]
9+
; CHECK-MIR-DAG: [[type_func:%[0-9]+:.*]] = OpExtInst [[type_void]], 3, 8
1010
; CHECK-MIR-DAG: [[func1:%[0-9]+:.*]] = OpExtInst [[type_void]], 3, 20, {{%[0-9]+:.*}}, [[type_func]], [[source]], {{%[0-9]+:.*}}, {{%[0-9]+:.*}}, [[compile_unit]]
1111
; CHECK-MIR-DAG: [[func2:%[0-9]+:.*]] = OpExtInst [[type_void]], 3, 20, {{%[0-9]+:.*}}, [[type_func]], [[source]], {{%[0-9]+:.*}}, {{%[0-9]+:.*}}, [[compile_unit]]
1212

@@ -18,7 +18,7 @@
1818
; CHECK-SPIRV: %[[#zero:]] = OpConstant %[[#Ty32]] 0
1919
; CHECK-SPIRV: %[[#debug_source:]] = OpExtInst %[[#void]] %[[#ext_inst_non_semantic]] DebugSource
2020
; CHECK-SPIRV: %[[#debug_compilation:]] = OpExtInst %[[#void]] %[[#ext_inst_non_semantic]] DebugCompilationUnit
21-
; CHECK-SPIRV: %[[#typefunc:]] = OpExtInst %[[#void]] %[[#ext_inst_non_semantic]] DebugTypeFunction %[[#zero]] %[[#void]]
21+
; CHECK-SPIRV: %[[#typefunc:]] = OpExtInst %[[#void]] %[[#ext_inst_non_semantic]] DebugTypeFunction %[[#zero]]
2222
; CHECK-SPIRV: %[[#func1:]] = OpExtInst %[[#void]] %[[#ext_inst_non_semantic]] DebugFunction %[[#test1]] %[[#typefunc]] %[[#debug_source]] %[[#]] %[[#]] %[[#debug_compilation]]
2323
; CHECK-SPIRV: %[[#func2:]] = OpExtInst %[[#void]] %[[#ext_inst_non_semantic]] DebugFunction %[[#test2]] %[[#typefunc]] %[[#debug_source]] %[[#]] %[[#]] %[[#debug_compilation]]
2424

0 commit comments

Comments
 (0)