Skip to content

[MLIR][Interfaces] Change MemorySlotInterface to use OpBuilder #91341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 27 additions & 36 deletions mlir/include/mlir/Interfaces/MemorySlotInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -40,42 +40,40 @@ def PromotableAllocationOpInterface
Provides the default Value of this memory slot. The provided Value
will be used as the reaching definition of loads done before any store.
This Value must outlive the promotion and dominate all the uses of this
slot's pointer. The provided rewriter can be used to create the default
slot's pointer. The provided builder can be used to create the default
value on the fly.

The rewriter is located at the beginning of the block where the slot
pointer is defined. All IR mutations must happen through the rewriter.
The builder is located at the beginning of the block where the slot
pointer is defined.
}], "::mlir::Value", "getDefaultValue",
(ins
"const ::mlir::MemorySlot &":$slot,
"::mlir::RewriterBase &":$rewriter)
"::mlir::OpBuilder &":$builder)
>,
InterfaceMethod<[{
Hook triggered for every new block argument added to a block.
This will only be called for slots declared by this operation.

The rewriter is located at the beginning of the block on call. All IR
mutations must happen through the rewriter.
The builder is located at the beginning of the block on call. All IR
mutations must happen through the builder.
}],
"void", "handleBlockArgument",
(ins
"const ::mlir::MemorySlot &":$slot,
"::mlir::BlockArgument":$argument,
"::mlir::RewriterBase &":$rewriter
"::mlir::OpBuilder &":$builder
)
>,
InterfaceMethod<[{
Hook triggered once the promotion of a slot is complete. This can
also clean up the created default value if necessary.
This will only be called for slots declared by this operation.

All IR mutations must happen through the rewriter.
}],
"void", "handlePromotionComplete",
(ins
"const ::mlir::MemorySlot &":$slot,
"::mlir::Value":$defaultValue,
"::mlir::RewriterBase &":$rewriter)
"::mlir::OpBuilder &":$builder)
>,
];
}
Expand Down Expand Up @@ -119,15 +117,14 @@ def PromotableMemOpInterface : OpInterface<"PromotableMemOpInterface"> {
The returned value must dominate all operations dominated by the storing
operation.

If IR must be mutated to extract a concrete value being stored, mutation
must happen through the provided rewriter. The rewriter is located
immediately after the memory operation on call. No IR deletion is
allowed in this method. IR mutations must not introduce new uses of the
memory slot. Existing control flow must not be modified.
The builder is located immediately after the memory operation on call.
No IR deletion is allowed in this method. IR mutations must not
introduce new uses of the memory slot. Existing control flow must not
be modified.
}],
"::mlir::Value", "getStored",
(ins "const ::mlir::MemorySlot &":$slot,
"::mlir::RewriterBase &":$rewriter,
"::mlir::OpBuilder &":$builder,
"::mlir::Value":$reachingDef,
"const ::mlir::DataLayout &":$dataLayout)
>,
Expand Down Expand Up @@ -166,14 +163,13 @@ def PromotableMemOpInterface : OpInterface<"PromotableMemOpInterface"> {
have been done at the point of calling this method, but it will be done
eventually.

The rewriter is located after the promotable operation on call. All IR
mutations must happen through the rewriter.
The builder is located after the promotable operation on call.
}],
"::mlir::DeletionKind",
"removeBlockingUses",
(ins "const ::mlir::MemorySlot &":$slot,
"const ::llvm::SmallPtrSetImpl<mlir::OpOperand *> &":$blockingUses,
"::mlir::RewriterBase &":$rewriter,
"::mlir::OpBuilder &":$builder,
"::mlir::Value":$reachingDefinition,
"const ::mlir::DataLayout &":$dataLayout)
>,
Expand Down Expand Up @@ -224,13 +220,12 @@ def PromotableOpInterface : OpInterface<"PromotableOpInterface"> {
have been done at the point of calling this method, but it will be done
eventually.

The rewriter is located after the promotable operation on call. All IR
mutations must happen through the rewriter.
The builder is located after the promotable operation on call.
}],
"::mlir::DeletionKind",
"removeBlockingUses",
(ins "const ::llvm::SmallPtrSetImpl<mlir::OpOperand *> &":$blockingUses,
"::mlir::RewriterBase &":$rewriter)
"::mlir::OpBuilder &":$builder)
>,
InterfaceMethod<[{
This method allows the promoted operation to visit the SSA values used
Expand All @@ -254,13 +249,12 @@ def PromotableOpInterface : OpInterface<"PromotableOpInterface"> {
scheduled for removal and if `requiresReplacedValues` returned
true.

The rewriter is located after the promotable operation on call. All IR
mutations must happen through the rewriter. During the transformation,
*no operation should be deleted*.
The builder is located after the promotable operation on call. During
the transformation, *no operation should be deleted*.
}],
"void", "visitReplacedValues",
(ins "::llvm::ArrayRef<std::pair<::mlir::Operation*, ::mlir::Value>>":$mutatedDefs,
"::mlir::RewriterBase &":$rewriter), [{}], [{ return; }]
"::mlir::OpBuilder &":$builder), [{}], [{ return; }]
>,
];
}
Expand Down Expand Up @@ -293,25 +287,23 @@ def DestructurableAllocationOpInterface
at the end of this call. Only generates subslots for the indices found in
`usedIndices` since all other subslots are unused.

The rewriter is located at the beginning of the block where the slot
pointer is defined. All IR mutations must happen through the rewriter.
The builder is located at the beginning of the block where the slot
pointer is defined.
}],
"::llvm::DenseMap<::mlir::Attribute, ::mlir::MemorySlot>",
"destructure",
(ins "const ::mlir::DestructurableMemorySlot &":$slot,
"const ::llvm::SmallPtrSetImpl<::mlir::Attribute> &":$usedIndices,
"::mlir::RewriterBase &":$rewriter)
"::mlir::OpBuilder &":$builder)
>,
InterfaceMethod<[{
Hook triggered once the destructuring of a slot is complete, meaning the
original slot is no longer being refered to and could be deleted.
This will only be called for slots declared by this operation.

All IR mutations must happen through the rewriter.
}],
"void", "handleDestructuringComplete",
(ins "const ::mlir::DestructurableMemorySlot &":$slot,
"::mlir::RewriterBase &":$rewriter)
"::mlir::OpBuilder &":$builder)
>,
];
}
Expand Down Expand Up @@ -376,15 +368,14 @@ def DestructurableAccessorOpInterface
Rewires the use of a slot to the generated subslots, without deleting
any operation. Returns whether the accessor should be deleted.

All IR mutations must happen through the rewriter. Deletion of
operations is not allowed, only the accessor can be scheduled for
deletion by returning the appropriate value.
Deletion of operations is not allowed, only the accessor can be
scheduled for deletion by returning the appropriate value.
}],
"::mlir::DeletionKind",
"rewire",
(ins "const ::mlir::DestructurableMemorySlot &":$slot,
"::llvm::DenseMap<::mlir::Attribute, ::mlir::MemorySlot> &":$subslots,
"::mlir::RewriterBase &":$rewriter,
"::mlir::OpBuilder &":$builder,
"const ::mlir::DataLayout &":$dataLayout)
>
];
Expand Down
2 changes: 1 addition & 1 deletion mlir/include/mlir/Transforms/Mem2Reg.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct Mem2RegStatistics {
/// at least one memory slot was promoted.
LogicalResult
tryToPromoteMemorySlots(ArrayRef<PromotableAllocationOpInterface> allocators,
RewriterBase &rewriter, const DataLayout &dataLayout,
OpBuilder &builder, const DataLayout &dataLayout,
Mem2RegStatistics statistics = {});

} // namespace mlir
Expand Down
2 changes: 1 addition & 1 deletion mlir/include/mlir/Transforms/SROA.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct SROAStatistics {
/// failure if no slot was destructured.
LogicalResult tryToDestructureMemorySlots(
ArrayRef<DestructurableAllocationOpInterface> allocators,
RewriterBase &rewriter, const DataLayout &dataLayout,
OpBuilder &builder, const DataLayout &dataLayout,
SROAStatistics statistics = {});

} // namespace mlir
Expand Down
Loading