Make the MCStreamer have a reset method and call that after finalization of the asm...
authorPedro Artigas <partigas@apple.com>
Wed, 12 Dec 2012 22:59:46 +0000 (22:59 +0000)
committerPedro Artigas <partigas@apple.com>
Wed, 12 Dec 2012 22:59:46 +0000 (22:59 +0000)
also changed MCContext to a single reset only method for simplicity as requested on the list

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

include/llvm/MC/MCAssembler.h
include/llvm/MC/MCContext.h
include/llvm/MC/MCObjectStreamer.h
include/llvm/MC/MCStreamer.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/MachineModuleInfo.cpp
lib/MC/MCAssembler.cpp
lib/MC/MCContext.cpp
lib/MC/MCObjectStreamer.cpp
lib/MC/MCStreamer.cpp

index 0ecb66c734a278004f9b690733ce623c46b8271d..8dba3b9c090a696a54499b44d43c9221e9ac920f 100644 (file)
@@ -802,6 +802,10 @@ public:
               raw_ostream &OS);
   ~MCAssembler();
 
+  /// Reuse an assembler instance
+  ///
+  void reset();
+
   MCContext &getContext() const { return Context; }
 
   MCAsmBackend &getBackend() const { return Backend; }
index 111ad484ffb5cfbf20320fa536a0c7427fc41c7c..ce22325e856f4040d6ecb1518b73b1e60cebf1b7 100644 (file)
@@ -137,16 +137,15 @@ namespace llvm {
 
     void *MachOUniquingMap, *ELFUniquingMap, *COFFUniquingMap;
 
-    /// Do automatic initialization in constructor and finalization in
-    /// destructor
-    bool AutoInitializationFinalization;
+    /// Do automatic reset in destructor
+    bool AutoReset;
 
     MCSymbol *CreateSymbol(StringRef Name);
 
   public:
     explicit MCContext(const MCAsmInfo &MAI, const MCRegisterInfo &MRI,
                        const MCObjectFileInfo *MOFI, const SourceMgr *Mgr = 0,
-                       bool AutoInitializationFinalization = true);
+                       bool DoAutoReset = true);
     ~MCContext();
 
     const SourceMgr *getSourceManager() const { return SrcMgr; }
@@ -162,11 +161,9 @@ namespace llvm {
     /// @name Module Lifetime Management
     /// @{
 
-    /// doInitialization - prepare to process a new module
-    void doInitialization();
-
-    /// doFinalization - clean up state from the current module
-    void doFinalization();
+    /// reset - return object to right after construction state to prepare
+    /// to process a new module
+    void reset();
 
     /// @}
 
index db305626499c07f9bd2dd2494e7265c29a53d081..843304b07fde28a7b4feb7d755b48b51484cea3c 100644 (file)
@@ -45,6 +45,11 @@ protected:
                    MCAssembler *_Assembler);
   ~MCObjectStreamer();
 
+public:
+  /// state management
+  virtual void reset();
+
+protected:
   MCSectionData *getCurrentSectionData() const {
     return CurSectionData;
   }
index c411030e2bcdf72f9afd328fa2ccf4c1feda7900..555bf1f285e08d7de3a946512cc32f2130f1537c 100644 (file)
@@ -92,6 +92,10 @@ namespace llvm {
   public:
     virtual ~MCStreamer();
 
+    /// State management
+    ///
+    virtual void reset();
+
     MCContext &getContext() const { return Context; }
 
     unsigned getNumFrameInfos() {
index 68ed280c551b82d5d83082e1fcede68c8f60da91..475b82557dcd7ce6686113f389ae3c7402923b22 100644 (file)
@@ -946,6 +946,8 @@ bool AsmPrinter::doFinalization(Module &M) {
   MMI = 0;
 
   OutStreamer.Finish();
+  OutStreamer.reset();
+
   return false;
 }
 
index ad88c51118198d0596ad3da809849008c1a08495..26650468c44b37f3238661ecb7ff72b729a44c77 100644 (file)
@@ -270,8 +270,6 @@ MachineModuleInfo::~MachineModuleInfo() {
 }
 
 bool MachineModuleInfo::doInitialization(Module &M) {
-  
-  Context.doInitialization();
 
   ObjFileMMI = 0;
   CompactUnwindEncoding = 0;
@@ -294,7 +292,7 @@ bool MachineModuleInfo::doFinalization(Module &M) {
   delete AddrLabelSymbols;
   AddrLabelSymbols = 0;
 
-  Context.doFinalization();
+  Context.reset();
 
   return false;
 }
index c47299c82a2f961f35947e422c5024d39fbd1a8a..8ca849be17b43424175bd044be0ca9a34c706780 100644 (file)
@@ -221,6 +221,19 @@ MCAssembler::MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
 MCAssembler::~MCAssembler() {
 }
 
+void MCAssembler::reset() {
+  Sections.clear();
+  Symbols.clear();
+  SectionMap.clear();
+  SymbolMap.clear();
+  IndirectSymbols.clear();
+  DataRegions.clear();
+  ThumbFuncs.clear();
+  RelaxAll = false;
+  NoExecStack = false;
+  SubsectionsViaSymbols = false;
+}
+
 bool MCAssembler::isSymbolLinkerVisible(const MCSymbol &Symbol) const {
   // Non-temporary labels should always be visible to the linker.
   if (!Symbol.isTemporary())
index 23ec0bb12d6a75e7c086881eecc4a93e2c415b22..19ff49cd8f789fcfc7657db5d8f08896eed8d2c6 100644 (file)
@@ -32,13 +32,14 @@ typedef StringMap<const MCSectionCOFF*> COFFUniqueMapTy;
 
 MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri,
                      const MCObjectFileInfo *mofi, const SourceMgr *mgr,
-                     bool DoAutoInitializationFinalization ) :
+                     bool DoAutoReset ) :
   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),
-  AutoInitializationFinalization(DoAutoInitializationFinalization) {
+  NextUniqueID(0), 
+  CurrentDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0), 
+  DwarfLocSeen(false), GenDwarfForAssembly(false), GenDwarfFileNumber(0),
+  AllowTemporaryLabels(true), AutoReset(DoAutoReset) {
+
   MachOUniquingMap = 0;
   ELFUniquingMap = 0;
   COFFUniquingMap = 0;
@@ -46,15 +47,12 @@ MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri,
   SecureLogFile = getenv("AS_SECURE_LOG_FILE");
   SecureLog = 0;
   SecureLogUsed = false;
-
-  if (AutoInitializationFinalization)
-    doInitialization();
 }
 
 MCContext::~MCContext() {
 
-  if (AutoInitializationFinalization)
-    doFinalization();
+  if (AutoReset)
+    reset();
 
   // NOTE: The symbols are all allocated out of a bump pointer allocator,
   // we don't need to free them here.
@@ -67,15 +65,7 @@ MCContext::~MCContext() {
 // Module Lifetime Management
 //===----------------------------------------------------------------------===//
 
-void MCContext::doInitialization() {
-  NextUniqueID = 0;
-  AllowTemporaryLabels = true;
-  DwarfLocSeen = false;
-  GenDwarfForAssembly = false;
-  GenDwarfFileNumber = 0;
-}
-
-void MCContext::doFinalization() {
+void MCContext::reset() {
   UsedNames.clear();
   Symbols.clear();
   Allocator.Reset();
@@ -95,6 +85,12 @@ void MCContext::doFinalization() {
   MachOUniquingMap = 0;
   ELFUniquingMap = 0;
   COFFUniquingMap = 0;
+
+  NextUniqueID = 0;
+  AllowTemporaryLabels = true;
+  DwarfLocSeen = false;
+  GenDwarfForAssembly = false;
+  GenDwarfFileNumber = 0;
 }
 
 //===----------------------------------------------------------------------===//
index c2171ffaa5e3e868b9423cf49df0b9d0ff1ac44d..98c8bdac3ab216297d3495ca37fdd5b3975c273a 100644 (file)
@@ -44,6 +44,11 @@ MCObjectStreamer::~MCObjectStreamer() {
   delete Assembler;
 }
 
+void MCObjectStreamer::reset() {
+  Assembler->reset();
+  MCStreamer::reset();
+}
+
 MCFragment *MCObjectStreamer::getCurrentFragment() const {
   assert(getCurrentSectionData() && "No current section!");
 
index 96d6d691d26b88e6db39fccbaa88983fab41da08..047ab636ab7ee1149c094c30358eca5b7a5e3b43 100644 (file)
@@ -34,6 +34,19 @@ MCStreamer::~MCStreamer() {
     delete W64UnwindInfos[i];
 }
 
+void MCStreamer::reset() {
+  for (unsigned i = 0; i < getNumW64UnwindInfos(); ++i)
+    delete W64UnwindInfos[i];
+  EmitEHFrame = true;
+  EmitDebugFrame = false;
+  CurrentW64UnwindInfo = 0;
+  LastSymbol = 0;
+  AutoInitSections = false;
+  const MCSection *section = NULL;
+  SectionStack.clear();
+  SectionStack.push_back(std::make_pair(section, section));  
+}
+
 const MCExpr *MCStreamer::BuildSymbolDiff(MCContext &Context,
                                           const MCSymbol *A,
                                           const MCSymbol *B) {