The AMDGPU toolchain support directly compiling GPU images using
cross-compilation such as clang --target=amdgcn-amd-amdhsa foo.c.
However, when attempting to link bitcode this does not work because the
-mcpu options are not forwarded to the linker among others. This patch
simply adds them so that clang --target=amdgcn-amd-amdhsa foo.c -flto
works correctly.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
clang/lib/Driver/ToolChains/AMDGPU.cpp | ||
---|---|---|
545 | What's the test against OK_Thin for? ThinLTO is a thing but I don't know if it exists (/works) on amdgpu, is this that? |
NVM the above, all the other call sites to addLTOOptions have that test in them so it must be fine
void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, ArgStringList &CmdArgs, const InputInfo &Output, const InputInfo &Input, bool IsThinLTO);
seems strange that it's a bool argument and not the result of getLTOMode, but pre-existing feature.
clang/lib/Driver/ToolChains/AMDGPU.cpp | ||
---|---|---|
545 | AMDGPU's linker is lld so it works "in theory". But in practice, separate linking of object files isn't fully supported by the ABI. So I consider it a "your mileage may vary" scenario. FWIW, it functioned properly with my experimental libc setup $ cat main.cpp int foo(); int main() { return foo(); } $ cat foo.cpp int foo() { return 3; } $ clang++ crt1.o main.cpp foo.cpp --target=amdgcn-amd-amdhsa -mcpu=gfx1030 -Wl,-plugin-opt=mcpu=gfx1030 -nogpulib -o image -flto=thin $ amdhsa_loader image; echo $? 3 |
clang/test/Driver/amdgpu-toolchain.c | ||
---|---|---|
7 | should add a test for thinlto? |
clang/test/Driver/amdgpu-toolchain.c | ||
---|---|---|
7 | Only thing it would change is adding -plugin-opt=thinlto. Not sure if it's worth a test since it's probably checked by other uses of addLTOOptions. |
What's the test against OK_Thin for? ThinLTO is a thing but I don't know if it exists (/works) on amdgpu, is this that?