Skip to content

Commit 76415d9

Browse files
committed
[MLIR][SROA][Mem2Reg] Add data layout to interface methods
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 63897a5 commit 76415d9

File tree

7 files changed

+163
-109
lines changed

7 files changed

+163
-109
lines changed

mlir/include/mlir/Interfaces/MemorySlotInterfaces.td

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ 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.
88-
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*.
86+
to memory slots.
9187

9288
If the same operation does both loads and stores on the same slot, the
9389
load must semantically happen first.
@@ -142,7 +138,8 @@ def PromotableMemOpInterface : OpInterface<"PromotableMemOpInterface"> {
142138
}], "bool", "canUsesBeRemoved",
143139
(ins "const ::mlir::MemorySlot &":$slot,
144140
"const ::llvm::SmallPtrSetImpl<::mlir::OpOperand *> &":$blockingUses,
145-
"::llvm::SmallVectorImpl<::mlir::OpOperand *> &":$newBlockingUses)
141+
"::llvm::SmallVectorImpl<::mlir::OpOperand *> &":$newBlockingUses,
142+
"const ::mlir::DataLayout &":$datalayout)
146143
>,
147144
InterfaceMethod<[{
148145
Transforms IR to ensure that the current operation does not use the
@@ -197,7 +194,8 @@ def PromotableOpInterface : OpInterface<"PromotableOpInterface"> {
197194
No IR mutation is allowed in this method.
198195
}], "bool", "canUsesBeRemoved",
199196
(ins "const ::llvm::SmallPtrSetImpl<::mlir::OpOperand *> &":$blockingUses,
200-
"::llvm::SmallVectorImpl<::mlir::OpOperand *> &":$newBlockingUses)
197+
"::llvm::SmallVectorImpl<::mlir::OpOperand *> &":$newBlockingUses,
198+
"const ::mlir::DataLayout &":$datalayout)
201199
>,
202200
InterfaceMethod<[{
203201
Transforms IR to ensure that the current operation does not use the
@@ -285,29 +283,28 @@ def DestructurableAllocationOpInterface
285283
def SafeMemorySlotAccessOpInterface
286284
: OpInterface<"SafeMemorySlotAccessOpInterface"> {
287285
let description = [{
288-
Describes operations using memory slots in a type-safe manner.
286+
Describes operations using memory slots in a safe manner.
289287
}];
290288
let cppNamespace = "::mlir";
291289

292290
let methods = [
293291
InterfaceMethod<[{
294292
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.
293+
done in a safe manner. To be safe, the access most only access the slot
294+
inside the bounds that its type implies.
299295

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`.
296+
If the safety of the accesses depends on the safety of the accesses to
297+
further memory slots, the result of this method will be conditioned to
298+
the safety of the accesses to the slots added by this method to
299+
`mustBeSafelyUsed`.
304300

305301
No IR mutation is allowed in this method.
306302
}],
307303
"::mlir::LogicalResult",
308304
"ensureOnlySafeAccesses",
309305
(ins "const ::mlir::MemorySlot &":$slot,
310-
"::mlir::SmallVectorImpl<::mlir::MemorySlot> &":$mustBeSafelyUsed)
306+
"::mlir::SmallVectorImpl<::mlir::MemorySlot> &":$mustBeSafelyUsed,
307+
"const ::mlir::DataLayout &":$dataLayout)
311308
>
312309
];
313310
}
@@ -323,21 +320,21 @@ def DestructurableAccessorOpInterface
323320
InterfaceMethod<[{
324321
For a given destructurable memory slot, returns whether this operation can
325322
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.
323+
destructuring. This may involve creating new operations.
328324

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

334330
No IR mutation is allowed in this method.
335331
}],
336332
"bool",
337333
"canRewire",
338334
(ins "const ::mlir::DestructurableMemorySlot &":$slot,
339335
"::llvm::SmallPtrSetImpl<::mlir::Attribute> &":$usedIndices,
340-
"::mlir::SmallVectorImpl<::mlir::MemorySlot> &":$mustBeSafelyUsed)
336+
"::mlir::SmallVectorImpl<::mlir::MemorySlot> &":$mustBeSafelyUsed,
337+
"const ::mlir::DataLayout &":$dataLayout)
341338
>,
342339
InterfaceMethod<[{
343340
Rewires the use of a slot to the generated subslots, without deleting
@@ -351,7 +348,8 @@ def DestructurableAccessorOpInterface
351348
"rewire",
352349
(ins "const ::mlir::DestructurableMemorySlot &":$slot,
353350
"::llvm::DenseMap<::mlir::Attribute, ::mlir::MemorySlot> &":$subslots,
354-
"::mlir::RewriterBase &":$rewriter)
351+
"::mlir::RewriterBase &":$rewriter,
352+
"const ::mlir::DataLayout &":$dataLayout)
355353
>
356354
];
357355
}

mlir/include/mlir/Transforms/Mem2Reg.h

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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)