MLIR 23.0.0git
ControlFlowInterfaces.cpp File Reference
#include <utility>
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/Operation.h"
#include "mlir/IR/PatternMatch.h"
#include "mlir/Interfaces/ControlFlowInterfaces.h"
#include "llvm/ADT/EquivalenceClasses.h"
#include "llvm/Support/DebugLog.h"
#include "mlir/Interfaces/ControlFlowInterfaces.cpp.inc"

Go to the source code of this file.

Typedefs

using StopConditionFn = function_ref<bool(Region *, ArrayRef<bool> visited)>
 Stop condition for traverseRegionGraph.

Functions

static LogicalResult verifyWeights (Operation *op, llvm::ArrayRef< int32_t > weights, std::size_t expectedWeightsNum, llvm::StringRef weightAnchorName, llvm::StringRef weightRefName)
static bool traverseRegionGraph (Region *begin, StopConditionFn stopConditionFn)
 Traverse the region graph starting at begin.
static bool isRegionReachable (Region *begin, Region *r)
 Return true if region r is reachable from region begin according to the RegionBranchOpInterface (by taking a branch).
static MutableArrayRef< OpOperandoperandsToOpOperands (OperandRange &operands)
static void getSuccessorOperandInputMapping (RegionBranchOpInterface branchOp, RegionBranchSuccessorMapping &mapping, RegionBranchPoint src)
static RegionBranchInverseSuccessorMapping invertRegionBranchSuccessorMapping (const RegionBranchSuccessorMapping &operandToInputs)
static bool isDefinedBefore (Operation *regionBranchOp, Value a, Value b)
 Return "true" if a can be used in lieu of b, where b is a region successor input and a is a "reachable value" of b.
static llvm::SmallDenseSet< ValuecomputeReachableValuesFromSuccessorInput (Value value, const RegionBranchInverseSuccessorMapping &inputToOperands)
 Compute all non-successor-input values that a successor input could have based on the given successor input to successor operand mapping.

Typedef Documentation

◆ StopConditionFn

Stop condition for traverseRegionGraph.

The traversal is interrupted if this function returns "true" for a successor region. The first parameter is the successor region. The second parameter indicates all already visited regions.

Definition at line 226 of file ControlFlowInterfaces.cpp.

Function Documentation

◆ computeReachableValuesFromSuccessorInput()

llvm::SmallDenseSet< Value > computeReachableValuesFromSuccessorInput ( Value value,
const RegionBranchInverseSuccessorMapping & inputToOperands )
static

Compute all non-successor-input values that a successor input could have based on the given successor input to successor operand mapping.

Example 1: r = scf.if ... { scf.yield a : ... } else { scf.yield b : ... } reachableValues(r) = {a, b}

Example 2: r = scf.for ... iter_args(arg0 = %0) -> ... { scf.yield arg0 : ... } reachableValues(arg0) = {%0} reachableValues(r) = {%0}

Example 3: r = scf.for ... iter_args(arg0 = %0) -> ... { ... scf.yield %1 : ... } reachableValues(arg0) = {%0, %1} reachableValues(r) = {%0, %1}

Definition at line 636 of file ControlFlowInterfaces.cpp.

References mlir::IROperand< DerivedT, IRValueT >::get().

◆ getSuccessorOperandInputMapping()

void getSuccessorOperandInputMapping ( RegionBranchOpInterface branchOp,
RegionBranchSuccessorMapping & mapping,
RegionBranchPoint src )
static

Definition at line 450 of file ControlFlowInterfaces.cpp.

References operandsToOpOperands().

◆ invertRegionBranchSuccessorMapping()

RegionBranchInverseSuccessorMapping invertRegionBranchSuccessorMapping ( const RegionBranchSuccessorMapping & operandToInputs)
static

Definition at line 477 of file ControlFlowInterfaces.cpp.

◆ isDefinedBefore()

bool isDefinedBefore ( Operation * regionBranchOp,
Value a,
Value b )
static

Return "true" if a can be used in lieu of b, where b is a region successor input and a is a "reachable value" of b.

Reachable values are successor operand values that are (maybe transitively) forwarded to b.

Definition at line 565 of file ControlFlowInterfaces.cpp.

References b, mlir::Region::getParentOp(), and mlir::Value::getParentRegion().

◆ isRegionReachable()

bool isRegionReachable ( Region * begin,
Region * r )
static

Return true if region r is reachable from region begin according to the RegionBranchOpInterface (by taking a branch).

Definition at line 307 of file ControlFlowInterfaces.cpp.

References mlir::Region::getParentOp(), and traverseRegionGraph().

◆ operandsToOpOperands()

MutableArrayRef< OpOperand > operandsToOpOperands ( OperandRange & operands)
static

Definition at line 445 of file ControlFlowInterfaces.cpp.

◆ traverseRegionGraph()

bool traverseRegionGraph ( Region * begin,
StopConditionFn stopConditionFn )
static

Traverse the region graph starting at begin.

The traversal is interrupted if stopCondition evaluates to "true" for a successor region. In that case, this function returns "true". Otherwise, if the traversal was not interrupted, this function returns "false".

Definition at line 232 of file ControlFlowInterfaces.cpp.

References mlir::Region::getParentOp(), and mlir::Region::getRegionNumber().

Referenced by isRegionReachable().

◆ verifyWeights()

LogicalResult verifyWeights ( Operation * op,
llvm::ArrayRef< int32_t > weights,
std::size_t expectedWeightsNum,
llvm::StringRef weightAnchorName,
llvm::StringRef weightRefName )
static