summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/MachineModuleInfo.cpp7
-rw-r--r--lib/MC/MCContext.cpp50
2 files changed, 48 insertions, 9 deletions
diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp
index 4fbbb05ee6..ad88c51118 100644
--- a/lib/CodeGen/MachineModuleInfo.cpp
+++ b/lib/CodeGen/MachineModuleInfo.cpp
@@ -253,7 +253,7 @@ void MMIAddrLabelMapCallbackPtr::allUsesReplacedWith(Value *V2) {
MachineModuleInfo::MachineModuleInfo(const MCAsmInfo &MAI,
const MCRegisterInfo &MRI,
const MCObjectFileInfo *MOFI)
- : ImmutablePass(ID), Context(MAI, MRI, MOFI) {
+ : ImmutablePass(ID), Context(MAI, MRI, MOFI, 0, false) {
initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry());
}
@@ -270,6 +270,9 @@ MachineModuleInfo::~MachineModuleInfo() {
}
bool MachineModuleInfo::doInitialization(Module &M) {
+
+ Context.doInitialization();
+
ObjFileMMI = 0;
CompactUnwindEncoding = 0;
CurCallSite = 0;
@@ -291,6 +294,8 @@ bool MachineModuleInfo::doFinalization(Module &M) {
delete AddrLabelSymbols;
AddrLabelSymbols = 0;
+ Context.doFinalization();
+
return false;
}
diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp
index dd9d956088..23ec0bb12d 100644
--- a/lib/MC/MCContext.cpp
+++ b/lib/MC/MCContext.cpp
@@ -31,12 +31,14 @@ typedef StringMap<const MCSectionCOFF*> COFFUniqueMapTy;
MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri,
- const MCObjectFileInfo *mofi, const SourceMgr *mgr) :
+ const MCObjectFileInfo *mofi, const SourceMgr *mgr,
+ bool DoAutoInitializationFinalization ) :
SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi),
Allocator(), Symbols(Allocator), UsedNames(Allocator),
NextUniqueID(0),
CurrentDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0),
- AllowTemporaryLabels(true) {
+ AllowTemporaryLabels(true),
+ AutoInitializationFinalization(DoAutoInitializationFinalization) {
MachOUniquingMap = 0;
ELFUniquingMap = 0;
COFFUniquingMap = 0;
@@ -45,22 +47,54 @@ MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri,
SecureLog = 0;
SecureLogUsed = false;
- DwarfLocSeen = false;
- GenDwarfForAssembly = false;
- GenDwarfFileNumber = 0;
+ if (AutoInitializationFinalization)
+ doInitialization();
}
MCContext::~MCContext() {
+
+ if (AutoInitializationFinalization)
+ doFinalization();
+
// NOTE: The symbols are all allocated out of a bump pointer allocator,
// we don't need to free them here.
+
+ // If the stream for the .secure_log_unique directive was created free it.
+ delete (raw_ostream*)SecureLog;
+}
+
+//===----------------------------------------------------------------------===//
+// Module Lifetime Management
+//===----------------------------------------------------------------------===//
+
+void MCContext::doInitialization() {
+ NextUniqueID = 0;
+ AllowTemporaryLabels = true;
+ DwarfLocSeen = false;
+ GenDwarfForAssembly = false;
+ GenDwarfFileNumber = 0;
+}
+
+void MCContext::doFinalization() {
+ UsedNames.clear();
+ Symbols.clear();
+ Allocator.Reset();
+ Instances.clear();
+ MCDwarfFiles.clear();
+ MCDwarfDirs.clear();
+ MCGenDwarfLabelEntries.clear();
+ DwarfDebugFlags = StringRef();
+ MCLineSections.clear();
+ MCLineSectionOrder.clear();
+ CurrentDwarfLoc = MCDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0);
// If we have the MachO uniquing map, free it.
delete (MachOUniqueMapTy*)MachOUniquingMap;
delete (ELFUniqueMapTy*)ELFUniquingMap;
delete (COFFUniqueMapTy*)COFFUniquingMap;
-
- // If the stream for the .secure_log_unique directive was created free it.
- delete (raw_ostream*)SecureLog;
+ MachOUniquingMap = 0;
+ ELFUniquingMap = 0;
+ COFFUniquingMap = 0;
}
//===----------------------------------------------------------------------===//