aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStella Laurenzo <stellaraccident@gmail.com>2021-02-26 13:11:02 -0800
committerStella Laurenzo <stellaraccident@gmail.com>2021-03-01 21:15:40 -0800
commitd36a15de1ff4d24e772233406d602c5f0b370f54 (patch)
tree12732a4889b4440edd4f627c3be7ab7c58498186
parent7c724a896f93c97fe75db6f37b0995c9b35e0b82 (diff)
downloadllvm-d36a15de1ff4d24e772233406d602c5f0b370f54.zip
llvm-d36a15de1ff4d24e772233406d602c5f0b370f54.tar.gz
llvm-d36a15de1ff4d24e772233406d602c5f0b370f54.tar.bz2
[mlir][linalg] Memoize indexing map generation.
Differential Revision: https://reviews.llvm.org/D97602
-rw-r--r--mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp7
-rw-r--r--mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp9
2 files changed, 13 insertions, 3 deletions
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
index acc8ff1..46e5780 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
@@ -2333,8 +2333,11 @@ static void printNamedStructuredOpResults(OpAsmPrinter &p,
template <typename NamedStructuredOpType>
static void printNamedStructuredOp(OpAsmPrinter &p, NamedStructuredOpType op) {
p << op.getOperationName();
- p.printOptionalAttrDict(op->getAttrs(),
- /*elidedAttrs=*/{"operand_segment_sizes"});
+ p.printOptionalAttrDict(
+ op->getAttrs(),
+ /*elidedAttrs=*/{"operand_segment_sizes",
+ // See generated code in mlir-linalg-yaml-gen.cpp
+ "linalg.memoized_indexing_maps"});
// Printing is shared with generic ops, except for the region and
// attributes.
diff --git a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
index 5578ff5..1dddc57 100644
--- a/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
+++ b/mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
@@ -651,11 +651,18 @@ static SmallVector<AffineExpr> getSymbolBindings({0} self) {
// {2}: Statements
static const char structuredOpIndexingMapsFormat[] = R"FMT(
ArrayAttr {0}::indexing_maps() {
+ static const char memoizeAttr[] = "linalg.memoized_indexing_maps";
+ ArrayAttr cached = getOperation()->getAttrOfType<ArrayAttr>(memoizeAttr);
+ if (cached)
+ return cached;
+
MLIRContext *context = getContext();
auto symbolBindings = getSymbolBindings(*this);
SmallVector<AffineMap> maps;
{2}
- return Builder(context).getAffineMapArrayAttr(maps);
+ cached = Builder(context).getAffineMapArrayAttr(maps);
+ getOperation()->setAttr(memoizeAttr, cached);
+ return cached;
}
)FMT";