Skip to content

Remove llvm::InitializeAll* calls (#468) #572

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

Open
wants to merge 1 commit into
base: ocl-open-160
Choose a base branch
from
Open
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
29 changes: 7 additions & 22 deletions opencl_clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Copyright (c) Intel Corporation (2009-2017).
#include "llvm/Support/Casting.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Threading.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Mutex.h"
#include "clang/Basic/LangOptions.h"
Expand Down Expand Up @@ -77,10 +76,6 @@ Copyright (c) Intel Corporation (2009-2017).

using namespace Intel::OpenCL::ClangFE;

static volatile bool lazyCCInit =
true; // the flag must be 'volatile' to prevent caching in a CPU register
static llvm::sys::Mutex lazyCCInitMutex;

llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;

void CommonClangTerminate() { llvm::llvm_shutdown(); }
Expand All @@ -89,23 +84,13 @@ void CommonClangTerminate() { llvm::llvm_shutdown(); }
// from a DllMain function (Windows specific), or from a function
// w\ __attribute__ ((constructor)) (Linux specific).
void CommonClangInitialize() {
if (lazyCCInit) {
llvm::sys::ScopedLock lock(lazyCCInitMutex);

if (lazyCCInit) {
// CommonClangTerminate calls llvm_shutdown to deallocate resources used
// by LLVM libraries. llvm_shutdown uses static mutex to make it safe for
// multi-threaded envirounment and LLVM libraries user is expected call
// llvm_shutdown before static object are destroyed, so we use atexit to
// satisfy this requirement.
atexit(CommonClangTerminate);
llvm::InitializeAllTargets();
llvm::InitializeAllAsmPrinters();
llvm::InitializeAllAsmParsers();
llvm::InitializeAllTargetMCs();
lazyCCInit = false;
}
}
// CommonClangTerminate calls llvm_shutdown to deallocate resources used
// by LLVM libraries. llvm_shutdown uses static mutex to make it safe for
// multi-threaded envirounment and LLVM libraries user is expected call
// llvm_shutdown before static object are destroyed, so we use atexit to
// satisfy this requirement.
llvm::once_flag OnceFlag;
llvm::call_once(OnceFlag, []() { atexit(CommonClangTerminate); });
}

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