summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2016-07-08 16:39:00 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2016-07-08 16:39:00 +0000
commitd9d02d8259e47dbd6b73385afa882ef9fa7b042c (patch)
treefd81d8becef9fbda0964a64adb4c59687948bf3e
parent44540a3db2575258cc28390f70cddc2f6b145938 (diff)
downloadbcm5719-llvm-d9d02d8259e47dbd6b73385afa882ef9fa7b042c.tar.gz
bcm5719-llvm-d9d02d8259e47dbd6b73385afa882ef9fa7b042c.zip
[CodeGen, TargetPassConfig] Remove a race from createRegAllocPass
The createRegAllocPass reads and writes to a global variable 'Registry' via calls to getDefault and setDefault. Run this under a call_once to avoid races. llvm-svn: 274875
-rw-r--r--llvm/lib/CodeGen/TargetPassConfig.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp
index 332a8b7e323..4bdfb0406cc 100644
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp
+++ b/llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -721,6 +721,7 @@ MachinePassRegistry RegisterRegAlloc::Registry;
/// A dummy default pass factory indicates whether the register allocator is
/// overridden on the command line.
+LLVM_DEFINE_ONCE_FLAG(InitializeDefaultRegisterAllocatorFlag);
static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
static RegisterRegAlloc
defaultRegAlloc("default",
@@ -734,6 +735,15 @@ RegAlloc("regalloc",
cl::init(&useDefaultRegisterAllocator),
cl::desc("Register allocator to use"));
+static void initializeDefaultRegisterAllocatorOnce() {
+ RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
+
+ if (!Ctor) {
+ Ctor = RegAlloc;
+ RegisterRegAlloc::setDefault(RegAlloc);
+ }
+}
+
/// Instantiate the default register allocator pass for this target for either
/// the optimized or unoptimized allocation path. This will be added to the pass
@@ -760,13 +770,11 @@ FunctionPass *TargetPassConfig::createTargetRegisterAllocator(bool Optimized) {
/// FIXME: When MachinePassRegistry register pass IDs instead of function ptrs,
/// this can be folded into addPass.
FunctionPass *TargetPassConfig::createRegAllocPass(bool Optimized) {
- RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
-
// Initialize the global default.
- if (!Ctor) {
- Ctor = RegAlloc;
- RegisterRegAlloc::setDefault(RegAlloc);
- }
+ llvm::call_once(InitializeDefaultRegisterAllocatorFlag,
+ initializeDefaultRegisterAllocatorOnce);
+
+ RegisterRegAlloc::FunctionPassCtor Ctor = RegisterRegAlloc::getDefault();
if (Ctor != useDefaultRegisterAllocator)
return Ctor();
OpenPOWER on IntegriCloud