@@ -200,53 +200,6 @@ emitIVToStableHLO(OpBuilder &builder, Value iv, InductionVariableRange range,
200
200
maps[iota] = accessMap;
201
201
}
202
202
203
- // Given an affine map for a load/store operation, compute the startIndices,
204
- // limitIndices and strides corresponding in the memref based on the loop
205
- // induction variables.
206
- //
207
- // (i) -> (0, i, 10) will give [0:1:1, begin:end:step, 10:11:1]
208
- // (i) -> (2 * i, i + 2, 10) will give [begin*2:end*2:2*step,
209
- // begin+2:end+2:step, 10:11:1]
210
- //
211
- // with begin:end:step corresponding to the range of the iv i.
212
- static LogicalResult affineMapToSlice (affine::AffineValueMap accessValueMap,
213
- SmallVectorImpl<int64_t > &strides,
214
- SmallVectorImpl<int64_t > &reverseDims) {
215
- auto rank = accessValueMap.getNumResults ();
216
-
217
- strides.reserve (rank);
218
-
219
- for (unsigned i = 0 ; i < rank; i++) {
220
- auto expr = accessValueMap.getResult (i);
221
-
222
- if (auto constExpr = dyn_cast<AffineConstantExpr>(expr)) {
223
- strides.push_back (1 );
224
- continue ;
225
- }
226
-
227
- Value iv = getIVForExpr (accessValueMap, expr);
228
- if (affine::isAffineForInductionVar (iv)) {
229
- strides.push_back (1 );
230
- continue ;
231
- }
232
-
233
- auto range = computeExprRange (accessValueMap, expr);
234
-
235
- if (!range.has_value ())
236
- return failure ();
237
-
238
- if (range->step < 0 ) {
239
- // 0:-1:-180 -> -179:1:1
240
- strides.push_back (-range->step );
241
- reverseDims.push_back (i);
242
- } else {
243
- strides.push_back (range->step );
244
- }
245
- }
246
-
247
- return success ();
248
- }
249
-
250
203
// The name is parallel context but a more accurate description would be
251
204
// LockStepContext
252
205
struct ParallelContext {
@@ -337,6 +290,54 @@ struct ParallelContext {
337
290
}
338
291
};
339
292
293
+ // Given an affine map for a load/store operation, compute the startIndices,
294
+ // limitIndices and strides corresponding in the memref based on the loop
295
+ // induction variables.
296
+ //
297
+ // (i) -> (0, i, 10) will give [0:1:1, begin:end:step, 10:11:1]
298
+ // (i) -> (2 * i, i + 2, 10) will give [begin*2:end*2:2*step,
299
+ // begin+2:end+2:step, 10:11:1]
300
+ //
301
+ // with begin:end:step corresponding to the range of the iv i.
302
+ static LogicalResult affineMapToSlice (affine::AffineValueMap accessValueMap,
303
+ SmallVectorImpl<int64_t > &strides,
304
+ SmallVectorImpl<int64_t > &reverseDims,
305
+ ParallelContext pc) {
306
+ auto rank = accessValueMap.getNumResults ();
307
+
308
+ strides.reserve (rank);
309
+
310
+ for (unsigned i = 0 ; i < rank; i++) {
311
+ auto expr = accessValueMap.getResult (i);
312
+
313
+ if (auto constExpr = dyn_cast<AffineConstantExpr>(expr)) {
314
+ strides.push_back (1 );
315
+ continue ;
316
+ }
317
+
318
+ Value iv = getIVForExpr (accessValueMap, expr);
319
+ if (affine::isAffineForInductionVar (iv) && !pc.isParallelIV (iv)) {
320
+ strides.push_back (1 );
321
+ continue ;
322
+ }
323
+
324
+ auto range = computeExprRange (accessValueMap, expr);
325
+
326
+ if (!range.has_value ())
327
+ return failure ();
328
+
329
+ if (range->step < 0 ) {
330
+ // 0:-1:-180 -> -179:1:1
331
+ strides.push_back (-range->step );
332
+ reverseDims.push_back (i);
333
+ } else {
334
+ strides.push_back (range->step );
335
+ }
336
+ }
337
+
338
+ return success ();
339
+ }
340
+
340
341
static SmallVector<int64_t >
341
342
affineMapShape (affine::AffineValueMap accessValueMap, ParallelContext pc) {
342
343
AffineMap map = accessValueMap.getAffineMap ();
@@ -1597,7 +1598,7 @@ tryRaisingOpToStableHLO(Operation *op, IRMapping &mapping, OpBuilder &builder,
1597
1598
SmallVector<int64_t > strides;
1598
1599
SmallVector<int64_t > reverseDims;
1599
1600
1600
- if (affineMapToSlice (accessValueMap, strides, reverseDims).failed ()) {
1601
+ if (affineMapToSlice (accessValueMap, strides, reverseDims, pc ).failed ()) {
1601
1602
LLVM_DEBUG (llvm::dbgs ()
1602
1603
<< " Failed to affine map to slice: " << *op << " \n " );
1603
1604
return failure ();
@@ -1733,7 +1734,7 @@ tryRaisingOpToStableHLO(Operation *op, IRMapping &mapping, OpBuilder &builder,
1733
1734
SmallVector<int64_t > strides;
1734
1735
SmallVector<int64_t > reverseDims;
1735
1736
1736
- if (affineMapToSlice (accessValueMap, strides, reverseDims).failed ()) {
1737
+ if (affineMapToSlice (accessValueMap, strides, reverseDims, pc ).failed ()) {
1737
1738
LLVM_DEBUG (llvm::dbgs ()
1738
1739
<< " Failed to affine map to slice: " << *op << " \n " );
1739
1740
return failure ();
0 commit comments