@@ -78,6 +78,11 @@ class SPIRVAsmPrinter : public AsmPrinter {
7878 void outputExecutionMode (const Module &M);
7979 void outputAnnotations (const Module &M);
8080 void outputModuleSections ();
81+ bool isHidden () {
82+ return MF->getFunction ()
83+ .getFnAttribute (SPIRV_BACKEND_SERVICE_FUN_NAME)
84+ .isValid ();
85+ }
8186
8287 void emitInstruction (const MachineInstr *MI) override ;
8388 void emitFunctionEntryLabel () override {}
@@ -131,7 +136,7 @@ void SPIRVAsmPrinter::emitFunctionHeader() {
131136 TII = ST->getInstrInfo ();
132137 const Function &F = MF->getFunction ();
133138
134- if (isVerbose ()) {
139+ if (isVerbose () && ! isHidden () ) {
135140 OutStreamer->getCommentOS ()
136141 << " -- Begin function "
137142 << GlobalValue::dropLLVMManglingEscape (F.getName ()) << ' \n ' ;
@@ -149,11 +154,18 @@ void SPIRVAsmPrinter::outputOpFunctionEnd() {
149154
150155// Emit OpFunctionEnd at the end of MF and clear BBNumToRegMap.
151156void SPIRVAsmPrinter::emitFunctionBodyEnd () {
157+ // Do not emit anything if it's an internal service function.
158+ if (isHidden ())
159+ return ;
152160 outputOpFunctionEnd ();
153161 MAI->BBNumToRegMap .clear ();
154162}
155163
156164void SPIRVAsmPrinter::emitOpLabel (const MachineBasicBlock &MBB) {
165+ // Do not emit anything if it's an internal service function.
166+ if (isHidden ())
167+ return ;
168+
157169 MCInst LabelInst;
158170 LabelInst.setOpcode (SPIRV::OpLabel);
159171 LabelInst.addOperand (MCOperand::createReg (MAI->getOrCreateMBBRegister (MBB)));
@@ -162,7 +174,9 @@ void SPIRVAsmPrinter::emitOpLabel(const MachineBasicBlock &MBB) {
162174}
163175
164176void SPIRVAsmPrinter::emitBasicBlockStart (const MachineBasicBlock &MBB) {
165- assert (!MBB.empty () && " MBB is empty!" );
177+ // Do not emit anything if it's an internal service function.
178+ if (MBB.empty ())
179+ return ;
166180
167181 // If it's the first MBB in MF, it has OpFunction and OpFunctionParameter, so
168182 // OpLabel should be output after them.
0 commit comments