[Mlir-commits] [mlir] 881c3bb - [mlir] Adapted standard Alloc and Alloca ops to use new side-effect resources.

Marcel Koester llvmlistbot at llvm.org
Wed May 13 04:53:04 PDT 2020


Author: Marcel Koester
Date: 2020-05-13T13:46:39+02:00
New Revision: 881c3bb6a7323fe01f95d4e95755c78cd805056f

URL: https://github.com/llvm/llvm-project/commit/881c3bb6a7323fe01f95d4e95755c78cd805056f
DIFF: https://github.com/llvm/llvm-project/commit/881c3bb6a7323fe01f95d4e95755c78cd805056f.diff

LOG: [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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
index 0e0b2dbfe864..30b5d438dd29 100644
--- a/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
+++ b/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td
@@ -143,12 +143,14 @@ class ComplexFloatArithmeticOp<string mnemonic, list<OpTrait> traits = []> :
 //
 //   %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", [{
@@ -310,7 +312,7 @@ def AddIOp : IntArithmeticOp<"addi", [Commutative]> {
 // 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
@@ -357,7 +359,7 @@ def AllocOp : AllocLikeOp<"alloc"> {
 // 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

diff  --git a/mlir/include/mlir/Interfaces/SideEffectInterfaces.td b/mlir/include/mlir/Interfaces/SideEffectInterfaces.td
index cd404df5c5c0..b81b42b7a3b4 100644
--- a/mlir/include/mlir/Interfaces/SideEffectInterfaces.td
+++ b/mlir/include/mlir/Interfaces/SideEffectInterfaces.td
@@ -33,6 +33,9 @@ class IntrinsicResource<string resourceName> :
 
 // A link to the DefaultResource class.
 def DefaultResource : IntrinsicResource<"DefaultResource">;
+// A link to the AutomaticAllocationScopeResource class.
+def AutomaticAllocationScopeResource :
+  IntrinsicResource<"AutomaticAllocationScopeResource">;
 
 //===----------------------------------------------------------------------===//
 // EffectOpInterface

diff  --git a/mlir/include/mlir/Interfaces/SideEffects.h b/mlir/include/mlir/Interfaces/SideEffects.h
index f3f4c44238a2..aff478dc02c1 100644
--- a/mlir/include/mlir/Interfaces/SideEffects.h
+++ b/mlir/include/mlir/Interfaces/SideEffects.h
@@ -122,6 +122,13 @@ struct DefaultResource : public Resource::Base<DefaultResource> {
   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


        


More information about the Mlir-commits mailing list