21 assert(!
verifyOpOrder() &&
"Expected valid operation ordering.");
41 assert(!
getParent() &&
"already inserted into a block!");
42 assert(block->
getParent() &&
"cannot insert before a block without a parent");
47 assert(!
getParent() &&
"already inserted into a block!");
48 assert(block->
getParent() &&
"cannot insert before a block without a parent");
55 assert(block->
getParent() &&
"cannot insert before a block without a parent");
67 assert(
getParent() &&
"Block has no parent");
78 while (currOp->getBlock() !=
this) {
97 for (
auto &op : *
this)
98 op.dropAllDefinedValueUses();
110 parentValidOpOrderPair.setInt(
false);
120 if (operations.empty() || llvm::hasSingleElement(operations))
124 for (
auto &i : *
this) {
127 if (prev && prev->orderIndex != Operation::kInvalidOrderIdx &&
128 prev->orderIndex >= i.orderIndex)
137 parentValidOpOrderPair.setInt(
true);
139 unsigned orderIndex = 0;
140 for (
auto &op : *
this)
141 op.orderIndex = (orderIndex += Operation::kOrderStride);
154 BlockArgument arg = BlockArgument::create(type,
this, arguments.size(), loc);
155 arguments.push_back(arg);
162 assert(types.size() == locs.size() &&
163 "incorrect number of block argument locations");
164 size_t initialSize = arguments.size();
165 arguments.reserve(initialSize + types.size());
167 for (
auto typeAndLoc : llvm::zip(types, locs))
168 addArgument(std::get<0>(typeAndLoc), std::get<1>(typeAndLoc));
169 return {arguments.data() + initialSize, arguments.data() + arguments.size()};
173 assert(index <= arguments.size() &&
"invalid insertion index");
175 auto arg = BlockArgument::create(type,
this, index, loc);
176 arguments.insert(arguments.begin() + index, arg);
181 arg.setArgNumber(index++);
189 "cannot insert arguments to blocks with predecessors");
194 assert(index < arguments.size());
195 arguments[index].destroy();
196 arguments.erase(arguments.begin() + index);
198 arg.setArgNumber(index++);
202 assert(start + num <= arguments.size());
203 for (
unsigned i = 0; i < num; ++i)
204 arguments[start + i].destroy();
205 arguments.erase(arguments.begin() + start, arguments.begin() + start + num);
207 arg.setArgNumber(start++);
216 auto firstDead = llvm::find_if(arguments, shouldEraseFn);
217 if (firstDead == arguments.end())
222 unsigned index = firstDead->getArgNumber();
223 firstDead->destroy();
226 for (
auto it = std::next(firstDead), e = arguments.end(); it != e; ++it) {
228 if (shouldEraseFn(*it)) {
231 it->setArgNumber(index++);
235 arguments.erase(firstDead, arguments.end());
274 auto *firstPred = *it;
276 return it ==
pred_end() ? firstPred :
nullptr;
287 auto *firstPred = *it;
288 for (++it; it != e; ++it)
289 if (*it != firstPred)
311 auto *newBB =
new Block();
316 newBB->getOperations().splice(newBB->end(),
getOperations(), splitBefore,
331 return I->getOperandNumber();
341 if (block->
empty() || llvm::hasSingleElement(*block->
getParent()))
355 if (except.contains(other)) {
361 while (!worklist.empty()) {
362 Block *next = worklist.pop_back_val();
366 if (!except.insert(next).second)
378 if ((count = blocks.size()))
379 base = blocks.data();
387 if (
auto *operand = llvm::dyn_cast_if_present<BlockOperand *>(
object))
388 return {operand + index};
389 return {llvm::dyn_cast_if_present<Block *const *>(
object) + index};
393 Block *BlockRange::dereference_iterator(OwnerT
object, ptrdiff_t index) {
394 if (
const auto *operand = llvm::dyn_cast_if_present<BlockOperand *>(
object))
395 return operand[index].get();
396 return llvm::dyn_cast_if_present<Block *const *>(
object)[index];
static Value getBase(Value v)
Looks through known "view-like" ops to find the base memref.
This class represents an argument of a Block.
unsigned getArgNumber() const
Returns the number of this argument.
A block operand represents an operand that holds a reference to a Block, e.g.
This class provides an abstraction over the different types of ranges over Blocks.
BlockRange(ArrayRef< Block * > blocks={})
Block represents an ordered list of Operations.
void recomputeOpOrder()
Recomputes the ordering of child operations within the block.
OpListType::iterator iterator
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 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.
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.
void invalidateOpOrder()
Invalidates the current ordering of operations.
Block * getSinglePredecessor()
If this block has exactly one predecessor, return it.
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.
void eraseArguments(unsigned start, unsigned num)
Erases 'num' arguments from the index 'start'.
OpListType & getOperations()
bool mightHaveTerminator()
Check whether this block might have a terminator.
BlockArgListType getArguments()
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,...
void eraseArgument(unsigned index)
Erase the argument at 'index' and remove it from the argument list.
Block * getSuccessor(unsigned i)
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.
Operation * getParentOp()
Returns the closest surrounding operation that contains this block.
BlockArgListType::iterator args_iterator
void dropAllUses()
Drop all uses of this object from their respective owners.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
This class provides the API for ops that are known to be terminators.
Operation is the basic unit of execution within MLIR.
Block * getSuccessor(unsigned index)
unsigned getNumSuccessors()
void dropAllReferences()
This drops all operand uses from this operation, which is an essential step in breaking cyclic depend...
bool mightHaveTrait()
Returns true if the operation might have the provided trait.
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
Block * getBlock()
Returns the operation block that contains this operation.
MutableArrayRef< BlockOperand > getBlockOperands()
unsigned getSuccessorIndex() const
Get the successor number in the predecessor terminator.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Operation * getParentOp()
Return the parent operation this region is attached to.
BlockListType & getBlocks()
BlockListType::iterator iterator
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.
Operation * getOwner() const
Return the owner of this operand.
Include the generated interface declarations.