MLIR  20.0.0git
Functions
RegionUtils.cpp File Reference
#include "mlir/Transforms/RegionUtils.h"
#include "mlir/Analysis/TopologicalSortUtils.h"
#include "mlir/IR/Block.h"
#include "mlir/IR/BuiltinOps.h"
#include "mlir/IR/IRMapping.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/IR/RegionGraphTraits.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/ADT/SmallSet.h"
#include <deque>
#include <iterator>

Go to the source code of this file.

Functions

static bool isUseSpeciallyKnownDead (OpOperand &use, LiveMap &liveMap)
 
static void processValue (Value value, LiveMap &liveMap)
 
static void propagateLiveness (Region &region, 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 &region)
 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...
 

Function Documentation

◆ ableToUpdatePredOperands()

static bool ableToUpdatePredOperands ( Block block)
static

Returns true if the predecessor terminators of the given block can not have their operands updated.

Definition at line 674 of file RegionUtils.cpp.

References mlir::Block::pred_begin(), and mlir::Block::pred_end().

◆ deleteDeadness()

static LogicalResult deleteDeadness ( RewriterBase rewriter,
MutableArrayRef< Region regions,
LiveMap &  liveMap 
)
static

◆ dropRedundantArguments() [1/2]

static LogicalResult dropRedundantArguments ( RewriterBase rewriter,
Block block 
)
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 930 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().

◆ dropRedundantArguments() [2/2]

static LogicalResult dropRedundantArguments ( RewriterBase rewriter,
MutableArrayRef< Region regions 
)
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 1012 of file RegionUtils.cpp.

References dropRedundantArguments().

◆ eraseTerminatorSuccessorOperands()

static void eraseTerminatorSuccessorOperands ( Operation terminator,
LiveMap &  liveMap 
)
static

◆ isUseSpeciallyKnownDead()

static bool isUseSpeciallyKnownDead ( OpOperand use,
LiveMap &  liveMap 
)
static

◆ mergeIdenticalBlocks() [1/2]

static LogicalResult mergeIdenticalBlocks ( RewriterBase rewriter,
MutableArrayRef< Region regions 
)
static

Identify identical blocks within the given regions and merge them, inserting new block arguments as necessary.

Definition at line 905 of file RegionUtils.cpp.

References mergeIdenticalBlocks().

◆ mergeIdenticalBlocks() [2/2]

static LogicalResult mergeIdenticalBlocks ( RewriterBase rewriter,
Region region 
)
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 849 of file RegionUtils.cpp.

References mlir::Region::empty(), mlir::Block::getArguments(), mlir::Operation::getRegions(), and mlir::Block::getSuccessors().

Referenced by mergeIdenticalBlocks(), and mlir::simplifyRegions().

◆ processValue()

static void processValue ( Value  value,
LiveMap &  liveMap 
)
static

Definition at line 305 of file RegionUtils.cpp.

References mlir::Value::getUses().

Referenced by getBackwardSliceImpl(), and propagateLiveness().

◆ propagateLiveness() [1/2]

static void propagateLiveness ( Operation op,
LiveMap &  liveMap 
)
static

◆ propagateLiveness() [2/2]

static void propagateLiveness ( Region region,
LiveMap &  liveMap 
)
static

◆ propagateTerminatorLiveness()

static void propagateTerminatorLiveness ( Operation op,
LiveMap &  liveMap 
)
static

◆ pruneRedundantArguments()

static SmallVector<SmallVector<Value, 8>, 2> pruneRedundantArguments ( const SmallVector< SmallVector< Value, 8 >, 2 > &  newArguments,
RewriterBase rewriter,
unsigned  numOldArguments,
Block block 
)
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 688 of file RegionUtils.cpp.

References mlir::detail::enumerate(), mlir::Block::eraseArgument(), mlir::Block::getArgument(), mlir::Block::getArguments(), and mlir::RewriterBase::replaceAllUsesWith().