Add a PatternRewriter hook to merge blocks, and use it to support for folding branches.
authorRiver Riddle <riverriddle@google.com>
Tue, 5 Nov 2019 19:57:03 +0000 (11:57 -0800)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Tue, 5 Nov 2019 19:57:38 +0000 (11:57 -0800)
commit2366561a39d80c3c6f0f5b1257760b5a9ed2f7bd
treecb79fed502c6e9d437b34cc1b89b5039952de79e
parent6d2432561c7822235091d5c58df3b8abb8732610
Add a PatternRewriter hook to merge blocks, and use it to support for folding branches.

A pattern rewriter hook, mergeBlock, is added that allows for merging the operations of one block into the end of another. This is used to support a canonicalization pattern for branch operations that folds the branch when the successor has a single predecessor(the branch block).

Example:
  ^bb0:
    %c0_i32 = constant 0 : i32
    br ^bb1(%c0_i32 : i32)
  ^bb1(%x : i32):
    return %x : i32

becomes:
  ^bb0:
    %c0_i32 = constant 0 : i32
    return %c0_i32 : i32
PiperOrigin-RevId: 278677825
mlir/include/mlir/Dialect/StandardOps/Ops.td
mlir/include/mlir/IR/PatternMatch.h
mlir/include/mlir/Transforms/DialectConversion.h
mlir/lib/Dialect/StandardOps/Ops.cpp
mlir/lib/IR/PatternMatch.cpp
mlir/lib/Transforms/DialectConversion.cpp
mlir/test/Transforms/canonicalize.mlir