diff --git a/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h b/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h --- a/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h +++ b/mlir/include/mlir/Dialect/Affine/Analysis/Utils.h @@ -38,11 +38,14 @@ // TODO: handle 'affine.if' ops. void getLoopIVs(Operation &op, SmallVectorImpl *loops); -/// Populates 'ops' with IVs of the loops surrounding `op`, along with -/// `affine.if` operations interleaved between these loops, ordered from the -/// outermost `affine.for` or `affine.if` operation to the innermost one. -void getEnclosingAffineForAndIfOps(Operation &op, - SmallVectorImpl *ops); +/// Populates 'ops' with affine operations enclosing `op` ordered from outermost +/// to innermost. affine.for, affine.if, or affine.parallel ops comprise such +/// surrounding affine ops. +/// TODO: Change this to return a list of enclosing ops up until the op that +/// starts an `AffineScope`. In such a case, `ops` is guaranteed by design to +/// have a successive chain of affine parent ops, and this is primarily what is +/// needed for most analyses. +void getEnclosingAffineOps(Operation &op, SmallVectorImpl *ops); /// Returns the nesting depth of this operation, i.e., the number of loops /// surrounding this operation. diff --git a/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp b/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp --- a/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp +++ b/mlir/lib/Dialect/Affine/Analysis/AffineAnalysis.cpp @@ -241,10 +241,12 @@ FlatAffineValueConstraints *domain) { SmallVector indices; SmallVector forOps; - for (Operation *op : ops) { - assert((isa(op)) && - "ops should have either AffineForOp or AffineIfOp"); + if (!isa(op)) { + // TODO: Support affine.parallel ops. + LLVM_DEBUG(llvm::dbgs() << "getIndexSet only handles affine.for/if ops"); + return failure(); + } if (AffineForOp forOp = dyn_cast(op)) forOps.push_back(forOp); } @@ -271,7 +273,7 @@ static LogicalResult getOpIndexSet(Operation *op, FlatAffineValueConstraints *indexSet) { SmallVector ops; - getEnclosingAffineForAndIfOps(*op, &ops); + getEnclosingAffineOps(*op, &ops); return getIndexSet(ops, indexSet); } diff --git a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp --- a/mlir/lib/Dialect/Affine/Analysis/Utils.cpp +++ b/mlir/lib/Dialect/Affine/Analysis/Utils.cpp @@ -45,18 +45,15 @@ std::reverse(loops->begin(), loops->end()); } -/// Populates 'ops' with IVs of the loops surrounding `op`, along with -/// `affine.if` operations interleaved between these loops, ordered from the -/// outermost `affine.for` operation to the innermost one. -void mlir::getEnclosingAffineForAndIfOps(Operation &op, - SmallVectorImpl *ops) { +void mlir::getEnclosingAffineOps(Operation &op, + SmallVectorImpl *ops) { ops->clear(); Operation *currOp = op.getParentOp(); - // Traverse up the hierarchy collecting all `affine.for` and `affine.if` - // operations. + // Traverse up the hierarchy collecting all `affine.for`, `affine.if`, and + // affine.parallel operations. while (currOp) { - if (isa(currOp)) + if (isa(currOp)) ops->push_back(currOp); currOp = currOp->getParentOp(); }