//===- Block.cpp - MLIR Block Class ---------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #include "mlir/IR/Block.h" #include "mlir/IR/Builders.h" #include "mlir/IR/Operation.h" #include "llvm/ADT/BitVector.h" usingnamespacemlir; //===----------------------------------------------------------------------===// // Block //===----------------------------------------------------------------------===// Block::~Block() { … } Region *Block::getParent() const { … } /// Returns the closest surrounding operation that contains this block or /// nullptr if this block is unlinked. Operation *Block::getParentOp() { … } /// Return if this block is the entry block in the parent region. bool Block::isEntryBlock() { … } /// Insert this block (which must not already be in a region) right before the /// specified block. void Block::insertBefore(Block *block) { … } void Block::insertAfter(Block *block) { … } /// Unlink this block from its current region and insert it right before the /// specific block. void Block::moveBefore(Block *block) { … } /// Unlink this block from its current region and insert it right before the /// block that the given iterator points to in the region region. void Block::moveBefore(Region *region, llvm::iplist<Block>::iterator iterator) { … } /// Unlink this Block from its parent Region and delete it. void Block::erase() { … } /// Returns 'op' if 'op' lies in this block, or otherwise finds the /// ancestor operation of 'op' that lies in this block. Returns nullptr if /// the latter fails. Operation *Block::findAncestorOpInBlock(Operation &op) { … } /// This drops all operand uses from operations within this block, which is /// an essential step in breaking cyclic dependences between references when /// they are to be deleted. void Block::dropAllReferences() { … } void Block::dropAllDefinedValueUses() { … } /// Returns true if the ordering of the child operations is valid, false /// otherwise. bool Block::isOpOrderValid() { … } /// Invalidates the current ordering of operations. void Block::invalidateOpOrder() { … } /// Verifies the current ordering of child operations. Returns false if the /// order is valid, true otherwise. bool Block::verifyOpOrder() { … } /// Recomputes the ordering of child operations within the block. void Block::recomputeOpOrder() { … } //===----------------------------------------------------------------------===// // Argument list management. //===----------------------------------------------------------------------===// /// Return a range containing the types of the arguments for this block. auto Block::getArgumentTypes() -> ValueTypeRange<BlockArgListType> { … } BlockArgument Block::addArgument(Type type, Location loc) { … } /// Add one argument to the argument list for each type specified in the list. auto Block::addArguments(TypeRange types, ArrayRef<Location> locs) -> iterator_range<args_iterator> { … } BlockArgument Block::insertArgument(unsigned index, Type type, Location loc) { … } /// Insert one value to the given position of the argument list. The existing /// arguments are shifted. The block is expected not to have predecessors. BlockArgument Block::insertArgument(args_iterator it, Type type, Location loc) { … } void Block::eraseArgument(unsigned index) { … } void Block::eraseArguments(unsigned start, unsigned num) { … } void Block::eraseArguments(const BitVector &eraseIndices) { … } void Block::eraseArguments(function_ref<bool(BlockArgument)> shouldEraseFn) { … } //===----------------------------------------------------------------------===// // Terminator management //===----------------------------------------------------------------------===// /// Get the terminator operation of this block. This function asserts that /// the block might have a valid terminator operation. Operation *Block::getTerminator() { … } /// Check whether this block might have a terminator. bool Block::mightHaveTerminator() { … } // Indexed successor access. unsigned Block::getNumSuccessors() { … } Block *Block::getSuccessor(unsigned i) { … } /// If this block has exactly one predecessor, return it. Otherwise, return /// null. /// /// Note that multiple edges from a single block (e.g. if you have a cond /// branch with the same block as the true/false destinations) is not /// considered to be a single predecessor. Block *Block::getSinglePredecessor() { … } /// If this block has a unique predecessor, i.e., all incoming edges originate /// from one block, return it. Otherwise, return null. Block *Block::getUniquePredecessor() { … } //===----------------------------------------------------------------------===// // Other //===----------------------------------------------------------------------===// /// Split the block into two blocks before the specified operation or /// iterator. /// /// Note that all operations BEFORE the specified iterator stay as part of /// the original basic block, and the rest of the operations in the original /// block are moved to the new block, including the old terminator. The /// original block is left without a terminator. /// /// The newly formed Block is returned, and the specified iterator is /// invalidated. Block *Block::splitBlock(iterator splitBefore) { … } //===----------------------------------------------------------------------===// // Predecessors //===----------------------------------------------------------------------===// Block *PredecessorIterator::unwrap(BlockOperand &value) { … } /// Get the successor number in the predecessor terminator. unsigned PredecessorIterator::getSuccessorIndex() const { … } //===----------------------------------------------------------------------===// // SuccessorRange //===----------------------------------------------------------------------===// SuccessorRange::SuccessorRange() : … { … } SuccessorRange::SuccessorRange(Block *block) : … { … } SuccessorRange::SuccessorRange(Operation *term) : … { … } //===----------------------------------------------------------------------===// // BlockRange //===----------------------------------------------------------------------===// BlockRange::BlockRange(ArrayRef<Block *> blocks) : … { … } BlockRange::BlockRange(SuccessorRange successors) : … { … } /// See `llvm::detail::indexed_accessor_range_base` for details. BlockRange::OwnerT BlockRange::offset_base(OwnerT object, ptrdiff_t index) { … } /// See `llvm::detail::indexed_accessor_range_base` for details. Block *BlockRange::dereference_iterator(OwnerT object, ptrdiff_t index) { … }