#define LLVM_IR_OPTBISECT_H
#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/ManagedStatic.h"
#include <limits>
namespace llvm {
/// Singleton instance of the OptBisect class, so multiple pass managers don't
/// need to coordinate their uses of OptBisect.
-extern ManagedStatic<OptBisect> OptBisector;
+OptBisect &getOptBisector();
+
} // end namespace llvm
#endif // LLVM_IR_OPTBISECT_H
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/JSON.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
struct TFInitializer {
TFInitializer() {
- assert(!IsInitialized && "TFInitialized should be called only once");
int Argc = 1;
const char *Name = "";
const char **NamePtr = &Name;
TF_InitMain(Name, &Argc, const_cast<char ***>(&NamePtr));
- IsInitialized = true;
}
- bool IsInitialized = false;
};
-llvm::ManagedStatic<TFInitializer> TFLibInitializer;
-
-bool ensureInitTF() { return TFLibInitializer->IsInitialized; }
+bool ensureInitTF() {
+ static TFInitializer TFLibInitializer;
+ return true;
+}
TFGraphPtr createTFGraph() {
return TFGraphPtr(TF_NewGraph(), &TF_DeleteGraph);
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ErrorOr.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
} // end anonymous namespace
-static ManagedStatic<BitcodeErrorCategoryType> ErrorCategory;
-
const std::error_category &llvm::BitcodeErrorCategory() {
- return *ErrorCategory;
+ static BitcodeErrorCategoryType ErrorCategory;
+ return ErrorCategory;
}
static Expected<StringRef> readBlobInRecord(BitstreamCursor &Stream,
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/MachineValueType.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/raw_ostream.h"
} // end anonymous namespace
-static ManagedStatic<std::set<EVT, EVT::compareRawBits>> EVTs;
-static ManagedStatic<EVTArray> SimpleVTArray;
-static ManagedStatic<sys::SmartMutex<true>> VTMutex;
-
/// getValueTypeList - Return a pointer to the specified value type.
///
const EVT *SDNode::getValueTypeList(EVT VT) {
+ static std::set<EVT, EVT::compareRawBits> EVTs;
+ static EVTArray SimpleVTArray;
+ static sys::SmartMutex<true> VTMutex;
+
if (VT.isExtended()) {
- sys::SmartScopedLock<true> Lock(*VTMutex);
- return &(*EVTs->insert(VT).first);
+ sys::SmartScopedLock<true> Lock(VTMutex);
+ return &(*EVTs.insert(VT).first);
}
assert(VT.getSimpleVT() < MVT::VALUETYPE_SIZE && "Value type out of range!");
- return &SimpleVTArray->VTs[VT.getSimpleVT().SimpleTy];
+ return &SimpleVTArray.VTs[VT.getSimpleVT().SimpleTy];
}
/// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
#include "llvm/DebugInfo/CodeView/CodeViewError.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
#include <string>
using namespace llvm;
};
} // namespace
-static llvm::ManagedStatic<CodeViewErrorCategory> CodeViewErrCategory;
const std::error_category &llvm::codeview::CVErrorCategory() {
- return *CodeViewErrCategory;
+ static CodeViewErrorCategory CodeViewErrCategory;
+ return CodeViewErrCategory;
}
char CodeViewError::ID;
#include "llvm/DebugInfo/MSF/MSFError.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
#include <string>
using namespace llvm;
};
} // namespace
-static llvm::ManagedStatic<MSFErrorCategory> MSFCategory;
-const std::error_category &llvm::msf::MSFErrCategory() { return *MSFCategory; }
+const std::error_category &llvm::msf::MSFErrCategory() {
+ static MSFErrorCategory MSFCategory;
+ return MSFCategory;
+}
char MSFError::ID;
#include "llvm/DebugInfo/PDB/DIA/DIAError.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
using namespace llvm;
using namespace llvm::pdb;
}
};
-static llvm::ManagedStatic<DIAErrorCategory> DIACategory;
-const std::error_category &llvm::pdb::DIAErrCategory() { return *DIACategory; }
+const std::error_category &llvm::pdb::DIAErrCategory() {
+ static DIAErrorCategory DIACategory;
+ return DIACategory;
+}
char DIAError::ID;
#include "llvm/DebugInfo/PDB/GenericError.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
using namespace llvm;
using namespace llvm::pdb;
};
} // namespace
-static llvm::ManagedStatic<PDBErrorCategory> PDBCategory;
-const std::error_category &llvm::pdb::PDBErrCategory() { return *PDBCategory; }
+const std::error_category &llvm::pdb::PDBErrCategory() {
+ static PDBErrorCategory PDBCategory;
+ return PDBCategory;
+}
char PDBError::ID;
#include "llvm/DebugInfo/PDB/Native/RawError.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
using namespace llvm;
using namespace llvm::pdb;
};
} // namespace
-static llvm::ManagedStatic<RawErrorCategory> RawCategory;
-const std::error_category &llvm::pdb::RawErrCategory() { return *RawCategory; }
+const std::error_category &llvm::pdb::RawErrCategory() {
+ static RawErrorCategory RawCategory;
+ return RawCategory;
+}
char RawError::ID;
#include "llvm/Object/ObjectFile.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Mutex.h"
#include <mutex>
/// Lock used to serialize all jit registration events, since they
/// modify global variables.
-ManagedStatic<sys::Mutex> JITDebugLock;
+sys::Mutex &getJITDebugLock() {
+ static sys::Mutex JITDebugLock;
+ return JITDebugLock;
+}
/// Do the registration.
void NotifyDebugger(jit_code_entry* JITCodeEntry) {
GDBJITRegistrationListener::~GDBJITRegistrationListener() {
// Free all registered object files.
- std::lock_guard<llvm::sys::Mutex> locked(*JITDebugLock);
+ std::lock_guard<llvm::sys::Mutex> locked(getJITDebugLock());
for (RegisteredObjectBufferMap::iterator I = ObjectBufferMap.begin(),
E = ObjectBufferMap.end();
I != E; ++I) {
const char *Buffer = DebugObj.getBinary()->getMemoryBufferRef().getBufferStart();
size_t Size = DebugObj.getBinary()->getMemoryBufferRef().getBufferSize();
- std::lock_guard<llvm::sys::Mutex> locked(*JITDebugLock);
+ std::lock_guard<llvm::sys::Mutex> locked(getJITDebugLock());
assert(ObjectBufferMap.find(K) == ObjectBufferMap.end() &&
"Second attempt to perform debug registration.");
jit_code_entry* JITCodeEntry = new jit_code_entry();
}
void GDBJITRegistrationListener::notifyFreeingObject(ObjectKey K) {
- std::lock_guard<llvm::sys::Mutex> locked(*JITDebugLock);
+ std::lock_guard<llvm::sys::Mutex> locked(getJITDebugLock());
RegisteredObjectBufferMap::iterator I = ObjectBufferMap.find(K);
if (I != ObjectBufferMap.end()) {
JITCodeEntry = nullptr;
}
-llvm::ManagedStatic<GDBJITRegistrationListener> GDBRegListener;
-
} // end namespace
namespace llvm {
JITEventListener* JITEventListener::createGDBRegistrationListener() {
- return &*GDBRegListener;
+ static GDBJITRegistrationListener GDBRegListener;
+ return &GDBRegListener;
}
} // namespace llvm
#include "llvm/ExecutionEngine/JITLink/ELF.h"
#include "llvm/ExecutionEngine/JITLink/MachO.h"
#include "llvm/Support/Format.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
}
};
-static ManagedStatic<JITLinkerErrorCategory> JITLinkerErrorCategory;
-
} // namespace
namespace llvm {
void JITLinkError::log(raw_ostream &OS) const { OS << ErrMsg; }
std::error_code JITLinkError::convertToErrorCode() const {
- return std::error_code(GenericJITLinkError, *JITLinkerErrorCategory);
+ static JITLinkerErrorCategory TheJITLinkerErrorCategory;
+ return std::error_code(GenericJITLinkError, TheJITLinkerErrorCategory);
}
const char *getGenericEdgeKindName(Edge::Kind K) {
#include "llvm/ExecutionEngine/Orc/Shared/OrcError.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
#include <type_traits>
}
};
-static ManagedStatic<OrcErrorCategory> OrcErrCat;
+OrcErrorCategory &getOrcErrCat() {
+ static OrcErrorCategory OrcErrCat;
+ return OrcErrCat;
+}
} // namespace
namespace llvm {
std::error_code orcError(OrcErrorCode ErrCode) {
typedef std::underlying_type<OrcErrorCode>::type UT;
- return std::error_code(static_cast<UT>(ErrCode), *OrcErrCat);
+ return std::error_code(static_cast<UT>(ErrCode), getOrcErrCat());
}
DuplicateDefinition::DuplicateDefinition(std::string SymbolName)
std::error_code JITSymbolNotFound::convertToErrorCode() const {
typedef std::underlying_type<OrcErrorCode>::type UT;
return std::error_code(static_cast<UT>(OrcErrorCode::JITSymbolNotFound),
- *OrcErrCat);
+ getOrcErrCat());
}
void JITSymbolNotFound::log(raw_ostream &OS) const {
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/Support/BinaryStreamReader.h"
#include "llvm/Support/FormatVariadic.h"
-#include "llvm/Support/ManagedStatic.h"
#include <cstdint>
#include <mutex>
using namespace llvm;
using namespace llvm::orc;
-// Serialize rendezvous with the debugger as well as access to shared data.
-ManagedStatic<std::mutex> JITDebugLock;
-
// Register debug object, return error message or null for success.
static void registerJITLoaderGDBImpl(const char *ObjAddr, size_t Size) {
LLVM_DEBUG({
E->symfile_size = Size;
E->prev_entry = nullptr;
- std::lock_guard<std::mutex> Lock(*JITDebugLock);
+ // Serialize rendezvous with the debugger as well as access to shared data.
+ static std::mutex JITDebugLock;
+ std::lock_guard<std::mutex> Lock(JITDebugLock);
// Insert this entry at the head of the list.
jit_code_entry *NextEntry = __jit_debug_descriptor.first_entry;
#include "llvm/Support/Debug.h"
#include "llvm/Support/Errno.h"
#include "llvm/Support/FileSystem.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Mutex.h"
#include "llvm/Support/Path.h"
}
}
-// There should be only a single event listener per process, otherwise perf gets
-// confused.
-llvm::ManagedStatic<PerfJITEventListener> PerfListener;
-
} // end anonymous namespace
namespace llvm {
JITEventListener *JITEventListener::createPerfJITEventListener() {
- return &*PerfListener;
+ // There should be only a single event listener per process, otherwise perf
+ // gets confused.
+ static PerfJITEventListener PerfListener;
+ return &PerfListener;
}
} // namespace llvm
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/MSVCErrorWorkarounds.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MathExtras.h"
#include <mutex>
}
};
-static ManagedStatic<RuntimeDyldErrorCategory> RTDyldErrorCategory;
-
}
char RuntimeDyldError::ID = 0;
}
std::error_code RuntimeDyldError::convertToErrorCode() const {
- return std::error_code(GenericRTDyldError, *RTDyldErrorCategory);
+ static RuntimeDyldErrorCategory RTDyldErrorCategory;
+ return std::error_code(GenericRTDyldError, RTDyldErrorCategory);
}
// Empty out-of-line virtual destructor as the key function.
/*===-- Operations on contexts --------------------------------------------===*/
-static ManagedStatic<LLVMContext> GlobalContext;
+static LLVMContext &getGlobalContext() {
+ static LLVMContext GlobalContext;
+ return GlobalContext;
+}
LLVMContextRef LLVMContextCreate() {
return wrap(new LLVMContext());
}
-LLVMContextRef LLVMGetGlobalContext() { return wrap(&*GlobalContext); }
+LLVMContextRef LLVMGetGlobalContext() { return wrap(&getGlobalContext()); }
void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
LLVMDiagnosticHandler Handler,
/*===-- Operations on modules ---------------------------------------------===*/
LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
- return wrap(new Module(ModuleID, *GlobalContext));
+ return wrap(new Module(ModuleID, getGlobalContext()));
}
LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/TypeSize.h"
#include <cassert>
#include <utility>
/// singleton OptBisect if not explicitly set.
OptPassGate &LLVMContextImpl::getOptPassGate() const {
if (!OPG)
- OPG = &(*OptBisector);
+ OPG = &getOptBisector();
return *OPG;
}
static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden,
cl::init(OptBisect::Disabled), cl::Optional,
cl::cb<void, int>([](int Limit) {
- llvm::OptBisector->setLimit(Limit);
+ llvm::getOptBisector().setLimit(Limit);
}),
cl::desc("Maximum optimization to perform"));
const int OptBisect::Disabled;
-ManagedStatic<OptBisect> llvm::OptBisector;
+OptBisect &llvm::getOptBisector() {
+ static OptBisect OptBisector;
+ return OptBisector;
+}
#include "llvm/ADT/STLExtras.h"
#include "llvm/Pass.h"
#include "llvm/PassInfo.h"
-#include "llvm/Support/ManagedStatic.h"
#include <cassert>
#include <memory>
#include <utility>
using namespace llvm;
-// FIXME: We use ManagedStatic to erase the pass registrar on shutdown.
-// Unfortunately, passes are registered with static ctors, and having
-// llvm_shutdown clear this map prevents successful resurrection after
-// llvm_shutdown is run. Ideally we should find a solution so that we don't
-// leak the map, AND can still resurrect after shutdown.
-static ManagedStatic<PassRegistry> PassRegistryObj;
PassRegistry *PassRegistry::getPassRegistry() {
- return &*PassRegistryObj;
+ static PassRegistry PassRegistryObj;
+ return &PassRegistryObj;
}
//===----------------------------------------------------------------------===//
#include "llvm/Object/Error.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
using namespace llvm;
using namespace object;
OS << Msg;
}
-static ManagedStatic<_object_error_category> error_category;
-
const std::error_category &object::object_category() {
- return *error_category;
+ static _object_error_category error_category;
+ return error_category;
}
llvm::Error llvm::object::isNotObjectErrorInvalidFileType(llvm::Error Err) {
void OptBisectInstrumentation::registerCallbacks(
PassInstrumentationCallbacks &PIC) {
- if (!OptBisector->isEnabled())
+ if (!getOptBisector().isEnabled())
return;
PIC.registerShouldRunOptionalPassCallback([](StringRef PassID, Any IR) {
- return isIgnored(PassID) || OptBisector->checkPass(PassID, getIRName(IR));
+ return isIgnored(PassID) ||
+ getOptBisector().checkPass(PassID, getIRName(IR));
});
}
#include "llvm/Support/Errc.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
return getCoverageMapErrString(Err);
}
-static ManagedStatic<CoverageMappingErrorCategoryType> ErrorCategory;
-
const std::error_category &llvm::coverage::coveragemap_category() {
- return *ErrorCategory;
+ static CoverageMappingErrorCategoryType ErrorCategory;
+ return ErrorCategory;
}
char CoverageMapError::ID = 0;
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/LEB128.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/SwapByteOrder.h"
} // end anonymous namespace
-static ManagedStatic<InstrProfErrorCategoryType> ErrorCategory;
-
const std::error_category &llvm::instrprof_category() {
- return *ErrorCategory;
+ static InstrProfErrorCategoryType ErrorCategory;
+ return ErrorCategory;
}
namespace {
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/raw_ostream.h"
#include <string>
#include <system_error>
} // end anonymous namespace
-static ManagedStatic<SampleProfErrorCategoryType> ErrorCategory;
-
const std::error_category &llvm::sampleprof_category() {
- return *ErrorCategory;
+ static SampleProfErrorCategoryType ErrorCategory;
+ return ErrorCategory;
}
void LineLocation::print(raw_ostream &OS) const {
#include "llvm/Support/Error.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
#include <system_error>
using namespace llvm;
}
-static ManagedStatic<ErrorErrorCategory> ErrorErrorCat;
+ErrorErrorCategory &getErrorErrorCat() {
+ static ErrorErrorCategory ErrorErrorCat;
+ return ErrorErrorCat;
+}
namespace llvm {
std::error_code ErrorList::convertToErrorCode() const {
return std::error_code(static_cast<int>(ErrorErrorCode::MultipleErrors),
- *ErrorErrorCat);
+ getErrorErrorCat());
}
std::error_code inconvertibleErrorCode() {
return std::error_code(static_cast<int>(ErrorErrorCode::InconvertibleError),
- *ErrorErrorCat);
+ getErrorErrorCat());
}
std::error_code FileError::convertToErrorCode() const {
std::error_code NestedEC = Err->convertToErrorCode();
if (NestedEC == inconvertibleErrorCode())
return std::error_code(static_cast<int>(ErrorErrorCode::FileError),
- *ErrorErrorCat);
+ getErrorErrorCat());
return NestedEC;
}
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/config.h"
-#include "llvm/Support/ManagedStatic.h"
#include <mutex>
#if HAVE_FCNTL_H
#include <fcntl.h>
extern "C" int tigetnum(char *capname);
#endif
-#ifdef LLVM_ENABLE_TERMINFO
-static ManagedStatic<std::mutex> TermColorMutex;
-#endif
-
bool checkTerminalEnvironmentForColors() {
if (const char *TermStr = std::getenv("TERM")) {
return StringSwitch<bool>(TermStr)
static bool terminalHasColors(int fd) {
#ifdef LLVM_ENABLE_TERMINFO
// First, acquire a global lock because these C routines are thread hostile.
- std::lock_guard<std::mutex> G(*TermColorMutex);
+ static std::mutex TermColorMutex;
+ std::lock_guard<std::mutex> G(TermColorMutex);
struct term *previous_term = set_curterm(nullptr);
int errret = 0;
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Operator.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Mutex.h"
#include <algorithm>
#include <cstring>
namespace {
typedef std::map<std::string, std::vector<unsigned> > key_val_pair_t;
typedef std::map<const GlobalValue *, key_val_pair_t> global_val_annot_t;
-typedef std::map<const Module *, global_val_annot_t> per_module_annot_t;
-} // anonymous namespace
-static ManagedStatic<per_module_annot_t> annotationCache;
-static sys::Mutex Lock;
+struct AnnotationCache {
+ sys::Mutex Lock;
+ std::map<const Module *, global_val_annot_t> Cache;
+};
+
+AnnotationCache &getAnnotationCache() {
+ static AnnotationCache AC;
+ return AC;
+}
+} // anonymous namespace
void clearAnnotationCache(const Module *Mod) {
- std::lock_guard<sys::Mutex> Guard(Lock);
- annotationCache->erase(Mod);
+ auto &AC = getAnnotationCache();
+ std::lock_guard<sys::Mutex> Guard(AC.Lock);
+ AC.Cache.erase(Mod);
}
static void cacheAnnotationFromMD(const MDNode *md, key_val_pair_t &retval) {
- std::lock_guard<sys::Mutex> Guard(Lock);
+ auto &AC = getAnnotationCache();
+ std::lock_guard<sys::Mutex> Guard(AC.Lock);
assert(md && "Invalid mdnode for annotation");
assert((md->getNumOperands() % 2) == 1 && "Invalid number of operands");
// start index = 1, to skip the global variable key
}
static void cacheAnnotationFromMD(const Module *m, const GlobalValue *gv) {
- std::lock_guard<sys::Mutex> Guard(Lock);
+ auto &AC = getAnnotationCache();
+ std::lock_guard<sys::Mutex> Guard(AC.Lock);
NamedMDNode *NMD = m->getNamedMetadata("nvvm.annotations");
if (!NMD)
return;
if (tmp.empty()) // no annotations for this gv
return;
- if ((*annotationCache).find(m) != (*annotationCache).end())
- (*annotationCache)[m][gv] = std::move(tmp);
+ if (AC.Cache.find(m) != AC.Cache.end())
+ AC.Cache[m][gv] = std::move(tmp);
else {
global_val_annot_t tmp1;
tmp1[gv] = std::move(tmp);
- (*annotationCache)[m] = std::move(tmp1);
+ AC.Cache[m] = std::move(tmp1);
}
}
bool findOneNVVMAnnotation(const GlobalValue *gv, const std::string &prop,
unsigned &retval) {
- std::lock_guard<sys::Mutex> Guard(Lock);
+ auto &AC = getAnnotationCache();
+ std::lock_guard<sys::Mutex> Guard(AC.Lock);
const Module *m = gv->getParent();
- if ((*annotationCache).find(m) == (*annotationCache).end())
+ if (AC.Cache.find(m) == AC.Cache.end())
cacheAnnotationFromMD(m, gv);
- else if ((*annotationCache)[m].find(gv) == (*annotationCache)[m].end())
+ else if (AC.Cache[m].find(gv) == AC.Cache[m].end())
cacheAnnotationFromMD(m, gv);
- if ((*annotationCache)[m][gv].find(prop) == (*annotationCache)[m][gv].end())
+ if (AC.Cache[m][gv].find(prop) == AC.Cache[m][gv].end())
return false;
- retval = (*annotationCache)[m][gv][prop][0];
+ retval = AC.Cache[m][gv][prop][0];
return true;
}
bool findAllNVVMAnnotation(const GlobalValue *gv, const std::string &prop,
std::vector<unsigned> &retval) {
- std::lock_guard<sys::Mutex> Guard(Lock);
+ auto &AC = getAnnotationCache();
+ std::lock_guard<sys::Mutex> Guard(AC.Lock);
const Module *m = gv->getParent();
- if ((*annotationCache).find(m) == (*annotationCache).end())
+ if (AC.Cache.find(m) == AC.Cache.end())
cacheAnnotationFromMD(m, gv);
- else if ((*annotationCache)[m].find(gv) == (*annotationCache)[m].end())
+ else if (AC.Cache[m].find(gv) == AC.Cache[m].end())
cacheAnnotationFromMD(m, gv);
- if ((*annotationCache)[m][gv].find(prop) == (*annotationCache)[m][gv].end())
+ if (AC.Cache[m][gv].find(prop) == AC.Cache[m][gv].end())
return false;
- retval = (*annotationCache)[m][gv][prop];
+ retval = AC.Cache[m][gv][prop];
return true;
}
#include "WebAssemblyRuntimeLibcallSignatures.h"
#include "WebAssemblySubtarget.h"
#include "llvm/CodeGen/RuntimeLibcalls.h"
-#include "llvm/Support/ManagedStatic.h"
using namespace llvm;
}
};
-ManagedStatic<RuntimeLibcallSignatureTable> RuntimeLibcallSignatures;
+RuntimeLibcallSignatureTable &getRuntimeLibcallSignatures() {
+ static RuntimeLibcallSignatureTable RuntimeLibcallSignatures;
+ return RuntimeLibcallSignatures;
+}
// Maps libcall names to their RTLIB::Libcall number. Builds the map in a
-// constructor for use with ManagedStatic
+// constructor for use with a static variable
struct StaticLibcallNameMap {
StringMap<RTLIB::Libcall> Map;
StaticLibcallNameMap() {
};
for (const auto &NameLibcall : NameLibcalls) {
if (NameLibcall.first != nullptr &&
- RuntimeLibcallSignatures->Table[NameLibcall.second] != unsupported) {
+ getRuntimeLibcallSignatures().Table[NameLibcall.second] !=
+ unsupported) {
assert(Map.find(NameLibcall.first) == Map.end() &&
"duplicate libcall names in name map");
Map[NameLibcall.first] = NameLibcall.second;
wasm::ValType PtrTy =
Subtarget.hasAddr64() ? wasm::ValType::I64 : wasm::ValType::I32;
- auto &Table = RuntimeLibcallSignatures->Table;
+ auto &Table = getRuntimeLibcallSignatures().Table;
switch (Table[LC]) {
case func:
break;
}
}
-static ManagedStatic<StaticLibcallNameMap> LibcallNameMap;
// TODO: If the RTLIB::Libcall-taking flavor of GetSignature remains unsed
// other than here, just roll its logic into this version.
void llvm::getLibcallSignature(const WebAssemblySubtarget &Subtarget,
StringRef Name,
SmallVectorImpl<wasm::ValType> &Rets,
SmallVectorImpl<wasm::ValType> &Params) {
- auto &Map = LibcallNameMap->Map;
+ static StaticLibcallNameMap LibcallNameMap;
+ auto &Map = LibcallNameMap.Map;
auto Val = Map.find(Name);
#ifndef NDEBUG
if (Val == Map.end()) {
#include "X86InstrRelaxTables.h"
#include "X86InstrInfo.h"
#include "llvm/ADT/STLExtras.h"
+#include <atomic>
using namespace llvm;
namespace {
// This class stores the short form tables. It is instantiated as a
-// ManagedStatic to lazily init the short form table.
+// function scope static variable to lazily init the short form table.
struct X86ShortFormTable {
// Stores relaxation table entries sorted by relaxed form opcode.
SmallVector<X86InstrRelaxTableEntry, 0> Table;
};
} // namespace
-static ManagedStatic<X86ShortFormTable> ShortTable;
-
const X86InstrRelaxTableEntry *llvm::lookupShortTable(unsigned RelaxOp) {
- auto &Table = ShortTable->Table;
+ static X86ShortFormTable ShortTable;
+ auto &Table = ShortTable.Table;
auto I = llvm::lower_bound(Table, RelaxOp);
if (I != Table.end() && I->KeyOp == RelaxOp)
return &*I;
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/MC/MCInstrDesc.h"
#include "llvm/Pass.h"
+#include <atomic>
#include <cassert>
#include <cstdint>
#include "X86InstrFoldTables.h"
#include "X86InstrInfo.h"
#include "llvm/ADT/STLExtras.h"
+#include <atomic>
#include <vector>
using namespace llvm;
namespace {
// This class stores the memory unfolding tables. It is instantiated as a
-// ManagedStatic to lazily init the unfolding table.
+// function scope static variable to lazily init the unfolding table.
struct X86MemUnfoldTable {
// Stores memory unfolding tables entries sorted by opcode.
std::vector<X86MemoryFoldTableEntry> Table;
};
}
-static ManagedStatic<X86MemUnfoldTable> MemUnfoldTable;
-
const X86MemoryFoldTableEntry *
llvm::lookupUnfoldTable(unsigned MemOp) {
- auto &Table = MemUnfoldTable->Table;
+ static X86MemUnfoldTable MemUnfoldTable;
+ auto &Table = MemUnfoldTable.Table;
auto I = llvm::lower_bound(Table, MemOp);
if (I != Table.end() && I->KeyOp == MemOp)
return &*I;
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/InitLLVM.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetSelect.h"
cl::value_desc("format"), cl::init("yaml"));
namespace {
-static ManagedStatic<std::vector<std::string>> RunPassNames;
+
+std::vector<std::string> &getRunPassNames() {
+ static std::vector<std::string> RunPassNames;
+ return RunPassNames;
+}
struct RunPassOption {
void operator=(const std::string &Val) const {
SmallVector<StringRef, 8> PassNames;
StringRef(Val).split(PassNames, ',', -1, false);
for (auto PassName : PassNames)
- RunPassNames->push_back(std::string(PassName));
+ getRunPassNames().push_back(std::string(PassName));
}
};
}
// Construct a custom pass pipeline that starts after instruction
// selection.
- if (!RunPassNames->empty()) {
+ if (!getRunPassNames().empty()) {
if (!MIR) {
WithColor::warning(errs(), argv[0])
<< "run-pass is for .mir file only.\n";
PM.add(&TPC);
PM.add(MMIWP);
TPC.printAndVerify("");
- for (const std::string &RunPassName : *RunPassNames) {
+ for (const std::string &RunPassName : getRunPassNames()) {
if (addPass(PM, argv0, RunPassName, TPC))
return 1;
}
//===----------------------------------------------------------------------===//
#include "xray-registry.h"
-#include "llvm/Support/ManagedStatic.h"
#include <unordered_map>
namespace llvm {
using HandlerType = std::function<Error()>;
-ManagedStatic<std::unordered_map<cl::SubCommand *, HandlerType>> Commands;
+static std::unordered_map<cl::SubCommand *, HandlerType> &getCommands() {
+ static std::unordered_map<cl::SubCommand *, HandlerType> Commands;
+ return Commands;
+}
CommandRegistration::CommandRegistration(cl::SubCommand *SC,
HandlerType Command) {
- assert(Commands->count(SC) == 0 &&
+ assert(getCommands().count(SC) == 0 &&
"Attempting to overwrite a command handler");
assert(Command && "Attempting to register an empty std::function<Error()>");
- (*Commands)[SC] = Command;
+ getCommands()[SC] = Command;
}
HandlerType dispatch(cl::SubCommand *SC) {
- auto It = Commands->find(SC);
- assert(It != Commands->end() &&
+ auto It = getCommands().find(SC);
+ assert(It != getCommands().end() &&
"Attempting to dispatch on un-registered SubCommand.");
return It->second;
}
#include "llvm/ADT/Twine.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest-spi.h"
#include "gtest/gtest.h"
}
};
-static llvm::ManagedStatic<TestErrorCategory> TestErrCategory;
-const std::error_category &TErrorCategory() { return *TestErrCategory; }
+const std::error_category &TErrorCategory() {
+ static TestErrorCategory TestErrCategory;
+ return TestErrCategory;
+}
char TestDebugError::ID;