This is an archive of the discontinued LLVM Phabricator instance.

[mlir][MemRef] Add pattern to resolve strided metadata of `memref.get_global` operation.
ClosedPublic

Authored by mravishankar on Apr 1 2023, 4:04 PM.

Details

Summary

This changes adds patterns to resolve the base pointer, offset, sizes
and strides of the result of a memref.get_global operation. Since
the operation can only result in static shaped memrefs, current
resolution kicks in only for non-zero offsets, and identity strides.

Also

  • Add a separate populateResolveExtractStridedMetadata method that adds just the pattern to resolve <memref op> -> memref.extract_strided_metadata operations.
  • Refactor the SubviewFolder pattern to allow resolving memref.subview -> memref.extract_strided_metadata.

This allows using these patterns for cases where there are already
existing memref.extract_strided_metadata operations.

Diff Detail

Event Timeline

mravishankar created this revision.Apr 1 2023, 4:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 1 2023, 4:04 PM
mravishankar requested review of this revision.Apr 1 2023, 4:04 PM
qcolombet accepted this revision.Apr 3 2023, 5:21 AM

LGTM but I think we're missing a test for populateResolveExtractStridedMetadataPatterns.
@nicolasvasilache should we use transform dialect for the test?

Couple of additional nits below.

mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp
734

Nit: rename this variable to getGlobalOp.

758

I think you can use mlir::computeSuffixProduct instead of doing the loop yourself.

This revision is now accepted and ready to land.Apr 3 2023, 5:21 AM

LGTM but I think we're missing a test for populateResolveExtractStridedMetadataPatterns.
@nicolasvasilache should we use transform dialect for the test?

There was already a test that was for this https://github.com/llvm/llvm-project/blob/31229d48bbfd394b64179d9be94f74ab70c84630/mlir/test/Dialect/MemRef/expand-strided-metadata.mlir#L102 .

Couple of additional nits below.