Lines Matching defs:ifOp

244 /// Promotes the `then` or the `else` block of `ifOp` (depending on whether
245 /// `elseBlock` is false or true) into `ifOp`'s containing block, and discards
247 static void promoteIfBlock(AffineIfOp ifOp, bool elseBlock) {
249 assert(ifOp.hasElse() && "else block expected");
251 Block *destBlock = ifOp->getBlock();
252 Block *srcBlock = elseBlock ? ifOp.getElseBlock() : ifOp.getThenBlock();
254 Block::iterator(ifOp), srcBlock->getOperations(), srcBlock->begin(),
256 ifOp.erase();
259 /// Returns the outermost affine.for/parallel op that the `ifOp` is invariant
260 /// on. The `ifOp` could be hoisted and placed right before such an operation.
261 /// This method assumes that the ifOp has been canonicalized (to be correct and
263 static Operation *getOutermostInvariantForOp(AffineIfOp ifOp) {
265 auto ifOperands = ifOp.getOperands();
266 auto *res = ifOp.getOperation();
286 /// A helper for the mechanics of mlir::hoistAffineIfOp. Hoists `ifOp` just over
288 /// otherwise the same `ifOp`.
289 static AffineIfOp hoistAffineIfOp(AffineIfOp ifOp, Operation *hoistOverOp) {
291 if (hoistOverOp == ifOp)
292 return ifOp;
301 auto hoistedIfOp = b.create<AffineIfOp>(ifOp.getLoc(), ifOp.getIntegerSet(),
302 ifOp.getOperands(),
308 // We use this unique name to identify/find `ifOp`'s clone in the else
314 ifOp->setAttr(idForIfOp, b.getBoolAttr(true));
318 promoteIfBlock(ifOp, /*elseBlock=*/false);
414 LogicalResult mlir::affine::hoistAffineIfOp(AffineIfOp ifOp, bool *folded) {
415 // Bail out early if the ifOp returns a result. TODO: Consider how to
417 if (ifOp.getNumResults() != 0)
425 RewritePatternSet patterns(ifOp.getContext());
426 AffineIfOp::getCanonicalizationPatterns(patterns, ifOp.getContext());
431 (void)applyOpPatternsGreedily(ifOp.getOperation(), frozenPatterns, config,
443 assert(llvm::all_of(ifOp.getOperands(),
451 auto *hoistOverOp = getOutermostInvariantForOp(ifOp);
453 AffineIfOp hoistedIfOp = ::hoistAffineIfOp(ifOp, hoistOverOp);
455 if (hoistedIfOp == ifOp)