14#ifndef MLIR_INTERFACES_CONTROLFLOWINTERFACES_H
15#define MLIR_INTERFACES_CONTROLFLOWINTERFACES_H
20#include "llvm/ADT/PointerUnion.h"
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/Support/raw_ostream.h"
25class BranchOpInterface;
26class RegionBranchOpInterface;
27class RegionBranchTerminatorOpInterface;
63 return producedOperandCount + forwardedOperands.size();
76 return index < producedOperandCount;
85 return forwardedOperands[
index - producedOperandCount].get();
93 return forwardedOperands;
100 "can't slice operands produced by the operation");
101 return forwardedOperands.slice(subStart - producedOperandCount, subLen);
106 void erase(
unsigned subStart,
unsigned subLen = 1) {
108 "can't erase operands produced by the operation");
109 forwardedOperands.erase(subStart - producedOperandCount, subLen);
120 "can't map operand produced by the operation");
123 (blockArgumentIndex - producedOperandCount);
129 unsigned producedOperandCount;
142std::optional<BlockArgument>
144 unsigned operandIndex, Block *successor);
148 const SuccessorOperands &operands);
203 assert(region &&
"Region must not be null");
214 bool isParent()
const {
return successor ==
nullptr; }
217 return successor ==
rhs.successor;
230 Region *successor =
nullptr;
252 bool isParent()
const {
return predecessor ==
nullptr; }
256 inline RegionBranchTerminatorOpInterface
261 return lhs.predecessor ==
rhs.predecessor;
281 : lower(lb), upper(
ub) {
282 assert((!
ub ||
ub >= lb) &&
"upper bound cannot be less than lower bound");
300 std::optional<unsigned> upper;
321 RewritePatternSet &
patterns, StringRef opName, PatternBenefit benefit = 1);
337 llvm_unreachable(
"defaultReplBuilderFn not implemented");
356 RewritePatternSet &
patterns, StringRef opName,
360 PatternBenefit benefit = 1);
371template <
typename ConcreteType>
374 static_assert(ConcreteType::template hasTrait<IsTerminator>(),
375 "expected operation to be a terminator");
376 static_assert(ConcreteType::template hasTrait<ZeroResults>(),
377 "expected operation to have zero results");
378 static_assert(ConcreteType::template hasTrait<ZeroSuccessors>(),
379 "expected operation to have zero successors");
392#include "mlir/Interfaces/ControlFlowInterfaces.h.inc"
396 RegionBranchTerminatorOpInterface predecessor)
397 : predecessor(predecessor.getOperation()) {}
399inline RegionBranchTerminatorOpInterface
403 return cast<RegionBranchTerminatorOpInterface>(predecessor);
413 return os <<
"<from parent>";
414 return os <<
"<region #"
427 return os <<
"<to parent>";
static InvocationBounds getUnknown()
Returns the unknown invocation bounds, i.e., there is no information on how many times a region may b...
std::optional< unsigned > getUpperBound() const
Return the upper bound.
InvocationBounds(unsigned lb, std::optional< unsigned > ub)
Create invocation bounds.
unsigned getLowerBound() const
Return the lower bound.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class provides a mutable adaptor for a range of operands.
This class helps build Operations.
Set of flags used to control the behavior of the various IR print methods (e.g.
Helper class for implementing traits.
A wrapper class that allows for printing an operation with a set of flags, useful to act as a "stream...
This class implements the operand iterators for the Operation class.
unsigned getBeginOperandIndex() const
Return the operand index of the first element of this range.
Operation is the basic unit of execution within MLIR.
This class represents a point being branched from in the methods of the RegionBranchOpInterface.
RegionBranchPoint(std::nullptr_t)=delete
Explicitly stops users from constructing with nullptr.
bool isParent() const
Returns true if branching from the parent op.
static constexpr RegionBranchPoint parent()
Returns an instance of RegionBranchPoint representing the parent operation.
RegionBranchPoint(RegionBranchTerminatorOpInterface predecessor)
Creates a RegionBranchPoint that branches from the given terminator.
RegionBranchTerminatorOpInterface getTerminatorPredecessorOrNull() const
Returns the terminator if branching from a region.
friend bool operator==(RegionBranchPoint lhs, RegionBranchPoint rhs)
Returns true if the two branch points are equal.
This class represents a successor of a region.
static RegionSuccessor parent()
Initialize a successor that branches after/out of the parent operation.
bool operator==(RegionSuccessor rhs) const
bool operator==(const Region *region) const
RegionSuccessor(Region *region)
Initialize a successor that branches to a region of the parent operation.
friend bool operator!=(RegionSuccessor lhs, RegionSuccessor rhs)
bool isParent() const
Return true if the successor is the parent operation.
Region * getSuccessor() const
Return the given region successor.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
unsigned getRegionNumber()
Return the number of this region in the parent operation.
SuccessorOperands(unsigned producedOperandCount, MutableOperandRange forwardedOperands)
Constructs a SuccessorOperands with the given amount of produced operands and forwarded operands.
MutableOperandRange slice(unsigned subStart, unsigned subLen) const
Get a slice of the operands forwarded to the successor.
void erase(unsigned subStart, unsigned subLen=1)
Erase operands forwarded to the successor.
MutableOperandRange getMutableForwardedOperands() const
Get the range of operands that are simply forwarded to the successor.
SuccessorOperands(MutableOperandRange forwardedOperands)
Constructs a SuccessorOperands with no produced operands that simply forwards operands to the success...
Value operator[](unsigned index) const
Returns the Value that is passed to the successors block argument denoted by index.
unsigned getOperandIndex(unsigned blockArgumentIndex) const
Gets the index of the forwarded operand within the operation which maps to the block argument denoted...
bool isOperandProduced(unsigned index) const
Returns true if the successor operand denoted by index is produced by the operation.
unsigned getProducedOperandCount() const
Returns the amount of operands that are produced internally by the operation.
bool empty() const
Returns true if there are no successor operands.
void append(ValueRange valueRange)
Add new operands that are forwarded to the successor.
unsigned size() const
Returns the amount of operands passed to the successor.
OperandRange getForwardedOperands() const
Get the range of operands that are simply forwarded to the successor.
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
static Value defaultReplBuilderFn(OpBuilder &builder, Location loc, Value value)
Default implementation of the non-successor-input replacement builder function.
std::optional< BlockArgument > getBranchSuccessorArgument(const SuccessorOperands &operands, unsigned operandIndex, Block *successor)
Return the BlockArgument corresponding to operand operandIndex in some successor if operandIndex is w...
LogicalResult verifyRegionBranchWeights(Operation *op)
Verify that the region weights attached to an operation implementing WeightedRegiobBranchOpInterface ...
LogicalResult verifyBranchSuccessorOperands(Operation *op, unsigned succNo, const SuccessorOperands &operands)
Verify that the given operands match those of the given successor block.
LogicalResult verifyRegionBranchOpInterface(Operation *op)
Verify that types match along control flow edges described the given op.
static LogicalResult defaultMatcherFn(Operation *op)
Default implementation of the pattern matcher function.
LogicalResult verifyBranchWeights(Operation *op)
Verify that the branch weights attached to an operation implementing WeightedBranchOpInterface are co...
Include the generated interface declarations.
DenseMap< OpOperand *, SmallVector< Value > > RegionBranchSuccessorMapping
A mapping from successor operands to successor inputs.
std::function< LogicalResult(Operation *)> PatternMatcherFn
Helper function for the region branch op inlining pattern that checks if the pattern is applicable to...
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
bool insideMutuallyExclusiveRegions(Operation *a, Operation *b)
Return true if a and b are in mutually exclusive regions as per RegionBranchOpInterface.
std::function< Value(OpBuilder &, Location, Value)> NonSuccessorInputReplacementBuilderFn
Helper function for the region branch op inlining pattern that builds replacement values for non-succ...
Region * getEnclosingRepetitiveRegion(Operation *op)
Return the first enclosing region of the given op that may be executed repetitively as per RegionBran...
bool operator!=(RegionBranchPoint lhs, RegionBranchPoint rhs)
const FrozenRewritePatternSet & patterns
DenseMap< Value, SmallVector< OpOperand * > > RegionBranchInverseSuccessorMapping
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
void populateRegionBranchOpInterfaceInliningPattern(RewritePatternSet &patterns, StringRef opName, NonSuccessorInputReplacementBuilderFn replBuilderFn=detail::defaultReplBuilderFn, PatternMatcherFn matcherFn=detail::defaultMatcherFn, PatternBenefit benefit=1)
Populate a pattern that inlines the body of region branch ops when there is a single acyclic path thr...
void populateRegionBranchOpInterfaceCanonicalizationPatterns(RewritePatternSet &patterns, StringRef opName, PatternBenefit benefit=1)
Populate canonicalization patterns that simplify successor operands/inputs of region branch operation...
This trait indicates that a terminator operation is "return-like".
static LogicalResult verifyTrait(Operation *op)