From d04a8d4b33ff316ca4cf961e06c9e312eff8e64f Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 3 Dec 2012 16:50:05 +0000 Subject: Use the new script to sort the includes of every file under lib. Sooooo many of these had incorrect or strange main module includes. I have manually inspected all of these, and fixed the main module include to be the nearest plausible thing I could find. If you own or care about any of these source files, I encourage you to take some time and check that these edits were sensible. I can't have broken anything (I strictly added headers, and reordered them, never removed), but they may not be the headers you'd really like to identify as containing the API being implemented. Many forward declarations and missing includes were added to a header files to allow them to parse cleanly when included first. The main module rule does in fact have its merits. =] git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169131 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/MachineModuleInfo.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'lib/CodeGen/MachineModuleInfo.cpp') diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index 005bf783e3..ddfd11b8e5 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/lib/CodeGen/MachineModuleInfo.cpp @@ -8,18 +8,17 @@ //===----------------------------------------------------------------------===// #include "llvm/CodeGen/MachineModuleInfo.h" - -#include "llvm/Constants.h" -#include "llvm/DerivedTypes.h" -#include "llvm/GlobalVariable.h" -#include "llvm/Module.h" +#include "llvm/ADT/PointerUnion.h" #include "llvm/Analysis/ValueTracking.h" -#include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineFunction.h" +#include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/Passes.h" +#include "llvm/Constants.h" +#include "llvm/DerivedTypes.h" +#include "llvm/GlobalVariable.h" #include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCSymbol.h" -#include "llvm/ADT/PointerUnion.h" +#include "llvm/Module.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/ErrorHandling.h" using namespace llvm; -- cgit v1.2.3-70-g09d2 From 49eb628c21b358380b76df82aa3dfe0baab4c6ec Mon Sep 17 00:00:00 2001 From: Pedro Artigas Date: Mon, 3 Dec 2012 21:56:57 +0000 Subject: moves doInitialization and doFinalization to the Pass class and removes some unreachable code in MachineModuleInfo reviewed by Evan Cheng git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169164 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/LoopPass.h | 3 +++ include/llvm/Analysis/RegionPass.h | 3 +++ include/llvm/CallGraphSCCPass.h | 3 +++ include/llvm/CodeGen/MachineModuleInfo.h | 6 ----- include/llvm/Pass.h | 41 ++++++++++---------------------- lib/CodeGen/MachineModuleInfo.cpp | 15 ------------ lib/VMCore/Pass.cpp | 20 ---------------- lib/VMCore/PassManager.cpp | 6 +++++ 8 files changed, 27 insertions(+), 70 deletions(-) (limited to 'lib/CodeGen/MachineModuleInfo.cpp') diff --git a/include/llvm/Analysis/LoopPass.h b/include/llvm/Analysis/LoopPass.h index c9770a7e45..4c16daffc0 100644 --- a/include/llvm/Analysis/LoopPass.h +++ b/include/llvm/Analysis/LoopPass.h @@ -39,6 +39,9 @@ public: // whatever action is necessary for the specified Loop. virtual bool runOnLoop(Loop *L, LPPassManager &LPM) = 0; + using llvm::Pass::doInitialization; + using llvm::Pass::doFinalization; + // Initialization and finalization hooks. virtual bool doInitialization(Loop *L, LPPassManager &LPM) { return false; diff --git a/include/llvm/Analysis/RegionPass.h b/include/llvm/Analysis/RegionPass.h index 6ed12e5db5..7d450887f0 100644 --- a/include/llvm/Analysis/RegionPass.h +++ b/include/llvm/Analysis/RegionPass.h @@ -57,6 +57,9 @@ public: /// @return The pass to print the LLVM IR in the region. Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const; + using llvm::Pass::doInitialization; + using llvm::Pass::doFinalization; + virtual bool doInitialization(Region *R, RGPassManager &RGM) { return false; } virtual bool doFinalization() { return false; } //@} diff --git a/include/llvm/CallGraphSCCPass.h b/include/llvm/CallGraphSCCPass.h index 8958ad2fc1..4446777669 100644 --- a/include/llvm/CallGraphSCCPass.h +++ b/include/llvm/CallGraphSCCPass.h @@ -39,6 +39,9 @@ public: /// corresponding to a CallGraph. Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const; + using llvm::Pass::doInitialization; + using llvm::Pass::doFinalization; + /// doInitialization - This method is called before the SCC's of the program /// has been processed, allowing the pass to do initialization as necessary. virtual bool doInitialization(CallGraph &CG) { diff --git a/include/llvm/CodeGen/MachineModuleInfo.h b/include/llvm/CodeGen/MachineModuleInfo.h index 545638e705..2d8c26def8 100644 --- a/include/llvm/CodeGen/MachineModuleInfo.h +++ b/include/llvm/CodeGen/MachineModuleInfo.h @@ -180,12 +180,6 @@ public: const MCObjectFileInfo *MOFI); ~MachineModuleInfo(); - using ModulePass::doInitialization; - bool doInitialization(); - - using ModulePass::doFinalization; - bool doFinalization(); - /// EndFunction - Discard function meta information. /// void EndFunction(); diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h index e92e31b1e9..35ec022516 100644 --- a/include/llvm/Pass.h +++ b/include/llvm/Pass.h @@ -104,6 +104,16 @@ public: return PassID; } + /// doInitialization - Virtual method overridden by subclasses to do + /// any necessary initialization before any pass is run. + /// + virtual bool doInitialization(Module &) { return false; } + + /// doFinalization - Virtual method overriden by subclasses to do any + /// necessary clean up after all passes have run. + /// + virtual bool doFinalization(Module &) { return false; } + /// print - Print out the internal state of the pass. This is called by /// Analyze to print out the contents of an analysis. Otherwise it is not /// necessary to implement this method. Beware that the module pointer MAY be @@ -227,20 +237,10 @@ public: /// createPrinterPass - Get a module printer pass. Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const; - /// doInitialization - Virtual method overridden by subclasses to do - /// any necessary initialization before any pass is run. - /// - virtual bool doInitialization(Module &) { return false; } - /// runOnModule - Virtual method overriden by subclasses to process the module /// being operated on. virtual bool runOnModule(Module &M) = 0; - /// doFinalization - Virtual method overriden by subclasses to do any - /// necessary clean up after all passes have run. - /// - virtual bool doFinalization(Module &) { return false; } - virtual void assignPassManager(PMStack &PMS, PassManagerType T); @@ -297,21 +297,11 @@ public: /// createPrinterPass - Get a function printer pass. Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const; - /// doInitialization - Virtual method overridden by subclasses to do - /// any necessary per-module initialization. - /// - virtual bool doInitialization(Module &); - /// runOnFunction - Virtual method overriden by subclasses to do the /// per-function processing of the pass. /// virtual bool runOnFunction(Function &F) = 0; - /// doFinalization - Virtual method overriden by subclasses to do any post - /// processing needed after all passes have run. - /// - virtual bool doFinalization(Module &); - virtual void assignPassManager(PMStack &PMS, PassManagerType T); @@ -338,10 +328,8 @@ public: /// createPrinterPass - Get a basic block printer pass. Pass *createPrinterPass(raw_ostream &O, const std::string &Banner) const; - /// doInitialization - Virtual method overridden by subclasses to do - /// any necessary per-module initialization. - /// - virtual bool doInitialization(Module &); + using llvm::Pass::doInitialization; + using llvm::Pass::doFinalization; /// doInitialization - Virtual method overridden by BasicBlockPass subclasses /// to do any necessary per-function initialization. @@ -358,11 +346,6 @@ public: /// virtual bool doFinalization(Function &); - /// doFinalization - Virtual method overriden by subclasses to do any post - /// processing needed after all passes have run. - /// - virtual bool doFinalization(Module &); - virtual void assignPassManager(PMStack &PMS, PassManagerType T); diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index ddfd11b8e5..7cd8f61c45 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/lib/CodeGen/MachineModuleInfo.cpp @@ -281,21 +281,6 @@ MachineModuleInfo::~MachineModuleInfo() { AddrLabelSymbols = 0; } -/// doInitialization - Initialize the state for a new module. -/// -bool MachineModuleInfo::doInitialization() { - assert(AddrLabelSymbols == 0 && "Improperly initialized"); - return false; -} - -/// doFinalization - Tear down the state after completion of a module. -/// -bool MachineModuleInfo::doFinalization() { - delete AddrLabelSymbols; - AddrLabelSymbols = 0; - return false; -} - /// EndFunction - Discard function meta information. /// void MachineModuleInfo::EndFunction() { diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp index 9d0ed48842..ec448e6420 100644 --- a/lib/VMCore/Pass.cpp +++ b/lib/VMCore/Pass.cpp @@ -133,16 +133,6 @@ Pass *FunctionPass::createPrinterPass(raw_ostream &O, return createPrintFunctionPass(Banner, &O); } -bool FunctionPass::doInitialization(Module &) { - // By default, don't do anything. - return false; -} - -bool FunctionPass::doFinalization(Module &) { - // By default, don't do anything. - return false; -} - PassManagerType FunctionPass::getPotentialPassManagerType() const { return PMT_FunctionPassManager; } @@ -157,11 +147,6 @@ Pass *BasicBlockPass::createPrinterPass(raw_ostream &O, llvm_unreachable("BasicBlockPass printing unsupported."); } -bool BasicBlockPass::doInitialization(Module &) { - // By default, don't do anything. - return false; -} - bool BasicBlockPass::doInitialization(Function &) { // By default, don't do anything. return false; @@ -172,11 +157,6 @@ bool BasicBlockPass::doFinalization(Function &) { return false; } -bool BasicBlockPass::doFinalization(Module &) { - // By default, don't do anything. - return false; -} - PassManagerType BasicBlockPass::getPotentialPassManagerType() const { return PMT_BasicBlockPassManager; } diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index 069bd356ad..875ab5cad7 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -309,6 +309,9 @@ public: /// whether any of the passes modifies the module, and if so, return true. bool runOnModule(Module &M); + using llvm::Pass::doInitialization; + using llvm::Pass::doFinalization; + /// doInitialization - Run all of the initializers for the module passes. /// bool doInitialization(); @@ -402,6 +405,9 @@ public: /// whether any of the passes modifies the module, and if so, return true. bool run(Module &M); + using llvm::Pass::doInitialization; + using llvm::Pass::doFinalization; + /// doInitialization - Run all of the initializers for the module passes. /// bool doInitialization(); -- cgit v1.2.3-70-g09d2 From d1abec365aa89a8497d9b615ccb4b21c72da9447 Mon Sep 17 00:00:00 2001 From: Pedro Artigas Date: Wed, 5 Dec 2012 17:12:22 +0000 Subject: - Added calls to doInitialization/doFinalization to immutable passes - fixed ordering of calls to doFinalization to be the reverse of the pass run order due to potential dependencies - fixed machine module info to operate in the doInitialization/doFinalization model, also fixes some FIXMEs reviewed by Evan Cheng git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169391 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineModuleInfo.h | 4 ++++ lib/CodeGen/MachineModuleInfo.cpp | 33 +++++++++++++++++++++---------- lib/VMCore/PassManager.cpp | 34 +++++++++++++++++++++++++++----- 3 files changed, 56 insertions(+), 15 deletions(-) (limited to 'lib/CodeGen/MachineModuleInfo.cpp') diff --git a/include/llvm/CodeGen/MachineModuleInfo.h b/include/llvm/CodeGen/MachineModuleInfo.h index 2d8c26def8..cf9e8b61ef 100644 --- a/include/llvm/CodeGen/MachineModuleInfo.h +++ b/include/llvm/CodeGen/MachineModuleInfo.h @@ -180,6 +180,10 @@ public: const MCObjectFileInfo *MOFI); ~MachineModuleInfo(); + // Initialization and Finalization + virtual bool doInitialization(Module &); + virtual bool doFinalization(Module &); + /// EndFunction - Discard function meta information. /// void EndFunction(); diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index 7cd8f61c45..4fbbb05ee6 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/lib/CodeGen/MachineModuleInfo.cpp @@ -253,15 +253,8 @@ void MMIAddrLabelMapCallbackPtr::allUsesReplacedWith(Value *V2) { MachineModuleInfo::MachineModuleInfo(const MCAsmInfo &MAI, const MCRegisterInfo &MRI, const MCObjectFileInfo *MOFI) - : ImmutablePass(ID), Context(MAI, MRI, MOFI), - ObjFileMMI(0), CompactUnwindEncoding(0), CurCallSite(0), CallsEHReturn(0), - CallsUnwindInit(0), DbgInfoAvailable(false), - UsesVAFloatArgument(false) { + : ImmutablePass(ID), Context(MAI, MRI, MOFI) { initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry()); - // Always emit some info, by default "no personality" info. - Personalities.push_back(NULL); - AddrLabelSymbols = 0; - TheModule = 0; } MachineModuleInfo::MachineModuleInfo() @@ -274,11 +267,31 @@ MachineModuleInfo::MachineModuleInfo() MachineModuleInfo::~MachineModuleInfo() { delete ObjFileMMI; +} + +bool MachineModuleInfo::doInitialization(Module &M) { + ObjFileMMI = 0; + CompactUnwindEncoding = 0; + CurCallSite = 0; + CallsEHReturn = 0; + CallsUnwindInit = 0; + DbgInfoAvailable = UsesVAFloatArgument = false; + // Always emit some info, by default "no personality" info. + Personalities.push_back(NULL); + AddrLabelSymbols = 0; + TheModule = 0; + + return false; +} + +bool MachineModuleInfo::doFinalization(Module &M) { + + Personalities.clear(); - // FIXME: Why isn't doFinalization being called?? - //assert(AddrLabelSymbols == 0 && "doFinalization not called"); delete AddrLabelSymbols; AddrLabelSymbols = 0; + + return false; } /// EndFunction - Discard function meta information. diff --git a/lib/VMCore/PassManager.cpp b/lib/VMCore/PassManager.cpp index 875ab5cad7..712b877501 100644 --- a/lib/VMCore/PassManager.cpp +++ b/lib/VMCore/PassManager.cpp @@ -1333,7 +1333,7 @@ bool BBPassManager::doInitialization(Module &M) { bool BBPassManager::doFinalization(Module &M) { bool Changed = false; - for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) + for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index) Changed |= getContainedPass(Index)->doFinalization(M); return Changed; @@ -1423,6 +1423,12 @@ bool FunctionPassManagerImpl::doInitialization(Module &M) { dumpArguments(); dumpPasses(); + SmallVectorImpl& IPV = getImmutablePasses(); + for (SmallVectorImpl::const_iterator I = IPV.begin(), + E = IPV.end(); I != E; ++I) { + Changed |= (*I)->doInitialization(M); + } + for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) Changed |= getContainedManager(Index)->doInitialization(M); @@ -1432,9 +1438,15 @@ bool FunctionPassManagerImpl::doInitialization(Module &M) { bool FunctionPassManagerImpl::doFinalization(Module &M) { bool Changed = false; - for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) + for (int Index = getNumContainedManagers() - 1; Index >= 0; --Index) Changed |= getContainedManager(Index)->doFinalization(M); + SmallVectorImpl& IPV = getImmutablePasses(); + for (SmallVectorImpl::const_iterator I = IPV.begin(), + E = IPV.end(); I != E; ++I) { + Changed |= (*I)->doFinalization(M); + } + return Changed; } @@ -1553,8 +1565,8 @@ bool FPPassManager::doInitialization(Module &M) { bool FPPassManager::doFinalization(Module &M) { bool Changed = false; - - for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) + + for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index) Changed |= getContainedPass(Index)->doFinalization(M); return Changed; @@ -1611,7 +1623,7 @@ MPPassManager::runOnModule(Module &M) { } // Finalize module passes - for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) + for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index) Changed |= getContainedPass(Index)->doFinalization(M); // Finalize on-the-fly passes @@ -1682,9 +1694,21 @@ bool PassManagerImpl::run(Module &M) { dumpArguments(); dumpPasses(); + SmallVectorImpl& IPV = getImmutablePasses(); + for (SmallVectorImpl::const_iterator I = IPV.begin(), + E = IPV.end(); I != E; ++I) { + Changed |= (*I)->doInitialization(M); + } + initializeAllAnalysisInfo(); for (unsigned Index = 0; Index < getNumContainedManagers(); ++Index) Changed |= getContainedManager(Index)->runOnModule(M); + + for (SmallVectorImpl::const_iterator I = IPV.begin(), + E = IPV.end(); I != E; ++I) { + Changed |= (*I)->doFinalization(M); + } + return Changed; } -- cgit v1.2.3-70-g09d2 From 486a7ad94fc948a0f52c32c860cdb2b166741249 Mon Sep 17 00:00:00 2001 From: Pedro Artigas Date: Thu, 6 Dec 2012 00:50:55 +0000 Subject: change MCContext to work on the doInitialization/doFinalization model reviewed by Evan Cheng git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169456 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCContext.h | 11 +++++++++++ lib/CodeGen/MachineModuleInfo.cpp | 5 +++++ lib/MC/MCContext.cpp | 37 +++++++++++++++++++++++++++++++------ 3 files changed, 47 insertions(+), 6 deletions(-) (limited to 'lib/CodeGen/MachineModuleInfo.cpp') diff --git a/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h index 78870d9633..766b90a1b1 100644 --- a/include/llvm/MC/MCContext.h +++ b/include/llvm/MC/MCContext.h @@ -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 /// @{ diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index 4fbbb05ee6..c5fd4a17c2 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/lib/CodeGen/MachineModuleInfo.cpp @@ -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; } diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index dd9d956088..cd95b1161a 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -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; } //===----------------------------------------------------------------------===// -- cgit v1.2.3-70-g09d2 From c7078924f044584d9e9b277862d34d5b43ff2b1e Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Thu, 6 Dec 2012 02:00:13 +0000 Subject: Revert r169456, "change MCContext to work on the doInitialization/doFinalization model" It broke many builders. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169462 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCContext.h | 11 ----------- lib/CodeGen/MachineModuleInfo.cpp | 5 ----- lib/MC/MCContext.cpp | 37 ++++++------------------------------- 3 files changed, 6 insertions(+), 47 deletions(-) (limited to 'lib/CodeGen/MachineModuleInfo.cpp') diff --git a/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h index 766b90a1b1..78870d9633 100644 --- a/include/llvm/MC/MCContext.h +++ b/include/llvm/MC/MCContext.h @@ -154,17 +154,6 @@ 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 /// @{ diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index c5fd4a17c2..4fbbb05ee6 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/lib/CodeGen/MachineModuleInfo.cpp @@ -270,9 +270,6 @@ MachineModuleInfo::~MachineModuleInfo() { } bool MachineModuleInfo::doInitialization(Module &M) { - - Context.doInitialization(); - ObjFileMMI = 0; CompactUnwindEncoding = 0; CurCallSite = 0; @@ -294,8 +291,6 @@ bool MachineModuleInfo::doFinalization(Module &M) { delete AddrLabelSymbols; AddrLabelSymbols = 0; - Context.doFinalization(); - return false; } diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index cd95b1161a..dd9d956088 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -44,48 +44,23 @@ 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; } -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); +MCContext::~MCContext() { + // NOTE: The symbols are all allocated out of a bump pointer allocator, + // we don't need to free them here. // If we have the MachO uniquing map, free it. delete (MachOUniqueMapTy*)MachOUniquingMap; delete (ELFUniqueMapTy*)ELFUniquingMap; delete (COFFUniqueMapTy*)COFFUniquingMap; - MachOUniquingMap = 0; - ELFUniquingMap = 0; - COFFUniquingMap = 0; + + // If the stream for the .secure_log_unique directive was created free it. + delete (raw_ostream*)SecureLog; } //===----------------------------------------------------------------------===// -- cgit v1.2.3-70-g09d2 From 873a1dd7d679ac9a9a92a93a4d2bbb157878efb4 Mon Sep 17 00:00:00 2001 From: Pedro Artigas Date: Thu, 6 Dec 2012 22:12:44 +0000 Subject: fixed valgrind issues of prior commit, this change applies r169456 changes back to the tree with fixes. on darwin no valgrind issues exist in the tests that used to fail. original change description: change MCContext to work on the doInitialization/doFinalization model reviewed by Evan Cheng git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169553 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCContext.h | 18 +++++++++++++- lib/CodeGen/MachineModuleInfo.cpp | 7 +++++- lib/MC/MCContext.cpp | 50 ++++++++++++++++++++++++++++++++------- 3 files changed, 65 insertions(+), 10 deletions(-) (limited to 'lib/CodeGen/MachineModuleInfo.cpp') diff --git a/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h index 78870d9633..111ad484ff 100644 --- a/include/llvm/MC/MCContext.h +++ b/include/llvm/MC/MCContext.h @@ -137,11 +137,16 @@ namespace llvm { void *MachOUniquingMap, *ELFUniquingMap, *COFFUniquingMap; + /// Do automatic initialization in constructor and finalization in + /// destructor + bool AutoInitializationFinalization; + MCSymbol *CreateSymbol(StringRef Name); public: 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); ~MCContext(); const SourceMgr *getSourceManager() const { return SrcMgr; } @@ -154,6 +159,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 /// @{ diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index 4fbbb05ee6..ad88c51118 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/lib/CodeGen/MachineModuleInfo.cpp @@ -253,7 +253,7 @@ void MMIAddrLabelMapCallbackPtr::allUsesReplacedWith(Value *V2) { MachineModuleInfo::MachineModuleInfo(const MCAsmInfo &MAI, const MCRegisterInfo &MRI, const MCObjectFileInfo *MOFI) - : ImmutablePass(ID), Context(MAI, MRI, MOFI) { + : ImmutablePass(ID), Context(MAI, MRI, MOFI, 0, false) { initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry()); } @@ -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; } diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index dd9d956088..23ec0bb12d 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -31,12 +31,14 @@ typedef StringMap COFFUniqueMapTy; MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri, - const MCObjectFileInfo *mofi, const SourceMgr *mgr) : + const MCObjectFileInfo *mofi, const SourceMgr *mgr, + bool DoAutoInitializationFinalization ) : 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) { + AllowTemporaryLabels(true), + AutoInitializationFinalization(DoAutoInitializationFinalization) { MachOUniquingMap = 0; ELFUniquingMap = 0; COFFUniquingMap = 0; @@ -45,22 +47,54 @@ MCContext::MCContext(const MCAsmInfo &mai, const MCRegisterInfo &mri, SecureLog = 0; SecureLogUsed = false; - DwarfLocSeen = false; - GenDwarfForAssembly = false; - GenDwarfFileNumber = 0; + if (AutoInitializationFinalization) + doInitialization(); } MCContext::~MCContext() { + + if (AutoInitializationFinalization) + doFinalization(); + // 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; +} + +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; } //===----------------------------------------------------------------------===// -- cgit v1.2.3-70-g09d2