[PATCH] D113653: [NVPTX][AsmPrinter] Avoid removing globals before calling AsmPrinter::doFinalization()
Kristina Bessonova via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 11 00:52:13 PST 2021
krisb created this revision.
krisb added a reviewer: tra.
Herald added subscribers: asavonic, hiraditya, jholewinski.
krisb requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
This patch doesn't affect any existing regression tests,
so I'd want to consider it at least as NFCI.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D113653
Files:
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
Index: llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
+++ llvm/lib/Target/NVPTX/NVPTXAsmPrinter.h
@@ -306,6 +306,9 @@
std::string getVirtualRegisterName(unsigned) const;
const MCSymbol *getFunctionFrameSymbol() const override;
+
+ // Do not allow base AsmPrinter doing something with globals.
+ void emitGlobalVariable(const GlobalVariable *GV) override {}
};
} // end namespace llvm
Index: llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
+++ 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<NVPTXTargetStreamer *>(OutStreamer->getTargetStreamer())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113653.386442.patch
Type: text/x-patch
Size: 1753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211111/f8192cc2/attachment.bin>
More information about the llvm-commits
mailing list