Skip to content

Commit 4a88836

Browse files
committed
Released writeSpirv from locking, too.
1 parent db7696e commit 4a88836

File tree

1 file changed

+44
-45
lines changed

1 file changed

+44
-45
lines changed

common_clang.cpp

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -294,53 +294,52 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
294294
success = clang::ExecuteCompilerInvocation(compiler.get());
295295
} catch (const std::exception &) {
296296
}
297-
{
298-
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
299-
pResult->setIRType(IR_TYPE_COMPILED_OBJECT);
300-
pResult->setIRName(optionsParser.getSourceName());
301-
302-
// Our error handler depends on the Diagnostics object, which we're
303-
// potentially about to delete. Uninstall the handler now so that any
304-
// later errors use the default handling behavior instead.
305-
// (currently commented out since setting the llvm error handling in
306-
// multi-threaded environment is unsupported)
307-
// llvm::remove_fatal_error_handler();
308-
err_ostream.flush();
309-
310-
if (success && (optionsParser.hasEmitSPIRV() || optionsParser.hasEmitSPIRVText())) {
311-
// Translate LLVM IR to SPIR-V.
312-
if (optionsParser.hasEmitSPIRVText())
313-
SPIRV::SPIRVUseTextFormat = true;
314-
llvm::StringRef LLVM_IR(static_cast<const char*>(pResult->GetIR()),
315-
pResult->GetIRSize());
316-
std::unique_ptr<llvm::MemoryBuffer> MB = llvm::MemoryBuffer::getMemBuffer(LLVM_IR, pResult->GetIRName(), false);
317-
llvm::LLVMContext Context;
318-
auto E = llvm::getOwningLazyBitcodeModule(std::move(MB), Context,
319-
/*ShouldLazyLoadMetadata=*/true);
320-
llvm::logAllUnhandledErrors(E.takeError(), err_ostream, "error: ");
321-
std::unique_ptr<llvm::Module> M = std::move(*E);
322-
323-
if (M->materializeAll()) {
324-
if (pBinaryResult) {
325-
*pBinaryResult = nullptr;
326-
}
327-
assert(!"Failed to read just compiled LLVM IR!");
328-
return CL_COMPILE_PROGRAM_FAILURE;
329-
}
330-
pResult->getIRBufferRef().clear();
331-
SmallVectorBuffer StreamBuf(pResult->getIRBufferRef());
332-
std::ostream OS(&StreamBuf);
333-
std::string Err;
334-
SPIRV::TranslatorOpts SPIRVOpts;
335-
SPIRVOpts.enableAllExtensions();
336-
if (!optionsParser.hasOptDisable()) {
337-
SPIRVOpts.setMemToRegEnabled(true);
297+
pResult->setIRType(IR_TYPE_COMPILED_OBJECT);
298+
pResult->setIRName(optionsParser.getSourceName());
299+
300+
// Our error handler depends on the Diagnostics object, which we're
301+
// potentially about to delete. Uninstall the handler now so that any
302+
// later errors use the default handling behavior instead.
303+
// (currently commented out since setting the llvm error handling in
304+
// multi-threaded environment is unsupported)
305+
// llvm::remove_fatal_error_handler();
306+
err_ostream.flush();
307+
308+
if (success && (optionsParser.hasEmitSPIRV() || optionsParser.hasEmitSPIRVText())) {
309+
// Translate LLVM IR to SPIR-V.
310+
if (optionsParser.hasEmitSPIRVText())
311+
SPIRV::SPIRVUseTextFormat = true;
312+
llvm::StringRef LLVM_IR(static_cast<const char*>(pResult->GetIR()),
313+
pResult->GetIRSize());
314+
std::unique_ptr<llvm::MemoryBuffer> MB = llvm::MemoryBuffer::getMemBuffer(LLVM_IR, pResult->GetIRName(), false);
315+
llvm::LLVMContext Context;
316+
auto E = llvm::getOwningLazyBitcodeModule(std::move(MB), Context,
317+
/*ShouldLazyLoadMetadata=*/true);
318+
llvm::logAllUnhandledErrors(E.takeError(), err_ostream, "error: ");
319+
std::unique_ptr<llvm::Module> M = std::move(*E);
320+
321+
if (M->materializeAll()) {
322+
if (pBinaryResult) {
323+
*pBinaryResult = nullptr;
338324
}
339-
success = llvm::writeSpirv(M.get(), SPIRVOpts, OS, Err);
340-
err_ostream << Err.c_str();
341-
err_ostream.flush();
325+
assert(!"Failed to read just compiled LLVM IR!");
326+
return CL_COMPILE_PROGRAM_FAILURE;
342327
}
343-
328+
pResult->getIRBufferRef().clear();
329+
SmallVectorBuffer StreamBuf(pResult->getIRBufferRef());
330+
std::ostream OS(&StreamBuf);
331+
std::string Err;
332+
SPIRV::TranslatorOpts SPIRVOpts;
333+
SPIRVOpts.enableAllExtensions();
334+
if (!optionsParser.hasOptDisable()) {
335+
SPIRVOpts.setMemToRegEnabled(true);
336+
}
337+
success = llvm::writeSpirv(M.get(), SPIRVOpts, OS, Err);
338+
err_ostream << Err.c_str();
339+
err_ostream.flush();
340+
}
341+
{
342+
llvm::sys::SmartScopedLock<true> compileGuard {*compileMutex};
344343
if (pBinaryResult) {
345344
*pBinaryResult = pResult.release();
346345
}

0 commit comments

Comments
 (0)