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



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@170041 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pedro Artigas 2012-12-12 22:59:46 +00:00
parent 5749801caa
commit 5399d2502a
10 changed files with 68 additions and 31 deletions

View File

@ -802,6 +802,10 @@ public:
raw_ostream &OS); raw_ostream &OS);
~MCAssembler(); ~MCAssembler();
/// Reuse an assembler instance
///
void reset();
MCContext &getContext() const { return Context; } MCContext &getContext() const { return Context; }
MCAsmBackend &getBackend() const { return Backend; } MCAsmBackend &getBackend() const { return Backend; }

View File

@ -137,16 +137,15 @@ namespace llvm {
void *MachOUniquingMap, *ELFUniquingMap, *COFFUniquingMap; void *MachOUniquingMap, *ELFUniquingMap, *COFFUniquingMap;
/// Do automatic initialization in constructor and finalization in /// Do automatic reset in destructor
/// destructor bool AutoReset;
bool AutoInitializationFinalization;
MCSymbol *CreateSymbol(StringRef Name); MCSymbol *CreateSymbol(StringRef Name);
public: public:
explicit MCContext(const MCAsmInfo &MAI, const MCRegisterInfo &MRI, explicit MCContext(const MCAsmInfo &MAI, const MCRegisterInfo &MRI,
const MCObjectFileInfo *MOFI, const SourceMgr *Mgr = 0, const MCObjectFileInfo *MOFI, const SourceMgr *Mgr = 0,
bool AutoInitializationFinalization = true); bool DoAutoReset = true);
~MCContext(); ~MCContext();
const SourceMgr *getSourceManager() const { return SrcMgr; } const SourceMgr *getSourceManager() const { return SrcMgr; }
@ -162,11 +161,9 @@ namespace llvm {
/// @name Module Lifetime Management /// @name Module Lifetime Management
/// @{ /// @{
/// doInitialization - prepare to process a new module /// reset - return object to right after construction state to prepare
void doInitialization(); /// to process a new module
void reset();
/// doFinalization - clean up state from the current module
void doFinalization();
/// @} /// @}

View File

@ -45,6 +45,11 @@ protected:
MCAssembler *_Assembler); MCAssembler *_Assembler);
~MCObjectStreamer(); ~MCObjectStreamer();
public:
/// state management
virtual void reset();
protected:
MCSectionData *getCurrentSectionData() const { MCSectionData *getCurrentSectionData() const {
return CurSectionData; return CurSectionData;
} }

View File

@ -92,6 +92,10 @@ namespace llvm {
public: public:
virtual ~MCStreamer(); virtual ~MCStreamer();
/// State management
///
virtual void reset();
MCContext &getContext() const { return Context; } MCContext &getContext() const { return Context; }
unsigned getNumFrameInfos() { unsigned getNumFrameInfos() {

View File

@ -946,6 +946,8 @@ bool AsmPrinter::doFinalization(Module &M) {
MMI = 0; MMI = 0;
OutStreamer.Finish(); OutStreamer.Finish();
OutStreamer.reset();
return false; return false;
} }

View File

@ -270,8 +270,6 @@ MachineModuleInfo::~MachineModuleInfo() {
} }
bool MachineModuleInfo::doInitialization(Module &M) { bool MachineModuleInfo::doInitialization(Module &M) {
Context.doInitialization();
ObjFileMMI = 0; ObjFileMMI = 0;
CompactUnwindEncoding = 0; CompactUnwindEncoding = 0;
@ -294,7 +292,7 @@ bool MachineModuleInfo::doFinalization(Module &M) {
delete AddrLabelSymbols; delete AddrLabelSymbols;
AddrLabelSymbols = 0; AddrLabelSymbols = 0;
Context.doFinalization(); Context.reset();
return false; return false;
} }

View File

@ -221,6 +221,19 @@ MCAssembler::MCAssembler(MCContext &Context_, MCAsmBackend &Backend_,
MCAssembler::~MCAssembler() { 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 { bool MCAssembler::isSymbolLinkerVisible(const MCSymbol &Symbol) const {
// Non-temporary labels should always be visible to the linker. // Non-temporary labels should always be visible to the linker.
if (!Symbol.isTemporary()) if (!Symbol.isTemporary())

View File

@ -32,13 +32,14 @@ typedef StringMap<const MCSectionCOFF*> COFFUniqueMapTy;
MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri, MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri,
const MCObjectFileInfo *mofi, const SourceMgr *mgr, const MCObjectFileInfo *mofi, const SourceMgr *mgr,
bool DoAutoInitializationFinalization ) : bool DoAutoReset ) :
SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi), SrcMgr(mgr), MAI(mai), MRI(mri), MOFI(mofi),
Allocator(), Symbols(Allocator), UsedNames(Allocator), Allocator(), Symbols(Allocator), UsedNames(Allocator),
NextUniqueID(0), NextUniqueID(0),
CurrentDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0), CurrentDwarfLoc(0,0,0,DWARF2_FLAG_IS_STMT,0,0),
AllowTemporaryLabels(true), DwarfLocSeen(false), GenDwarfForAssembly(false), GenDwarfFileNumber(0),
AutoInitializationFinalization(DoAutoInitializationFinalization) { AllowTemporaryLabels(true), AutoReset(DoAutoReset) {
MachOUniquingMap = 0; MachOUniquingMap = 0;
ELFUniquingMap = 0; ELFUniquingMap = 0;
COFFUniquingMap = 0; COFFUniquingMap = 0;
@ -46,15 +47,12 @@ MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri,
SecureLogFile = getenv("AS_SECURE_LOG_FILE"); SecureLogFile = getenv("AS_SECURE_LOG_FILE");
SecureLog = 0; SecureLog = 0;
SecureLogUsed = false; SecureLogUsed = false;
if (AutoInitializationFinalization)
doInitialization();
} }
MCContext::~MCContext() { MCContext::~MCContext() {
if (AutoInitializationFinalization) if (AutoReset)
doFinalization(); reset();
// NOTE: The symbols are all allocated out of a bump pointer allocator, // NOTE: The symbols are all allocated out of a bump pointer allocator,
// we don't need to free them here. // we don't need to free them here.
@ -67,15 +65,7 @@ MCContext::~MCContext() {
// Module Lifetime Management // Module Lifetime Management
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void MCContext::doInitialization() { void MCContext::reset() {
NextUniqueID = 0;
AllowTemporaryLabels = true;
DwarfLocSeen = false;
GenDwarfForAssembly = false;
GenDwarfFileNumber = 0;
}
void MCContext::doFinalization() {
UsedNames.clear(); UsedNames.clear();
Symbols.clear(); Symbols.clear();
Allocator.Reset(); Allocator.Reset();
@ -95,6 +85,12 @@ void MCContext::doFinalization() {
MachOUniquingMap = 0; MachOUniquingMap = 0;
ELFUniquingMap = 0; ELFUniquingMap = 0;
COFFUniquingMap = 0; COFFUniquingMap = 0;
NextUniqueID = 0;
AllowTemporaryLabels = true;
DwarfLocSeen = false;
GenDwarfForAssembly = false;
GenDwarfFileNumber = 0;
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -44,6 +44,11 @@ MCObjectStreamer::~MCObjectStreamer() {
delete Assembler; delete Assembler;
} }
void MCObjectStreamer::reset() {
Assembler->reset();
MCStreamer::reset();
}
MCFragment *MCObjectStreamer::getCurrentFragment() const { MCFragment *MCObjectStreamer::getCurrentFragment() const {
assert(getCurrentSectionData() && "No current section!"); assert(getCurrentSectionData() && "No current section!");

View File

@ -34,6 +34,19 @@ MCStreamer::~MCStreamer() {
delete W64UnwindInfos[i]; 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 MCExpr *MCStreamer::BuildSymbolDiff(MCContext &Context,
const MCSymbol *A, const MCSymbol *A,
const MCSymbol *B) { const MCSymbol *B) {