Skip to content

Commit 01ed6ba

Browse files
lamb-jsearlmc1
authored andcommitted
[Comgr][SPIRV] Add Comgr CMake option to disable SPIRV
By passing -DCOMGR_DISABLE_SPIRV=1 when building Comgr via cmake, a user can avoid installing and linking against the SPIRV-LLVM-Translator Change-Id: Id1624af4b3a0eb14a31ddedf3fd4474a3af95931
1 parent 6d15522 commit 01ed6ba

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

amd/comgr/CMakeLists.txt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ set(AMD_COMGR_PRIVATE_COMPILE_DEFINITIONS ${LLVM_DEFINITIONS})
166166
set(AMD_COMGR_PUBLIC_LINKER_OPTIONS)
167167
set(AMD_COMGR_PRIVATE_LINKER_OPTIONS)
168168

169+
if(${COMGR_DISABLE_SPIRV})
170+
list(APPEND AMD_COMGR_PRIVATE_COMPILE_OPTIONS "-DCOMGR_DISABLE_SPIRV")
171+
endif()
172+
169173
list(APPEND AMD_COMGR_PRIVATE_COMPILE_OPTIONS "-DAMD_COMGR_GIT_COMMIT=${AMD_COMGR_GIT_COMMIT}")
170174
list(APPEND AMD_COMGR_PRIVATE_COMPILE_OPTIONS "-DAMD_COMGR_GIT_BRANCH=${AMD_COMGR_GIT_BRANCH}")
171175
message("----COMGR_GIT_COMMIT: ${AMD_COMGR_GIT_COMMIT}")
@@ -383,8 +387,18 @@ set(LLD_LIBS
383387
lldELF
384388
lldCommon)
385389

390+
if (${COMGR_DISABLE_SPIRV})
391+
message("-- Comgr SPIRV Disabled")
392+
set(SPIRV_DYNAMIC_LIB "")
393+
set(SPIRV_STATIC_LIB "")
394+
else()
395+
message("-- Comgr SPIRV Enabled")
396+
set(SPIRV_DYNAMIC_LIB "LLVMSPIRVAMDLib")
397+
set(SPIRV_STATIC_LIB "SPIRVAMDLib")
398+
endif()
399+
386400
if (LLVM_LINK_LLVM_DYLIB)
387-
set(LLVM_LIBS LLVM)
401+
set(LLVM_LIBS LLVM ${SPIRV_DYNAMIC_LIB})
388402
else()
389403
llvm_map_components_to_libnames(LLVM_LIBS
390404
${LLVM_TARGETS_TO_BUILD}
@@ -405,7 +419,7 @@ else()
405419
Support
406420
Symbolize
407421
TargetParser
408-
SPIRVAMDLib
422+
${SPIRV_STATIC_LIB}
409423
)
410424
endif()
411425

amd/comgr/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ may be enabled during development via `-DADDRESS_SANITIZER=On` during the Comgr
8080
Comgr can be built as a static library by passing
8181
`-DCOMGR_BUILD_SHARED_LIBS=OFF` during the Comgr `cmake` step.
8282

83+
Comgr SPIRV-related APIs can be disabled by passing
84+
`-DCOMGR_DISABLE_SPIRV=1` during the Comgr `cmake` step. This removes any
85+
dependency on LLVM SPIRV libraries or the llvm-spirv tool.
86+
8387
Depending on the Code Object Manager
8488
------------------------------------
8589

amd/comgr/src/comgr-compiler.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@
8181
#include "llvm/Support/WithColor.h"
8282
#include "llvm/TargetParser/Host.h"
8383

84+
#ifndef COMGR_DISABLE_SPIRV
8485
#include "LLVMSPIRVLib/LLVMSPIRVLib.h"
86+
#endif
87+
8588
#include "time-stat/ts-interface.h"
8689

8790
#include <csignal>
@@ -1852,6 +1855,12 @@ amd_comgr_status_t AMDGPUCompiler::linkToExecutable() {
18521855
}
18531856

18541857
amd_comgr_status_t AMDGPUCompiler::translateSpirvToBitcode() {
1858+
#ifdef COMGR_DISABLE_SPIRV
1859+
LogS << "Calling AMDGPUCompiler::translateSpirvToBitcode() not supported "
1860+
<< "Comgr is built with -DCOMGR_DISABLE_SPIRV. Re-build LLVM and Comgr "
1861+
<< "with LLVM-SPIRV-Translator support to continue.\n";
1862+
return AMD_COMGR_STATUS_ERROR;
1863+
#else
18551864
if (auto Status = createTmpDirs()) {
18561865
return Status;
18571866
}
@@ -1906,6 +1915,7 @@ amd_comgr_status_t AMDGPUCompiler::translateSpirvToBitcode() {
19061915
}
19071916

19081917
return AMD_COMGR_STATUS_SUCCESS;
1918+
#endif
19091919
}
19101920

19111921
AMDGPUCompiler::AMDGPUCompiler(DataAction *ActionInfo, DataSet *InSet,

0 commit comments

Comments
 (0)