[Mlir-commits] [mlir] f478721 - [MLIR][LLVM] Add accessor for LLVMModule and invoke convertDialectAttributes on GlobalOps

Andrew Gozillon llvmlistbot at llvm.org
Thu Apr 27 12:53:19 PDT 2023


Author: Andrew Gozillon
Date: 2023-04-27T14:51:54-05:00
New Revision: f478721231bdb71ba8f0f6fb21673b9b7f652add

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

LOG: [MLIR][LLVM] Add accessor for LLVMModule and invoke convertDialectAttributes on GlobalOps

This patch seeks to do two things add an accessor method to
retrieve the ModuleTranslations contained LLVM Module for direct
usage by dialects that are being lowered to LLVM-IR. One particular
use case for this is in the OpenMP Dialect, when interfacing
with the OMPIRBuilder in certain cases it is useful to be able
to access the LLVM Module directly.

The second is invoking convertDialectAttributes on GlobalOp's
so as to be able to lower dialect specific attributes that are
applied or lowered onto GlobalOp's.

Reviewers: ftynse

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

Added: 
    

Modified: 
    mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
    mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
index 967a3e71c0e46..9e3e05eec25ee 100644
--- a/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
+++ b/mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
@@ -164,6 +164,9 @@ class ModuleTranslation {
   /// constructed.
   llvm::OpenMPIRBuilder *getOpenMPBuilder();
 
+  /// Returns the LLVM module in which the IR is being constructed.
+  llvm::Module *getLLVMModule() { return llvmModule.get(); }
+
   /// Translates the given location.
   const llvm::DILocation *translateLoc(Location loc, llvm::DILocalScope *scope);
 

diff  --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 2251c5ff1e764..f3f5b24876a20 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -771,6 +771,10 @@ LogicalResult ModuleTranslation::convertGlobals() {
     }
   }
 
+  for (auto op : getModuleBody(mlirModule).getOps<LLVM::GlobalOp>())
+    if (failed(convertDialectAttributes(op)))
+      return failure();
+
   return success();
 }
 


        


More information about the Mlir-commits mailing list