summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/MC/MCAssembler.h4
-rw-r--r--include/llvm/MC/MCContext.h15
-rw-r--r--include/llvm/MC/MCObjectStreamer.h5
-rw-r--r--include/llvm/MC/MCStreamer.h4
-rw-r--r--lib/CodeGen/AsmPrinter/AsmPrinter.cpp2
-rw-r--r--lib/CodeGen/MachineModuleInfo.cpp4
-rw-r--r--lib/MC/MCAssembler.cpp13
-rw-r--r--lib/MC/MCContext.cpp34
-rw-r--r--lib/MC/MCObjectStreamer.cpp5
-rw-r--r--lib/MC/MCStreamer.cpp13
10 files changed, 68 insertions, 31 deletions
diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h
index 0ecb66c734..8dba3b9c09 100644
--- a/include/llvm/MC/MCAssembler.h
+++ b/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/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h
index 111ad484ff..ce22325e85 100644
--- a/include/llvm/MC/MCContext.h
+++ b/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/include/llvm/MC/MCObjectStreamer.h b/include/llvm/MC/MCObjectStreamer.h
index db30562649..843304b07f 100644
--- a/include/llvm/MC/MCObjectStreamer.h
+++ b/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/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h
index c411030e2b..555bf1f285 100644
--- a/include/llvm/MC/MCStreamer.h
+++ b/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/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 68ed280c55..475b82557d 100644
--- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/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/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp
index ad88c51118..26650468c4 100644
--- a/lib/CodeGen/MachineModuleInfo.cpp
+++ b/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/lib/MC/MCAssembler.cpp b/lib/MC/MCAssembler.cpp
index c47299c82a..8ca849be17 100644
--- a/lib/MC/MCAssembler.cpp
+++ b/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/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp
index 23ec0bb12d..19ff49cd8f 100644
--- a/lib/MC/MCContext.cpp
+++ b/lib/MC/MCContext.cpp
@@ -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;
}
//===----------------------------------------------------------------------===//
diff --git a/lib/MC/MCObjectStreamer.cpp b/lib/MC/MCObjectStreamer.cpp
index c2171ffaa5..98c8bdac3a 100644
--- a/lib/MC/MCObjectStreamer.cpp
+++ b/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/lib/MC/MCStreamer.cpp b/lib/MC/MCStreamer.cpp
index 96d6d691d2..047ab636ab 100644
--- a/lib/MC/MCStreamer.cpp
+++ b/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) {