diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp index 167d3b0c02c..fdc452b44f9 100644 --- a/lib/Analysis/BasicAliasAnalysis.cpp +++ b/lib/Analysis/BasicAliasAnalysis.cpp @@ -22,8 +22,9 @@ #include "llvm/Instructions.h" #include "llvm/Pass.h" #include "llvm/Target/TargetData.h" -#include "llvm/Support/GetElementPtrTypeIterator.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/GetElementPtrTypeIterator.h" +#include "llvm/Support/ManagedStatic.h" #include using namespace llvm; @@ -801,21 +802,23 @@ static const char *OnlyReadsMemoryFns[] = { "feof_unlocked", "ferror_unlocked", "fileno_unlocked" }; +static ManagedStatic > NoMemoryTable; +static ManagedStatic > OnlyReadsMemoryTable; + + AliasAnalysis::ModRefBehavior BasicAliasAnalysis::getModRefBehavior(Function *F, CallSite CS, std::vector *Info) { if (!F->isExternal()) return UnknownModRefBehavior; - static std::vector NoMemoryTable, OnlyReadsMemoryTable; - static bool Initialized = false; if (!Initialized) { - NoMemoryTable.insert(NoMemoryTable.end(), - DoesntAccessMemoryFns, - DoesntAccessMemoryFns+ + NoMemoryTable->insert(NoMemoryTable->end(), + DoesntAccessMemoryFns, + DoesntAccessMemoryFns+ sizeof(DoesntAccessMemoryFns)/sizeof(DoesntAccessMemoryFns[0])); - OnlyReadsMemoryTable.insert(OnlyReadsMemoryTable.end(), + OnlyReadsMemoryTable->insert(OnlyReadsMemoryTable->end(), OnlyReadsMemoryFns, OnlyReadsMemoryFns+ sizeof(OnlyReadsMemoryFns)/sizeof(OnlyReadsMemoryFns[0])); @@ -824,22 +827,22 @@ BasicAliasAnalysis::getModRefBehavior(Function *F, CallSite CS, #undef GET_MODREF_BEHAVIOR // Sort the table the first time through. - std::sort(NoMemoryTable.begin(), NoMemoryTable.end(), StringCompare()); - std::sort(OnlyReadsMemoryTable.begin(), OnlyReadsMemoryTable.end(), + std::sort(NoMemoryTable->begin(), NoMemoryTable->end(), StringCompare()); + std::sort(OnlyReadsMemoryTable->begin(), OnlyReadsMemoryTable->end(), StringCompare()); Initialized = true; } std::vector::iterator Ptr = - std::lower_bound(NoMemoryTable.begin(), NoMemoryTable.end(), + std::lower_bound(NoMemoryTable->begin(), NoMemoryTable->end(), F->getName().c_str(), StringCompare()); - if (Ptr != NoMemoryTable.end() && *Ptr == F->getName()) + if (Ptr != NoMemoryTable->end() && *Ptr == F->getName()) return DoesNotAccessMemory; - Ptr = std::lower_bound(OnlyReadsMemoryTable.begin(), - OnlyReadsMemoryTable.end(), + Ptr = std::lower_bound(OnlyReadsMemoryTable->begin(), + OnlyReadsMemoryTable->end(), F->getName().c_str(), StringCompare()); - if (Ptr != OnlyReadsMemoryTable.end() && *Ptr == F->getName()) + if (Ptr != OnlyReadsMemoryTable->end() && *Ptr == F->getName()) return OnlyReadsMemory; return UnknownModRefBehavior; diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp index 57620b50d6c..4a3ccfaa070 100644 --- a/lib/Support/CommandLine.cpp +++ b/lib/Support/CommandLine.cpp @@ -18,6 +18,7 @@ #include "llvm/Config/config.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/ManagedStatic.h" #include "llvm/System/Path.h" #include #include @@ -61,36 +62,23 @@ static std::string ProgramName = ""; static const char *ProgramOverview = 0; // This collects additional help to be printed. -static std::vector &MoreHelp() { - static std::vector moreHelp; - return moreHelp; -} +static ManagedStatic > MoreHelp; -extrahelp::extrahelp(const char* Help) +extrahelp::extrahelp(const char *Help) : morehelp(Help) { - MoreHelp().push_back(Help); + MoreHelp->push_back(Help); } //===----------------------------------------------------------------------===// // Basic, shared command line option processing machinery. // -// Return the global command line option vector. Making it a function scoped -// static ensures that it will be initialized correctly before its first use. -// -static std::map &getOpts() { - static std::map CommandLineOptions; - return CommandLineOptions; -} +static ManagedStatic > Options; +static ManagedStatic > PositionalOptions; static Option *getOption(const std::string &Str) { - std::map::iterator I = getOpts().find(Str); - return I != getOpts().end() ? I->second : 0; -} - -static std::vector &getPositionalOpts() { - static std::vector Positional; - return Positional; + std::map::iterator I = Options->find(Str); + return I != Options->end() ? I->second : 0; } static void AddArgument(const char *ArgName, Option *Opt) { @@ -99,7 +87,7 @@ static void AddArgument(const char *ArgName, Option *Opt) { << ArgName << "' defined more than once!\n"; } else { // Add argument to the argument map! - getOpts()[ArgName] = Opt; + (*Options)[ArgName] = Opt; } } @@ -107,7 +95,7 @@ static void AddArgument(const char *ArgName, Option *Opt) { // options have already been processed and the map has been deleted! // static void RemoveArgument(const char *ArgName, Option *Opt) { - if(getOpts().empty()) return; + if (Options->empty()) return; #ifndef NDEBUG // This disgusting HACK is brought to you courtesy of GCC 3.3.2, which ICE's @@ -115,7 +103,7 @@ static void RemoveArgument(const char *ArgName, Option *Opt) { std::string Tmp = ArgName; assert(getOption(Tmp) == Opt && "Arg not in map!"); #endif - getOpts().erase(ArgName); + Options->erase(ArgName); } static inline bool ProvideOption(Option *Handler, const char *ArgName, @@ -303,7 +291,7 @@ static Option *LookupOption(const char *&Arg, const char *&Value) { if (*Arg == 0) return 0; // Look up the option. - std::map &Opts = getOpts(); + std::map &Opts = *Options; std::map::iterator I = Opts.find(std::string(Arg, ArgEnd)); return (I != Opts.end()) ? I->second : 0; @@ -311,7 +299,7 @@ static Option *LookupOption(const char *&Arg, const char *&Value) { void cl::ParseCommandLineOptions(int &argc, char **argv, const char *Overview) { - assert((!getOpts().empty() || !getPositionalOpts().empty()) && + assert((!Options->empty() || !PositionalOptions->empty()) && "No options specified, or ParseCommandLineOptions called more" " than once!"); sys::Path progname(argv[0]); @@ -319,8 +307,8 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, ProgramOverview = Overview; bool ErrorParsing = false; - std::map &Opts = getOpts(); - std::vector &PositionalOpts = getPositionalOpts(); + std::map &Opts = *Options; + std::vector &PositionalOpts = *PositionalOptions; // Check out the positional arguments to collect information about them. unsigned NumPositionalRequired = 0; @@ -608,9 +596,9 @@ void cl::ParseCommandLineOptions(int &argc, char **argv, // Free all of the memory allocated to the map. Command line options may only // be processed once! - getOpts().clear(); + Opts.clear(); PositionalOpts.clear(); - MoreHelp().clear(); + MoreHelp->clear(); // If we had an error processing our arguments, don't let the program execute if (ErrorParsing) exit(1); @@ -661,12 +649,12 @@ void Option::addArgument(const char *ArgStr) { AddArgument(ArgStr, this); if (getFormattingFlag() == Positional) - getPositionalOpts().push_back(this); + PositionalOptions->push_back(this); else if (getNumOccurrencesFlag() == ConsumeAfter) { - if (!getPositionalOpts().empty() && - getPositionalOpts().front()->getNumOccurrencesFlag() == ConsumeAfter) + if (!PositionalOptions->empty() && + PositionalOptions->front()->getNumOccurrencesFlag() == ConsumeAfter) error("Cannot specify more than one option with cl::ConsumeAfter!"); - getPositionalOpts().insert(getPositionalOpts().begin(), this); + PositionalOptions->insert(PositionalOptions->begin(), this); } } @@ -676,13 +664,13 @@ void Option::removeArgument(const char *ArgStr) { if (getFormattingFlag() == Positional) { std::vector::iterator I = - std::find(getPositionalOpts().begin(), getPositionalOpts().end(), this); - assert(I != getPositionalOpts().end() && "Arg not registered!"); - getPositionalOpts().erase(I); + std::find(PositionalOptions->begin(), PositionalOptions->end(), this); + assert(I != PositionalOptions->end() && "Arg not registered!"); + PositionalOptions->erase(I); } else if (getNumOccurrencesFlag() == ConsumeAfter) { - assert(!getPositionalOpts().empty() && getPositionalOpts()[0] == this && + assert(!PositionalOptions->empty() && (*PositionalOptions)[0] == this && "Arg not registered correctly!"); - getPositionalOpts().erase(getPositionalOpts().begin()); + PositionalOptions->erase(PositionalOptions->begin()); } } @@ -904,22 +892,22 @@ public: if (Value == false) return; // Copy Options into a vector so we can sort them as we like... - std::vector > Options; - copy(getOpts().begin(), getOpts().end(), std::back_inserter(Options)); + std::vector > Opts; + copy(Options->begin(), Options->end(), std::back_inserter(Opts)); // Eliminate Hidden or ReallyHidden arguments, depending on ShowHidden - Options.erase(std::remove_if(Options.begin(), Options.end(), - std::ptr_fun(ShowHidden ? isReallyHidden : isHidden)), - Options.end()); + Opts.erase(std::remove_if(Opts.begin(), Opts.end(), + std::ptr_fun(ShowHidden ? isReallyHidden : isHidden)), + Opts.end()); // Eliminate duplicate entries in table (from enum flags options, f.e.) { // Give OptionSet a scope std::set OptionSet; - for (unsigned i = 0; i != Options.size(); ++i) - if (OptionSet.count(Options[i].second) == 0) - OptionSet.insert(Options[i].second); // Add new entry to set + for (unsigned i = 0; i != Opts.size(); ++i) + if (OptionSet.count(Opts[i].second) == 0) + OptionSet.insert(Opts[i].second); // Add new entry to set else - Options.erase(Options.begin()+i--); // Erase duplicate + Opts.erase(Opts.begin()+i--); // Erase duplicate } if (ProgramOverview) @@ -927,8 +915,8 @@ public: std::cout << "USAGE: " << ProgramName << " [options]"; - // Print out the positional options... - std::vector &PosOpts = getPositionalOpts(); + // Print out the positional options. + std::vector &PosOpts = *PositionalOptions; Option *CAOpt = 0; // The cl::ConsumeAfter option, if it exists... if (!PosOpts.empty() && PosOpts[0]->getNumOccurrencesFlag() == ConsumeAfter) CAOpt = PosOpts[0]; @@ -946,21 +934,21 @@ public: // Compute the maximum argument length... MaxArgLen = 0; - for (unsigned i = 0, e = Options.size(); i != e; ++i) - MaxArgLen = std::max(MaxArgLen, Options[i].second->getOptionWidth()); + for (unsigned i = 0, e = Opts.size(); i != e; ++i) + MaxArgLen = std::max(MaxArgLen, Opts[i].second->getOptionWidth()); std::cout << "OPTIONS:\n"; - for (unsigned i = 0, e = Options.size(); i != e; ++i) - Options[i].second->printOptionInfo(MaxArgLen); + for (unsigned i = 0, e = Opts.size(); i != e; ++i) + Opts[i].second->printOptionInfo(MaxArgLen); // Print any extra help the user has declared. - for (std::vector::iterator I = MoreHelp().begin(), - E = MoreHelp().end(); I != E; ++I) + for (std::vector::iterator I = MoreHelp->begin(), + E = MoreHelp->end(); I != E; ++I) std::cout << *I; - MoreHelp().clear(); + MoreHelp->clear(); // Halt the program since help information was printed - getOpts().clear(); // Don't bother making option dtors remove from map. + Options->clear(); // Don't bother making option dtors remove from map. exit(1); } }; @@ -1001,7 +989,7 @@ public: std::cout << " with assertions"; #endif std::cout << ".\n"; - getOpts().clear(); // Don't bother making option dtors remove from map. + Options->clear(); // Don't bother making option dtors remove from map. exit(1); } else { (*OverrideVersionPrinter)(); diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp index b0012ceb518..0c4f18f6307 100644 --- a/lib/Support/Timer.cpp +++ b/lib/Support/Timer.cpp @@ -13,6 +13,7 @@ #include "llvm/Support/Timer.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/ManagedStatic.h" #include "llvm/System/Process.h" #include #include @@ -32,8 +33,8 @@ namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); } // would get destroyed before the Statistic, causing havoc to ensue. We "fix" // this by creating the string the first time it is needed and never destroying // it. +static ManagedStatic LibSupportInfoOutputFilename; static std::string &getLibSupportInfoOutputFilename() { - static std::string *LibSupportInfoOutputFilename = new std::string(); return *LibSupportInfoOutputFilename; } @@ -127,7 +128,7 @@ static TimeRecord getTimeRecord(bool Start) { return Result; } -static std::vector ActiveTimers; +static ManagedStatic > ActiveTimers; void Timer::startTimer() { Started = true; @@ -137,7 +138,7 @@ void Timer::startTimer() { SystemTime -= TR.SystemTime; MemUsed -= TR.MemUsed; PeakMemBase = TR.MemUsed; - ActiveTimers.push_back(this); + ActiveTimers->push_back(this); } void Timer::stopTimer() { @@ -147,13 +148,13 @@ void Timer::stopTimer() { SystemTime += TR.SystemTime; MemUsed += TR.MemUsed; - if (ActiveTimers.back() == this) { - ActiveTimers.pop_back(); + if (ActiveTimers->back() == this) { + ActiveTimers->pop_back(); } else { std::vector::iterator I = - std::find(ActiveTimers.begin(), ActiveTimers.end(), this); - assert(I != ActiveTimers.end() && "stop but no startTimer?"); - ActiveTimers.erase(I); + std::find(ActiveTimers->begin(), ActiveTimers->end(), this); + assert(I != ActiveTimers->end() && "stop but no startTimer?"); + ActiveTimers->erase(I); } } @@ -172,8 +173,8 @@ void Timer::sum(const Timer &T) { void Timer::addPeakMemoryMeasurement() { size_t MemUsed = getMemUsage(); - for (std::vector::iterator I = ActiveTimers.begin(), - E = ActiveTimers.end(); I != E; ++I) + for (std::vector::iterator I = ActiveTimers->begin(), + E = ActiveTimers->end(); I != E; ++I) (*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase); } @@ -181,14 +182,14 @@ void Timer::addPeakMemoryMeasurement() { // NamedRegionTimer Implementation //===----------------------------------------------------------------------===// -static Timer &getNamedRegionTimer(const std::string &Name) { - static std::map NamedTimers; +static ManagedStatic > NamedTimers; - std::map::iterator I = NamedTimers.lower_bound(Name); - if (I != NamedTimers.end() && I->first == Name) +static Timer &getNamedRegionTimer(const std::string &Name) { + std::map::iterator I = NamedTimers->lower_bound(Name); + if (I != NamedTimers->end() && I->first == Name) return I->second; - return NamedTimers.insert(I, std::make_pair(Name, Timer(Name)))->second; + return NamedTimers->insert(I, std::make_pair(Name, Timer(Name)))->second; } NamedRegionTimer::NamedRegionTimer(const std::string &Name) diff --git a/utils/TableGen/IntrinsicEmitter.cpp b/utils/TableGen/IntrinsicEmitter.cpp index ff15996f0cc..fabb7e77143 100644 --- a/utils/TableGen/IntrinsicEmitter.cpp +++ b/utils/TableGen/IntrinsicEmitter.cpp @@ -182,11 +182,11 @@ void IntrinsicEmitter::EmitModRefInfo(const std::vector &Ints, switch (Ints[i].ModRef) { default: break; case CodeGenIntrinsic::NoMem: - OS << " NoMemoryTable.push_back(\"" << Ints[i].Name << "\");\n"; + OS << " NoMemoryTable->push_back(\"" << Ints[i].Name << "\");\n"; break; case CodeGenIntrinsic::ReadArgMem: case CodeGenIntrinsic::ReadMem: - OS << " OnlyReadsMemoryTable.push_back(\"" << Ints[i].Name << "\");\n"; + OS << " OnlyReadsMemoryTable->push_back(\"" << Ints[i].Name << "\");\n"; break; } }