Skip to content

Commit 98c6bc5

Browse files
authored
[MLIR][SROA][Mem2Reg] Add data layout to interface methods (#85644)
This commit expends the Mem2Reg and SROA interface methods with passed in handles to a `DataLayout` structure. This is done to avoid superfluous retreiving of data layouts during each conversion of intrinsics. This change, additionally, enables subsequent changes to make the LLVM dialect implementation of these interfaces type agnostic.
1 parent 3eb8063 commit 98c6bc5

File tree

7 files changed

+165
-108
lines changed

7 files changed

+165
-108
lines changed

mlir/include/mlir/Interfaces/MemorySlotInterfaces.td

+22-21
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,10 @@ def PromotableAllocationOpInterface
8383
def PromotableMemOpInterface : OpInterface<"PromotableMemOpInterface"> {
8484
let description = [{
8585
Describes an operation that can load from memory slots and/or store
86-
to memory slots. Loads and stores must be of whole values of the same
87-
type as the slot itself.
86+
to memory slots.
8887

89-
For a memory operation on a slot to be valid, it must operate on the slot
90-
pointer *only as a pointer to an element of the type of the slot*.
88+
For a memory operation on a slot to be valid, it must strictly operate
89+
within the bounds of the slot.
9190

9291
If the same operation does both loads and stores on the same slot, the
9392
load must semantically happen first.
@@ -142,7 +141,8 @@ def PromotableMemOpInterface : OpInterface<"PromotableMemOpInterface"> {
142141
}], "bool", "canUsesBeRemoved",
143142
(ins "const ::mlir::MemorySlot &":$slot,
144143
"const ::llvm::SmallPtrSetImpl<::mlir::OpOperand *> &":$blockingUses,
145-
"::llvm::SmallVectorImpl<::mlir::OpOperand *> &":$newBlockingUses)
144+
"::llvm::SmallVectorImpl<::mlir::OpOperand *> &":$newBlockingUses,
145+
"const ::mlir::DataLayout &":$datalayout)
146146
>,
147147
InterfaceMethod<[{
148148
Transforms IR to ensure that the current operation does not use the
@@ -197,7 +197,8 @@ def PromotableOpInterface : OpInterface<"PromotableOpInterface"> {
197197
No IR mutation is allowed in this method.
198198
}], "bool", "canUsesBeRemoved",
199199
(ins "const ::llvm::SmallPtrSetImpl<::mlir::OpOperand *> &":$blockingUses,
200-
"::llvm::SmallVectorImpl<::mlir::OpOperand *> &":$newBlockingUses)
200+
"::llvm::SmallVectorImpl<::mlir::OpOperand *> &":$newBlockingUses,
201+
"const ::mlir::DataLayout &":$datalayout)
201202
>,
202203
InterfaceMethod<[{
203204
Transforms IR to ensure that the current operation does not use the
@@ -285,29 +286,28 @@ def DestructurableAllocationOpInterface
285286
def SafeMemorySlotAccessOpInterface
286287
: OpInterface<"SafeMemorySlotAccessOpInterface"> {
287288
let description = [{
288-
Describes operations using memory slots in a type-safe manner.
289+
Describes operations using memory slots in a safe manner.
289290
}];
290291
let cppNamespace = "::mlir";
291292

292293
let methods = [
293294
InterfaceMethod<[{
294295
Returns whether all accesses in this operation to the provided slot are
295-
done in a type-safe manner. To be type-safe, the access must only load
296-
the value in this type as the type of the slot, and without assuming any
297-
context around the slot. For example, a type-safe load must not load
298-
outside the bounds of the slot.
296+
done in a safe manner. To be safe, the access most only access the slot
297+
inside the bounds that its type implies.
299298

300-
If the type-safety of the accesses depends on the type-safety of the
301-
accesses to further memory slots, the result of this method will be
302-
conditioned to the type-safety of the accesses to the slots added by
303-
this method to `mustBeSafelyUsed`.
299+
If the safety of the accesses depends on the safety of the accesses to
300+
further memory slots, the result of this method will be conditioned to
301+
the safety of the accesses to the slots added by this method to
302+
`mustBeSafelyUsed`.
304303

305304
No IR mutation is allowed in this method.
306305
}],
307306
"::mlir::LogicalResult",
308307
"ensureOnlySafeAccesses",
309308
(ins "const ::mlir::MemorySlot &":$slot,
310-
"::mlir::SmallVectorImpl<::mlir::MemorySlot> &":$mustBeSafelyUsed)
309+
"::mlir::SmallVectorImpl<::mlir::MemorySlot> &":$mustBeSafelyUsed,
310+
"const ::mlir::DataLayout &":$dataLayout)
311311
>
312312
];
313313
}
@@ -323,21 +323,21 @@ def DestructurableAccessorOpInterface
323323
InterfaceMethod<[{
324324
For a given destructurable memory slot, returns whether this operation can
325325
rewire its uses of the slot to use the slots generated after
326-
destructuring. This may involve creating new operations, and usually
327-
amounts to checking if the pointer types match.
326+
destructuring. This may involve creating new operations.
328327

329328
This method must also register the indices it will access within the
330329
`usedIndices` set. If the accessor generates new slots mapping to
331330
subelements, they must be registered in `mustBeSafelyUsed` to ensure
332-
they are used in a locally type-safe manner.
331+
they are used in a safe manner.
333332

334333
No IR mutation is allowed in this method.
335334
}],
336335
"bool",
337336
"canRewire",
338337
(ins "const ::mlir::DestructurableMemorySlot &":$slot,
339338
"::llvm::SmallPtrSetImpl<::mlir::Attribute> &":$usedIndices,
340-
"::mlir::SmallVectorImpl<::mlir::MemorySlot> &":$mustBeSafelyUsed)
339+
"::mlir::SmallVectorImpl<::mlir::MemorySlot> &":$mustBeSafelyUsed,
340+
"const ::mlir::DataLayout &":$dataLayout)
341341
>,
342342
InterfaceMethod<[{
343343
Rewires the use of a slot to the generated subslots, without deleting
@@ -351,7 +351,8 @@ def DestructurableAccessorOpInterface
351351
"rewire",
352352
(ins "const ::mlir::DestructurableMemorySlot &":$slot,
353353
"::llvm::DenseMap<::mlir::Attribute, ::mlir::MemorySlot> &":$subslots,
354-
"::mlir::RewriterBase &":$rewriter)
354+
"::mlir::RewriterBase &":$rewriter,
355+
"const ::mlir::DataLayout &":$dataLayout)
355356
>
356357
];
357358
}

mlir/include/mlir/Transforms/Mem2Reg.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct Mem2RegStatistics {
2727
/// at least one memory slot was promoted.
2828
LogicalResult
2929
tryToPromoteMemorySlots(ArrayRef<PromotableAllocationOpInterface> allocators,
30-
RewriterBase &rewriter,
30+
RewriterBase &rewriter, const DataLayout &dataLayout,
3131
Mem2RegStatistics statistics = {});
3232

3333
} // namespace mlir

mlir/include/mlir/Transforms/SROA.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ struct SROAStatistics {
3131
/// failure if no slot was destructured.
3232
LogicalResult tryToDestructureMemorySlots(
3333
ArrayRef<DestructurableAllocationOpInterface> allocators,
34-
RewriterBase &rewriter, SROAStatistics statistics = {});
34+
RewriterBase &rewriter, const DataLayout &dataLayout,
35+
SROAStatistics statistics = {});
3536

3637
} // namespace mlir
3738

0 commit comments

Comments
 (0)