Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change CALL_ONCE_INITIALIZATION implementation to use static initialization #4818

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions include/llvm/PassSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,12 @@ namespace llvm {

class TargetMachine;

#define CALL_ONCE_INITIALIZATION(function) \
static volatile sys::cas_flag initialized = 0; \
sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
if (old_val == 0) { \
function(Registry); \
sys::MemoryFence(); \
TsanIgnoreWritesBegin(); \
TsanHappensBefore(&initialized); \
initialized = 2; \
TsanIgnoreWritesEnd(); \
} else { \
sys::cas_flag tmp = initialized; \
sys::MemoryFence(); \
while (tmp != 2) { \
tmp = initialized; \
sys::MemoryFence(); \
} \
} \
TsanHappensAfter(&initialized);
#define CALL_ONCE_INITIALIZATION(function) \
static bool initialized_once = [&] { \
function(Registry); \
return true; \
}(); \
(void) initialized_once;

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis) \
static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
Expand Down