This is an archive of the discontinued LLVM Phabricator instance.

[mlir][memref] Add pass to expand realloc operations, simplify lowering to LLVM
ClosedPublic

Authored by maerhart on Sep 4 2023, 6:17 AM.

Details

Summary

There are two motivations for this change:

  1. It considerably simplifies adding support for the realloc operation to the new buffer deallocation pass by lowering the realloc such that no deallocation operation is inserted and the deallocation pass itself can insert that dealloc
  2. The lowering is expressed on a higher level and thus easier to understand, and the lowerings of the memref operations it is composed of don't have to be duplicated in the MemRefToLLVM lowering (also see discussion in https://reviews.llvm.org/D133424)

Diff Detail

Event Timeline

maerhart created this revision.Sep 4 2023, 6:17 AM
Herald added a reviewer: ftynse. · View Herald Transcript
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added a reviewer: dcaballe. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
maerhart requested review of this revision.Sep 4 2023, 6:17 AM
maerhart updated this revision to Diff 555748.Sep 4 2023, 7:03 AM

fix cmake build

springerm added inline comments.Sep 4 2023, 7:42 AM
mlir/include/mlir/Dialect/MemRef/Transforms/Passes.td
209

memref.realloc

210

a

239

I would call it emitDeallocs with a default value of true.

mlir/lib/Dialect/MemRef/Transforms/ExpandRealloc.cpp
1

There is usually a small description here

59

I would put an assert(op.getType().getRank() == 1), same for the operand.

61

If it's not already there, let's add a check to the verifier that the operand memref or the result memref type have an identity layout map. And then let's also put an assert here, just to be safe.

131–140

You can use mlir::getValueOrCreateConstantIndexOp.

143

can be const

maerhart updated this revision to Diff 555759.Sep 4 2023, 8:37 AM
maerhart marked 8 inline comments as done.

address comments

springerm accepted this revision.Sep 5 2023, 1:22 AM
This revision is now accepted and ready to land.Sep 5 2023, 1:22 AM

Forgot to hit 'submit' yesterday for the attached comment. Thanks for reviewing!

mlir/lib/Dialect/MemRef/Transforms/ExpandRealloc.cpp
61

Both the source and result are already verified to have identity layout, but I've added assertions.

This revision was landed with ongoing or failed builds.Sep 5 2023, 1:59 AM
This revision was automatically updated to reflect the committed changes.