Skip to content

Commit ab28a10

Browse files
authored
Remove llvm::InitializeAll* calls (#468) (#571)
opencl-clang only uses clang libraries to generate frontend IR and explicitly disables llvm optimizations. In addition, opencl-clang doesn't parse/print assembly. Therefore, there is no need to initialize llvm target machines, target MCs, asm printers and asm parsers This PR removes opencl-clang's dependency on some llvm libraries. (cherry picked from commit 44edebc) jira: CMPLRLLVM-69301
1 parent 7eef465 commit ab28a10

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

common_clang.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ Copyright (c) Intel Corporation (2009-2017).
3737
#include "llvm/Support/Casting.h"
3838
#include "llvm/Support/Path.h"
3939
#include "llvm/Support/Threading.h"
40-
#include "llvm/Support/TargetSelect.h"
4140
#include "llvm/Support/ManagedStatic.h"
4241
#include "llvm/Support/Mutex.h"
4342
#include "llvm/Support/VirtualFileSystem.h"
@@ -81,10 +80,6 @@ Copyright (c) Intel Corporation (2009-2017).
8180

8281
using namespace Intel::OpenCL::ClangFE;
8382

84-
static volatile bool lazyCCInit =
85-
true; // the flag must be 'volatile' to prevent caching in a CPU register
86-
static llvm::sys::Mutex lazyCCInitMutex;
87-
8883
llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;
8984

9085
void CommonClangTerminate() { llvm::llvm_shutdown(); }
@@ -93,23 +88,13 @@ void CommonClangTerminate() { llvm::llvm_shutdown(); }
9388
// from a DllMain function (Windows specific), or from a function
9489
// w\ __attribute__ ((constructor)) (Linux specific).
9590
void CommonClangInitialize() {
96-
if (lazyCCInit) {
97-
llvm::sys::ScopedLock lock(lazyCCInitMutex);
98-
99-
if (lazyCCInit) {
100-
// CommonClangTerminate calls llvm_shutdown to deallocate resources used
101-
// by LLVM libraries. llvm_shutdown uses static mutex to make it safe for
102-
// multi-threaded envirounment and LLVM libraries user is expected call
103-
// llvm_shutdown before static object are destroyed, so we use atexit to
104-
// satisfy this requirement.
105-
atexit(CommonClangTerminate);
106-
llvm::InitializeAllTargets();
107-
llvm::InitializeAllAsmPrinters();
108-
llvm::InitializeAllAsmParsers();
109-
llvm::InitializeAllTargetMCs();
110-
lazyCCInit = false;
111-
}
112-
}
91+
// CommonClangTerminate calls llvm_shutdown to deallocate resources used
92+
// by LLVM libraries. llvm_shutdown uses static mutex to make it safe for
93+
// multi-threaded envirounment and LLVM libraries user is expected call
94+
// llvm_shutdown before static object are destroyed, so we use atexit to
95+
// satisfy this requirement.
96+
llvm::once_flag OnceFlag;
97+
llvm::call_once(OnceFlag, []() { atexit(CommonClangTerminate); });
11398
}
11499

115100
static bool GetHeaders(std::vector<Resource> &Result) {

0 commit comments

Comments
 (0)