@@ -51,20 +51,20 @@ class AffineLoopAnalysis {
51
51
return analyzeMemoryAccess (loopOperation) &&
52
52
analyzeBody (loopOperation, functionAnalysis);
53
53
}
54
- bool analyzeReference (mlir::Value);
54
+ bool analyzeReference (mlir::Value, mlir::Operation * );
55
55
bool analyzeMemoryAccess (fir::DoLoopOp loopOperation) {
56
56
for (auto loadOp : loopOperation.getOps <fir::LoadOp>())
57
- if (!analyzeReference (loadOp.memref ()))
57
+ if (!analyzeReference (loadOp.memref (), loadOp ))
58
58
return false ;
59
59
for (auto storeOp : loopOperation.getOps <fir::StoreOp>())
60
- if (!analyzeReference (storeOp.memref ()))
60
+ if (!analyzeReference (storeOp.memref (), storeOp ))
61
61
return false ;
62
62
return true ;
63
63
}
64
64
};
65
65
66
66
// / Calculates arguments for creating an IntegerSet symCount, dimCount are the
67
- // / final number of symbols and dimensions of the affine map. If integer set if
67
+ // / final number of symbols and dimensions of the affine map. Integer set if
68
68
// / possible is in Optional IntegerSet
69
69
class AffineIfCondition {
70
70
public:
@@ -213,37 +213,43 @@ class AffineFunctionAnalysis {
213
213
llvm::DenseMap<mlir::Operation *, AffineIfAnalysis> ifAnalysisMap;
214
214
};
215
215
216
- bool analyzeCoordinate (mlir::Value coordinate) {
216
+ bool analyzeCoordinate (mlir::Value coordinate, mlir::Operation *op ) {
217
217
if (auto blockArg = coordinate.dyn_cast <mlir::BlockArgument>()) {
218
218
if (isa<fir::DoLoopOp>(blockArg.getOwner ()->getParentOp ())) {
219
219
return true ;
220
220
} else {
221
- llvm::dbgs () << " AffineLoopAnalysis: array coordinate is not a "
222
- " loop induction variable (owner not loopOp)\n " ;
221
+ LLVM_DEBUG (llvm::dbgs ()
222
+ << " AffineLoopAnalysis: array coordinate is not a "
223
+ " loop induction variable (owner not loopOp)\n " ;
224
+ op->dump (););
223
225
return false ;
224
226
}
225
227
} else {
226
- llvm::dbgs () << " AffineLoopAnalysis: array coordinate is not a loop "
227
- " induction variable (not a block argument)\n " ;
228
+ LLVM_DEBUG (llvm::dbgs ()
229
+ << " AffineLoopAnalysis: array coordinate is not a loop "
230
+ " induction variable (not a block argument)\n " ;
231
+ op->dump (); coordinate.getDefiningOp ()->dump (););
228
232
return false ;
229
233
}
230
234
}
231
- bool AffineLoopAnalysis::analyzeReference (mlir::Value memref) {
235
+ bool AffineLoopAnalysis::analyzeReference (mlir::Value memref,
236
+ mlir::Operation *op) {
232
237
if (auto acoOp = memref.getDefiningOp <ArrayCoorOp>()) {
233
238
bool canPromote = true ;
234
239
for (auto coordinate : acoOp.indices ())
235
- canPromote = canPromote && analyzeCoordinate (coordinate);
240
+ canPromote = canPromote && analyzeCoordinate (coordinate, op );
236
241
return canPromote;
237
242
}
238
243
if (auto coOp = memref.getDefiningOp <CoordinateOp>()) {
239
244
LLVM_DEBUG (llvm::dbgs () << " AffineLoopAnalysis: cannot promote loop, "
240
- " array uses non ArrayCoorOp\n " ;
241
- coOp.dump (););
245
+ " array memory operation uses non ArrayCoorOp\n " ;
246
+ op-> dump (); coOp.dump (););
242
247
243
248
return false ;
244
249
}
245
250
LLVM_DEBUG (llvm::dbgs () << " AffineLoopAnalysis: unknown type of memory "
246
- " reference for array load\n " ;);
251
+ " reference for array load\n " ;
252
+ op->dump (););
247
253
return false ;
248
254
}
249
255
@@ -311,38 +317,48 @@ mlir::Type coordinateArrayElement(fir::ArrayCoorOp op) {
311
317
void populateIndexArgs (fir::ArrayCoorOp acoOp, fir::ShapeOp shape,
312
318
SmallVectorImpl<mlir::Value> &indexArgs,
313
319
mlir::PatternRewriter &rewriter) {
314
- auto iter = shape.extents ().begin ();
315
320
auto one = rewriter.create <mlir::ConstantOp>(
316
321
acoOp.getLoc (), rewriter.getIndexType (), rewriter.getIndexAttr (1 ));
317
- auto end = shape.extents (). size ();
318
- for (decltype (end) i = 0 ; i < end; ++i ) {
322
+ auto extents = shape.extents ();
323
+ for (auto i = extents. begin () ; i < extents. end (); i++ ) {
319
324
indexArgs.push_back (one);
320
- indexArgs.push_back (*iter++ );
325
+ indexArgs.push_back (*i );
321
326
indexArgs.push_back (one);
322
327
}
323
328
}
329
+
324
330
void populateIndexArgs (fir::ArrayCoorOp acoOp, fir::ShapeShiftOp shape,
325
331
SmallVectorImpl<mlir::Value> &indexArgs,
326
332
mlir::PatternRewriter &rewriter) {
327
- auto iter = shape.pairs ().begin ();
328
333
auto one = rewriter.create <mlir::ConstantOp>(
329
334
acoOp.getLoc (), rewriter.getIndexType (), rewriter.getIndexAttr (1 ));
330
- auto end = shape.pairs (). size ();
331
- for (decltype (end) i = 0 ; i < end; ++(++i) ) {
332
- indexArgs.push_back (*iter ++);
333
- indexArgs.push_back (*iter ++);
335
+ auto extents = shape.pairs ();
336
+ for (auto i = extents. begin () ; i < extents. end (); ) {
337
+ indexArgs.push_back (*i ++);
338
+ indexArgs.push_back (*i ++);
334
339
indexArgs.push_back (one);
335
340
}
336
341
}
342
+ void populateIndexArgs (fir::ArrayCoorOp acoOp, fir::SliceOp slice,
343
+ SmallVectorImpl<mlir::Value> &indexArgs,
344
+ mlir::PatternRewriter &rewriter) {
345
+ auto extents = slice.triples ();
346
+ for (auto i = extents.begin (); i < extents.end ();) {
347
+ indexArgs.push_back (*i++);
348
+ indexArgs.push_back (*i++);
349
+ indexArgs.push_back (*i++);
350
+ }
351
+ }
352
+
337
353
void populateIndexArgs (fir::ArrayCoorOp acoOp,
338
354
SmallVectorImpl<mlir::Value> &indexArgs,
339
355
mlir::PatternRewriter &rewriter) {
340
- if (auto shape = acoOp.shape ().getDefiningOp <ShapeOp>()) {
356
+ if (auto shape = acoOp.shape ().getDefiningOp <ShapeOp>())
341
357
return populateIndexArgs (acoOp, shape, indexArgs, rewriter);
342
- }
343
358
if (auto shapeShift = acoOp.shape ().getDefiningOp <ShapeShiftOp>())
344
359
return populateIndexArgs (acoOp, shapeShift, indexArgs, rewriter);
345
- llvm::dbgs () << " AffinePromotion: need to populateIndexArgs for slice\n " ;
360
+ if (auto slice = acoOp.shape ().getDefiningOp <SliceOp>())
361
+ return populateIndexArgs (acoOp, slice, indexArgs, rewriter);
346
362
return ;
347
363
}
348
364
0 commit comments