Skip to content

Commit 5c611cc

Browse files
do not emit anything if it's an internal service function
1 parent e0c003b commit 5c611cc

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ void SPIRVAsmPrinter::outputOpFunctionEnd() {
149149

150150
// Emit OpFunctionEnd at the end of MF and clear BBNumToRegMap.
151151
void SPIRVAsmPrinter::emitFunctionBodyEnd() {
152+
// Do not emit anything if it's an internal service function.
153+
if (MF->getFunction().getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME).isValid())
154+
return;
155+
152156
outputOpFunctionEnd();
153157
MAI->BBNumToRegMap.clear();
154158
}
@@ -162,7 +166,9 @@ void SPIRVAsmPrinter::emitOpLabel(const MachineBasicBlock &MBB) {
162166
}
163167

164168
void SPIRVAsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
165-
assert(!MBB.empty() && "MBB is empty!");
169+
// Do not emit anything if it's an internal service function.
170+
if (MBB.empty())
171+
return;
166172

167173
// If it's the first MBB in MF, it has OpFunction and OpFunctionParameter, so
168174
// OpLabel should be output after them.
@@ -600,16 +606,6 @@ void SPIRVAsmPrinter::outputModuleSections() {
600606
}
601607

602608
bool SPIRVAsmPrinter::doInitialization(Module &M) {
603-
// Discard the internal service function
604-
for (Function &F : M) {
605-
if (!F.getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME).isValid())
606-
continue;
607-
getAnalysis<MachineModuleInfoWrapperPass>()
608-
.getMMI()
609-
.deleteMachineFunctionFor(F);
610-
break;
611-
}
612-
613609
ModuleSectionsEmitted = false;
614610
// We need to call the parent's one explicitly.
615611
return AsmPrinter::doInitialization(M);

llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ bool SPIRVCallLowering::lowerReturn(MachineIRBuilder &MIRBuilder,
3636
const Value *Val, ArrayRef<Register> VRegs,
3737
FunctionLoweringInfo &FLI,
3838
Register SwiftErrorVReg) const {
39-
// Discard the internal service function
40-
if (FLI.Fn && FLI.Fn->getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME).isValid())
39+
// Ignore if called from the internal service function
40+
if (MIRBuilder.getMF()
41+
.getFunction()
42+
.getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME)
43+
.isValid())
4144
return true;
4245

4346
// Maybe run postponed production of types for function pointers
@@ -497,6 +500,16 @@ void SPIRVCallLowering::produceIndirectPtrTypes(
497500

498501
bool SPIRVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
499502
CallLoweringInfo &Info) const {
503+
// Ignore if called from the internal service function
504+
if (MIRBuilder.getMF()
505+
.getFunction()
506+
.getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME)
507+
.isValid()) {
508+
// insert a no-op
509+
MIRBuilder.buildTrap();
510+
return true;
511+
}
512+
500513
// Currently call returns should have single vregs.
501514
// TODO: handle the case of multiple registers.
502515
if (Info.OrigRet.Regs.size() > 1)

llvm/test/CodeGen/SPIRV/extensions/SPV_INTEL_function_pointers/fp-simple-hierarchy.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - | FileCheck %s
1+
; RUN: llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_function_pointers %s -o - | FileCheck %s
22
; TODO: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
33

44
; CHECK: OpFunction

0 commit comments

Comments
 (0)