diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h --- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h +++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h @@ -200,6 +200,7 @@ const Function *F; std::string CurrentFnName; + void emitStartOfAsmFile(Module &M) override; void emitBasicBlockStart(const MachineBasicBlock &MBB) override; void emitFunctionEntryLabel() override; void emitFunctionBodyStart() override; diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp --- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp @@ -762,13 +762,21 @@ return InitList->getNumOperands() == 0; } -bool NVPTXAsmPrinter::doInitialization(Module &M) { +void NVPTXAsmPrinter::emitStartOfAsmFile(Module &M) { // Construct a default subtarget off of the TargetMachine defaults. The // rest of NVPTX isn't friendly to change subtargets per function and // so the default TargetMachine will have all of the options. const NVPTXTargetMachine &NTM = static_cast(TM); const auto* STI = static_cast(NTM.getSubtargetImpl()); + SmallString<128> Str1; + raw_svector_ostream OS1(Str1); + // Emit header before any dwarf directives are emitted below. + emitHeader(M, OS1, *STI); + OutStreamer->emitRawText(OS1.str()); +} + +bool NVPTXAsmPrinter::doInitialization(Module &M) { if (M.alias_size()) { report_fatal_error("Module has aliases, which NVPTX does not support."); return true; // error @@ -784,26 +792,9 @@ return true; // error } - SmallString<128> Str1; - raw_svector_ostream OS1(Str1); - // We need to call the parent's one explicitly. bool Result = AsmPrinter::doInitialization(M); - // Emit header before any dwarf directives are emitted below. - emitHeader(M, OS1, *STI); - OutStreamer->emitRawText(OS1.str()); - - // Emit module-level inline asm if it exists. - if (!M.getModuleInlineAsm().empty()) { - OutStreamer->AddComment("Start of file scope inline assembly"); - OutStreamer->AddBlankLine(); - OutStreamer->emitRawText(StringRef(M.getModuleInlineAsm())); - OutStreamer->AddBlankLine(); - OutStreamer->AddComment("End of file scope inline assembly"); - OutStreamer->AddBlankLine(); - } - GlobalsEmitted = false; return Result;