This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Explicitly track branch instructions in translation to LLVM IR
ClosedPublic

Authored by ftynse on Dec 8 2020, 7:09 AM.

Details

Summary

The current implementation of the translation to LLVM IR relies on the
existence of a one-to-one mapping between MLIR blocks and LLVM IR basic blocks
in order to configure PHI nodes with appropriate source blocks. The one-to-one
mapping model is broken in presence of OpenMP operations that use LLVM's
OpenMPIRBuilder, which produces multiple blocks under the hood. This can lead
to invalid LLVM IR being emitted if OpenMPIRBuilder moved the branch operation
into a basic block different from the one it was originally created in;
specifically, a block that is not a direct predecessor could be used in the PHI
node. Instead, keep track of the mapping between MLIR LLVM dialect branch
operations and their LLVM IR counterparts and take the parent basic block of
the LLVM IR instruction at the moment of connecting the PHI nodes to
predecessors.

This behavior cannot be triggered as of now, but will be once we introduce the
conversion of OpenMP workshare loops.

Diff Detail

Event Timeline

ftynse created this revision.Dec 8 2020, 7:09 AM
ftynse requested review of this revision.Dec 8 2020, 7:09 AM
rriddle added inline comments.Dec 8 2020, 4:10 PM
mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
158

This will break when the terminator is not a BranchInst, e.g. SwitchInst or CallBr.

ftynse updated this revision to Diff 310480.Dec 9 2020, 3:12 AM

Address review.

mlir/include/mlir/Target/LLVMIR/ModuleTranslation.h
158

We don't have either of those in the LLVM dialect yet, but I updated to Instruction * for future-proofness.

Thanks for fixing this. LGTM.

This revision is now accepted and ready to land.Dec 9 2020, 11:17 AM
This revision was landed with ongoing or failed builds.Dec 10 2020, 2:09 AM
This revision was automatically updated to reflect the committed changes.