Skip to content

Commit 44edebc

Browse files
authored
Remove llvm::InitializeAll* calls (#468)
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.
1 parent 53843ee commit 44edebc

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

opencl_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 "clang/Basic/LangOptions.h"
@@ -77,10 +76,6 @@ Copyright (c) Intel Corporation (2009-2017).
7776

7877
using namespace Intel::OpenCL::ClangFE;
7978

80-
static volatile bool lazyCCInit =
81-
true; // the flag must be 'volatile' to prevent caching in a CPU register
82-
static llvm::sys::Mutex lazyCCInitMutex;
83-
8479
llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;
8580

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

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

0 commit comments

Comments
 (0)