mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
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 llvm-svn: 294143
This commit is contained in:
parent
2883d7625a
commit
aa9de58af3
@ -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)); \
|
||||
|
@ -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 RegisterAGBase {
|
||||
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 RegisterAGBase {
|
||||
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 RegisterAGBase {
|
||||
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)); \
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -733,7 +733,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 llvm::once_flag InitializeDefaultRegisterAllocatorFlag;
|
||||
static FunctionPass *useDefaultRegisterAllocator() { return nullptr; }
|
||||
static RegisterRegAlloc
|
||||
defaultRegAlloc("default",
|
||||
|
@ -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();
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user