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 @@ -306,6 +306,11 @@ std::string getVirtualRegisterName(unsigned) const; const MCSymbol *getFunctionFrameSymbol() const override; + + // Make emitGlobalVariable() no-op for NVPTX. + // Global variables have been already emitted by the time the base AsmPrinter + // attempts to do so in doFinalization() (see NVPTXAsmPrinter::emitGlobals()). + void emitGlobalVariable(const GlobalVariable *GV) override {} }; } // end namespace llvm 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 @@ -887,33 +887,11 @@ GlobalsEmitted = true; } - // XXX Temproarily remove global variables so that doFinalization() will not - // emit them again (global variables are emitted at beginning). - - Module::GlobalListType &global_list = M.getGlobalList(); - int i, n = global_list.size(); - GlobalVariable **gv_array = new GlobalVariable *[n]; - - // first, back-up GlobalVariable in gv_array - i = 0; - for (Module::global_iterator I = global_list.begin(), E = global_list.end(); - I != E; ++I) - gv_array[i++] = &*I; - - // second, empty global_list - while (!global_list.empty()) - global_list.remove(global_list.begin()); - // call doFinalization bool ret = AsmPrinter::doFinalization(M); - // now we restore global variables - for (i = 0; i < n; i++) - global_list.insert(global_list.end(), gv_array[i]); - clearAnnotationCache(&M); - delete[] gv_array; // Close the last emitted section if (HasDebugInfo) { static_cast(OutStreamer->getTargetStreamer())