[all-commits] [llvm/llvm-project] 448adf: [mlir] Only conditionally lower CF branching ops t...

Tres via All-commits all-commits at lists.llvm.org
Thu Aug 4 07:37:16 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 448adfee05b737a26dda34e7ae2cd4948760fff0
      https://github.com/llvm/llvm-project/commit/448adfee05b737a26dda34e7ae2cd4948760fff0
  Author: Tres Popp <tpopp at google.com>
  Date:   2022-08-04 (Thu, 04 Aug 2022)

  Changed paths:
    M mlir/docs/TargetLLVMIR.md
    M mlir/lib/Conversion/ControlFlowToLLVM/ControlFlowToLLVM.cpp
    A mlir/test/Conversion/ControlFlowToLLVM/invalid.mlir

  Log Message:
  -----------
  [mlir] Only conditionally lower CF branching ops to LLVM

Previously cf.br cf.cond_br and cf.switch always lowered to their LLVM
equivalents. These ops are all ops that take in some values of given
types and jump to other blocks with argument lists of the same types. If
the types are not the same, a verification failure will later occur. This led
to confusions, as everything works when func->llvm and cf->llvm lowering
both occur because func->llvm updates the blocks and argument lists
while cf->llvm updates the branching ops. Without func->llvm though,
there will potentially be a type mismatch.

This change now only lowers the CF ops if they will later pass
verification. This is possible because the parent op and its blocks will
be updated before the contained branching ops, so they can test their
new operand types against the types of the blocks they jump to.

Another plan was to have func->llvm only update the entry block
signature and to allow cf->llvm to update all other blocks, but this had
2 problems:
1. This would create a FuncOp lowering in cf->llvm lowering which is
   awkward
2. This new pattern would only be applied if the containing FuncOp is
   marked invalid. This is infeasible with the shared LLVM type
   conversion/target infrastructure.

See previous discussions at
https://discourse.llvm.org/t/lowering-cf-to-llvm/63863 and
https://github.com/llvm/llvm-project/issues/55301

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




More information about the All-commits mailing list