Skip to content

Commit d36a15d

Browse files
[mlir][linalg] Memoize indexing map generation.
Differential Revision: https://reviews.llvm.org/D97602
1 parent 7c724a8 commit d36a15d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,8 +2333,11 @@ static void printNamedStructuredOpResults(OpAsmPrinter &p,
23332333
template <typename NamedStructuredOpType>
23342334
static void printNamedStructuredOp(OpAsmPrinter &p, NamedStructuredOpType op) {
23352335
p << op.getOperationName();
2336-
p.printOptionalAttrDict(op->getAttrs(),
2337-
/*elidedAttrs=*/{"operand_segment_sizes"});
2336+
p.printOptionalAttrDict(
2337+
op->getAttrs(),
2338+
/*elidedAttrs=*/{"operand_segment_sizes",
2339+
// See generated code in mlir-linalg-yaml-gen.cpp
2340+
"linalg.memoized_indexing_maps"});
23382341

23392342
// Printing is shared with generic ops, except for the region and
23402343
// attributes.

mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,18 @@ static SmallVector<AffineExpr> getSymbolBindings({0} self) {
651651
// {2}: Statements
652652
static const char structuredOpIndexingMapsFormat[] = R"FMT(
653653
ArrayAttr {0}::indexing_maps() {
654+
static const char memoizeAttr[] = "linalg.memoized_indexing_maps";
655+
ArrayAttr cached = getOperation()->getAttrOfType<ArrayAttr>(memoizeAttr);
656+
if (cached)
657+
return cached;
658+
654659
MLIRContext *context = getContext();
655660
auto symbolBindings = getSymbolBindings(*this);
656661
SmallVector<AffineMap> maps;
657662
{2}
658-
return Builder(context).getAffineMapArrayAttr(maps);
663+
cached = Builder(context).getAffineMapArrayAttr(maps);
664+
getOperation()->setAttr(memoizeAttr, cached);
665+
return cached;
659666
}
660667
)FMT";
661668

0 commit comments

Comments
 (0)