change MCContext to work on the doInitialization/doFinalization model
authorPedro Artigas <partigas@apple.com>
Thu, 6 Dec 2012 00:50:55 +0000 (00:50 +0000)
committerPedro Artigas <partigas@apple.com>
Thu, 6 Dec 2012 00:50:55 +0000 (00:50 +0000)
reviewed by Evan Cheng <evan.cheng@apple.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169456 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCContext.h
lib/CodeGen/MachineModuleInfo.cpp
lib/MC/MCContext.cpp

index 78870d9633e2660e2cff70beeb75105dfd6abe76..766b90a1b1cb9599e2601f736506b0f8b54d8643 100644 (file)
@@ -154,6 +154,17 @@ namespace llvm {
 
     void setAllowTemporaryLabels(bool Value) { AllowTemporaryLabels = Value; }
 
+    /// @name Module Lifetime Management
+    /// @{
+
+    /// doInitialization - prepare to process a new module
+    void doInitialization();
+
+    /// doFinalization - clean up state from the current module
+    void doFinalization();
+
+    /// @}
+
     /// @name Symbol Management
     /// @{
 
index 4fbbb05ee6b489eab44054f15b1a8baa8ffd4ea7..c5fd4a17c27bc185b4c2874e9adec199132d0e43 100644 (file)
@@ -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;
 }
 
index dd9d956088a44480c7546c08b92f251384b19d2e..cd95b1161a892977acc6a5234b878fd9c48e408c 100644 (file)
@@ -44,23 +44,48 @@ MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri,
   SecureLogFile = getenv("AS_SECURE_LOG_FILE");
   SecureLog = 0;
   SecureLogUsed = false;
+}
+
+MCContext::~MCContext() {
+  // 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;
 }
 
-MCContext::~MCContext() {
-  // NOTE: The symbols are all allocated out of a bump pointer allocator,
-  // we don't need to free them here.
+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;
 }
 
 //===----------------------------------------------------------------------===//