[llvm] 9f374a7 - [NVPTX][AsmPrinter] Avoid removing globals before calling AsmPrinter::doFinalization()
Kristina Bessonova via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 27 04:04:14 PST 2021
Author: Kristina Bessonova
Date: 2021-11-27T14:02:34+02:00
New Revision: 9f374a74c2aabed998a731ac9f14bd8baa4208ba
URL: https://github.com/llvm/llvm-project/commit/9f374a74c2aabed998a731ac9f14bd8baa4208ba
DIFF: https://github.com/llvm/llvm-project/commit/9f374a74c2aabed998a731ac9f14bd8baa4208ba.diff
LOG: [NVPTX][AsmPrinter] Avoid removing globals before calling AsmPrinter::doFinalization()
Instead of removing globals from a module, we, it seems, can just override
AsmPrinter::emitGlobalVariable() to do nothing as NVPTXAsmPrinter already
emitted globals by this time and we don't want to do it twice.
Reviewed By: tra
Differential Revision: https://reviews.llvm.org/D113653
Added:
Modified:
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
index aab6d2034f11..c2ddfd6164f4 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
@@ -887,33 +887,11 @@ bool NVPTXAsmPrinter::doFinalization(Module &M) {
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<NVPTXTargetStreamer *>(OutStreamer->getTargetStreamer())
diff --git a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
index 5d680e731e4a..2a3a38d7b2f1 100644
--- a/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
+++ b/llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
@@ -306,6 +306,11 @@ class LLVM_LIBRARY_VISIBILITY NVPTXAsmPrinter : public AsmPrinter {
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
More information about the llvm-commits
mailing list