Skip to content

Commit a7f9e94

Browse files
committed
[Comgr] Add -relink-builtin-bitcode-postop to device library linking
Compiling with the ROCm device libraries is currently possible via the *_COMPILE_SOURCE_WITH_DEVICE_LIBS_TO_BC action. However, with this action it is possible to encounter LLD errors if new device library calls are introduced during optimization. In this patch, we add a newly introduced LLVM option, -relink-builtin-bitcode-postop (llvm#69371), to re-link the device libraries after optimization, resolving any newly introduced definitions. We also update the relevant test to reflect this improvement Change-Id: I3889b7a5ffab795065684c59486c6a9965a038f2
1 parent 80ffe80 commit a7f9e94

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

amd/comgr/docs/ReleaseNotes.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ did not end with a .s file extension, it was not handled properly by the Comgr
6161
ASSEMBLE\_SOURCE\_TO\_RELOCATABLE action.
6262
- Switched getline() from C++ to C-style to avoid issues with stdlibc++ and
6363
pytorch
64-
64+
- Added new -relink-builtin-bitcode-postop LLVM option to device library. This
65+
fixes an issue with the \*COMPILE\_SOURCE\_WITH\_DEVICE\_LIBRARIES\_TO\_BC where
66+
OpenCL applications that leveraged AMDGPUSimplifyLibCalls optimizations would
67+
need to re-link bitcodes separately to avoid errors at runtime.
6568

6669
New APIs
6770
--------

amd/comgr/src/comgr-compiler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,8 @@ amd_comgr_status_t AMDGPUCompiler::addDeviceLibraries() {
10821082
return AMD_COMGR_STATUS_ERROR;
10831083
}
10841084
Args.push_back(Saver.save(Twine("--rocm-path=") + FakeRocmDir).data());
1085+
Args.push_back("-mllvm");
1086+
Args.push_back("-relink-builtin-bitcode-postop");
10851087
NoGpuLib = false;
10861088

10871089
for (auto DeviceLib : getDeviceLibraries()) {

amd/comgr/test/compile_source_with_device_libs_to_bc_test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ int main(int argc, char *argv[]) {
4848
amd_comgr_action_info_t DataAction;
4949
amd_comgr_status_t Status;
5050
const char *CodeGenOptions[] = {"-mllvm", "-amdgpu-early-inline-all",
51-
"-mcode-object-version=5"};
51+
"-mcode-object-version=5", "-mllvm", "-amdgpu-prelink"};
5252
size_t CodeGenOptionsCount =
5353
sizeof(CodeGenOptions) / sizeof(CodeGenOptions[0]);
5454

0 commit comments

Comments
 (0)