Skip to content

Commit 28aa0aa

Browse files
committed
[AMDGPU] Use the AMDGPUToolChain when targeting C/C++ directly
Summary: The `getToolChain` pass uses the triple to determine which toolchain to create. Currently the `amdgcn-amd-amdhsa` triple maps to the `ROCmToolChain` which uses things expected to be provided by `ROCm`. This is neded for OpenCL, but directly targeting C++ does not want this since it's primarily being used for creating GPU runtime code. As far as I know I'm the only user of this, so this shouldn't change anything. Unfortunately, there's no good logic for detercting this, so I simply checked ahead of time if the input is either `foo.cl` or `-x cl foo.c` to choose between the two. This allows us to use the AMDGPU target normally, as otherwise it will error without passing `-nogpulib`.
1 parent 7e37d02 commit 28aa0aa

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6404,9 +6404,20 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
64046404
case llvm::Triple::CUDA:
64056405
TC = std::make_unique<toolchains::NVPTXToolChain>(*this, Target, Args);
64066406
break;
6407-
case llvm::Triple::AMDHSA:
6408-
TC = std::make_unique<toolchains::ROCMToolChain>(*this, Target, Args);
6407+
case llvm::Triple::AMDHSA: {
6408+
bool IsOpenCL = llvm::any_of(
6409+
Args.filtered(options::OPT_INPUT, options::OPT_x), [](auto &Arg) {
6410+
if (Arg->getOption().matches(options::OPT_INPUT))
6411+
return StringRef(Arg->getValue()).ends_with(".cl");
6412+
return StringRef(Arg->getValue()).ends_with("cl");
6413+
});
6414+
TC =
6415+
IsOpenCL
6416+
? std::make_unique<toolchains::ROCMToolChain>(*this, Target, Args)
6417+
: std::make_unique<toolchains::AMDGPUToolChain>(*this, Target,
6418+
Args);
64096419
break;
6420+
}
64106421
case llvm::Triple::AMDPAL:
64116422
case llvm::Triple::Mesa3D:
64126423
TC = std::make_unique<toolchains::AMDGPUToolChain>(*this, Target, Args);

0 commit comments

Comments
 (0)