@@ -454,19 +454,17 @@ LogicalResult MemRefRegion::compute(Operation *op, unsigned loopDepth,
454
454
unsigned rank = access.getRank ();
455
455
456
456
LLVM_DEBUG (llvm::dbgs () << " MemRefRegion::compute: " << *op
457
- << " depth : " << loopDepth << " \n " ;);
457
+ << " \n depth : " << loopDepth << " \n " ;);
458
458
459
459
// 0-d memrefs.
460
460
if (rank == 0 ) {
461
- SmallVector<AffineForOp , 4 > ivs;
462
- getAffineForIVs (*op, & ivs);
461
+ SmallVector<Value , 4 > ivs;
462
+ getAffineIVs (*op, ivs);
463
463
assert (loopDepth <= ivs.size () && " invalid 'loopDepth'" );
464
464
// The first 'loopDepth' IVs are symbols for this region.
465
465
ivs.resize (loopDepth);
466
- SmallVector<Value, 4 > regionSymbols;
467
- extractForInductionVars (ivs, ®ionSymbols);
468
466
// A 0-d memref has a 0-d region.
469
- cst.reset (rank, loopDepth, /* numLocals=*/ 0 , regionSymbols );
467
+ cst.reset (rank, loopDepth, /* numLocals=*/ 0 , ivs );
470
468
return success ();
471
469
}
472
470
@@ -503,23 +501,24 @@ LogicalResult MemRefRegion::compute(Operation *op, unsigned loopDepth,
503
501
// Add inequalities for loop lower/upper bounds.
504
502
for (unsigned i = 0 ; i < numDims + numSymbols; ++i) {
505
503
auto operand = operands[i];
506
- if (auto loop = getForInductionVarOwner (operand)) {
504
+ if (auto affineFor = getForInductionVarOwner (operand)) {
507
505
// Note that cst can now have more dimensions than accessMap if the
508
506
// bounds expressions involve outer loops or other symbols.
509
507
// TODO: rewrite this to use getInstIndexSet; this way
510
508
// conditionals will be handled when the latter supports it.
511
- if (failed (cst.addAffineForOpDomain (loop )))
509
+ if (failed (cst.addAffineForOpDomain (affineFor )))
512
510
return failure ();
513
- } else {
514
- // Has to be a valid symbol.
515
- auto symbol = operand ;
516
- assert (isValidSymbol (symbol));
511
+ } else if ( auto parallelOp = getAffineParallelInductionVarOwner (operand)) {
512
+ if ( failed (cst. addAffineParallelOpDomain (parallelOp)))
513
+ return failure () ;
514
+ } else if (isValidSymbol (operand)) {
517
515
// Check if the symbol is a constant.
518
- if (auto *op = symbol.getDefiningOp ()) {
519
- if (auto constOp = dyn_cast<arith::ConstantIndexOp>(op)) {
520
- cst.addBound (FlatAffineValueConstraints::EQ, symbol, constOp.value ());
521
- }
522
- }
516
+ Value symbol = operand;
517
+ if (auto constVal = getConstantIntValue (symbol))
518
+ cst.addBound (FlatAffineValueConstraints::EQ, symbol, constVal.value ());
519
+ } else {
520
+ LLVM_DEBUG (llvm::dbgs () << " unknown affine dimensional value" );
521
+ return failure ();
523
522
}
524
523
}
525
524
@@ -552,16 +551,14 @@ LogicalResult MemRefRegion::compute(Operation *op, unsigned loopDepth,
552
551
553
552
// Eliminate any loop IVs other than the outermost 'loopDepth' IVs, on which
554
553
// this memref region is symbolic.
555
- SmallVector<AffineForOp , 4 > enclosingIVs;
556
- getAffineForIVs (*op, & enclosingIVs);
554
+ SmallVector<Value , 4 > enclosingIVs;
555
+ getAffineIVs (*op, enclosingIVs);
557
556
assert (loopDepth <= enclosingIVs.size () && " invalid loop depth" );
558
557
enclosingIVs.resize (loopDepth);
559
558
SmallVector<Value, 4 > vars;
560
559
cst.getValues (cst.getNumDimVars (), cst.getNumDimAndSymbolVars (), &vars);
561
- for (auto var : vars) {
562
- AffineForOp iv;
563
- if ((iv = getForInductionVarOwner (var)) &&
564
- !llvm::is_contained (enclosingIVs, iv)) {
560
+ for (Value var : vars) {
561
+ if ((isAffineInductionVar (var)) && !llvm::is_contained (enclosingIVs, var)) {
565
562
cst.projectOut (var);
566
563
}
567
564
}
@@ -1264,21 +1261,19 @@ bool MemRefAccess::operator==(const MemRefAccess &rhs) const {
1264
1261
[](AffineExpr e) { return e == 0 ; });
1265
1262
}
1266
1263
1267
- // / Populates 'loops' with IVs of the surrounding affine.for and affine.parallel
1268
- // / ops ordered from the outermost one to the innermost.
1269
- static void getAffineIVs (Operation &op, SmallVectorImpl<Value> &loops) {
1264
+ void mlir::getAffineIVs (Operation &op, SmallVectorImpl<Value> &ivs) {
1270
1265
auto *currOp = op.getParentOp ();
1271
1266
AffineForOp currAffineForOp;
1272
- // Traverse up the hierarchy collecting all 'affine.for' operation while
1273
- // skipping over 'affine.if' operations.
1267
+ // Traverse up the hierarchy collecting all 'affine.for' and affine.parallel
1268
+ // operation while skipping over 'affine.if' operations.
1274
1269
while (currOp) {
1275
1270
if (AffineForOp currAffineForOp = dyn_cast<AffineForOp>(currOp))
1276
- loops .push_back (currAffineForOp.getInductionVar ());
1271
+ ivs .push_back (currAffineForOp.getInductionVar ());
1277
1272
else if (auto parOp = dyn_cast<AffineParallelOp>(currOp))
1278
- llvm::append_range (loops , parOp.getIVs ());
1273
+ llvm::append_range (ivs , parOp.getIVs ());
1279
1274
currOp = currOp->getParentOp ();
1280
1275
}
1281
- std::reverse (loops .begin (), loops .end ());
1276
+ std::reverse (ivs .begin (), ivs .end ());
1282
1277
}
1283
1278
1284
1279
// / Returns the number of surrounding loops common to 'loopsA' and 'loopsB',
0 commit comments