@@ -373,15 +373,15 @@ static void generateUnrolledLoop(
373373}
374374
375375// / Unrolls 'forOp' by 'unrollFactor', returns the unrolled main loop and the
376- // / eplilog loop, if the loop is unrolled. Otherwise return null.
377- UnrolledLoopInfo mlir::loopUnrollByFactor (
376+ // / eplilog loop, if the loop is unrolled.
377+ FailureOr< UnrolledLoopInfo> mlir::loopUnrollByFactor (
378378 scf::ForOp forOp, uint64_t unrollFactor,
379379 function_ref<void (unsigned , Operation *, OpBuilder)> annotateFn) {
380380 assert (unrollFactor > 0 && " expected positive unroll factor" );
381381
382382 // Return if the loop body is empty.
383383 if (llvm::hasSingleElement (forOp.getBody ()->getOperations ()))
384- return {forOp, nullptr };
384+ return UnrolledLoopInfo {forOp, nullptr };
385385
386386 // Compute tripCount = ceilDiv((upperBound - lowerBound), step) and populate
387387 // 'upperBoundUnrolled' and 'stepUnrolled' for static and dynamic cases.
@@ -402,8 +402,8 @@ UnrolledLoopInfo mlir::loopUnrollByFactor(
402402 if (unrollFactor == 1 ) {
403403 if (*constTripCount == 1 &&
404404 failed (forOp.promoteIfSingleIteration (rewriter)))
405- return { nullptr , nullptr } ;
406- return {forOp, nullptr };
405+ return failure () ;
406+ return UnrolledLoopInfo {forOp, nullptr };
407407 }
408408
409409 int64_t tripCountEvenMultiple =
@@ -470,8 +470,8 @@ UnrolledLoopInfo mlir::loopUnrollByFactor(
470470 }
471471 epilogueForOp->setOperands (epilogueForOp.getNumControlOperands (),
472472 epilogueForOp.getInitArgs ().size (), results);
473- ( void ) epilogueForOp.promoteIfSingleIteration (rewriter);
474- resultLoops.epilogueLoopOp = epilogueForOp;
473+ if ( epilogueForOp.promoteIfSingleIteration (rewriter). failed ())
474+ resultLoops.epilogueLoopOp = epilogueForOp;
475475 }
476476
477477 // Create unrolled loop.
@@ -493,8 +493,8 @@ UnrolledLoopInfo mlir::loopUnrollByFactor(
493493 },
494494 annotateFn, iterArgs, yieldedValues);
495495 // Promote the loop body up if this has turned into a single iteration loop.
496- ( void ) forOp.promoteIfSingleIteration (rewriter);
497- resultLoops.mainLoopOp = forOp;
496+ if ( forOp.promoteIfSingleIteration (rewriter). failed ())
497+ resultLoops.mainLoopOp = forOp;
498498 return resultLoops;
499499}
500500
0 commit comments