Skip to content

Commit 37deb09

Browse files
authored
[MLIR][Affine] Fix signatures of normalize memref utilities (llvm#134466)
These methods were passing derived op types by pointers, which deviates from the style. While on this, fix obsolete comments on those methods.
1 parent bd84d66 commit 37deb09

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

mlir/include/mlir/Dialect/Affine/Utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ LogicalResult replaceAllMemRefUsesWith(Value oldMemRef, Value newMemRef,
247247
/// and updates all its indexing uses. Returns failure if any of its uses
248248
/// escape (while leaving the IR in a valid state).
249249
template <typename AllocLikeOp>
250-
LogicalResult normalizeMemRef(AllocLikeOp *op);
250+
LogicalResult normalizeMemRef(AllocLikeOp op);
251251
extern template LogicalResult
252-
normalizeMemRef<memref::AllocaOp>(memref::AllocaOp *op);
252+
normalizeMemRef<memref::AllocaOp>(memref::AllocaOp op);
253253
extern template LogicalResult
254-
normalizeMemRef<memref::AllocOp>(memref::AllocOp *op);
254+
normalizeMemRef<memref::AllocOp>(memref::AllocOp op);
255255

256256
/// Normalizes `memrefType` so that the affine layout map of the memref is
257257
/// transformed to an identity map with a new shape being computed for the

mlir/lib/Dialect/Affine/Utils/Utils.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ static AffineExpr createDimSizeExprForTiledLayout(AffineExpr oldMapOutput,
17411741
template <typename AllocLikeOp>
17421742
static void createNewDynamicSizes(MemRefType oldMemRefType,
17431743
MemRefType newMemRefType, AffineMap map,
1744-
AllocLikeOp *allocOp, OpBuilder b,
1744+
AllocLikeOp allocOp, OpBuilder b,
17451745
SmallVectorImpl<Value> &newDynamicSizes) {
17461746
// Create new input for AffineApplyOp.
17471747
SmallVector<Value, 4> inAffineApply;
@@ -1750,13 +1750,13 @@ static void createNewDynamicSizes(MemRefType oldMemRefType,
17501750
for (unsigned d = 0; d < oldMemRefType.getRank(); ++d) {
17511751
if (oldMemRefShape[d] < 0) {
17521752
// Use dynamicSizes of allocOp for dynamic dimension.
1753-
inAffineApply.emplace_back(allocOp->getDynamicSizes()[dynIdx]);
1753+
inAffineApply.emplace_back(allocOp.getDynamicSizes()[dynIdx]);
17541754
dynIdx++;
17551755
} else {
17561756
// Create ConstantOp for static dimension.
17571757
auto constantAttr = b.getIntegerAttr(b.getIndexType(), oldMemRefShape[d]);
17581758
inAffineApply.emplace_back(
1759-
b.create<arith::ConstantOp>(allocOp->getLoc(), constantAttr));
1759+
b.create<arith::ConstantOp>(allocOp.getLoc(), constantAttr));
17601760
}
17611761
}
17621762

@@ -1780,18 +1780,17 @@ static void createNewDynamicSizes(MemRefType oldMemRefType,
17801780
AffineMap newMap =
17811781
AffineMap::get(map.getNumInputs(), map.getNumSymbols(), newMapOutput);
17821782
Value affineApp =
1783-
b.create<AffineApplyOp>(allocOp->getLoc(), newMap, inAffineApply);
1783+
b.create<AffineApplyOp>(allocOp.getLoc(), newMap, inAffineApply);
17841784
newDynamicSizes.emplace_back(affineApp);
17851785
}
17861786
newDimIdx++;
17871787
}
17881788
}
17891789

1790-
// TODO: Currently works for static memrefs with a single layout map.
17911790
template <typename AllocLikeOp>
1792-
LogicalResult mlir::affine::normalizeMemRef(AllocLikeOp *allocOp) {
1793-
MemRefType memrefType = allocOp->getType();
1794-
OpBuilder b(*allocOp);
1791+
LogicalResult mlir::affine::normalizeMemRef(AllocLikeOp allocOp) {
1792+
MemRefType memrefType = allocOp.getType();
1793+
OpBuilder b(allocOp);
17951794

17961795
// Fetch a new memref type after normalizing the old memref to have an
17971796
// identity map layout.
@@ -1801,27 +1800,27 @@ LogicalResult mlir::affine::normalizeMemRef(AllocLikeOp *allocOp) {
18011800
// transformed to an identity map.
18021801
return failure();
18031802

1804-
Value oldMemRef = allocOp->getResult();
1803+
Value oldMemRef = allocOp.getResult();
18051804

1806-
SmallVector<Value, 4> symbolOperands(allocOp->getSymbolOperands());
1805+
SmallVector<Value, 4> symbolOperands(allocOp.getSymbolOperands());
18071806
AffineMap layoutMap = memrefType.getLayout().getAffineMap();
18081807
AllocLikeOp newAlloc;
18091808
// Check if `layoutMap` is a tiled layout. Only single layout map is
18101809
// supported for normalizing dynamic memrefs.
18111810
SmallVector<std::tuple<AffineExpr, unsigned, unsigned>> tileSizePos;
18121811
(void)getTileSizePos(layoutMap, tileSizePos);
18131812
if (newMemRefType.getNumDynamicDims() > 0 && !tileSizePos.empty()) {
1814-
MemRefType oldMemRefType = cast<MemRefType>(oldMemRef.getType());
1813+
auto oldMemRefType = cast<MemRefType>(oldMemRef.getType());
18151814
SmallVector<Value, 4> newDynamicSizes;
18161815
createNewDynamicSizes(oldMemRefType, newMemRefType, layoutMap, allocOp, b,
18171816
newDynamicSizes);
18181817
// Add the new dynamic sizes in new AllocOp.
18191818
newAlloc =
1820-
b.create<AllocLikeOp>(allocOp->getLoc(), newMemRefType, newDynamicSizes,
1821-
allocOp->getAlignmentAttr());
1819+
b.create<AllocLikeOp>(allocOp.getLoc(), newMemRefType, newDynamicSizes,
1820+
allocOp.getAlignmentAttr());
18221821
} else {
1823-
newAlloc = b.create<AllocLikeOp>(allocOp->getLoc(), newMemRefType,
1824-
allocOp->getAlignmentAttr());
1822+
newAlloc = b.create<AllocLikeOp>(allocOp.getLoc(), newMemRefType,
1823+
allocOp.getAlignmentAttr());
18251824
}
18261825
// Replace all uses of the old memref.
18271826
if (failed(replaceAllMemRefUsesWith(oldMemRef, /*newMemRef=*/newAlloc,
@@ -1842,14 +1841,14 @@ LogicalResult mlir::affine::normalizeMemRef(AllocLikeOp *allocOp) {
18421841
return hasSingleEffect<MemoryEffects::Free>(op, oldMemRef);
18431842
}));
18441843
oldMemRef.replaceAllUsesWith(newAlloc);
1845-
allocOp->erase();
1844+
allocOp.erase();
18461845
return success();
18471846
}
18481847

18491848
template LogicalResult
1850-
mlir::affine::normalizeMemRef<memref::AllocaOp>(memref::AllocaOp *op);
1849+
mlir::affine::normalizeMemRef<memref::AllocaOp>(memref::AllocaOp op);
18511850
template LogicalResult
1852-
mlir::affine::normalizeMemRef<memref::AllocOp>(memref::AllocOp *op);
1851+
mlir::affine::normalizeMemRef<memref::AllocOp>(memref::AllocOp op);
18531852

18541853
MemRefType mlir::affine::normalizeMemRefType(MemRefType memrefType) {
18551854
unsigned rank = memrefType.getRank();

mlir/lib/Dialect/MemRef/Transforms/NormalizeMemRefs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,12 +356,12 @@ void NormalizeMemRefs::normalizeFuncOpMemRefs(func::FuncOp funcOp,
356356
SmallVector<memref::AllocOp, 4> allocOps;
357357
funcOp.walk([&](memref::AllocOp op) { allocOps.push_back(op); });
358358
for (memref::AllocOp allocOp : allocOps)
359-
(void)normalizeMemRef(&allocOp);
359+
(void)normalizeMemRef(allocOp);
360360

361361
SmallVector<memref::AllocaOp> allocaOps;
362362
funcOp.walk([&](memref::AllocaOp op) { allocaOps.push_back(op); });
363363
for (memref::AllocaOp allocaOp : allocaOps)
364-
(void)normalizeMemRef(&allocaOp);
364+
(void)normalizeMemRef(allocaOp);
365365

366366
// We use this OpBuilder to create new memref layout later.
367367
OpBuilder b(funcOp);

0 commit comments

Comments
 (0)