Skip to content

Commit

Permalink
[mlir][linalg] Memoize indexing map generation.
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D97602
  • Loading branch information
stellaraccident committed Mar 2, 2021
1 parent 7c724a8 commit d36a15d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 5 additions & 2 deletions mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-yaml-gen.cpp
Expand Up @@ -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";

Expand Down

0 comments on commit d36a15d

Please sign in to comment.