13 #ifndef MLIR_IR_BLOCK_H
14 #define MLIR_IR_BLOCK_H
19 #include "llvm/ADT/SmallPtrSet.h"
28 template <
typename ValueRangeT>
33 public llvm::ilist_node_with_parent<Block, Region> {
45 operations.pop_back();
148 bool empty() {
return operations.empty(); }
187 template <
typename OpT>
192 template <
typename OpT>
198 template <
typename OpT>
202 template <
typename OpT>
212 auto endIt = --
end();
213 return {
begin(), endIt};
302 typename Iterator = ForwardIterator,
typename FnT,
303 typename ArgT = detail::first_argument<FnT>,
304 typename RetT = detail::walkResultType<FnT>>
306 if constexpr (std::is_same<ArgT, Block *>::value &&
309 if constexpr (std::is_same<RetT, void>::value) {
312 RetT result = callback(
this);
313 if (result.wasSkipped())
315 if (result.wasInterrupted())
321 if constexpr (std::is_same<RetT, void>::value) {
322 walk<Order, Iterator>(
begin(),
end(), std::forward<FnT>(callback));
324 if (walk<Order, Iterator>(
begin(),
end(), std::forward<FnT>(callback))
329 if constexpr (std::is_same<ArgT, Block *>::value &&
332 return callback(
this);
334 if constexpr (!std::is_same<RetT, void>::value)
358 for (
auto &op : llvm::make_early_inc_range(llvm::make_range(
begin,
end))) {
359 if constexpr (std::is_same<RetT, WalkResult>::value) {
360 if (detail::walk<Order, Iterator>(&op, callback).wasInterrupted())
363 detail::walk<Order, Iterator>(&op, callback);
366 if constexpr (std::is_same<RetT, WalkResult>::value)
391 return &Block::operations;
394 void print(raw_ostream &os);
407 llvm::PointerIntPair<
Region *, 1,
bool> parentValidOpOrderPair;
413 std::vector<BlockArgument> arguments;
418 friend struct llvm::ilist_traits<
Block>;
This class provides management for the lifetime of the state used when printing the IR.
This class represents an argument of a Block.
A block operand represents an operand that holds a reference to a Block, e.g.
Block represents an ordered list of Operations.
void recomputeOpOrder()
Recomputes the ordering of child operations within the block.
OpListType::iterator iterator
Block * splitBlock(Operation *splitBeforeOp)
Operation * findAncestorOpInBlock(Operation &op)
Returns 'op' if 'op' lies in this block, or otherwise finds the ancestor operation of 'op' that lies ...
ValueTypeRange< BlockArgListType > getArgumentTypes()
Return a range containing the types of the arguments for this block.
unsigned getNumSuccessors()
void push_front(Operation *op)
SuccessorRange::iterator succ_iterator
BlockArgument getArgument(unsigned i)
bool hasNoSuccessors()
Returns true if this blocks has no successors.
unsigned getNumArguments()
void erase()
Unlink this Block from its parent region and delete it.
BlockArgument insertArgument(args_iterator it, Type type, Location loc)
Insert one value to the position in the argument list indicated by the given iterator.
iterator_range< args_iterator > addArguments(TypeRange types, ArrayRef< Location > locs)
Add one argument to the argument list for each type specified in the list.
Block * splitBlock(iterator splitBefore)
Split the block into two blocks before the specified operation or iterator.
Region * getParent() const
Provide a 'getParent' method for ilist_node_with_parent methods.
bool isOpOrderValid()
Returns true if the ordering of the child operations is valid, false otherwise.
op_iterator< OpT > op_begin()
BlockArgListType::reverse_iterator reverse_args_iterator
pred_iterator pred_begin()
void dropAllDefinedValueUses()
This drops all uses of values defined in this block or in the blocks of nested regions wherever the u...
bool verifyOpOrder()
Verifies the current ordering of child operations matches the validOpOrder flag.
SuccessorRange getSuccessors()
void invalidateOpOrder()
Invalidates the current ordering of operations.
Block * getSinglePredecessor()
If this block has exactly one predecessor, return it.
void printAsOperand(raw_ostream &os, bool printType=true)
Print out the name of the block without printing its body.
reverse_args_iterator args_rend()
RetT walk(FnT &&callback)
Walk all nested operations, blocks (including this block) or regions, depending on the type of callba...
void insertAfter(Block *block)
Insert this block (which must not already be in a region) right after the specified block.
Operation * getTerminator()
Get the terminator operation of this block.
succ_iterator succ_begin()
iterator_range< pred_iterator > getPredecessors()
BlockArgument addArgument(Type type, Location loc)
Add one value to the argument list.
RetT walk(Block::iterator begin, Block::iterator end, FnT &&callback)
Walk all nested operations, blocks (excluding this block) or regions, depending on the type of callba...
void eraseArguments(unsigned start, unsigned num)
Erases 'num' arguments from the index 'start'.
OpListType & getOperations()
void print(raw_ostream &os)
bool mightHaveTerminator()
Check whether this block might have a terminator.
BlockArgListType getArguments()
PredecessorIterator pred_iterator
bool isReachable(Block *other, SmallPtrSet< Block *, 16 > &&except={})
Return "true" if there is a path from this block to the given block (according to the successors rela...
Block * getUniquePredecessor()
If this block has a unique predecessor, i.e., all incoming edges originate from one block,...
op_iterator< OpT > op_end()
void eraseArgument(unsigned index)
Erase the argument at 'index' and remove it from the argument list.
iterator_range< op_iterator< OpT > > getOps()
Return an iterator range over the operations within this block that are of 'OpT'.
Block * getSuccessor(unsigned i)
args_iterator args_begin()
bool isEntryBlock()
Return if this block is the entry block in the parent region.
void dropAllReferences()
This drops all operand uses from operations within this block, which is an essential step in breaking...
void insertBefore(Block *block)
Insert this block (which must not already be in a region) right before the specified block.
void moveBefore(Block *block)
Unlink this block from its current region and insert it right before the specific block.
void push_back(Operation *op)
reverse_args_iterator args_rbegin()
bool hasNoPredecessors()
Return true if this block has no predecessors.
static OpListType Block::* getSublistAccess(Operation *)
Returns pointer to member of operation list.
iterator_range< iterator > without_terminator()
Return an iterator range over the operation within this block excluding the terminator operation at t...
Operation * getParentOp()
Returns the closest surrounding operation that contains this block.
BlockArgListType::iterator args_iterator
reverse_iterator rbegin()
OpListType::reverse_iterator reverse_iterator
llvm::iplist< Operation > OpListType
This is the list of operations in the block.
This class represents a single IR object that contains a use list.
BlockOperand * getFirstUse() const
Return the first operand that is using this value, for use by custom use/def iterators.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Operation is the basic unit of execution within MLIR.
Implement a predecessor iterator for blocks.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
This class implements the successor iterators for Block.
This class provides an abstraction over the various different ranges of value types.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class implements iteration on the types of a given range of values.
static WalkResult advance()
static WalkResult interrupt()
A utility iterator that filters out operations that are not 'OpT'.
This class provides iteration over the held operations of a block for a specific operation type.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
void printType(Type type, AsmPrinter &printer)
Prints an LLVM Dialect type.
decltype(walk(nullptr, std::declval< FnT >())) walkResultType
Utility to provide the return type of a templated walk method.
inline ::llvm::hash_code hash_value(const PolynomialBase< D, T > &arg)
Include the generated interface declarations.
WalkOrder
Traversal order for region, block and operation walk utilities.
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
static mlir::Block::iterator getEmptyKey()
static bool isEqual(mlir::Block::iterator lhs, mlir::Block::iterator rhs)
static mlir::Block::iterator getTombstoneKey()
static unsigned getHashValue(mlir::Block::iterator iter)
This iterator enumerates the elements in "forward" order.