Skip to content

[MLIR] Add a BlobAttr interface for attribute to wrap arbitrary content and use it as linkLibs for ModuleToObject #120116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2024

Conversation

joker-eph
Copy link
Collaborator

This change allows to expose through an interface attributes wrapping content as external
resources, and the usage inside the ModuleToObject show how we will be able to provide
runtime libraries without relying on the filesystem.

@llvmbot
Copy link
Member

llvmbot commented Dec 16, 2024

@llvm/pr-subscribers-mlir-gpu
@llvm/pr-subscribers-mlir-ods

@llvm/pr-subscribers-mlir-core

Author: Mehdi Amini (joker-eph)

Changes

This change allows to expose through an interface attributes wrapping content as external
resources, and the usage inside the ModuleToObject show how we will be able to provide
runtime libraries without relying on the filesystem.


Patch is 25.57 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/120116.diff

14 Files Affected:

  • (modified) mlir/include/mlir/Dialect/GPU/IR/CompilationInterfaces.h (+5-5)
  • (modified) mlir/include/mlir/IR/BuiltinAttributeInterfaces.td (+18)
  • (modified) mlir/include/mlir/IR/BuiltinAttributes.td (+11-2)
  • (modified) mlir/include/mlir/Target/LLVM/ModuleToObject.h (+1-1)
  • (modified) mlir/include/mlir/Target/LLVM/NVVM/Utils.h (+9-6)
  • (modified) mlir/include/mlir/Target/LLVM/ROCDL/Utils.h (+4-3)
  • (modified) mlir/lib/Dialect/GPU/IR/GPUDialect.cpp (+7-5)
  • (modified) mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp (+4-2)
  • (modified) mlir/lib/IR/BuiltinAttributes.cpp (+7)
  • (modified) mlir/lib/Target/LLVM/ModuleToObject.cpp (+43-11)
  • (modified) mlir/lib/Target/LLVM/NVVM/Target.cpp (+8-10)
  • (modified) mlir/lib/Target/LLVM/ROCDL/Target.cpp (+9-11)
  • (modified) mlir/unittests/Target/LLVM/CMakeLists.txt (+4)
  • (modified) mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp (+72)
diff --git a/mlir/include/mlir/Dialect/GPU/IR/CompilationInterfaces.h b/mlir/include/mlir/Dialect/GPU/IR/CompilationInterfaces.h
index 5b6e03a2e6e75e..c950ef220f692f 100644
--- a/mlir/include/mlir/Dialect/GPU/IR/CompilationInterfaces.h
+++ b/mlir/include/mlir/Dialect/GPU/IR/CompilationInterfaces.h
@@ -51,7 +51,7 @@ class TargetOptions {
   /// obtaining the parent symbol table. The default compilation target is
   /// `Fatbin`.
   TargetOptions(
-      StringRef toolkitPath = {}, ArrayRef<std::string> linkFiles = {},
+      StringRef toolkitPath = {}, ArrayRef<Attribute> librariesToLink = {},
       StringRef cmdOptions = {}, StringRef elfSection = {},
       CompilationTarget compilationTarget = getDefaultCompilationTarget(),
       function_ref<SymbolTable *()> getSymbolTableCallback = {},
@@ -66,8 +66,8 @@ class TargetOptions {
   /// Returns the toolkit path.
   StringRef getToolkitPath() const;
 
-  /// Returns the files to link to.
-  ArrayRef<std::string> getLinkFiles() const;
+  /// Returns the LLVM libraries to link to.
+  ArrayRef<Attribute> getLibrariesToLink() const;
 
   /// Returns the command line options.
   StringRef getCmdOptions() const;
@@ -113,7 +113,7 @@ class TargetOptions {
   /// appropiate value: ie. `TargetOptions(TypeID::get<DerivedClass>())`.
   TargetOptions(
       TypeID typeID, StringRef toolkitPath = {},
-      ArrayRef<std::string> linkFiles = {}, StringRef cmdOptions = {},
+      ArrayRef<Attribute> librariesToLink = {}, StringRef cmdOptions = {},
       StringRef elfSection = {},
       CompilationTarget compilationTarget = getDefaultCompilationTarget(),
       function_ref<SymbolTable *()> getSymbolTableCallback = {},
@@ -126,7 +126,7 @@ class TargetOptions {
   std::string toolkitPath;
 
   /// List of files to link with the LLVM module.
-  SmallVector<std::string> linkFiles;
+  SmallVector<Attribute> librariesToLink;
 
   /// An optional set of command line options to be used by the compilation
   /// process.
diff --git a/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td b/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td
index 954429c7d8eaeb..017559cc353e6b 100644
--- a/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td
+++ b/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td
@@ -34,6 +34,24 @@ def TypedAttrInterface : AttrInterface<"TypedAttr"> {
   >];
 }
 
+//===----------------------------------------------------------------------===//
+// BlobAttrInterface
+//===----------------------------------------------------------------------===//
+
+def BlobAttrInterface : AttrInterface<"BlobAttr"> {
+  let cppNamespace = "::mlir";
+  let description = [{
+    This interface allows an attribute to expose a blob of data without more
+    information. The data must be stored so that it can be accessed as a
+    contiguous ArrayRef.
+  }];
+
+  let methods = [InterfaceMethod<
+    "Get the attribute's data",
+    "::llvm::ArrayRef<char>", "getData"
+  >];
+}
+
 //===----------------------------------------------------------------------===//
 // ElementsAttrInterface
 //===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/IR/BuiltinAttributes.td b/mlir/include/mlir/IR/BuiltinAttributes.td
index 492b8309a5ea33..06f5e172a9909d 100644
--- a/mlir/include/mlir/IR/BuiltinAttributes.td
+++ b/mlir/include/mlir/IR/BuiltinAttributes.td
@@ -153,7 +153,8 @@ def Builtin_DenseArrayRawDataParameter : ArrayRefParameter<
   }];
 }
 
-def Builtin_DenseArray : Builtin_Attr<"DenseArray", "dense_array"> {
+def Builtin_DenseArray : Builtin_Attr<"DenseArray", "dense_array", 
+    [BlobAttrInterface]> {
   let summary = "A dense array of integer or floating point elements.";
   let description = [{
     A dense array attribute is an attribute that represents a dense array of
@@ -211,6 +212,10 @@ def Builtin_DenseArray : Builtin_Attr<"DenseArray", "dense_array"> {
     int64_t size() const { return getSize(); }
     /// Return true if there are no elements in the dense array.
     bool empty() const { return !size(); }
+    /// BlobAttrInterface method.
+    ArrayRef<char> getData() {
+      return getRawData();
+    }
   }];
 }
 
@@ -431,7 +436,7 @@ def Builtin_DenseStringElementsAttr : Builtin_Attr<
 //===----------------------------------------------------------------------===//
 
 def Builtin_DenseResourceElementsAttr : Builtin_Attr<"DenseResourceElements",
-    "dense_resource_elements", [ElementsAttrInterface]> {
+    "dense_resource_elements", [ElementsAttrInterface, BlobAttrInterface]> {
   let summary = "An Attribute containing a dense multi-dimensional array "
                 "backed by a resource";
   let description = [{
@@ -485,6 +490,10 @@ def Builtin_DenseResourceElementsAttr : Builtin_Attr<"DenseResourceElements",
       "ShapedType":$type, "StringRef":$blobName, "AsmResourceBlob":$blob
     )>
   ];
+  let extraClassDeclaration = [{
+    /// BlobAttrInterface method.
+    ArrayRef<char> getData();
+  }];
 
   let skipDefaultBuilders = 1;
 }
diff --git a/mlir/include/mlir/Target/LLVM/ModuleToObject.h b/mlir/include/mlir/Target/LLVM/ModuleToObject.h
index 07fc55b41ae9c5..11fea6f0a44432 100644
--- a/mlir/include/mlir/Target/LLVM/ModuleToObject.h
+++ b/mlir/include/mlir/Target/LLVM/ModuleToObject.h
@@ -83,7 +83,7 @@ class ModuleToObject {
 
   /// Loads multiple bitcode files.
   LogicalResult loadBitcodeFilesFromList(
-      llvm::LLVMContext &context, ArrayRef<std::string> fileList,
+      llvm::LLVMContext &context, ArrayRef<Attribute> librariesToLink,
       SmallVector<std::unique_ptr<llvm::Module>> &llvmModules,
       bool failureOnError = true);
 
diff --git a/mlir/include/mlir/Target/LLVM/NVVM/Utils.h b/mlir/include/mlir/Target/LLVM/NVVM/Utils.h
index 65ae8a6bdb4ada..2d6157b1e5a60d 100644
--- a/mlir/include/mlir/Target/LLVM/NVVM/Utils.h
+++ b/mlir/include/mlir/Target/LLVM/NVVM/Utils.h
@@ -46,14 +46,15 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
   /// Returns the CUDA toolkit path.
   StringRef getToolkitPath() const;
 
-  /// Returns the bitcode files to be loaded.
-  ArrayRef<std::string> getFileList() const;
+  /// Returns the bitcode libraries to be linked into the gpu module after
+  /// translation to LLVM IR.
+  ArrayRef<Attribute> getLibrariesToLink() const;
 
-  /// Appends `nvvm/libdevice.bc` into `fileList`. Returns failure if the
+  /// Appends `nvvm/libdevice.bc` into `librariesToLink`. Returns failure if the
   /// library couldn't be found.
   LogicalResult appendStandardLibs();
 
-  /// Loads the bitcode files in `fileList`.
+  /// Loads the bitcode files in `librariesToLink`.
   virtual std::optional<SmallVector<std::unique_ptr<llvm::Module>>>
   loadBitcodeFiles(llvm::Module &module) override;
 
@@ -64,8 +65,10 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
   /// CUDA toolkit path.
   std::string toolkitPath;
 
-  /// List of LLVM bitcode files to link to.
-  SmallVector<std::string> fileList;
+  /// List of LLVM bitcode to link into after translation to LLVM IR.
+  /// The attributes can be StringAttr pointing to a file path, or
+  /// a Resource blob pointing to the LLVM bitcode in-memory.
+  SmallVector<Attribute> librariesToLink;
 };
 } // namespace NVVM
 } // namespace mlir
diff --git a/mlir/include/mlir/Target/LLVM/ROCDL/Utils.h b/mlir/include/mlir/Target/LLVM/ROCDL/Utils.h
index 2d8204b55d360d..8f5d4162984fac 100644
--- a/mlir/include/mlir/Target/LLVM/ROCDL/Utils.h
+++ b/mlir/include/mlir/Target/LLVM/ROCDL/Utils.h
@@ -16,6 +16,7 @@
 #include "mlir/Dialect/GPU/IR/CompilationInterfaces.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Dialect/LLVMIR/ROCDLDialect.h"
+#include "mlir/IR/Attributes.h"
 #include "mlir/Support/LLVM.h"
 #include "mlir/Target/LLVM/ModuleToObject.h"
 
@@ -61,8 +62,8 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
   /// Returns the ROCM toolkit path.
   StringRef getToolkitPath() const;
 
-  /// Returns the bitcode files to be loaded.
-  ArrayRef<std::string> getFileList() const;
+  /// Returns the LLVM bitcode libraries to be linked.
+  ArrayRef<Attribute> getLibrariesToLink() const;
 
   /// Appends standard ROCm device libraries to `fileList`.
   LogicalResult appendStandardLibs(AMDGCNLibraries libs);
@@ -107,7 +108,7 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
   std::string toolkitPath;
 
   /// List of LLVM bitcode files to link to.
-  SmallVector<std::string> fileList;
+  SmallVector<Attribute> librariesToLink;
 
   /// AMD GCN libraries to use when linking, the default is using none.
   AMDGCNLibraries deviceLibs = AMDGCNLibraries::None;
diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
index 1fad251b2f79e0..ed2d81ee65eb4a 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -2483,7 +2483,7 @@ KernelMetadataAttr KernelTableAttr::lookup(StringAttr key) const {
 //===----------------------------------------------------------------------===//
 
 TargetOptions::TargetOptions(
-    StringRef toolkitPath, ArrayRef<std::string> linkFiles,
+    StringRef toolkitPath, ArrayRef<Attribute> librariesToLink,
     StringRef cmdOptions, StringRef elfSection,
     CompilationTarget compilationTarget,
     function_ref<SymbolTable *()> getSymbolTableCallback,
@@ -2491,14 +2491,14 @@ TargetOptions::TargetOptions(
     function_ref<void(llvm::Module &)> linkedLlvmIRCallback,
     function_ref<void(llvm::Module &)> optimizedLlvmIRCallback,
     function_ref<void(StringRef)> isaCallback)
-    : TargetOptions(TypeID::get<TargetOptions>(), toolkitPath, linkFiles,
+    : TargetOptions(TypeID::get<TargetOptions>(), toolkitPath, librariesToLink,
                     cmdOptions, elfSection, compilationTarget,
                     getSymbolTableCallback, initialLlvmIRCallback,
                     linkedLlvmIRCallback, optimizedLlvmIRCallback,
                     isaCallback) {}
 
 TargetOptions::TargetOptions(
-    TypeID typeID, StringRef toolkitPath, ArrayRef<std::string> linkFiles,
+    TypeID typeID, StringRef toolkitPath, ArrayRef<Attribute> librariesToLink,
     StringRef cmdOptions, StringRef elfSection,
     CompilationTarget compilationTarget,
     function_ref<SymbolTable *()> getSymbolTableCallback,
@@ -2506,7 +2506,7 @@ TargetOptions::TargetOptions(
     function_ref<void(llvm::Module &)> linkedLlvmIRCallback,
     function_ref<void(llvm::Module &)> optimizedLlvmIRCallback,
     function_ref<void(StringRef)> isaCallback)
-    : toolkitPath(toolkitPath.str()), linkFiles(linkFiles),
+    : toolkitPath(toolkitPath.str()), librariesToLink(librariesToLink),
       cmdOptions(cmdOptions.str()), elfSection(elfSection.str()),
       compilationTarget(compilationTarget),
       getSymbolTableCallback(getSymbolTableCallback),
@@ -2519,7 +2519,9 @@ TypeID TargetOptions::getTypeID() const { return typeID; }
 
 StringRef TargetOptions::getToolkitPath() const { return toolkitPath; }
 
-ArrayRef<std::string> TargetOptions::getLinkFiles() const { return linkFiles; }
+ArrayRef<Attribute> TargetOptions::getLibrariesToLink() const {
+  return librariesToLink;
+}
 
 StringRef TargetOptions::getCmdOptions() const { return cmdOptions; }
 
diff --git a/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp b/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
index 295ece4782fdbf..86f741f0b640a9 100644
--- a/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
@@ -68,8 +68,10 @@ void GpuModuleToBinaryPass::runOnOperation() {
     }
     return &parentTable.value();
   };
-
-  TargetOptions targetOptions(toolkitPath, linkFiles, cmdOptions, elfSection,
+  SmallVector<Attribute> librariesToLink;
+  for (const std::string &path : linkFiles)
+    librariesToLink.push_back(StringAttr::get(&getContext(), path));
+  TargetOptions targetOptions(toolkitPath, librariesToLink, cmdOptions, elfSection,
                               *targetFormat, lazyTableBuilder);
   if (failed(transformGpuModulesToBinaries(
           getOperation(), OffloadingLLVMTranslationAttrInterface(nullptr),
diff --git a/mlir/lib/IR/BuiltinAttributes.cpp b/mlir/lib/IR/BuiltinAttributes.cpp
index f288dd42baaa16..70882b994f0e7e 100644
--- a/mlir/lib/IR/BuiltinAttributes.cpp
+++ b/mlir/lib/IR/BuiltinAttributes.cpp
@@ -862,6 +862,7 @@ DenseArrayAttrImpl<T> DenseArrayAttrImpl<T>::get(MLIRContext *context,
   Type elementType = DenseArrayAttrUtil<T>::getElementType(context);
   auto rawArray = ArrayRef<char>(reinterpret_cast<const char *>(content.data()),
                                  content.size() * sizeof(T));
+  llvm::errs() << " sizeof(T) " << sizeof(T) << "\n";
   return llvm::cast<DenseArrayAttrImpl<T>>(
       Base::get(context, elementType, content.size(), rawArray));
 }
@@ -1544,6 +1545,12 @@ DenseResourceElementsAttr DenseResourceElementsAttr::get(ShapedType type,
   return get(type, manager.insert(blobName, std::move(blob)));
 }
 
+ArrayRef<char> DenseResourceElementsAttr::getData() {
+  if (AsmResourceBlob *blob = this->getRawHandle().getBlob())
+    return blob->template getDataAs<char>();
+  return {};
+}
+
 //===----------------------------------------------------------------------===//
 // DenseResourceElementsAttrBase
 
diff --git a/mlir/lib/Target/LLVM/ModuleToObject.cpp b/mlir/lib/Target/LLVM/ModuleToObject.cpp
index 3f5b3d5e31864b..442c799fffe7da 100644
--- a/mlir/lib/Target/LLVM/ModuleToObject.cpp
+++ b/mlir/lib/Target/LLVM/ModuleToObject.cpp
@@ -14,6 +14,8 @@
 #include "mlir/Target/LLVM/ModuleToObject.h"
 
 #include "mlir/ExecutionEngine/OptUtils.h"
+#include "mlir/IR/BuiltinAttributeInterfaces.h"
+#include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Export.h"
@@ -25,6 +27,7 @@
 #include "llvm/Linker/Linker.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/raw_ostream.h"
@@ -89,22 +92,51 @@ ModuleToObject::loadBitcodeFile(llvm::LLVMContext &context, StringRef path) {
 }
 
 LogicalResult ModuleToObject::loadBitcodeFilesFromList(
-    llvm::LLVMContext &context, ArrayRef<std::string> fileList,
+    llvm::LLVMContext &context, ArrayRef<Attribute> librariesToLink,
     SmallVector<std::unique_ptr<llvm::Module>> &llvmModules,
     bool failureOnError) {
-  for (const std::string &str : fileList) {
-    // Test if the path exists, if it doesn't abort.
-    StringRef pathRef = StringRef(str.data(), str.size());
-    if (!llvm::sys::fs::is_regular_file(pathRef)) {
+  for (Attribute linkLib : librariesToLink) {
+    // Attributes in this list can be either list of file paths using
+    // StringAttr, or a resource attribute pointing to the LLVM bitcode in
+    // memory.
+    if (auto filePath = dyn_cast<StringAttr>(linkLib)) {
+      // Test if the path exists, if it doesn't abort.
+      if (!llvm::sys::fs::is_regular_file(filePath.strref())) {
+        getOperation().emitError()
+            << "File path: " << filePath << " does not exist or is not a file.";
+        return failure();
+      }
+      // Load the file or abort on error.
+      if (auto bcFile = loadBitcodeFile(context, filePath))
+        llvmModules.push_back(std::move(bcFile));
+      else if (failureOnError)
+        return failure();
+      continue;
+    }
+    if (auto blobAttr = dyn_cast<BlobAttr>(linkLib)) {
+      // Load the file or abort on error.
+      llvm::SMDiagnostic error;
+      ArrayRef<char> data = blobAttr.getData();
+      std::unique_ptr<llvm::MemoryBuffer> buffer =
+          llvm::MemoryBuffer::getMemBuffer(StringRef(data.data(), data.size()),
+                                           "blobLinkedLib",
+                                           /*RequiresNullTerminator=*/false);
+      std::unique_ptr<llvm::Module> mod =
+          getLazyIRModule(std::move(buffer), error, context);
+      if (mod) {
+        llvmModules.push_back(std::move(mod));
+      } else if (failureOnError) {
+        getOperation().emitError()
+            << "Couldn't load LLVM library for linking: " << error.getMessage();
+        return failure();
+      }
+      continue;
+    }
+    if (failureOnError) {
       getOperation().emitError()
-          << "File path: " << pathRef << " does not exist or is not a file.\n";
+          << "Unknown attribute describing LLVM library to load: " << linkLib;
       return failure();
     }
-    // Load the file or abort on error.
-    if (auto bcFile = loadBitcodeFile(context, pathRef))
-      llvmModules.push_back(std::move(bcFile));
-    else if (failureOnError)
-      return failure();
   }
   return success();
 }
diff --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp
index 745c1a5a6ee601..a9f7806b10f404 100644
--- a/mlir/lib/Target/LLVM/NVVM/Target.cpp
+++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp
@@ -93,17 +93,15 @@ SerializeGPUModuleBase::SerializeGPUModuleBase(
                      targetOptions.getOptimizedLlvmIRCallback(),
                      targetOptions.getISACallback()),
       target(target), toolkitPath(targetOptions.getToolkitPath()),
-      fileList(targetOptions.getLinkFiles()) {
+      librariesToLink(targetOptions.getLibrariesToLink()) {
 
   // If `targetOptions` have an empty toolkitPath use `getCUDAToolkitPath`
   if (toolkitPath.empty())
     toolkitPath = getCUDAToolkitPath();
 
   // Append the files in the target attribute.
-  if (ArrayAttr files = target.getLink())
-    for (Attribute attr : files.getValue())
-      if (auto file = dyn_cast<StringAttr>(attr))
-        fileList.push_back(file.str());
+  if (target.getLink())
+    librariesToLink.append(target.getLink().begin(), target.getLink().end());
 
   // Append libdevice to the files to be loaded.
   (void)appendStandardLibs();
@@ -126,8 +124,8 @@ NVVMTargetAttr SerializeGPUModuleBase::getTarget() const { return target; }
 
 StringRef SerializeGPUModuleBase::getToolkitPath() const { return toolkitPath; }
 
-ArrayRef<std::string> SerializeGPUModuleBase::getFileList() const {
-  return fileList;
+ArrayRef<Attribute> SerializeGPUModuleBase::getLibrariesToLink() const {
+  return librariesToLink;
 }
 
 // Try to append `libdevice` from a CUDA toolkit installation.
@@ -149,7 +147,7 @@ LogicalResult SerializeGPUModuleBase::appendStandardLibs() {
                                  << " does not exist or is not a file.\n";
       return failure();
     }
-    fileList.push_back(pathRef.str());
+    librariesToLink.push_back(StringAttr::get(target.getContext(), pathRef));
   }
   return success();
 }
@@ -157,8 +155,8 @@ LogicalResult SerializeGPUModuleBase::appendStandardLibs() {
 std::optional<SmallVector<std::unique_ptr<llvm::Module>>>
 SerializeGPUModuleBase::loadBitcodeFiles(llvm::Module &module) {
   SmallVector<std::unique_ptr<llvm::Module>> bcFiles;
-  if (failed(loadBitcodeFilesFromList(module.getContext(), fileList, bcFiles,
-                                      true)))
+  if (failed(loadBitcodeFilesFromList(module.getContext(), librariesToLink,
+                                      bcFiles, true)))
     return std::nullopt;
   return std::move(bcFiles);
 }
diff --git a/mlir/lib/Target/LLVM/ROCDL/Target.cpp b/mlir/lib/Target/LLVM/ROCDL/Target.cpp
index 227b45133b57e3..cd7a67e58d612b 100644
--- a/mlir/lib/Target/LLVM/ROCDL/Target.cpp
+++ b/mlir/lib/Target/LLVM/ROCDL/Target.cpp
@@ -97,17 +97,15 @@ SerializeGPUModuleBase::SerializeGPUModuleBase(
     : ModuleToObject(module, target.getTriple(), target.getChip(),
                      target.getFeatures(), target.getO()),
       target(target), toolkitPath(targetOptions.getToolkitPath()),
-      fileList(targetOptions.getLinkFiles()) {
+      librariesToLink(targetOptions.getLibrariesToLink()) {
 
   // If `targetOptions` has an empty toolkitPath use `getROCMPath`
   if (toolkitPath.empty())
     toolkitPath = getROCMPath();
 
   // Append the files in the target attribute.
-  if (ArrayAttr files = target.getLink())
-    for (Attribute attr : files.getValue())
-      if (auto file = dyn_cast<StringAttr>(attr))
-        fileList.push_back(file.str());
+  if (target.getLink())
+    librariesToLink.append(target.getLink().begin(), target.getLink().end());
 }
 
 void SerializeGPUModuleBase::init() {
@@ -128,8 +126,8 @@ ROCDLTarge...
[truncated]

@llvmbot
Copy link
Member

llvmbot commented Dec 16, 2024

@llvm/pr-subscribers-mlir-llvm

Author: Mehdi Amini (joker-eph)

Changes

This change allows to expose through an interface attributes wrapping content as external
resources, and the usage inside the ModuleToObject show how we will be able to provide
runtime libraries without relying on the filesystem.


Patch is 25.57 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/120116.diff

14 Files Affected:

  • (modified) mlir/include/mlir/Dialect/GPU/IR/CompilationInterfaces.h (+5-5)
  • (modified) mlir/include/mlir/IR/BuiltinAttributeInterfaces.td (+18)
  • (modified) mlir/include/mlir/IR/BuiltinAttributes.td (+11-2)
  • (modified) mlir/include/mlir/Target/LLVM/ModuleToObject.h (+1-1)
  • (modified) mlir/include/mlir/Target/LLVM/NVVM/Utils.h (+9-6)
  • (modified) mlir/include/mlir/Target/LLVM/ROCDL/Utils.h (+4-3)
  • (modified) mlir/lib/Dialect/GPU/IR/GPUDialect.cpp (+7-5)
  • (modified) mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp (+4-2)
  • (modified) mlir/lib/IR/BuiltinAttributes.cpp (+7)
  • (modified) mlir/lib/Target/LLVM/ModuleToObject.cpp (+43-11)
  • (modified) mlir/lib/Target/LLVM/NVVM/Target.cpp (+8-10)
  • (modified) mlir/lib/Target/LLVM/ROCDL/Target.cpp (+9-11)
  • (modified) mlir/unittests/Target/LLVM/CMakeLists.txt (+4)
  • (modified) mlir/unittests/Target/LLVM/SerializeNVVMTarget.cpp (+72)
diff --git a/mlir/include/mlir/Dialect/GPU/IR/CompilationInterfaces.h b/mlir/include/mlir/Dialect/GPU/IR/CompilationInterfaces.h
index 5b6e03a2e6e75e..c950ef220f692f 100644
--- a/mlir/include/mlir/Dialect/GPU/IR/CompilationInterfaces.h
+++ b/mlir/include/mlir/Dialect/GPU/IR/CompilationInterfaces.h
@@ -51,7 +51,7 @@ class TargetOptions {
   /// obtaining the parent symbol table. The default compilation target is
   /// `Fatbin`.
   TargetOptions(
-      StringRef toolkitPath = {}, ArrayRef<std::string> linkFiles = {},
+      StringRef toolkitPath = {}, ArrayRef<Attribute> librariesToLink = {},
       StringRef cmdOptions = {}, StringRef elfSection = {},
       CompilationTarget compilationTarget = getDefaultCompilationTarget(),
       function_ref<SymbolTable *()> getSymbolTableCallback = {},
@@ -66,8 +66,8 @@ class TargetOptions {
   /// Returns the toolkit path.
   StringRef getToolkitPath() const;
 
-  /// Returns the files to link to.
-  ArrayRef<std::string> getLinkFiles() const;
+  /// Returns the LLVM libraries to link to.
+  ArrayRef<Attribute> getLibrariesToLink() const;
 
   /// Returns the command line options.
   StringRef getCmdOptions() const;
@@ -113,7 +113,7 @@ class TargetOptions {
   /// appropiate value: ie. `TargetOptions(TypeID::get<DerivedClass>())`.
   TargetOptions(
       TypeID typeID, StringRef toolkitPath = {},
-      ArrayRef<std::string> linkFiles = {}, StringRef cmdOptions = {},
+      ArrayRef<Attribute> librariesToLink = {}, StringRef cmdOptions = {},
       StringRef elfSection = {},
       CompilationTarget compilationTarget = getDefaultCompilationTarget(),
       function_ref<SymbolTable *()> getSymbolTableCallback = {},
@@ -126,7 +126,7 @@ class TargetOptions {
   std::string toolkitPath;
 
   /// List of files to link with the LLVM module.
-  SmallVector<std::string> linkFiles;
+  SmallVector<Attribute> librariesToLink;
 
   /// An optional set of command line options to be used by the compilation
   /// process.
diff --git a/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td b/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td
index 954429c7d8eaeb..017559cc353e6b 100644
--- a/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td
+++ b/mlir/include/mlir/IR/BuiltinAttributeInterfaces.td
@@ -34,6 +34,24 @@ def TypedAttrInterface : AttrInterface<"TypedAttr"> {
   >];
 }
 
+//===----------------------------------------------------------------------===//
+// BlobAttrInterface
+//===----------------------------------------------------------------------===//
+
+def BlobAttrInterface : AttrInterface<"BlobAttr"> {
+  let cppNamespace = "::mlir";
+  let description = [{
+    This interface allows an attribute to expose a blob of data without more
+    information. The data must be stored so that it can be accessed as a
+    contiguous ArrayRef.
+  }];
+
+  let methods = [InterfaceMethod<
+    "Get the attribute's data",
+    "::llvm::ArrayRef<char>", "getData"
+  >];
+}
+
 //===----------------------------------------------------------------------===//
 // ElementsAttrInterface
 //===----------------------------------------------------------------------===//
diff --git a/mlir/include/mlir/IR/BuiltinAttributes.td b/mlir/include/mlir/IR/BuiltinAttributes.td
index 492b8309a5ea33..06f5e172a9909d 100644
--- a/mlir/include/mlir/IR/BuiltinAttributes.td
+++ b/mlir/include/mlir/IR/BuiltinAttributes.td
@@ -153,7 +153,8 @@ def Builtin_DenseArrayRawDataParameter : ArrayRefParameter<
   }];
 }
 
-def Builtin_DenseArray : Builtin_Attr<"DenseArray", "dense_array"> {
+def Builtin_DenseArray : Builtin_Attr<"DenseArray", "dense_array", 
+    [BlobAttrInterface]> {
   let summary = "A dense array of integer or floating point elements.";
   let description = [{
     A dense array attribute is an attribute that represents a dense array of
@@ -211,6 +212,10 @@ def Builtin_DenseArray : Builtin_Attr<"DenseArray", "dense_array"> {
     int64_t size() const { return getSize(); }
     /// Return true if there are no elements in the dense array.
     bool empty() const { return !size(); }
+    /// BlobAttrInterface method.
+    ArrayRef<char> getData() {
+      return getRawData();
+    }
   }];
 }
 
@@ -431,7 +436,7 @@ def Builtin_DenseStringElementsAttr : Builtin_Attr<
 //===----------------------------------------------------------------------===//
 
 def Builtin_DenseResourceElementsAttr : Builtin_Attr<"DenseResourceElements",
-    "dense_resource_elements", [ElementsAttrInterface]> {
+    "dense_resource_elements", [ElementsAttrInterface, BlobAttrInterface]> {
   let summary = "An Attribute containing a dense multi-dimensional array "
                 "backed by a resource";
   let description = [{
@@ -485,6 +490,10 @@ def Builtin_DenseResourceElementsAttr : Builtin_Attr<"DenseResourceElements",
       "ShapedType":$type, "StringRef":$blobName, "AsmResourceBlob":$blob
     )>
   ];
+  let extraClassDeclaration = [{
+    /// BlobAttrInterface method.
+    ArrayRef<char> getData();
+  }];
 
   let skipDefaultBuilders = 1;
 }
diff --git a/mlir/include/mlir/Target/LLVM/ModuleToObject.h b/mlir/include/mlir/Target/LLVM/ModuleToObject.h
index 07fc55b41ae9c5..11fea6f0a44432 100644
--- a/mlir/include/mlir/Target/LLVM/ModuleToObject.h
+++ b/mlir/include/mlir/Target/LLVM/ModuleToObject.h
@@ -83,7 +83,7 @@ class ModuleToObject {
 
   /// Loads multiple bitcode files.
   LogicalResult loadBitcodeFilesFromList(
-      llvm::LLVMContext &context, ArrayRef<std::string> fileList,
+      llvm::LLVMContext &context, ArrayRef<Attribute> librariesToLink,
       SmallVector<std::unique_ptr<llvm::Module>> &llvmModules,
       bool failureOnError = true);
 
diff --git a/mlir/include/mlir/Target/LLVM/NVVM/Utils.h b/mlir/include/mlir/Target/LLVM/NVVM/Utils.h
index 65ae8a6bdb4ada..2d6157b1e5a60d 100644
--- a/mlir/include/mlir/Target/LLVM/NVVM/Utils.h
+++ b/mlir/include/mlir/Target/LLVM/NVVM/Utils.h
@@ -46,14 +46,15 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
   /// Returns the CUDA toolkit path.
   StringRef getToolkitPath() const;
 
-  /// Returns the bitcode files to be loaded.
-  ArrayRef<std::string> getFileList() const;
+  /// Returns the bitcode libraries to be linked into the gpu module after
+  /// translation to LLVM IR.
+  ArrayRef<Attribute> getLibrariesToLink() const;
 
-  /// Appends `nvvm/libdevice.bc` into `fileList`. Returns failure if the
+  /// Appends `nvvm/libdevice.bc` into `librariesToLink`. Returns failure if the
   /// library couldn't be found.
   LogicalResult appendStandardLibs();
 
-  /// Loads the bitcode files in `fileList`.
+  /// Loads the bitcode files in `librariesToLink`.
   virtual std::optional<SmallVector<std::unique_ptr<llvm::Module>>>
   loadBitcodeFiles(llvm::Module &module) override;
 
@@ -64,8 +65,10 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
   /// CUDA toolkit path.
   std::string toolkitPath;
 
-  /// List of LLVM bitcode files to link to.
-  SmallVector<std::string> fileList;
+  /// List of LLVM bitcode to link into after translation to LLVM IR.
+  /// The attributes can be StringAttr pointing to a file path, or
+  /// a Resource blob pointing to the LLVM bitcode in-memory.
+  SmallVector<Attribute> librariesToLink;
 };
 } // namespace NVVM
 } // namespace mlir
diff --git a/mlir/include/mlir/Target/LLVM/ROCDL/Utils.h b/mlir/include/mlir/Target/LLVM/ROCDL/Utils.h
index 2d8204b55d360d..8f5d4162984fac 100644
--- a/mlir/include/mlir/Target/LLVM/ROCDL/Utils.h
+++ b/mlir/include/mlir/Target/LLVM/ROCDL/Utils.h
@@ -16,6 +16,7 @@
 #include "mlir/Dialect/GPU/IR/CompilationInterfaces.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
 #include "mlir/Dialect/LLVMIR/ROCDLDialect.h"
+#include "mlir/IR/Attributes.h"
 #include "mlir/Support/LLVM.h"
 #include "mlir/Target/LLVM/ModuleToObject.h"
 
@@ -61,8 +62,8 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
   /// Returns the ROCM toolkit path.
   StringRef getToolkitPath() const;
 
-  /// Returns the bitcode files to be loaded.
-  ArrayRef<std::string> getFileList() const;
+  /// Returns the LLVM bitcode libraries to be linked.
+  ArrayRef<Attribute> getLibrariesToLink() const;
 
   /// Appends standard ROCm device libraries to `fileList`.
   LogicalResult appendStandardLibs(AMDGCNLibraries libs);
@@ -107,7 +108,7 @@ class SerializeGPUModuleBase : public LLVM::ModuleToObject {
   std::string toolkitPath;
 
   /// List of LLVM bitcode files to link to.
-  SmallVector<std::string> fileList;
+  SmallVector<Attribute> librariesToLink;
 
   /// AMD GCN libraries to use when linking, the default is using none.
   AMDGCNLibraries deviceLibs = AMDGCNLibraries::None;
diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
index 1fad251b2f79e0..ed2d81ee65eb4a 100644
--- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
+++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
@@ -2483,7 +2483,7 @@ KernelMetadataAttr KernelTableAttr::lookup(StringAttr key) const {
 //===----------------------------------------------------------------------===//
 
 TargetOptions::TargetOptions(
-    StringRef toolkitPath, ArrayRef<std::string> linkFiles,
+    StringRef toolkitPath, ArrayRef<Attribute> librariesToLink,
     StringRef cmdOptions, StringRef elfSection,
     CompilationTarget compilationTarget,
     function_ref<SymbolTable *()> getSymbolTableCallback,
@@ -2491,14 +2491,14 @@ TargetOptions::TargetOptions(
     function_ref<void(llvm::Module &)> linkedLlvmIRCallback,
     function_ref<void(llvm::Module &)> optimizedLlvmIRCallback,
     function_ref<void(StringRef)> isaCallback)
-    : TargetOptions(TypeID::get<TargetOptions>(), toolkitPath, linkFiles,
+    : TargetOptions(TypeID::get<TargetOptions>(), toolkitPath, librariesToLink,
                     cmdOptions, elfSection, compilationTarget,
                     getSymbolTableCallback, initialLlvmIRCallback,
                     linkedLlvmIRCallback, optimizedLlvmIRCallback,
                     isaCallback) {}
 
 TargetOptions::TargetOptions(
-    TypeID typeID, StringRef toolkitPath, ArrayRef<std::string> linkFiles,
+    TypeID typeID, StringRef toolkitPath, ArrayRef<Attribute> librariesToLink,
     StringRef cmdOptions, StringRef elfSection,
     CompilationTarget compilationTarget,
     function_ref<SymbolTable *()> getSymbolTableCallback,
@@ -2506,7 +2506,7 @@ TargetOptions::TargetOptions(
     function_ref<void(llvm::Module &)> linkedLlvmIRCallback,
     function_ref<void(llvm::Module &)> optimizedLlvmIRCallback,
     function_ref<void(StringRef)> isaCallback)
-    : toolkitPath(toolkitPath.str()), linkFiles(linkFiles),
+    : toolkitPath(toolkitPath.str()), librariesToLink(librariesToLink),
       cmdOptions(cmdOptions.str()), elfSection(elfSection.str()),
       compilationTarget(compilationTarget),
       getSymbolTableCallback(getSymbolTableCallback),
@@ -2519,7 +2519,9 @@ TypeID TargetOptions::getTypeID() const { return typeID; }
 
 StringRef TargetOptions::getToolkitPath() const { return toolkitPath; }
 
-ArrayRef<std::string> TargetOptions::getLinkFiles() const { return linkFiles; }
+ArrayRef<Attribute> TargetOptions::getLibrariesToLink() const {
+  return librariesToLink;
+}
 
 StringRef TargetOptions::getCmdOptions() const { return cmdOptions; }
 
diff --git a/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp b/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
index 295ece4782fdbf..86f741f0b640a9 100644
--- a/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
+++ b/mlir/lib/Dialect/GPU/Transforms/ModuleToBinary.cpp
@@ -68,8 +68,10 @@ void GpuModuleToBinaryPass::runOnOperation() {
     }
     return &parentTable.value();
   };
-
-  TargetOptions targetOptions(toolkitPath, linkFiles, cmdOptions, elfSection,
+  SmallVector<Attribute> librariesToLink;
+  for (const std::string &path : linkFiles)
+    librariesToLink.push_back(StringAttr::get(&getContext(), path));
+  TargetOptions targetOptions(toolkitPath, librariesToLink, cmdOptions, elfSection,
                               *targetFormat, lazyTableBuilder);
   if (failed(transformGpuModulesToBinaries(
           getOperation(), OffloadingLLVMTranslationAttrInterface(nullptr),
diff --git a/mlir/lib/IR/BuiltinAttributes.cpp b/mlir/lib/IR/BuiltinAttributes.cpp
index f288dd42baaa16..70882b994f0e7e 100644
--- a/mlir/lib/IR/BuiltinAttributes.cpp
+++ b/mlir/lib/IR/BuiltinAttributes.cpp
@@ -862,6 +862,7 @@ DenseArrayAttrImpl<T> DenseArrayAttrImpl<T>::get(MLIRContext *context,
   Type elementType = DenseArrayAttrUtil<T>::getElementType(context);
   auto rawArray = ArrayRef<char>(reinterpret_cast<const char *>(content.data()),
                                  content.size() * sizeof(T));
+  llvm::errs() << " sizeof(T) " << sizeof(T) << "\n";
   return llvm::cast<DenseArrayAttrImpl<T>>(
       Base::get(context, elementType, content.size(), rawArray));
 }
@@ -1544,6 +1545,12 @@ DenseResourceElementsAttr DenseResourceElementsAttr::get(ShapedType type,
   return get(type, manager.insert(blobName, std::move(blob)));
 }
 
+ArrayRef<char> DenseResourceElementsAttr::getData() {
+  if (AsmResourceBlob *blob = this->getRawHandle().getBlob())
+    return blob->template getDataAs<char>();
+  return {};
+}
+
 //===----------------------------------------------------------------------===//
 // DenseResourceElementsAttrBase
 
diff --git a/mlir/lib/Target/LLVM/ModuleToObject.cpp b/mlir/lib/Target/LLVM/ModuleToObject.cpp
index 3f5b3d5e31864b..442c799fffe7da 100644
--- a/mlir/lib/Target/LLVM/ModuleToObject.cpp
+++ b/mlir/lib/Target/LLVM/ModuleToObject.cpp
@@ -14,6 +14,8 @@
 #include "mlir/Target/LLVM/ModuleToObject.h"
 
 #include "mlir/ExecutionEngine/OptUtils.h"
+#include "mlir/IR/BuiltinAttributeInterfaces.h"
+#include "mlir/IR/BuiltinAttributes.h"
 #include "mlir/IR/BuiltinOps.h"
 #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Export.h"
@@ -25,6 +27,7 @@
 #include "llvm/Linker/Linker.h"
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/raw_ostream.h"
@@ -89,22 +92,51 @@ ModuleToObject::loadBitcodeFile(llvm::LLVMContext &context, StringRef path) {
 }
 
 LogicalResult ModuleToObject::loadBitcodeFilesFromList(
-    llvm::LLVMContext &context, ArrayRef<std::string> fileList,
+    llvm::LLVMContext &context, ArrayRef<Attribute> librariesToLink,
     SmallVector<std::unique_ptr<llvm::Module>> &llvmModules,
     bool failureOnError) {
-  for (const std::string &str : fileList) {
-    // Test if the path exists, if it doesn't abort.
-    StringRef pathRef = StringRef(str.data(), str.size());
-    if (!llvm::sys::fs::is_regular_file(pathRef)) {
+  for (Attribute linkLib : librariesToLink) {
+    // Attributes in this list can be either list of file paths using
+    // StringAttr, or a resource attribute pointing to the LLVM bitcode in
+    // memory.
+    if (auto filePath = dyn_cast<StringAttr>(linkLib)) {
+      // Test if the path exists, if it doesn't abort.
+      if (!llvm::sys::fs::is_regular_file(filePath.strref())) {
+        getOperation().emitError()
+            << "File path: " << filePath << " does not exist or is not a file.";
+        return failure();
+      }
+      // Load the file or abort on error.
+      if (auto bcFile = loadBitcodeFile(context, filePath))
+        llvmModules.push_back(std::move(bcFile));
+      else if (failureOnError)
+        return failure();
+      continue;
+    }
+    if (auto blobAttr = dyn_cast<BlobAttr>(linkLib)) {
+      // Load the file or abort on error.
+      llvm::SMDiagnostic error;
+      ArrayRef<char> data = blobAttr.getData();
+      std::unique_ptr<llvm::MemoryBuffer> buffer =
+          llvm::MemoryBuffer::getMemBuffer(StringRef(data.data(), data.size()),
+                                           "blobLinkedLib",
+                                           /*RequiresNullTerminator=*/false);
+      std::unique_ptr<llvm::Module> mod =
+          getLazyIRModule(std::move(buffer), error, context);
+      if (mod) {
+        llvmModules.push_back(std::move(mod));
+      } else if (failureOnError) {
+        getOperation().emitError()
+            << "Couldn't load LLVM library for linking: " << error.getMessage();
+        return failure();
+      }
+      continue;
+    }
+    if (failureOnError) {
       getOperation().emitError()
-          << "File path: " << pathRef << " does not exist or is not a file.\n";
+          << "Unknown attribute describing LLVM library to load: " << linkLib;
       return failure();
     }
-    // Load the file or abort on error.
-    if (auto bcFile = loadBitcodeFile(context, pathRef))
-      llvmModules.push_back(std::move(bcFile));
-    else if (failureOnError)
-      return failure();
   }
   return success();
 }
diff --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp
index 745c1a5a6ee601..a9f7806b10f404 100644
--- a/mlir/lib/Target/LLVM/NVVM/Target.cpp
+++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp
@@ -93,17 +93,15 @@ SerializeGPUModuleBase::SerializeGPUModuleBase(
                      targetOptions.getOptimizedLlvmIRCallback(),
                      targetOptions.getISACallback()),
       target(target), toolkitPath(targetOptions.getToolkitPath()),
-      fileList(targetOptions.getLinkFiles()) {
+      librariesToLink(targetOptions.getLibrariesToLink()) {
 
   // If `targetOptions` have an empty toolkitPath use `getCUDAToolkitPath`
   if (toolkitPath.empty())
     toolkitPath = getCUDAToolkitPath();
 
   // Append the files in the target attribute.
-  if (ArrayAttr files = target.getLink())
-    for (Attribute attr : files.getValue())
-      if (auto file = dyn_cast<StringAttr>(attr))
-        fileList.push_back(file.str());
+  if (target.getLink())
+    librariesToLink.append(target.getLink().begin(), target.getLink().end());
 
   // Append libdevice to the files to be loaded.
   (void)appendStandardLibs();
@@ -126,8 +124,8 @@ NVVMTargetAttr SerializeGPUModuleBase::getTarget() const { return target; }
 
 StringRef SerializeGPUModuleBase::getToolkitPath() const { return toolkitPath; }
 
-ArrayRef<std::string> SerializeGPUModuleBase::getFileList() const {
-  return fileList;
+ArrayRef<Attribute> SerializeGPUModuleBase::getLibrariesToLink() const {
+  return librariesToLink;
 }
 
 // Try to append `libdevice` from a CUDA toolkit installation.
@@ -149,7 +147,7 @@ LogicalResult SerializeGPUModuleBase::appendStandardLibs() {
                                  << " does not exist or is not a file.\n";
       return failure();
     }
-    fileList.push_back(pathRef.str());
+    librariesToLink.push_back(StringAttr::get(target.getContext(), pathRef));
   }
   return success();
 }
@@ -157,8 +155,8 @@ LogicalResult SerializeGPUModuleBase::appendStandardLibs() {
 std::optional<SmallVector<std::unique_ptr<llvm::Module>>>
 SerializeGPUModuleBase::loadBitcodeFiles(llvm::Module &module) {
   SmallVector<std::unique_ptr<llvm::Module>> bcFiles;
-  if (failed(loadBitcodeFilesFromList(module.getContext(), fileList, bcFiles,
-                                      true)))
+  if (failed(loadBitcodeFilesFromList(module.getContext(), librariesToLink,
+                                      bcFiles, true)))
     return std::nullopt;
   return std::move(bcFiles);
 }
diff --git a/mlir/lib/Target/LLVM/ROCDL/Target.cpp b/mlir/lib/Target/LLVM/ROCDL/Target.cpp
index 227b45133b57e3..cd7a67e58d612b 100644
--- a/mlir/lib/Target/LLVM/ROCDL/Target.cpp
+++ b/mlir/lib/Target/LLVM/ROCDL/Target.cpp
@@ -97,17 +97,15 @@ SerializeGPUModuleBase::SerializeGPUModuleBase(
     : ModuleToObject(module, target.getTriple(), target.getChip(),
                      target.getFeatures(), target.getO()),
       target(target), toolkitPath(targetOptions.getToolkitPath()),
-      fileList(targetOptions.getLinkFiles()) {
+      librariesToLink(targetOptions.getLibrariesToLink()) {
 
   // If `targetOptions` has an empty toolkitPath use `getROCMPath`
   if (toolkitPath.empty())
     toolkitPath = getROCMPath();
 
   // Append the files in the target attribute.
-  if (ArrayAttr files = target.getLink())
-    for (Attribute attr : files.getValue())
-      if (auto file = dyn_cast<StringAttr>(attr))
-        fileList.push_back(file.str());
+  if (target.getLink())
+    librariesToLink.append(target.getLink().begin(), target.getLink().end());
 }
 
 void SerializeGPUModuleBase::init() {
@@ -128,8 +126,8 @@ ROCDLTarge...
[truncated]

Copy link

github-actions bot commented Dec 16, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@fabianmcg fabianmcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general LGTM, see the comments. Also, cool addition!

Copy link
Contributor

@fabianmcg fabianmcg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! LGTM, See the formatter error.

Copy link
Contributor

@River707 River707 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My gut wants to say BlobInterface could be a method on ElementsAttr (that only works for contiguous data), but there are some warts there that could make it mildly annoying right now. I'm fine with a BlobInterface right now (given it's very direct), we can come back to ElementsAttr later for cleanup.

…nt and use it as linkLibs for ModuleToObject

This change allows to expose through an interface attributes wrapping content as external
resources, and the usage inside the ModuleToObject show how we will be able to provide
runtime libraries without relying on the filesystem.
@joker-eph joker-eph merged commit 72e8b9a into llvm:main Dec 17, 2024
8 checks passed
@joker-eph joker-eph deleted the blobAttr branch December 17, 2024 00:31
@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 17, 2024

LLVM Buildbot has detected a new failure on builder premerge-monolithic-windows running on premerge-windows-1 while building mlir at step 5 "clean-build-dir".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/35/builds/4702

Here is the relevant piece of the build log for the reference
Step 5 (clean-build-dir) failure: Delete failed. (failure)
Step 7 (build-unified-tree) failure: build (failure)
...
[8436/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\openmp-modifiers.cpp.obj
[8437/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\mod-file.cpp.obj
[8438/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\pointer-assignment.cpp.obj
[8439/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\program-tree.cpp.obj
[8440/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\resolve-labels.cpp.obj
[8441/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\resolve-directives.cpp.obj
[8442/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\resolve-names-utils.cpp.obj
[8443/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\resolve-names.cpp.obj
[8444/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\rewrite-directives.cpp.obj
[8445/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\rewrite-parse-tree.cpp.obj
FAILED: tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/rewrite-parse-tree.cpp.obj 
sccache C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe  /nologo /TP -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\flang\lib\Semantics -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Semantics -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\include -Itools\flang\include -Iinclude -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\mlir\include -Itools\mlir\include -Itools\clang\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\clang\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2  -MD  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes /Fotools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\rewrite-parse-tree.cpp.obj /Fdtools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\FortranSemantics.pdb /FS -c C:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Semantics\rewrite-parse-tree.cpp
C:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\include\flang\Evaluate\call.h(94): fatal error C1060: compiler is out of heap space
[8446/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\scope.cpp.obj
FAILED: tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/scope.cpp.obj 
sccache C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe  /nologo /TP -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\flang\lib\Semantics -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Semantics -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\include -Itools\flang\include -Iinclude -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\mlir\include -Itools\mlir\include -Itools\clang\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\clang\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2  -MD  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes /Fotools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\scope.cpp.obj /Fdtools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\FortranSemantics.pdb /FS -c C:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Semantics\scope.cpp
C:\BuildTools\VC\Tools\MSVC\14.29.30133\include\type_traits(2037): fatal error C1060: compiler is out of heap space
[8447/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\runtime-type-info.cpp.obj
FAILED: tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/runtime-type-info.cpp.obj 
sccache C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe  /nologo /TP -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\flang\lib\Semantics -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Semantics -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\include -Itools\flang\include -Iinclude -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\mlir\include -Itools\mlir\include -Itools\clang\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\clang\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2  -MD  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes /Fotools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\runtime-type-info.cpp.obj /Fdtools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\FortranSemantics.pdb /FS -c C:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Semantics\runtime-type-info.cpp
C:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\include\llvm/TargetParser/Triple.h(50): fatal error C1060: compiler is out of heap space
[8448/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\semantics.cpp.obj
FAILED: tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/semantics.cpp.obj 
sccache C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe  /nologo /TP -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\flang\lib\Semantics -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Semantics -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\include -Itools\flang\include -Iinclude -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\mlir\include -Itools\mlir\include -Itools\clang\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\clang\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2  -MD  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes /Fotools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\semantics.cpp.obj /Fdtools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\FortranSemantics.pdb /FS -c C:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Semantics\semantics.cpp

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The paging file is too small for this operation to complete. (Exception from HRESULT: 0x800705AF)
   at shim.ShimProgram.Main(String[] args)
[8449/13026] Building CXX object tools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\symbol.cpp.obj
FAILED: tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/symbol.cpp.obj 
sccache C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe  /nologo /TP -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\flang\lib\Semantics -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Semantics -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\include -Itools\flang\include -Iinclude -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\mlir\include -Itools\mlir\include -Itools\clang\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\clang\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2  -MD  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes /Fotools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\symbol.cpp.obj /Fdtools\flang\lib\Semantics\CMakeFiles\FortranSemantics.dir\FortranSemantics.pdb /FS -c C:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Semantics\symbol.cpp
[8450/13026] Building CXX object tools\flang\lib\Lower\CMakeFiles\FortranLower.dir\VectorSubscripts.cpp.obj
FAILED: tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/VectorSubscripts.cpp.obj 
sccache C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe  /nologo /TP -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\flang\lib\Lower -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Lower -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\include -Itools\flang\include -Iinclude -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\mlir\include -Itools\mlir\include -Itools\clang\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\clang\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2  -MD  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes /Fotools\flang\lib\Lower\CMakeFiles\FortranLower.dir\VectorSubscripts.cpp.obj /Fdtools\flang\lib\Lower\CMakeFiles\FortranLower.dir\FortranLower.pdb /FS -c C:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Lower\VectorSubscripts.cpp
C:\BuildTools\VC\Tools\MSVC\14.29.30133\include\type_traits(1650): fatal error C1060: compiler is out of heap space
[8451/13026] Building CXX object tools\flang\lib\Lower\CMakeFiles\FortranLower.dir\Runtime.cpp.obj
FAILED: tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/Runtime.cpp.obj 
sccache C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe  /nologo /TP -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\flang\lib\Lower -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Lower -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\include -Itools\flang\include -Iinclude -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\mlir\include -Itools\mlir\include -Itools\clang\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\clang\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2  -MD  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes /Fotools\flang\lib\Lower\CMakeFiles\FortranLower.dir\Runtime.cpp.obj /Fdtools\flang\lib\Lower\CMakeFiles\FortranLower.dir\FortranLower.pdb /FS -c C:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Lower\Runtime.cpp
C:\BuildTools\VC\Tools\MSVC\14.29.30133\include\variant(177): fatal error C1060: compiler is out of heap space
[8452/13026] Building CXX object tools\flang\lib\Lower\CMakeFiles\FortranLower.dir\OpenMP\ReductionProcessor.cpp.obj
FAILED: tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/ReductionProcessor.cpp.obj 
sccache C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe  /nologo /TP -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\flang\lib\Lower -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Lower -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\include -Itools\flang\include -Iinclude -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\mlir\include -Itools\mlir\include -Itools\clang\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\clang\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2  -MD  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes /Fotools\flang\lib\Lower\CMakeFiles\FortranLower.dir\OpenMP\ReductionProcessor.cpp.obj /Fdtools\flang\lib\Lower\CMakeFiles\FortranLower.dir\FortranLower.pdb /FS -c C:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Lower\OpenMP\ReductionProcessor.cpp
C:\BuildTools\VC\Tools\MSVC\14.29.30133\include\variant(701): fatal error C1060: compiler is out of heap space
[8453/13026] Building CXX object tools\flang\lib\Lower\CMakeFiles\FortranLower.dir\OpenMP\Utils.cpp.obj
FAILED: tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Utils.cpp.obj 
sccache C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe  /nologo /TP -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\flang\lib\Lower -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Lower -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\include -Itools\flang\include -Iinclude -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\mlir\include -Itools\mlir\include -Itools\clang\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\clang\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2  -MD  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes /Fotools\flang\lib\Lower\CMakeFiles\FortranLower.dir\OpenMP\Utils.cpp.obj /Fdtools\flang\lib\Lower\CMakeFiles\FortranLower.dir\FortranLower.pdb /FS -c C:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Lower\OpenMP\Utils.cpp
C:\BuildTools\VC\Tools\MSVC\14.29.30133\include\variant(479): fatal error C1060: compiler is out of heap space
[8454/13026] Building CXX object tools\flang\lib\Lower\CMakeFiles\FortranLower.dir\OpenMP\Decomposer.cpp.obj
FAILED: tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Decomposer.cpp.obj 
sccache C:\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64\cl.exe  /nologo /TP -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_GLIBCXX_ASSERTIONS -D_HAS_EXCEPTIONS=0 -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools\flang\lib\Lower -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Lower -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\include -Itools\flang\include -Iinclude -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\mlir\include -Itools\mlir\include -Itools\clang\include -IC:\ws\buildbot\premerge-monolithic-windows\llvm-project\llvm\..\clang\include /DWIN32 /D_WINDOWS   /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -wd4251 -wd4275 -w14062 -we4238 /Gw /O2 /Ob2  -MD  /EHs-c- /GR- -UNDEBUG -std:c++17 /showIncludes /Fotools\flang\lib\Lower\CMakeFiles\FortranLower.dir\OpenMP\Decomposer.cpp.obj /Fdtools\flang\lib\Lower\CMakeFiles\FortranLower.dir\FortranLower.pdb /FS -c C:\ws\buildbot\premerge-monolithic-windows\llvm-project\flang\lib\Lower\OpenMP\Decomposer.cpp

norx1991 added a commit that referenced this pull request Dec 17, 2024
Fix bazel build after #120116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants