[PATCH] D79620: [mlir] Adapted standard Alloc and Alloca ops to use different side-effect resources.

Marcel Koester via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 8 01:34:29 PDT 2020


dfki-mako created this revision.
Herald added subscribers: llvm-commits, Kayjukh, frgossen, grosul1, Joonsoo, stephenneuendorffer, liufengdb, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, jpienaar, rriddle, mehdi_amini.
Herald added a project: LLVM.
dfki-mako added reviewers: rriddle, herhut, mehdi_amini.
dfki-mako added a project: MLIR.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79620

Files:
  mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
  mlir/include/mlir/Interfaces/SideEffects.h
  mlir/include/mlir/Interfaces/SideEffects.td


Index: mlir/include/mlir/Interfaces/SideEffects.td
===================================================================
--- mlir/include/mlir/Interfaces/SideEffects.td
+++ mlir/include/mlir/Interfaces/SideEffects.td
@@ -33,6 +33,9 @@
 
 // A link to the DefaultResource class.
 def DefaultResource : IntrinsicResource<"DefaultResource">;
+// A link to the AutomaticAllocationScopeResource class.
+def AutomaticAllocationScopeResource :
+  IntrinsicResource<"AutomaticAllocationScopeResource">;
 
 //===----------------------------------------------------------------------===//
 // EffectOpInterface
Index: mlir/include/mlir/Interfaces/SideEffects.h
===================================================================
--- mlir/include/mlir/Interfaces/SideEffects.h
+++ mlir/include/mlir/Interfaces/SideEffects.h
@@ -122,6 +122,13 @@
   StringRef getName() final { return "<Default>"; }
 };
 
+/// An automatic allocation-scope resource that is valid in the context of a
+/// parent AutomaticAllocationScope trait.
+struct AutomaticAllocationScopeResource
+    : public Resource::Base<AutomaticAllocationScopeResource> {
+  StringRef getName() final { return "AutomaticAllocationScope"; }
+};
+
 /// This class represents a specific instance of an effect. It contains the
 /// effect being applied, a resource that corresponds to where the effect is
 /// applied, and an optional value(either operand, result, or region entry
Index: mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
===================================================================
--- mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
+++ mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
@@ -129,12 +129,14 @@
 //
 //   %0 = alloclike(%m)[%s] : memref<8x?xf32, (d0, d1)[s0] -> ((d0 + s0), d1)>
 //
-class AllocLikeOp<string mnemonic, list<OpTrait> traits = []> :
-    Std_Op<mnemonic, !listconcat(traits, [MemoryEffects<[MemAlloc]>])> {
+class AllocLikeOp<string mnemonic,
+                  Resource resource,
+                  list<OpTrait> traits = []> :
+    Std_Op<mnemonic, !listconcat([MemoryEffects<[MemAlloc<resource>]>], traits)> {
 
   let arguments = (ins Variadic<Index>:$value,
                    Confined<OptionalAttr<I64Attr>, [IntMinValue<0>]>:$alignment);
-  let results = (outs Res<AnyMemRef, "", [MemAlloc]>);
+  let results = (outs Res<AnyMemRef, "", [MemAlloc<resource>]>);
 
   let builders = [OpBuilder<
     "OpBuilder &builder, OperationState &result, MemRefType memrefType", [{
@@ -276,7 +278,7 @@
 // AllocOp
 //===----------------------------------------------------------------------===//
 
-def AllocOp : AllocLikeOp<"alloc"> {
+def AllocOp : AllocLikeOp<"alloc", DefaultResource> {
   let summary = "memory allocation operation";
   let description = [{
     The `alloc` operation allocates a region of memory, as specified by its
@@ -323,7 +325,7 @@
 // AllocaOp
 //===----------------------------------------------------------------------===//
 
-def AllocaOp : AllocLikeOp<"alloca"> {
+def AllocaOp : AllocLikeOp<"alloca", AutomaticAllocationScopeResource> {
   let summary = "stack memory allocation operation";
   let description = [{
     The `alloca` operation allocates memory on the stack, to be automatically


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79620.262832.patch
Type: text/x-patch
Size: 3216 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200508/d2975f30/attachment.bin>


More information about the llvm-commits mailing list