From 7212ee4534066fa03d361763d5d7195c7a51c521 Mon Sep 17 00:00:00 2001 From: Pedro Artigas Date: Wed, 12 Dec 2012 22:59:46 +0000 Subject: [PATCH] Make the MCStreamer have a reset method and call that after finalization of the asm printer, also changed MCContext to a single reset only method for simplicity as requested on the list llvm-svn: 170041 --- llvm/include/llvm/MC/MCAssembler.h | 4 ++++ llvm/include/llvm/MC/MCContext.h | 15 ++++++------- llvm/include/llvm/MC/MCObjectStreamer.h | 5 +++++ llvm/include/llvm/MC/MCStreamer.h | 4 ++++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 2 ++ llvm/lib/CodeGen/MachineModuleInfo.cpp | 4 +--- llvm/lib/MC/MCAssembler.cpp | 13 ++++++++++++ llvm/lib/MC/MCContext.cpp | 34 +++++++++++++----------------- llvm/lib/MC/MCObjectStreamer.cpp | 5 +++++ llvm/lib/MC/MCStreamer.cpp | 13 ++++++++++++ 10 files changed, 68 insertions(+), 31 deletions(-) diff --git a/llvm/include/llvm/MC/MCAssembler.h b/llvm/include/llvm/MC/MCAssembler.h index 0ecb66c..8dba3b9 100644 --- a/llvm/include/llvm/MC/MCAssembler.h +++ b/llvm/include/llvm/MC/MCAssembler.h @@ -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; } diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h index 111ad48..ce22325 100644 --- a/llvm/include/llvm/MC/MCContext.h +++ b/llvm/include/llvm/MC/MCContext.h @@ -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(); /// @} diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h index db30562..843304b 100644 --- a/llvm/include/llvm/MC/MCObjectStreamer.h +++ b/llvm/include/llvm/MC/MCObjectStreamer.h @@ -45,6 +45,11 @@ protected: MCAssembler *_Assembler); ~MCObjectStreamer(); +public: + /// state management + virtual void reset(); + +protected: MCSectionData *getCurrentSectionData() const { return CurSectionData; } diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h index c411030..555bf1f 100644 --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -92,6 +92,10 @@ namespace llvm { public: virtual ~MCStreamer(); + /// State management + /// + virtual void reset(); + MCContext &getContext() const { return Context; } unsigned getNumFrameInfos() { diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 68ed280..475b825 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -946,6 +946,8 @@ bool AsmPrinter::doFinalization(Module &M) { MMI = 0; OutStreamer.Finish(); + OutStreamer.reset(); + return false; } diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp index ad88c51..2665046 100644 --- a/llvm/lib/CodeGen/MachineModuleInfo.cpp +++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp @@ -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; } diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index c47299c..8ca849b 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -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()) diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index 23ec0bb..19ff49c 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -32,13 +32,14 @@ typedef StringMap 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; } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp index c2171ff..98c8bda 100644 --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -44,6 +44,11 @@ MCObjectStreamer::~MCObjectStreamer() { delete Assembler; } +void MCObjectStreamer::reset() { + Assembler->reset(); + MCStreamer::reset(); +} + MCFragment *MCObjectStreamer::getCurrentFragment() const { assert(getCurrentSectionData() && "No current section!"); diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index 96d6d69..047ab63 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -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) { -- 2.7.4