Skip to content

Commit 18850e2

Browse files
remove the function __spirv_globals_entry in ASMPrinter
1 parent 388e124 commit 18850e2

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

llvm/lib/Target/SPIRV/SPIRVAsmPrinter.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,20 @@ class SPIRVAsmPrinter : public AsmPrinter {
8585
void outputModuleSections();
8686
void outputFPFastMathDefaultInfo();
8787
bool isHidden() {
88-
return MF->getFunction()
89-
.getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME)
90-
.isValid();
88+
const Function &F = MF->getFunction();
89+
if (F.getFnAttribute(SPIRV_BACKEND_SERVICE_FUN_NAME).isValid())
90+
return true;
91+
92+
if (F.getName() == "__spirv_globals_entry")
93+
return true;
94+
95+
return false;
9196
}
9297

9398
void emitInstruction(const MachineInstr *MI) override;
9499
void emitFunctionEntryLabel() override {}
95100
void emitFunctionHeader() override;
96-
void emitFunctionBodyStart() override {}
101+
void emitFunctionBodyStart() override {};
97102
void emitFunctionBodyEnd() override;
98103
void emitBasicBlockStart(const MachineBasicBlock &MBB) override;
99104
void emitBasicBlockEnd(const MachineBasicBlock &MBB) override {}
@@ -110,6 +115,11 @@ class SPIRVAsmPrinter : public AsmPrinter {
110115
};
111116
} // namespace
112117

118+
// Add this helper method to check if function should be deleted
119+
static bool shouldDeleteFunction(const Function &F) {
120+
return F.getName() == "__spirv_globals_entry";
121+
}
122+
113123
void SPIRVAsmPrinter::getAnalysisUsage(AnalysisUsage &AU) const {
114124
AU.addRequired<SPIRVModuleAnalysis>();
115125
AU.addPreserved<SPIRVModuleAnalysis>();
@@ -149,14 +159,15 @@ void SPIRVAsmPrinter::cleanUp(Module &M) {
149159
}
150160

151161
void SPIRVAsmPrinter::emitFunctionHeader() {
162+
const Function &F = MF->getFunction();
152163
if (ModuleSectionsEmitted == false) {
153164
outputModuleSections();
154165
ModuleSectionsEmitted = true;
155166
}
167+
156168
// Get the subtarget from the current MachineFunction.
157169
ST = &MF->getSubtarget<SPIRVSubtarget>();
158170
TII = ST->getInstrInfo();
159-
const Function &F = MF->getFunction();
160171

161172
if (isVerbose() && !isHidden()) {
162173
OutStreamer->getCommentOS()
@@ -174,6 +185,7 @@ void SPIRVAsmPrinter::outputOpFunctionEnd() {
174185
outputMCInst(FunctionEndInst);
175186
}
176187

188+
177189
void SPIRVAsmPrinter::emitFunctionBodyEnd() {
178190
if (!isHidden())
179191
outputOpFunctionEnd();
@@ -278,6 +290,10 @@ void SPIRVAsmPrinter::outputInstruction(const MachineInstr *MI) {
278290
}
279291

280292
void SPIRVAsmPrinter::emitInstruction(const MachineInstr *MI) {
293+
const Function &F = MF->getFunction();
294+
if (F.getName() == "__spirv_globals_entry") {
295+
return;
296+
}
281297
SPIRV_MC::verifyInstructionPredicates(MI->getOpcode(),
282298
getSubtargetInfo().getFeatureBits());
283299

@@ -295,8 +311,14 @@ void SPIRVAsmPrinter::emitInstruction(const MachineInstr *MI) {
295311
}
296312

297313
void SPIRVAsmPrinter::outputModuleSection(SPIRV::ModuleSectionType MSType) {
298-
for (const MachineInstr *MI : MAI->getMSInstrs(MSType))
299-
outputInstruction(MI);
314+
const Function &F = MF->getFunction();
315+
for (const MachineInstr *MI : MAI->getMSInstrs(MSType)) {
316+
if (F.getName() != "__spirv_globals_entry" || ((MI->getOpcode() != SPIRV::OpName)
317+
&& (MI->getOpcode() != SPIRV::OpTypeVoid)
318+
&& (MI->getOpcode() != SPIRV::OpTypeFunction))) {
319+
outputInstruction(MI);
320+
}
321+
}
300322
}
301323

302324
void SPIRVAsmPrinter::outputDebugSourceAndStrings(const Module &M) {

0 commit comments

Comments
 (0)