[mlir] Translate global initializers after creating all LLVM IR globals
authorJean Perier <jperier@nvidia.com>
Thu, 25 Mar 2021 08:40:42 +0000 (09:40 +0100)
committerJean Perier <jperier@nvidia.com>
Thu, 25 Mar 2021 08:53:58 +0000 (09:53 +0100)
commitffa455d4d45168bd30abef036f0f9c8b570c9941
tree1ae6d87c335c944942c93fba1e1e7500be23a003
parent74ed5124bae163c2046d589026cf17f4fa71f6f4
[mlir] Translate global initializers after creating all LLVM IR globals

In case an operation in a global initializer region refers to another
global variable defined afterwards in the module of itself, translation
to LLVM IR was currently crashing because it could not find the LLVM IR global
when going through the initializer block.

To solve this problem, split global conversion to LLVM IR into two passes. A
first pass that creates LLVM IR global variables, and a second one that converts
the initializer, if any, and adds it to the llvm global.

Differential Revision: https://reviews.llvm.org/D99246
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
mlir/test/Target/LLVMIR/llvmir.mlir