Skip to content

Commit 881c3bb

Browse files
committed
[mlir] Adapted standard Alloc and Alloca ops to use new side-effect resources.
The current standard Alloca node is not annotated with the MemEffect<Alloc> trait. This CL updates the Alloc and Alloca memory-effect annotations using the latest Resource objects. Alloca nodes will use a newly defined AutomaticAllocationScopeResource to distinguish between Alloc and Alloca memory effects. Differential Revision: https://reviews.llvm.org/D79620
1 parent e072b20 commit 881c3bb

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

mlir/include/mlir/Dialect/StandardOps/IR/Ops.td

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,14 @@ class ComplexFloatArithmeticOp<string mnemonic, list<OpTrait> traits = []> :
143143
//
144144
// %0 = alloclike(%m)[%s] : memref<8x?xf32, (d0, d1)[s0] -> ((d0 + s0), d1)>
145145
//
146-
class AllocLikeOp<string mnemonic, list<OpTrait> traits = []> :
147-
Std_Op<mnemonic, !listconcat(traits, [MemoryEffects<[MemAlloc]>])> {
146+
class AllocLikeOp<string mnemonic,
147+
Resource resource,
148+
list<OpTrait> traits = []> :
149+
Std_Op<mnemonic, !listconcat([MemoryEffects<[MemAlloc<resource>]>], traits)> {
148150

149151
let arguments = (ins Variadic<Index>:$value,
150152
Confined<OptionalAttr<I64Attr>, [IntMinValue<0>]>:$alignment);
151-
let results = (outs Res<AnyMemRef, "", [MemAlloc]>);
153+
let results = (outs Res<AnyMemRef, "", [MemAlloc<resource>]>);
152154

153155
let builders = [OpBuilder<
154156
"OpBuilder &builder, OperationState &result, MemRefType memrefType", [{
@@ -310,7 +312,7 @@ def AddIOp : IntArithmeticOp<"addi", [Commutative]> {
310312
// AllocOp
311313
//===----------------------------------------------------------------------===//
312314

313-
def AllocOp : AllocLikeOp<"alloc"> {
315+
def AllocOp : AllocLikeOp<"alloc", DefaultResource> {
314316
let summary = "memory allocation operation";
315317
let description = [{
316318
The `alloc` operation allocates a region of memory, as specified by its
@@ -357,7 +359,7 @@ def AllocOp : AllocLikeOp<"alloc"> {
357359
// AllocaOp
358360
//===----------------------------------------------------------------------===//
359361

360-
def AllocaOp : AllocLikeOp<"alloca"> {
362+
def AllocaOp : AllocLikeOp<"alloca", AutomaticAllocationScopeResource> {
361363
let summary = "stack memory allocation operation";
362364
let description = [{
363365
The `alloca` operation allocates memory on the stack, to be automatically

mlir/include/mlir/Interfaces/SideEffectInterfaces.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class IntrinsicResource<string resourceName> :
3333

3434
// A link to the DefaultResource class.
3535
def DefaultResource : IntrinsicResource<"DefaultResource">;
36+
// A link to the AutomaticAllocationScopeResource class.
37+
def AutomaticAllocationScopeResource :
38+
IntrinsicResource<"AutomaticAllocationScopeResource">;
3639

3740
//===----------------------------------------------------------------------===//
3841
// EffectOpInterface

mlir/include/mlir/Interfaces/SideEffects.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ struct DefaultResource : public Resource::Base<DefaultResource> {
122122
StringRef getName() final { return "<Default>"; }
123123
};
124124

125+
/// An automatic allocation-scope resource that is valid in the context of a
126+
/// parent AutomaticAllocationScope trait.
127+
struct AutomaticAllocationScopeResource
128+
: public Resource::Base<AutomaticAllocationScopeResource> {
129+
StringRef getName() final { return "AutomaticAllocationScope"; }
130+
};
131+
125132
/// This class represents a specific instance of an effect. It contains the
126133
/// effect being applied, a resource that corresponds to where the effect is
127134
/// applied, and an optional value(either operand, result, or region entry

0 commit comments

Comments
 (0)