mirror of
https://github.com/RPCS3/llvm.git
synced 2025-01-31 07:43:37 +00:00
Fix more static dtor issues
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@30725 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b336409673
commit
90aa839c88
@ -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 <algorithm>
|
||||
using namespace llvm;
|
||||
|
||||
@ -801,21 +802,23 @@ static const char *OnlyReadsMemoryFns[] = {
|
||||
"feof_unlocked", "ferror_unlocked", "fileno_unlocked"
|
||||
};
|
||||
|
||||
static ManagedStatic<std::vector<const char*> > NoMemoryTable;
|
||||
static ManagedStatic<std::vector<const char*> > OnlyReadsMemoryTable;
|
||||
|
||||
|
||||
AliasAnalysis::ModRefBehavior
|
||||
BasicAliasAnalysis::getModRefBehavior(Function *F, CallSite CS,
|
||||
std::vector<PointerAccessInfo> *Info) {
|
||||
if (!F->isExternal()) return UnknownModRefBehavior;
|
||||
|
||||
static std::vector<const char*> 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<const char*>::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;
|
||||
|
@ -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 <algorithm>
|
||||
#include <functional>
|
||||
@ -61,36 +62,23 @@ static std::string ProgramName = "<premain>";
|
||||
static const char *ProgramOverview = 0;
|
||||
|
||||
// This collects additional help to be printed.
|
||||
static std::vector<const char*> &MoreHelp() {
|
||||
static std::vector<const char*> moreHelp;
|
||||
return moreHelp;
|
||||
}
|
||||
static ManagedStatic<std::vector<const char*> > 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<std::string, Option*> &getOpts() {
|
||||
static std::map<std::string, Option*> CommandLineOptions;
|
||||
return CommandLineOptions;
|
||||
}
|
||||
static ManagedStatic<std::map<std::string, Option*> > Options;
|
||||
static ManagedStatic<std::vector<Option*> > PositionalOptions;
|
||||
|
||||
static Option *getOption(const std::string &Str) {
|
||||
std::map<std::string,Option*>::iterator I = getOpts().find(Str);
|
||||
return I != getOpts().end() ? I->second : 0;
|
||||
}
|
||||
|
||||
static std::vector<Option*> &getPositionalOpts() {
|
||||
static std::vector<Option*> Positional;
|
||||
return Positional;
|
||||
std::map<std::string,Option*>::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<std::string, Option*> &Opts = getOpts();
|
||||
std::map<std::string, Option*> &Opts = *Options;
|
||||
std::map<std::string, Option*>::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<std::string, Option*> &Opts = getOpts();
|
||||
std::vector<Option*> &PositionalOpts = getPositionalOpts();
|
||||
std::map<std::string, Option*> &Opts = *Options;
|
||||
std::vector<Option*> &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<Option*>::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<std::pair<std::string, Option*> > Options;
|
||||
copy(getOpts().begin(), getOpts().end(), std::back_inserter(Options));
|
||||
std::vector<std::pair<std::string, Option*> > 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<Option*> 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<Option*> &PosOpts = getPositionalOpts();
|
||||
// Print out the positional options.
|
||||
std::vector<Option*> &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<const char *>::iterator I = MoreHelp().begin(),
|
||||
E = MoreHelp().end(); I != E; ++I)
|
||||
for (std::vector<const char *>::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)();
|
||||
|
@ -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 <algorithm>
|
||||
#include <fstream>
|
||||
@ -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<std::string> 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<Timer*> ActiveTimers;
|
||||
static ManagedStatic<std::vector<Timer*> > 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<Timer*>::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<Timer*>::iterator I = ActiveTimers.begin(),
|
||||
E = ActiveTimers.end(); I != E; ++I)
|
||||
for (std::vector<Timer*>::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<std::string, Timer> NamedTimers;
|
||||
static ManagedStatic<std::map<std::string, Timer> > NamedTimers;
|
||||
|
||||
std::map<std::string, Timer>::iterator I = NamedTimers.lower_bound(Name);
|
||||
if (I != NamedTimers.end() && I->first == Name)
|
||||
static Timer &getNamedRegionTimer(const std::string &Name) {
|
||||
std::map<std::string, Timer>::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)
|
||||
|
@ -182,11 +182,11 @@ void IntrinsicEmitter::EmitModRefInfo(const std::vector<CodeGenIntrinsic> &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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user