Page MenuHomePhabricator

[mlir] Translate global initializers after creating all LLVM IR globals
ClosedPublic

Authored by jeanPerier on Mar 24 2021, 2:04 AM.

Details

Summary

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.

Diff Detail

Event Timeline

jeanPerier created this revision.Mar 24 2021, 2:04 AM
jeanPerier requested review of this revision.Mar 24 2021, 2:04 AM
ftynse accepted this revision.Mar 24 2021, 6:22 AM

Thanks!

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
369

Nit: I would prefer a name that makes it clearer what this function does, e.g. shouldDropGlobalInitializer. The current want reads like it performs the action of dropping

This revision is now accepted and ready to land.Mar 24 2021, 6:22 AM

Rename dropGlobalInitializer to shouldDropGlobalInitializer.

jeanPerier marked an inline comment as done.Mar 25 2021, 1:39 AM
jeanPerier added inline comments.
mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
369

Thanks, that's a better name.

This revision was landed with ongoing or failed builds.Mar 25 2021, 1:54 AM
This revision was automatically updated to reflect the committed changes.
jeanPerier marked an inline comment as done.