[llvm] r294143 - Revamp llvm::once_flag to be closer to std::once_flag
Kamil Rytarowski via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 5 13:13:06 PST 2017
Author: kamil
Date: Sun Feb 5 15:13:06 2017
New Revision: 294143
URL: http://llvm.org/viewvc/llvm-project?rev=294143&view=rev
Log:
Revamp llvm::once_flag to be closer to std::once_flag
Summary:
Make this interface reusable similarly to std::call_once and std::once_flag interface.
This makes porting LLDB to NetBSD easier as there was in the original approach a portable way to specify a non-static once_flag. With this change translating std::once_flag to llvm::once_flag is mechanical.
Sponsored by <The NetBSD Foundation>
Reviewers: mehdi_amini, labath, joerg
Reviewed By: mehdi_amini
Subscribers: emaste, clayborg
Differential Revision: https://reviews.llvm.org/D29566
Modified:
llvm/trunk/include/llvm/CodeGen/Passes.h
llvm/trunk/include/llvm/PassSupport.h
llvm/trunk/include/llvm/Support/Threading.h
llvm/trunk/lib/CodeGen/TargetPassConfig.cpp
llvm/trunk/lib/Support/ManagedStatic.cpp
llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp
Modified: llvm/trunk/include/llvm/CodeGen/Passes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/Passes.h?rev=294143&r1=294142&r2=294143&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/Passes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/Passes.h Sun Feb 5 15:13:06 2017
@@ -418,7 +418,7 @@ namespace llvm {
Registry.registerPass(*PI, true); \
return PI; \
} \
- LLVM_DEFINE_ONCE_FLAG(Initialize##passName##PassFlag); \
+ static llvm::once_flag Initialize##passName##PassFlag; \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
llvm::call_once(Initialize##passName##PassFlag, \
initialize##passName##PassOnce, std::ref(Registry)); \
Modified: llvm/trunk/include/llvm/PassSupport.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassSupport.h?rev=294143&r1=294142&r2=294143&view=diff
==============================================================================
--- llvm/trunk/include/llvm/PassSupport.h (original)
+++ llvm/trunk/include/llvm/PassSupport.h Sun Feb 5 15:13:06 2017
@@ -41,7 +41,7 @@ class TargetMachine;
Registry.registerPass(*PI, true); \
return PI; \
} \
- LLVM_DEFINE_ONCE_FLAG(Initialize##passName##PassFlag); \
+ static llvm::once_flag Initialize##passName##PassFlag; \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
llvm::call_once(Initialize##passName##PassFlag, \
initialize##passName##PassOnce, std::ref(Registry)); \
@@ -61,7 +61,7 @@ class TargetMachine;
Registry.registerPass(*PI, true); \
return PI; \
} \
- LLVM_DEFINE_ONCE_FLAG(Initialize##passName##PassFlag); \
+ static llvm::once_flag Initialize##passName##PassFlag; \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
llvm::call_once(Initialize##passName##PassFlag, \
initialize##passName##PassOnce, std::ref(Registry)); \
@@ -152,7 +152,7 @@ struct RegisterAnalysisGroup : public Re
Registry.registerAnalysisGroup(&agName::ID, 0, *AI, false, true); \
return AI; \
} \
- LLVM_DEFINE_ONCE_FLAG(Initialize##agName##AnalysisGroupFlag); \
+ static llvm::once_flag Initialize##agName##AnalysisGroupFlag; \
void llvm::initialize##agName##AnalysisGroup(PassRegistry &Registry) { \
llvm::call_once(Initialize##agName##AnalysisGroupFlag, \
initialize##agName##AnalysisGroupOnce, \
@@ -173,7 +173,7 @@ struct RegisterAnalysisGroup : public Re
true); \
return AI; \
} \
- LLVM_DEFINE_ONCE_FLAG(Initialize##passName##PassFlag); \
+ static llvm::once_flag Initialize##passName##PassFlag; \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
llvm::call_once(Initialize##passName##PassFlag, \
initialize##passName##PassOnce, std::ref(Registry)); \
@@ -194,7 +194,7 @@ struct RegisterAnalysisGroup : public Re
Registry.registerAnalysisGroup(&agName::ID, &passName::ID, *AI, def, true); \
return AI; \
} \
- LLVM_DEFINE_ONCE_FLAG(Initialize##passName##PassFlag); \
+ static llvm::once_flag Initialize##passName##PassFlag; \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
llvm::call_once(Initialize##passName##PassFlag, \
initialize##passName##PassOnce, std::ref(Registry)); \
Modified: llvm/trunk/include/llvm/Support/Threading.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Threading.h?rev=294143&r1=294142&r2=294143&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Threading.h (original)
+++ llvm/trunk/include/llvm/Support/Threading.h Sun Feb 5 15:13:06 2017
@@ -60,19 +60,18 @@ namespace llvm {
typedef std::once_flag once_flag;
- /// This macro is the only way you should define your once flag for LLVM's
- /// call_once.
-#define LLVM_DEFINE_ONCE_FLAG(flag) static once_flag flag
-
#else
enum InitStatus { Uninitialized = 0, Wait = 1, Done = 2 };
- typedef volatile sys::cas_flag once_flag;
- /// This macro is the only way you should define your once flag for LLVM's
- /// call_once.
-#define LLVM_DEFINE_ONCE_FLAG(flag) \
- static ::llvm::once_flag flag = ::llvm::Uninitialized
+ /// \brief The llvm::once_flag structure
+ ///
+ /// This type is modeled after std::once_flag to use with llvm::call_once.
+ /// This structure must be used as an opaque object. It is a struct to force
+ /// autoinitialization and behave like std::once_flag.
+ struct once_flag {
+ volatile sys::cas_flag status = Uninitialized;
+ };
#endif
@@ -82,7 +81,7 @@ namespace llvm {
/// \code
/// void foo() {...};
/// ...
- /// LLVM_DEFINE_ONCE_FLAG(flag);
+ /// static once_flag flag;
/// call_once(flag, foo);
/// \endcode
///
@@ -96,24 +95,24 @@ namespace llvm {
#else
// For other platforms we use a generic (if brittle) version based on our
// atomics.
- sys::cas_flag old_val = sys::CompareAndSwap(&flag, Wait, Uninitialized);
+ sys::cas_flag old_val = sys::CompareAndSwap(&flag.status, Wait, Uninitialized);
if (old_val == Uninitialized) {
std::forward<Function>(F)(std::forward<Args>(ArgList)...);
sys::MemoryFence();
TsanIgnoreWritesBegin();
- TsanHappensBefore(&flag);
- flag = Done;
+ TsanHappensBefore(&flag.status);
+ flag.status = Done;
TsanIgnoreWritesEnd();
} else {
// Wait until any thread doing the call has finished.
- sys::cas_flag tmp = flag;
+ sys::cas_flag tmp = flag.status;
sys::MemoryFence();
while (tmp != Done) {
- tmp = flag;
+ tmp = flag.status;
sys::MemoryFence();
}
}
- TsanHappensAfter(&flag);
+ TsanHappensAfter(&flag.status);
#endif
}
Modified: llvm/trunk/lib/CodeGen/TargetPassConfig.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetPassConfig.cpp?rev=294143&r1=294142&r2=294143&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetPassConfig.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetPassConfig.cpp Sun Feb 5 15:13:06 2017
@@ -733,7 +733,7 @@ MachinePassRegistry RegisterRegAlloc::Re
/// A dummy default pass factory indicates whether the register allocator is
/// overridden on the command line.
-LLVM_DEFINE_ONCE_FLAG(InitializeDefaultRegisterAllocatorFlag);
+static llvm::once_flag InitializeDefaultRegisterAllocatorFlag;
static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
static RegisterRegAlloc
defaultRegAlloc("default",
Modified: llvm/trunk/lib/Support/ManagedStatic.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ManagedStatic.cpp?rev=294143&r1=294142&r2=294143&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ManagedStatic.cpp (original)
+++ llvm/trunk/lib/Support/ManagedStatic.cpp Sun Feb 5 15:13:06 2017
@@ -21,7 +21,7 @@ using namespace llvm;
static const ManagedStaticBase *StaticList = nullptr;
static sys::Mutex *ManagedStaticMutex = nullptr;
-LLVM_DEFINE_ONCE_FLAG(mutex_init_flag);
+static llvm::once_flag mutex_init_flag;
static void initializeMutex() {
ManagedStaticMutex = new sys::Mutex();
Modified: llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp?rev=294143&r1=294142&r2=294143&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86InstrFMA3Info.cpp Sun Feb 5 15:13:06 2017
@@ -23,7 +23,7 @@ using namespace llvm;
/// This flag is used in the method llvm::call_once() used below to make the
/// initialization of the map 'OpcodeToGroup' thread safe.
-LLVM_DEFINE_ONCE_FLAG(InitGroupsOnceFlag);
+static llvm::once_flag InitGroupsOnceFlag;
static ManagedStatic<X86InstrFMA3Info> X86InstrFMA3InfoObj;
X86InstrFMA3Info *X86InstrFMA3Info::getX86InstrFMA3Info() {
More information about the llvm-commits
mailing list