MLIR
22.0.0git
|
#include "mlir/Transforms/RegionUtils.h"
#include "mlir/Analysis/SliceAnalysis.h"
#include "mlir/Analysis/TopologicalSortUtils.h"
#include "mlir/IR/Block.h"
#include "mlir/IR/Dominance.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/Value.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Support/LogicalResult.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/DebugLog.h"
#include <deque>
#include <iterator>
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "region-utils" |
Functions | |
static bool | isUseSpeciallyKnownDead (OpOperand &use, LiveMap &liveMap) |
static void | processValue (Value value, LiveMap &liveMap) |
static void | propagateLiveness (Region ®ion, LiveMap &liveMap) |
static void | propagateTerminatorLiveness (Operation *op, LiveMap &liveMap) |
static void | propagateLiveness (Operation *op, LiveMap &liveMap) |
static void | eraseTerminatorSuccessorOperands (Operation *terminator, LiveMap &liveMap) |
static LogicalResult | deleteDeadness (RewriterBase &rewriter, MutableArrayRef< Region > regions, LiveMap &liveMap) |
static bool | ableToUpdatePredOperands (Block *block) |
Returns true if the predecessor terminators of the given block can not have their operands updated. More... | |
static SmallVector< SmallVector< Value, 8 >, 2 > | pruneRedundantArguments (const SmallVector< SmallVector< Value, 8 >, 2 > &newArguments, RewriterBase &rewriter, unsigned numOldArguments, Block *block) |
Prunes the redundant list of new arguments. More... | |
static LogicalResult | mergeIdenticalBlocks (RewriterBase &rewriter, Region ®ion) |
Identify identical blocks within the given region and merge them, inserting new block arguments as necessary. More... | |
static LogicalResult | mergeIdenticalBlocks (RewriterBase &rewriter, MutableArrayRef< Region > regions) |
Identify identical blocks within the given regions and merge them, inserting new block arguments as necessary. More... | |
static LogicalResult | dropRedundantArguments (RewriterBase &rewriter, Block &block) |
If a block's argument is always the same across different invocations, then drop the argument and use the value directly inside the block. More... | |
static LogicalResult | dropRedundantArguments (RewriterBase &rewriter, MutableArrayRef< Region > regions) |
This optimization drops redundant argument to blocks. More... | |
#define DEBUG_TYPE "region-utils" |
Definition at line 33 of file RegionUtils.cpp.
|
static |
Returns true if the predecessor terminators of the given block can not have their operands updated.
Definition at line 701 of file RegionUtils.cpp.
References mlir::Block::pred_begin(), and mlir::Block::pred_end().
|
static |
Definition at line 438 of file RegionUtils.cpp.
References mlir::Region::empty(), mlir::RewriterBase::eraseOp(), eraseTerminatorSuccessorOperands(), mlir::Region::front(), mlir::Region::getBlocks(), and mlir::Region::hasOneBlock().
Referenced by mlir::runRegionDCE().
|
static |
If a block's argument is always the same across different invocations, then drop the argument and use the value directly inside the block.
Definition at line 957 of file RegionUtils.cpp.
References mlir::detail::enumerate(), mlir::SuccessorOperands::erase(), mlir::Block::eraseArgument(), mlir::Block::getArguments(), mlir::SuccessorOperands::getForwardedOperands(), mlir::Block::pred_begin(), mlir::Block::pred_end(), and mlir::RewriterBase::replaceAllUsesWith().
Referenced by dropRedundantArguments(), and mlir::simplifyRegions().
|
static |
This optimization drops redundant argument to blocks.
I.e., if a given argument to a block receives the same value from each of the block predecessors, we can remove the argument from the block and use directly the original value. This is a simple example:
cond = llvm.call @rand() : () -> i1 val0 = llvm.mlir.constant(1 : i64) : i64 val1 = llvm.mlir.constant(2 : i64) : i64 val2 = llvm.mlir.constant(3 : i64) : i64 llvm.cond_br cond, ^bb1(val0 : i64, val1 : i64), ^bb2(val0 : i64, val2 : i64)
^bb1(arg0 : i64, arg1 : i64): llvm.call @foo(arg0, arg1)
The previous IR can be rewritten as: cond = llvm.call @rand() : () -> i1 val0 = llvm.mlir.constant(1 : i64) : i64 val1 = llvm.mlir.constant(2 : i64) : i64 val2 = llvm.mlir.constant(3 : i64) : i64 llvm.cond_br cond, ^bb1(val1 : i64), ^bb2(val2 : i64)
^bb1(arg0 : i64): llvm.call @foo(val0, arg0)
Definition at line 1039 of file RegionUtils.cpp.
References dropRedundantArguments().
|
static |
Definition at line 412 of file RegionUtils.cpp.
References mlir::SuccessorOperands::erase(), mlir::Block::getArgument(), mlir::Operation::getNumSuccessors(), mlir::Operation::getSuccessor(), and mlir::SuccessorOperands::size().
Referenced by deleteDeadness().
|
static |
Definition at line 307 of file RegionUtils.cpp.
References mlir::OpOperand::getOperandNumber(), mlir::detail::IROperandBase::getOwner(), and mlir::Operation::hasTrait().
|
static |
Identify identical blocks within the given regions and merge them, inserting new block arguments as necessary.
Definition at line 932 of file RegionUtils.cpp.
References mergeIdenticalBlocks().
|
static |
Identify identical blocks within the given region and merge them, inserting new block arguments as necessary.
Returns success if any blocks were merged, failure otherwise.
Definition at line 876 of file RegionUtils.cpp.
References mlir::Region::empty(), mlir::Block::getArguments(), mlir::Operation::getRegions(), mlir::Block::getSuccessors(), and mlir::Region::hasOneBlock().
Referenced by mergeIdenticalBlocks(), and mlir::simplifyRegions().
|
static |
Definition at line 330 of file RegionUtils.cpp.
References mlir::Value::getUses().
Referenced by getBackwardSliceImpl(), and propagateLiveness().
|
static |
Definition at line 366 of file RegionUtils.cpp.
References mlir::Operation::getRegions(), mlir::Operation::getResults(), mlir::Operation::hasTrait(), processValue(), propagateLiveness(), propagateTerminatorLiveness(), and mlir::wouldOpBeTriviallyDead().
|
static |
Definition at line 388 of file RegionUtils.cpp.
References mlir::Region::empty(), mlir::Region::front(), and processValue().
Referenced by propagateLiveness(), and mlir::runRegionDCE().
|
static |
Definition at line 342 of file RegionUtils.cpp.
References mlir::Block::getArgument(), mlir::Operation::getNumSuccessors(), mlir::SuccessorOperands::getProducedOperandCount(), mlir::Operation::getSuccessor(), and mlir::Operation::getSuccessors().
Referenced by propagateLiveness().
|
static |
Prunes the redundant list of new arguments.
E.g., if we are passing an argument list like [x, y, z, x] this would return [x, y, z] and it would update the block
(to whom the argument are passed to) accordingly. The new arguments are passed as arguments at the back of the block, hence we need to know how many numOldArguments
were before, in order to correctly replace the new arguments in the block
Definition at line 715 of file RegionUtils.cpp.
References mlir::detail::enumerate(), mlir::Block::eraseArgument(), mlir::Block::getArgument(), mlir::Block::getArguments(), and mlir::RewriterBase::replaceAllUsesWith().