[Mlir-commits] [mlir] a428b5a - [mlir][target][LLVMIR] Change translation order to translate non-LLVM ops before function bodies.

Fabian Mora llvmlistbot at llvm.org
Fri Jul 28 06:04:01 PDT 2023


Author: Fabian Mora
Date: 2023-07-28T13:03:41Z
New Revision: a428b5afbd6d48edda9d21ffabd57eee1e7b984d

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

LOG: [mlir][target][LLVMIR] Change translation order to translate non-LLVM ops before function bodies.

Convert function bodies after all other operations, breaking possible declaration-reference issues between top non-LLVM Ops and non-LLVM ops inside function bodies.

Example:
```
mydialect.global @myglobal : i32
llvm.func @bar(...) {
...
%address = mydialect.global_address @myglobal : llvm.ptr
...
}
```
With the previous scheme `mydialect.global_address` always got translated before `mydialect.global`, this change ensures `mydialect.global` gets translated first.

Reviewed By: mehdi_amini

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index 974859cfdd2552..c92b85ff3d2991 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -1391,8 +1391,6 @@ mlir::translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext,
     return nullptr;
   if (failed(translator.createTBAAMetadata()))
     return nullptr;
-  if (failed(translator.convertFunctions()))
-    return nullptr;
 
   // Convert other top-level operations if possible.
   llvm::IRBuilder<> llvmBuilder(llvmContext);
@@ -1405,6 +1403,12 @@ mlir::translateModuleToLLVMIR(Operation *module, llvm::LLVMContext &llvmContext,
     }
   }
 
+  // Operations in function bodies with symbolic references must be converted
+  // after the top-level operations they refer to are declared, so we do it
+  // last.
+  if (failed(translator.convertFunctions()))
+    return nullptr;
+
   // Convert module itself.
   if (failed(translator.convertOperation(*module, llvmBuilder)))
     return nullptr;


        


More information about the Mlir-commits mailing list