Skip to content

Commit fe06526

Browse files
authored
revert db7696e and 4a88836 (#427) (#452)
llvm-related variable initialization, clang::ExecuteCompilerInvocation and llvm-spirv aren't thread safe, at least for 90 branch. (cherry picked from commit 76bc7f9)
1 parent bbf1402 commit fe06526

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

opencl_clang.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static volatile bool lazyCCInit =
8181
true; // the flag must be 'volatile' to prevent caching in a CPU register
8282
static llvm::sys::Mutex lazyCCInitMutex;
8383

84-
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > compileMutex;
84+
llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;
8585

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

@@ -208,6 +208,7 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
208208
CommonClangInitialize();
209209

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

213214
// Create the clang compiler
@@ -219,8 +220,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
219220
// Prepare error log
220221
llvm::raw_string_ostream err_ostream(pResult->getLogRef());
221222
{
222-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
223-
224223
// Parse options
225224
optionsParser.processOptions(pszOptions, pszOptionsEx);
226225

@@ -337,7 +336,6 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
337336
err_ostream.flush();
338337
}
339338
{
340-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
341339
if (pBinaryResult) {
342340
*pBinaryResult = pResult.release();
343341
}

options_compile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Copyright (c) Intel Corporation (2009-2017).
4343

4444
using namespace llvm::opt;
4545

46-
static llvm::ManagedStatic<llvm::sys::SmartMutex<true> > compileOptionsMutex;
46+
extern llvm::ManagedStatic<llvm::sys::SmartMutex<true>> compileMutex;
4747

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

466466
try {
467467
CompileOptionsParser optionsParser("200");

0 commit comments

Comments
 (0)