Index: clang/CMakeLists.txt =================================================================== --- clang/CMakeLists.txt +++ clang/CMakeLists.txt @@ -866,6 +866,22 @@ llvm_distribution_add_targets() endif() +# add LLVM_TOOLS_BINARY_DIR to Defines to make llc, llvm-link and opt available +# for HIP toolchain +add_definitions( -DLLVM_TOOLS_BINARY_DIR="${TOOLS_BINARY_DIR} " ) +message(STATUS "found llvm executable dir: ${TOOLS_BINARY_DIR}") + +# add LLD_BINARY_DIR to Defines to make lld available for HIP toolchain +find_program(LLD_BINARY NAMES lld) +if(LLD_BINARY MATCHES "-NOTFOUND") + message(SEND_ERROR "Could not find lld executable") +else() + message(STATUS "found lld executable: ${LLD_BINARY}") +endif() +get_filename_component(LLD_BINARY_DIR ${LLD_BINARY} DIRECTORY) +add_definitions( -DLLD_BINARY_DIR="${LLD_BINARY_DIR} " ) + + configure_file( ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake ${CLANG_BINARY_DIR}/include/clang/Config/config.h) Index: clang/lib/Driver/ToolChains/HIP.cpp =================================================================== --- clang/lib/Driver/ToolChains/HIP.cpp +++ clang/lib/Driver/ToolChains/HIP.cpp @@ -105,9 +105,8 @@ CmdArgs.push_back("-o"); auto OutputFileName = getOutputFileName(C, OutputFilePrefix, "-linked", "bc"); CmdArgs.push_back(OutputFileName); - SmallString<128> ExecPath(C.getDriver().Dir); - llvm::sys::path::append(ExecPath, "llvm-link"); - const char *Exec = Args.MakeArgString(ExecPath); + const char *Exec = + Args.MakeArgString(getToolChain().GetProgramPath("llvm-link")); C.addCommand(std::make_unique(JA, *this, Exec, CmdArgs, Inputs)); return OutputFileName; } @@ -133,9 +132,8 @@ auto OutputFileName = getOutputFileName(C, OutputFilePrefix, "-optimized", "bc"); OptArgs.push_back(OutputFileName); - SmallString<128> OptPath(C.getDriver().Dir); - llvm::sys::path::append(OptPath, "opt"); - const char *OptExec = Args.MakeArgString(OptPath); + const char *OptExec = + Args.MakeArgString(getToolChain().GetProgramPath("opt")); C.addCommand(std::make_unique(JA, *this, OptExec, OptArgs, Inputs)); return OutputFileName; } @@ -180,9 +178,7 @@ auto LlcOutputFile = getOutputFileName(C, OutputFilePrefix, "", OutputIsAsm ? "s" : "o"); LlcArgs.push_back(LlcOutputFile); - SmallString<128> LlcPath(C.getDriver().Dir); - llvm::sys::path::append(LlcPath, "llc"); - const char *Llc = Args.MakeArgString(LlcPath); + const char *Llc = Args.MakeArgString(getToolChain().GetProgramPath("llc")); C.addCommand(std::make_unique(JA, *this, Llc, LlcArgs, Inputs)); return LlcOutputFile; } @@ -196,9 +192,7 @@ // The output from ld.lld is an HSA code object file. ArgStringList LldArgs{ "-flavor", "gnu", "-shared", "-o", Output.getFilename(), InputFileName}; - SmallString<128> LldPath(C.getDriver().Dir); - llvm::sys::path::append(LldPath, "lld"); - const char *Lld = Args.MakeArgString(LldPath); + const char *Lld = Args.MakeArgString(getToolChain().GetProgramPath("lld")); C.addCommand(std::make_unique(JA, *this, Lld, LldArgs, Inputs)); } @@ -230,9 +224,8 @@ Args.MakeArgString(std::string("-outputs=").append(OutputFileName)); BundlerArgs.push_back(BundlerOutputArg); - SmallString<128> BundlerPath(C.getDriver().Dir); - llvm::sys::path::append(BundlerPath, "clang-offload-bundler"); - const char *Bundler = Args.MakeArgString(BundlerPath); + const char *Bundler = Args.MakeArgString( + T.getToolChain().GetProgramPath("clang-offload-bundler")); C.addCommand(std::make_unique(JA, T, Bundler, BundlerArgs, Inputs)); } @@ -277,6 +270,16 @@ // Lookup binaries into the driver directory, this is used to // discover the clang-offload-bundler executable. getProgramPaths().push_back(getDriver().Dir); + +// add llvm binaries in case they are not in the driver directory +#if defined(LLVM_TOOLS_BINARY_DIR) + getProgramPaths().push_back(LLVM_TOOLS_BINARY_DIR); +#endif + +// add lld binary in case they are not in the driver directory +#if defined(LLD_BINARY_DIR) + getProgramPaths().push_back(LLD_BINARY_DIR); +#endif } void HIPToolChain::addClangTargetOptions(