[PATCH] D72806: [HIP] fix paths for executables not in clang bin directory

2020-01-17 Thread Holger Wünsche via Phabricator via cfe-commits
DieGoldeneEnte abandoned this revision.
DieGoldeneEnte added a comment.

Adding the paths for llvm/lld is not needed, because GetProgramPath is actually 
also searching in $PATH. This means D72903  
already is enough to fix my problem.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72806/new/

https://reviews.llvm.org/D72806



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72806: [HIP] fix paths for executables not in clang bin directory

2020-01-17 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

Tank you for splitting the patch. For CMake parts @beanz would be the person to 
make the call.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72806/new/

https://reviews.llvm.org/D72806



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72806: [HIP] fix paths for executables not in clang bin directory

2020-01-17 Thread Holger Wünsche via Phabricator via cfe-commits
DieGoldeneEnte updated this revision to Diff 238708.
DieGoldeneEnte added a comment.

This patch now only adds the executable dirs to the program path, the code to 
search them is now in D72903 .


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72806/new/

https://reviews.llvm.org/D72806

Files:
  clang/CMakeLists.txt
  clang/lib/Driver/ToolChains/HIP.cpp


Index: clang/lib/Driver/ToolChains/HIP.cpp
===
--- clang/lib/Driver/ToolChains/HIP.cpp
+++ clang/lib/Driver/ToolChains/HIP.cpp
@@ -277,6 +277,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(
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -866,6 +866,24 @@
   llvm_distribution_add_targets()
 endif()
 
+# add LLVM_TOOLS_BINARY_DIR to Defines to make llc, llvm-link and opt available
+# for HIP toolchain
+if(DEFINED LLVM_TOOLS_BINARY_DIR)
+  add_definitions( -DLLVM_TOOLS_BINARY_DIR="${LLVM_TOOLS_BINARY_DIR} " )
+  message(STATUS "found llvm executable dir: ${LLVM_TOOLS_BINARY_DIR}")
+endif()
+
+# add LLD_BINARY_DIR to Defines to make lld available for HIP toolchain
+find_program(LLD_BINARY NAMES lld)
+if(NOT LLD_BINARY MATCHES "-NOTFOUND" AND NOT DEFINED LLD_BINARY_DIR)
+  message(STATUS "found lld executable: ${LLD_BINARY}")
+  get_filename_component(LLD_BINARY_DIR ${LLD_BINARY} DIRECTORY)
+endif()
+if(DEFINED LLD_BINARY)
+  add_definitions( -DLLD_BINARY_DIR="${LLD_BINARY_DIR} " )
+endif()
+
+
 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
@@ -277,6 +277,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(
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -866,6 +866,24 @@
   llvm_distribution_add_targets()
 endif()
 
+# add LLVM_TOOLS_BINARY_DIR to Defines to make llc, llvm-link and opt available
+# for HIP toolchain
+if(DEFINED LLVM_TOOLS_BINARY_DIR)
+  add_definitions( -DLLVM_TOOLS_BINARY_DIR="${LLVM_TOOLS_BINARY_DIR} " )
+  message(STATUS "found llvm executable dir: ${LLVM_TOOLS_BINARY_DIR}")
+endif()
+
+# add LLD_BINARY_DIR to Defines to make lld available for HIP toolchain
+find_program(LLD_BINARY NAMES lld)
+if(NOT LLD_BINARY MATCHES "-NOTFOUND" AND NOT DEFINED LLD_BINARY_DIR)
+  message(STATUS "found lld executable: ${LLD_BINARY}")
+  get_filename_component(LLD_BINARY_DIR ${LLD_BINARY} DIRECTORY)
+endif()
+if(DEFINED LLD_BINARY)
+  add_definitions( -DLLD_BINARY_DIR="${LLD_BINARY_DIR} " )
+endif()
+
+
 configure_file(
   ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
   ${CLANG_BINARY_DIR}/include/clang/Config/config.h)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72806: [HIP] fix paths for executables not in clang bin directory

2020-01-16 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D72806#1825400 , @DieGoldeneEnte 
wrote:

>




> Even in case we don't add the extra directories for llvm and lld, it would be 
> a good idea to use the getProgramPath function instead of building it 
> manually (so only the changes in HIP.cpp except lines 273-282). This was 
> planned anyways according to the comments in HIP.cpp line 270-271:
> 
>>   // Lookup binaries into the driver directory, this is used to
>>   // discover the clang-offload-bundler executable.

Agreed. GetProgramPath() change makes sense on its own merits.

In the future it may help to keep intependent changes in separate patches. It 
makes it easier to review and land them that way. I.e. the patch with 
GetProgramPath()  would be stamped w/o problems as it's an obvious clean up 
local to HIP only. Changing build for everyone will need more scrutiny and 
would be easier to deal with if it's not commingled with other changes.

It's not too late to split this patch in two. :-)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72806/new/

https://reviews.llvm.org/D72806



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72806: [HIP] fix paths for executables not in clang bin directory

2020-01-16 Thread Holger Wünsche via Phabricator via cfe-commits
DieGoldeneEnte added a comment.

In D72806#1825362 , @tra wrote:

> In D72806#1825333 , @DieGoldeneEnte 
> wrote:
>
> > In D72806#1824560 , @yaxunl wrote:
> >
> > > What's the use case of this change?
> > >
> > > Normally clang needs to call opt/llc/lld from the same directory of 
> > > clang. Why do we need to find them in other directories?
> >
> >
> > My motivation is the nix-package manager, which has llvm, lld and clang in 
> > different packages (which results in different directories).
>
>
> We've had similar issues with use of clang for CUDA on Debian (I think), 
> where CUDA was scattered all over the place.
>  The way to do it was to create a 'shim' directory structure which would put 
> all relevant tools in the right places.
>  Something similar could be done in your case -- make a package which would 
> depend on individual tool packages and which would symlink all of them into 
> one dir and point your compiler there.


That's what I will do if we don't fix this here. But I think it would be 
cleaner if one can set the directories.

Even in case we don't add the extra directories for llvm and lld, it would be a 
good idea to use the getProgramPath function instead of building it manually 
(so only the changes in HIP.cpp except lines 273-282). This was planned anyways 
according to the comments in HIP.cpp line 270-271:

>   // Lookup binaries into the driver directory, this is used to
>   // discover the clang-offload-bundler executable.




CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72806/new/

https://reviews.llvm.org/D72806



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72806: [HIP] fix paths for executables not in clang bin directory

2020-01-16 Thread Artem Belevich via Phabricator via cfe-commits
tra added a comment.

In D72806#1825333 , @DieGoldeneEnte 
wrote:

> In D72806#1824560 , @yaxunl wrote:
>
> > What's the use case of this change?
> >
> > Normally clang needs to call opt/llc/lld from the same directory of clang. 
> > Why do we need to find them in other directories?
>
>
> My motivation is the nix-package manager, which has llvm, lld and clang in 
> different packages (which results in different directories).


We've had similar issues with use of clang for CUDA on Debian (I think), where 
CUDA was scattered all over the place.
The way to do it was to create a 'shim' directory structure which would put all 
relevant tools in the right places.
Something similar could be done in your case -- make a package which would 
depend on individual tool packages and which would symlink all of them into one 
dir and point your compiler there.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72806/new/

https://reviews.llvm.org/D72806



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72806: [HIP] fix paths for executables not in clang bin directory

2020-01-16 Thread Holger Wünsche via Phabricator via cfe-commits
DieGoldeneEnte updated this revision to Diff 238645.
DieGoldeneEnte added a comment.

The build doesn't fail anymore if lld is not present, also one can set 
LLD_BINARY_DIR manually. I also exchanged TOOLS_BINARY_DIR with 
LLVM_TOOLS_BINARY_DIR, since it is better readable and if compiled with llvm 
this is necessary to populate the variable (although the path is already 
present in that case, because clang and all the other utils should be in the 
same directory.

Tests still work as before.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72806/new/

https://reviews.llvm.org/D72806

Files:
  clang/CMakeLists.txt
  clang/lib/Driver/ToolChains/HIP.cpp

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(
Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -866,6 +866,24 @@
   llvm_distribution_add_targets()
 endif()
 
+# add LLVM_TOOLS_BINARY_DIR to Defines to make llc, llvm-link and opt available
+# for HIP toolchain
+if(DEFINED LLVM_TOOLS_BINARY_DIR)
+  add_definitions( -DLLVM_TOOLS_BINARY_DIR="${LLVM_TOOLS_BINARY_DIR} " )
+  message(STATUS "found llvm executable dir: ${LLVM_TOOLS_BINARY_DIR}")
+endif()
+
+# add LLD_BINARY_DIR to Defines to make lld available for HIP toolchain
+find_program(LLD_BINARY NAMES lld)
+if(NOT LLD_BINARY MATCHES "-NOTFOUND" AND NOT DEFINED LLD_BINARY_DIR)
+  message(STATUS "found lld executable: ${LLD_BINARY}")
+  get_filename_component(LLD_BINARY_DIR ${LLD_BINARY} DIRECTORY)
+endif()
+if(DEFINED LLD_BINARY)
+  add_definitions( -DLLD_BINARY_DIR="${LLD_BINARY_DIR} " )
+endif()
+
+
 configure_file(
   ${CLANG_SOURCE_DIR}/include/clang/Config/config.h.cmake
   ${CLANG_BINARY_DIR}/include/clang/Config/config.h)
___
cfe-commits mailing list

[PATCH] D72806: [HIP] fix paths for executables not in clang bin directory

2020-01-16 Thread Holger Wünsche via Phabricator via cfe-commits
DieGoldeneEnte added a comment.

In D72806#1824560 , @yaxunl wrote:

> What's the use case of this change?
>
> Normally clang needs to call opt/llc/lld from the same directory of clang. 
> Why do we need to find them in other directories?


My motivation is the nix-package manager, which has llvm, lld and clang in 
different packages (which results in different directories).

> Where is TOOLS_BINARY_DIR defined?

If clang is compiled standalone with llvm as external library the 
TOOLS_BINARY_DIR is pulled from the LLVMConfig.cmake. If clang is compiled 
together with llvm the variable is set in the llvm/CMakeLists.txt .
Upon closer inspection I noticed I can/should use LLVM_TOOLS_BINARY_DIR (which 
is more readable). In the end it points to the llvm/bin directory.

> Also we cannot let the build fail because of lld not found, since users may 
> be building clang for other language and they do not need lld.

Removed the message, so build doesn't fail. Since I check for the existence of 
the define in the code only the cmake rules needed to be changed.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72806/new/

https://reviews.llvm.org/D72806



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72806: [HIP] fix paths for executables not in clang bin directory

2020-01-16 Thread Artem Belevich via Phabricator via cfe-commits
tra added a reviewer: beanz.
tra added a subscriber: beanz.
tra added a comment.

LGTM. Added @beanz for the review of CMake file changes.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72806/new/

https://reviews.llvm.org/D72806



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72806: [HIP] fix paths for executables not in clang bin directory

2020-01-16 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

What's the use case of this change?

Normally clang needs to call opt/llc/lld from the same directory of clang. Why 
do we need to find them in other directories?

Where is TOOLS_BINARY_DIR defined?

Also we cannot let the build fail because of lld not found, since users may be 
building clang for other language and they do not need lld.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72806/new/

https://reviews.llvm.org/D72806



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D72806: [HIP] fix paths for executables not in clang bin directory

2020-01-15 Thread Holger Wünsche via Phabricator via cfe-commits
DieGoldeneEnte created this revision.
DieGoldeneEnte added a reviewer: yaxunl.
Herald added subscribers: cfe-commits, mgorny.
Herald added a project: clang.

The previous code constructed the executable paths for llvm-link, opt, lld, llc 
and clang-offload-bundler for the path to the compiler. This change uses cmake 
to find the directory containing llvm and lld and searches them using the 
GetProgramPath method in addition to the compiler directory.

The test completed without error (except one which failed even without my 
patch) and I was able to confirm successful compilation using the hip toolchain 
by compiling a simple program with clang, lld, and llvm executables in 
different directories.


Repository:
  rC Clang

https://reviews.llvm.org/D72806

Files:
  clang/CMakeLists.txt
  clang/lib/Driver/ToolChains/HIP.cpp

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(
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