aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineModuleInfo.cpp
diff options
context:
space:
mode:
authorHendrik Greving <hgreving@google.com>2020-11-11 17:56:14 -0800
committerHendrik Greving <hgreving@google.com>2020-11-30 20:28:13 -0800
commitd4ba5e15f4f2f41f13625cc10e4df74b44620803 (patch)
tree4c97b890ea5529867a1202aa633455cbc1ac6d9b /llvm/lib/CodeGen/MachineModuleInfo.cpp
parent173bb3c2eb094920708ab8f61dae2fe22d331773 (diff)
downloadllvm-d4ba5e15f4f2f41f13625cc10e4df74b44620803.zip
llvm-d4ba5e15f4f2f41f13625cc10e4df74b44620803.tar.gz
llvm-d4ba5e15f4f2f41f13625cc10e4df74b44620803.tar.bz2
Add MachineModuleInfo constructor with external MCContext
Adds a constructor to MachineModuleInfo and MachineModuleInfoWapperPass that takes an external MCContext. If provided, the external context will be used throughout codegen instead of MMI's default one. This enables external drivers to take ownership of data put on the MMI's context during codegen. The internal context is used otherwise and destroyed upon finish. Differential Revision: https://reviews.llvm.org/D91313
Diffstat (limited to 'llvm/lib/CodeGen/MachineModuleInfo.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineModuleInfo.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp
index be08f0a..f75acbb 100644
--- a/llvm/lib/CodeGen/MachineModuleInfo.cpp
+++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp
@@ -170,6 +170,7 @@ void MachineModuleInfo::finalize() {
AddrLabelSymbols = nullptr;
Context.reset();
+ // We don't clear the ExternalContext.
delete ObjFileMMI;
ObjFileMMI = nullptr;
@@ -187,6 +188,7 @@ MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI)
HasSplitStack = MMI.HasSplitStack;
HasNosplitStack = MMI.HasNosplitStack;
AddrLabelSymbols = MMI.AddrLabelSymbols;
+ ExternalContext = MMI.ExternalContext;
TheModule = MMI.TheModule;
}
@@ -196,6 +198,14 @@ MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM)
initialize();
}
+MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM,
+ MCContext *ExtContext)
+ : TM(*TM), Context(TM->getMCAsmInfo(), TM->getMCRegisterInfo(),
+ TM->getObjFileLowering(), nullptr, nullptr, false),
+ ExternalContext(ExtContext) {
+ initialize();
+}
+
MachineModuleInfo::~MachineModuleInfo() { finalize(); }
//===- Address of Block Management ----------------------------------------===//
@@ -204,7 +214,7 @@ ArrayRef<MCSymbol *>
MachineModuleInfo::getAddrLabelSymbolToEmit(const BasicBlock *BB) {
// Lazily create AddrLabelSymbols.
if (!AddrLabelSymbols)
- AddrLabelSymbols = new MMIAddrLabelMap(Context);
+ AddrLabelSymbols = new MMIAddrLabelMap(getContext());
return AddrLabelSymbols->getAddrLabelSymbolToEmit(const_cast<BasicBlock*>(BB));
}
@@ -296,6 +306,12 @@ MachineModuleInfoWrapperPass::MachineModuleInfoWrapperPass(
initializeMachineModuleInfoWrapperPassPass(*PassRegistry::getPassRegistry());
}
+MachineModuleInfoWrapperPass::MachineModuleInfoWrapperPass(
+ const LLVMTargetMachine *TM, MCContext *ExtContext)
+ : ImmutablePass(ID), MMI(TM, ExtContext) {
+ initializeMachineModuleInfoWrapperPassPass(*PassRegistry::getPassRegistry());
+}
+
// Handle the Pass registration stuff necessary to use DataLayout's.
INITIALIZE_PASS(MachineModuleInfoWrapperPass, "machinemoduleinfo",
"Machine Module Information", false, false)