@@ -289,51 +289,50 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
289289 success = clang::ExecuteCompilerInvocation (compiler.get ());
290290 } catch (const std::exception &) {
291291 }
292- {
293- llvm::sys::SmartScopedLock<true > compileGuard {*compileMutex};
294- pResult->setIRType (IR_TYPE_COMPILED_OBJECT);
295- pResult->setIRName (optionsParser.getSourceName ());
296-
297- // Our error handler depends on the Diagnostics object, which we're
298- // potentially about to delete. Uninstall the handler now so that any
299- // later errors use the default handling behavior instead.
300- // (currently commented out since setting the llvm error handling in
301- // multi-threaded environment is unsupported)
302- // llvm::remove_fatal_error_handler();
303- err_ostream.flush ();
304-
305- if (success && optionsParser.hasEmitSPIRV ()) {
306- // Translate LLVM IR to SPIR-V.
307- llvm::StringRef LLVM_IR (static_cast <const char *>(pResult->GetIR ()),
308- pResult->GetIRSize ());
309- std::unique_ptr<llvm::MemoryBuffer> MB = llvm::MemoryBuffer::getMemBuffer (LLVM_IR, pResult->GetIRName (), false );
310- llvm::LLVMContext Context;
311- auto E = llvm::getOwningLazyBitcodeModule (std::move (MB), Context,
312- /* ShouldLazyLoadMetadata=*/ true );
313- llvm::logAllUnhandledErrors (E.takeError (), err_ostream, " error: " );
314- std::unique_ptr<llvm::Module> M = std::move (*E);
315-
316- if (M->materializeAll ()) {
317- if (pBinaryResult) {
318- *pBinaryResult = nullptr ;
319- }
320- assert (!" Failed to read just compiled LLVM IR!" );
321- return CL_COMPILE_PROGRAM_FAILURE;
322- }
323- pResult->getIRBufferRef ().clear ();
324- SmallVectorBuffer StreamBuf (pResult->getIRBufferRef ());
325- std::ostream OS (&StreamBuf);
326- std::string Err;
327- SPIRV::TranslatorOpts SPIRVOpts;
328- SPIRVOpts.enableAllExtensions ();
329- if (!optionsParser.hasOptDisable ()) {
330- SPIRVOpts.setMemToRegEnabled (true );
292+ pResult->setIRType (IR_TYPE_COMPILED_OBJECT);
293+ pResult->setIRName (optionsParser.getSourceName ());
294+
295+ // Our error handler depends on the Diagnostics object, which we're
296+ // potentially about to delete. Uninstall the handler now so that any
297+ // later errors use the default handling behavior instead.
298+ // (currently commented out since setting the llvm error handling in
299+ // multi-threaded environment is unsupported)
300+ // llvm::remove_fatal_error_handler();
301+ err_ostream.flush ();
302+
303+ if (success && optionsParser.hasEmitSPIRV ()) {
304+ // Translate LLVM IR to SPIR-V.
305+ llvm::StringRef LLVM_IR (static_cast <const char *>(pResult->GetIR ()),
306+ pResult->GetIRSize ());
307+ std::unique_ptr<llvm::MemoryBuffer> MB = llvm::MemoryBuffer::getMemBuffer (LLVM_IR, pResult->GetIRName (), false );
308+ llvm::LLVMContext Context;
309+ auto E = llvm::getOwningLazyBitcodeModule (std::move (MB), Context,
310+ /* ShouldLazyLoadMetadata=*/ true );
311+ llvm::logAllUnhandledErrors (E.takeError (), err_ostream, " error: " );
312+ std::unique_ptr<llvm::Module> M = std::move (*E);
313+
314+ if (M->materializeAll ()) {
315+ if (pBinaryResult) {
316+ *pBinaryResult = nullptr ;
331317 }
332- success = llvm::writeSpirv (M.get (), SPIRVOpts, OS, Err);
333- err_ostream << Err.c_str ();
334- err_ostream.flush ();
318+ assert (!" Failed to read just compiled LLVM IR!" );
319+ return CL_COMPILE_PROGRAM_FAILURE;
335320 }
336-
321+ pResult->getIRBufferRef ().clear ();
322+ SmallVectorBuffer StreamBuf (pResult->getIRBufferRef ());
323+ std::ostream OS (&StreamBuf);
324+ std::string Err;
325+ SPIRV::TranslatorOpts SPIRVOpts;
326+ SPIRVOpts.enableAllExtensions ();
327+ if (!optionsParser.hasOptDisable ()) {
328+ SPIRVOpts.setMemToRegEnabled (true );
329+ }
330+ success = llvm::writeSpirv (M.get (), SPIRVOpts, OS, Err);
331+ err_ostream << Err.c_str ();
332+ err_ostream.flush ();
333+ }
334+ {
335+ llvm::sys::SmartScopedLock<true > compileGuard {*compileMutex};
337336 if (pBinaryResult) {
338337 *pBinaryResult = pResult.release ();
339338 }
0 commit comments