[Mlir-commits] [mlir] 1ce314c - [MLIR][GPU][lld] Use LLD bundled in ROCm, removing workaround

Krzysztof Drewniak llvmlistbot at llvm.org
Thu Feb 10 11:37:36 PST 2022


Author: Krzysztof Drewniak
Date: 2022-02-10T19:37:30Z
New Revision: 1ce314ce6b5e4f40bb266d7a2cb7525257d59b84

URL: https://github.com/llvm/llvm-project/commit/1ce314ce6b5e4f40bb266d7a2cb7525257d59b84
DIFF: https://github.com/llvm/llvm-project/commit/1ce314ce6b5e4f40bb266d7a2cb7525257d59b84.diff

LOG: [MLIR][GPU][lld] Use LLD bundled in ROCm, removing workaround

Having clarified that executing the SerializeToHsaco pass can
depend on a ROCm installation, switch from calling lld as a library to
using the copy of lld guaranteed to be included in a ROCm install.

This removes the workaround introduced in D119277

Reviewed By: whchung

Differential Revision: https://reviews.llvm.org/D119463

Added: 
    

Modified: 
    lld/Common/CommonLinkerContext.cpp
    lld/include/lld/Common/Driver.h
    mlir/lib/Dialect/GPU/CMakeLists.txt
    mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp

Removed: 
    


################################################################################
diff  --git a/lld/Common/CommonLinkerContext.cpp b/lld/Common/CommonLinkerContext.cpp
index 90f0f942a38c4..50ccbb37c7966 100644
--- a/lld/Common/CommonLinkerContext.cpp
+++ b/lld/Common/CommonLinkerContext.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "lld/Common/CommonLinkerContext.h"
-#include "lld/Common/Driver.h"
 #include "lld/Common/ErrorHandler.h"
 #include "lld/Common/Memory.h"
 
@@ -44,11 +43,3 @@ void CommonLinkerContext::destroy() {
     return;
   delete lctx;
 }
-
-// Temporary API that forces global state cleanup between explicit calls to
-// drivers. See discussion in https://reviews.llvm.org/D119049.
-void lld::cleanup() {
-  // Delete the global context and clear the global context pointer, so that it
-  // cannot be accessed anymore.
-  CommonLinkerContext::destroy();
-}

diff  --git a/lld/include/lld/Common/Driver.h b/lld/include/lld/Common/Driver.h
index 4420918e22ada..f3a80a86e9890 100644
--- a/lld/include/lld/Common/Driver.h
+++ b/lld/include/lld/Common/Driver.h
@@ -52,11 +52,6 @@ namespace wasm {
 bool link(llvm::ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
           llvm::raw_ostream &stderrOS, bool exitEarly, bool disableOutput);
 }
-
-// Temporary API that forces global state cleanup between explicit calls to
-// drivers above. DO NOT USE - this will be replaced by safeLldMain(). See
-// discussion in https://reviews.llvm.org/D119049.
-void cleanup();
 } // namespace lld
 
 #endif

diff  --git a/mlir/lib/Dialect/GPU/CMakeLists.txt b/mlir/lib/Dialect/GPU/CMakeLists.txt
index 69db5ca0e1b0b..1b2f884126f3e 100644
--- a/mlir/lib/Dialect/GPU/CMakeLists.txt
+++ b/mlir/lib/Dialect/GPU/CMakeLists.txt
@@ -126,11 +126,6 @@ if(MLIR_ENABLE_ROCM_RUNNER)
       "Building mlir with ROCm support requires the AMDGPU backend")
   endif()
 
-  # Ensure lld is enabled.
-  if (NOT "lld" IN_LIST LLVM_ENABLE_PROJECTS)
-    message(SEND_ERROR "lld is not enabled. Please revise LLVM_ENABLE_PROJECTS")
-  endif()
-
   set(DEFAULT_ROCM_PATH "/opt/rocm" CACHE PATH "Fallback path to search for ROCm installs")
   target_compile_definitions(obj.MLIRGPUTransforms
     PRIVATE
@@ -138,21 +133,9 @@ if(MLIR_ENABLE_ROCM_RUNNER)
     MLIR_GPU_TO_HSACO_PASS_ENABLE=1
   )
 
-  target_include_directories(obj.MLIRGPUTransforms
-    PRIVATE
-    ${MLIR_SOURCE_DIR}/../lld/include
-  )
-
   target_link_libraries(MLIRGPUOps
     PRIVATE
-    lldELF
     MLIRExecutionEngine
     MLIRROCDLToLLVMIRTranslation
   )
-
-  # Link lldELF also to libmlir.so. Create an alias that starts with LLVM
-  # because LINK_COMPONENTS elements are implicitly prefixed with LLVM.
-  add_library(LLVMAliasTolldELF ALIAS lldELF)
-  set_property(GLOBAL APPEND PROPERTY MLIR_LLVM_LINK_COMPONENTS AliasTolldELF)
-
 endif()

diff  --git a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
index d32f8ae3fbbee..8bef525ec887a 100644
--- a/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/SerializeToHsaco.cpp
@@ -52,8 +52,6 @@
 
 #include "llvm/Transforms/IPO/Internalize.h"
 
-#include "lld/Common/Driver.h"
-
 #include <mutex>
 
 using namespace mlir;
@@ -435,20 +433,15 @@ SerializeToHsacoPass::createHsaco(const SmallVectorImpl<char> &isaBinary) {
   }
   llvm::FileRemover cleanupHsaco(tempHsacoFilename);
 
-  {
-    static std::mutex mutex;
-    const std::lock_guard<std::mutex> lock(mutex);
-    // Invoke lld. Expect a true return value from lld.
-    bool r = lld::elf::link({"ld.lld", "-shared", tempIsaBinaryFilename.c_str(),
-                             "-o", tempHsacoFilename.c_str()},
-                            llvm::outs(), llvm::errs(), /*exitEarly=*/false,
-                            /*disableOutput=*/false);
-    // Allow for calling the driver again in the same process.
-    lld::cleanup();
-    if (!r) {
-      emitError(loc, "lld invocation error");
-      return {};
-    }
+  std::string theRocmPath = getRocmPath();
+  llvm::SmallString<32> lldPath(std::move(theRocmPath));
+  llvm::sys::path::append(lldPath, "llvm", "bin", "ld.lld");
+  int lldResult = llvm::sys::ExecuteAndWait(
+      lldPath,
+      {"ld.lld", "-shared", tempIsaBinaryFilename, "-o", tempHsacoFilename});
+  if (lldResult != 0) {
+    emitError(loc, "lld invocation error");
+    return {};
   }
 
   // Load the HSA code object.


        


More information about the Mlir-commits mailing list