Skip to content

Commit

Permalink
revert db7696e and 4a88836 (#427) (#448)
Browse files Browse the repository at this point in the history
llvm-related variable initialization, clang::ExecuteCompilerInvocation
and llvm-spirv aren't thread safe, at least for 90 branch.

(cherry picked from commit 76bc7f9)
  • Loading branch information
wenju-he authored Jun 1, 2023
1 parent 6cf0cbc commit b72f84d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions common_clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static volatile bool lazyCCInit =
true; // the flag must be 'volatile' to prevent caching in a CPU register
static llvm::sys::Mutex lazyCCInitMutex;

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

void CommonClangTerminate() { llvm::llvm_shutdown(); }

Expand Down Expand Up @@ -213,6 +213,7 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
CommonClangInitialize();

try {
llvm::sys::SmartScopedLock<true> compileGuard{*compileMutex};
std::unique_ptr<OCLFEBinaryResult> pResult(new OCLFEBinaryResult());

// Create the clang compiler
Expand All @@ -224,8 +225,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
// Prepare error log
llvm::raw_string_ostream err_ostream(pResult->getLogRef());
{
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};

// Parse options
optionsParser.processOptions(pszOptions, pszOptionsEx);

Expand Down Expand Up @@ -343,7 +342,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
err_ostream.flush();
}
{
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
if (pBinaryResult) {
*pBinaryResult = pResult.release();
}
Expand Down
4 changes: 2 additions & 2 deletions options_compile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Copyright (c) Intel Corporation (2009-2017).

using namespace llvm::opt;

static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > compileOptionsMutex;
extern llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;

static const OptTable::Info ClangOptionsInfoTable[] = {
#define PREFIX(NAME, VALUE)
Expand Down Expand Up @@ -410,7 +410,7 @@ extern "C" CC_DLL_EXPORT bool CheckCompileOptions(const char *pszOptions,
size_t uiUnknownOptionsSize) {
// LLVM doesn't guarantee thread safety,
// therefore we serialize execution of LLVM code.
llvm::sys::SmartScopedLock<true> compileOptionsGuard {*compileOptionsMutex};
llvm::sys::SmartScopedLock<true> compileOptionsGuard{*compileMutex};

try {
CompileOptionsParser optionsParser("200");
Expand Down

0 comments on commit b72f84d

Please sign in to comment.