[mlir] Optimize const values AffineMap::compose (#141005)
The original implementation will create two intermediate AffineMap in the context, calling this compose function with different values multiple times will occupy a lot of memory. To improve the performance, we can call the AffineExpr::replace directly, so we don't need to store all combinations of values in the context.
This commit is contained in:
parent
e9dbf31be5
commit
d5802c30ae
@ -580,15 +580,13 @@ AffineMap AffineMap::compose(AffineMap map) const {
|
|||||||
SmallVector<int64_t, 4> AffineMap::compose(ArrayRef<int64_t> values) const {
|
SmallVector<int64_t, 4> AffineMap::compose(ArrayRef<int64_t> values) const {
|
||||||
assert(getNumSymbols() == 0 && "Expected symbol-less map");
|
assert(getNumSymbols() == 0 && "Expected symbol-less map");
|
||||||
SmallVector<AffineExpr, 4> exprs;
|
SmallVector<AffineExpr, 4> exprs;
|
||||||
exprs.reserve(values.size());
|
|
||||||
MLIRContext *ctx = getContext();
|
MLIRContext *ctx = getContext();
|
||||||
for (auto v : values)
|
for (int64_t value : values)
|
||||||
exprs.push_back(getAffineConstantExpr(v, ctx));
|
exprs.push_back(getAffineConstantExpr(value, ctx));
|
||||||
auto resMap = compose(AffineMap::get(0, 0, exprs, ctx));
|
|
||||||
SmallVector<int64_t, 4> res;
|
SmallVector<int64_t, 4> res;
|
||||||
res.reserve(resMap.getNumResults());
|
res.reserve(getNumResults());
|
||||||
for (auto e : resMap.getResults())
|
for (auto e : getResults())
|
||||||
res.push_back(cast<AffineConstantExpr>(e).getValue());
|
res.push_back(cast<AffineConstantExpr>(e.replaceDims(exprs)).getValue());
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user