LLVM IR dialect and translation: support conditional branches with arguments
authorAlex Zinenko <zinenko@google.com>
Tue, 26 Feb 2019 10:02:26 +0000 (02:02 -0800)
committerjpienaar <jpienaar@google.com>
Fri, 29 Mar 2019 23:43:05 +0000 (16:43 -0700)
commit1da1b4c32104d40992341f181b50a9a79539759c
tree5b750139d7c1ff05389d00b33dc66d322154f098
parent970715be9c51bd2b31a90420cfe6cda3aac12368
LLVM IR dialect and translation: support conditional branches with arguments

Since the goal of the LLVM IR dialect is to reflect LLVM IR in MLIR, the
dialect and the conversion procedure must account for the differences betweeen
block arguments and LLVM IR PHI nodes. In particular, LLVM IR disallows PHI
nodes with different values coming from the same source. Therefore, the LLVM IR
dialect now disallows `cond_br` operations that have identical successors
accepting arguments, which would lead to invalid PHI nodes. The conversion
process resolves the potential PHI source ambiguity by injecting dummy blocks
if the same block is used more than once as a successor in an instruction.
These dummy blocks branch unconditionally to the original successors, pass them
the original operands (available in the dummy block because it is dominated by
the original block) and are used instead of them in the original terminator
operation.

PiperOrigin-RevId: 235682798
mlir/g3doc/ConversionToLLVMDialect.md
mlir/g3doc/Dialects/LLVM.md
mlir/include/mlir/LLVMIR/llvm_ops.td
mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp
mlir/lib/Target/LLVMIR/ConvertToLLVMIR.cpp
mlir/test/LLVMIR/convert-to-llvmir.mlir
mlir/test/Target/llvmir.mlir