67 scf::WhileOp whileOp,
RewriterBase &rewriter,
bool forceCreateCheck) {
70 if (!forceCreateCheck && isa<scf::YieldOp>(whileOp.getAfterBody()->front())) {
77 Block *beforeBlock = whileOp.getBeforeBody();
79 for (
auto [arg, init] :
80 llvm::zip_equal(beforeBlock->
getArguments(), whileOp.getInits())) {
81 mapper.
map(arg, init);
84 for (
auto &op : *beforeBlock) {
85 if (isa<scf::ConditionOp>(op)) {
90 rewriter.
insert(op.clone(mapper));
93 scf::ConditionOp condOp = whileOp.getConditionOp();
96 condOp.getArgs(), [&](
Value arg) { return mapper.lookupOrDefault(arg); });
99 auto newLoopOp = scf::WhileOp::create(
100 rewriter, whileOp.getLoc(), whileOp.getResultTypes(), clonedCondArgs,
103 auto newBlock = builder.getBlock();
104 rewriter.mergeBlocks(whileOp.getAfterBody(), newBlock, args);
105 auto yieldOp = cast<scf::YieldOp>(newBlock->getTerminator());
106 rewriter.mergeBlocks(whileOp.getBeforeBody(), newBlock,
107 yieldOp.getResults());
108 rewriter.eraseOp(yieldOp);
112 scf::YieldOp::create(builder, loc, args);
116 auto ifOp = scf::IfOp::create(
117 rewriter, whileOp.getLoc(), clonedCondition,
120 rewriter.moveOpBefore(newLoopOp, builder.getInsertionBlock(),
121 builder.getInsertionPoint());
122 scf::YieldOp::create(builder, loc, newLoopOp.getResults());
126 scf::YieldOp::create(builder, loc, clonedCondArgs);
Block represents an ordered list of Operations.
BlockArgListType getArguments()
This is a utility class for mapping one set of IR entities to another.
auto lookupOrDefault(T from) const
Lookup a mapped value within the map.
void map(Value from, Value to)
Inserts a new mapping for 'from' to 'to'.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
RAII guard to reset the insertion point of the builder when destroyed.
This class helps build Operations.
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
Operation * insert(Operation *op)
Insert the given operation at the current insertion point and return it.
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
virtual void replaceOp(Operation *op, ValueRange newValues)
Replace the results of the given (original) operation with the specified list of values (replacements...
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...
FailureOr< WhileOp > wrapWhileLoopInZeroTripCheck(WhileOp whileOp, RewriterBase &rewriter, bool forceCreateCheck=false)
Create zero-trip-check around a while op and return the new loop op in the check.
Include the generated interface declarations.