This is an archive of the discontinued LLVM Phabricator instance.

Add `shape.get_extent`.
ClosedPublic

Authored by silvas on May 21 2020, 11:33 AM.

Details

Summary

This op extracts an extent from a shape.

This also is the first op which constant folds to shape.const_size,
which revealed that sahpe.const_size needs a folder (ConstantLike ops
seem to always need folders for the constant folding infra to work).

Diff Detail

Event Timeline

silvas created this revision.May 21 2020, 11:33 AM
Herald added a project: Restricted Project. · View Herald Transcript
silvas updated this revision to Diff 265558.May 21 2020, 11:34 AM

Update commit message.

jpienaar accepted this revision.May 24 2020, 9:05 PM
jpienaar marked an inline comment as done.

Nice, thanks

mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
214

This fits on one line

[I'm actually not sure why this one isn't generated by default, we have the generation for unwrapped types that I would have expected to trigger here ...]

mlir/lib/Dialect/Shape/IR/Shape.cpp
290

I'm not convinced of this unless we add this check to this op's verify method.

294

What is the type? E.g., are we storing it wrong?

Is only shape.const_shape expected here? If not, then this conversion (and whether it is signed/unsigned/signless) seem to need to support more cases (based on the requirement of getInt()).

This revision is now accepted and ready to land.May 24 2020, 9:05 PM

Just a note of a typo in your commit message "sahpe". I see you updated the diff with an updated commit message, so I'm guessing it's fixed, but arc doesn't propagate updated commit messages unfortunately.

tpopp added inline comments.May 25 2020, 1:08 AM
mlir/lib/Dialect/Shape/IR/Shape.cpp
298

There is a getIndexAtrr(int64_t) method that you could use here.

jpienaar added inline comments.May 26 2020, 6:21 AM
mlir/lib/Dialect/Shape/IR/Shape.cpp
290

And this is not UB: this is an error. It can be folded to constant size error.

silvas marked 5 inline comments as done.May 26 2020, 5:03 PM
silvas added inline comments.
mlir/lib/Dialect/Shape/IR/Shape.cpp
294

Good catch. We were using I64ElementsAttr for representing shapes when constant folding, but we should have been using IndexElementsAttr (which doesn't exist yet). I'll add IndexElementsAttr to core and fix this as part of the upgrade the shape dialect to using that.

298

it is just elements.getValue({dimToGet}) after the IndexElementsAttr fix (patches will be uploaded soon).

This revision was automatically updated to reflect the committed changes.
silvas marked 2 inline comments as done.