diff --git a/shared/source/compiler_interface/compiler_interface.cpp b/shared/source/compiler_interface/compiler_interface.cpp index 8f4ba47baa..cb404fdab2 100644 --- a/shared/source/compiler_interface/compiler_interface.cpp +++ b/shared/source/compiler_interface/compiler_interface.cpp @@ -211,6 +211,9 @@ TranslationOutput::ErrorCode CompilerInterface::compile( if (outType == IGC::CodeType::undefined) { outType = getPreferredIntermediateRepresentation(device); + if (outType != IGC::CodeType::spirV) { + outType = IGC::CodeType::llvmBc; + } } CIF::CIFMain *fclMain = nullptr; diff --git a/shared/test/common/mocks/mock_compiler_interface.h b/shared/test/common/mocks/mock_compiler_interface.h index 326154cbcc..f98114339d 100644 --- a/shared/test/common/mocks/mock_compiler_interface.h +++ b/shared/test/common/mocks/mock_compiler_interface.h @@ -169,6 +169,13 @@ class MockCompilerInterface : public CompilerInterface { } }; + IGC::CodeType::CodeType_t getPreferredIntermediateRepresentation(const Device &device) override { + if (preferredIr != IGC::CodeType::undefined) { + return preferredIr; + } + return CompilerInterface::getPreferredIntermediateRepresentation(device); + } + static std::vector getDummyGenBinary(); static void releaseDummyGenBinary(); @@ -190,6 +197,7 @@ class MockCompilerInterface : public CompilerInterface { SipKernelType requestedSipKernel = SipKernelType::count; IGC::IgcOclDeviceCtxTagOCL *peekIgcDeviceCtx(Device *device) { return igcDeviceContexts[device].get(); } + IGC::CodeType::CodeType_t preferredIr = IGC::CodeType::undefined; }; template <> diff --git a/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp b/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp index cc4b87c8a0..1077999fb0 100644 --- a/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp +++ b/shared/test/unit_test/compiler_interface/compiler_interface_tests.cpp @@ -173,6 +173,21 @@ TEST_F(CompilerInterfaceTest, WhenPreferredIntermediateRepresentationSpecifiedTh EXPECT_EQ(TranslationOutput::ErrorCode::success, err); } +TEST_F(CompilerInterfaceTest, GivenCompileCommandWhenPreferredIntermediateNotSpirvThenUseLlvmBc) { + USE_REAL_FILE_SYSTEM(); + + CompilerCacheConfig config = {}; + config.enabled = false; + auto tempCompilerCache = std::make_unique(config); + pCompilerInterface->cache.reset(tempCompilerCache.release()); + inputArgs.outType = IGC::CodeType::undefined; + pCompilerInterface->preferredIr = IGC::CodeType::oclC; + TranslationOutput translationOutput; + auto err = pCompilerInterface->compile(*pDevice, inputArgs, translationOutput); + EXPECT_EQ(IGC::CodeType::llvmBc, translationOutput.intermediateCodeType); + EXPECT_EQ(TranslationOutput::ErrorCode::success, err); +} + TEST_F(CompilerInterfaceTest, whenCompilerIsNotAvailableThenBuildFailsGracefully) { pCompilerInterface->defaultIgc.entryPoint.reset(nullptr); pCompilerInterface->failLoadIgc = true;