diff --git a/mlir/include/mlir/Interfaces/SideEffects.td b/mlir/include/mlir/Interfaces/SideEffects.td --- a/mlir/include/mlir/Interfaces/SideEffects.td +++ b/mlir/include/mlir/Interfaces/SideEffects.td @@ -16,6 +16,24 @@ include "mlir/IR/OpBase.td" +//===----------------------------------------------------------------------===// +// Resource Bindings +//===----------------------------------------------------------------------===// + +// A generic resource that can be attachted to a general base side effect. +class Resource { + /// The resource that the associated effect is being applied to. + string name = resourceName; +} + +// An intrinsic resource that lives in the ::mlir::SideEffects namespace. +class IntrinsicResource : + Resource { +} + +// A link to the DefaultResource class. +def DefaultResource : IntrinsicResource<"DefaultResource">; + //===----------------------------------------------------------------------===// // EffectOpInterface //===----------------------------------------------------------------------===// @@ -114,7 +132,7 @@ // This class is the general base side effect class. This is used by derived // effect interfaces to define their effects. class SideEffect : OpVariableDecorator { + Resource resourceReference> : OpVariableDecorator { /// The name of the base effects class. string baseEffectName = interface.baseEffectName; @@ -125,7 +143,7 @@ string effect = effectName; /// The resource that the effect is being applied to. - string resource = resourceName; + string resource = resourceReference.name; } // This class is the base used for specifying effects applied to an operation. @@ -159,8 +177,8 @@ } // The base class for defining specific memory effects. -class MemoryEffect - : SideEffect; +class MemoryEffect + : SideEffect; // This class represents the trait for memory effects that may be placed on // operations. @@ -173,30 +191,30 @@ // The following effect indicates that the operation allocates from some // resource. An 'allocate' effect implies only allocation of the resource, and // not any visible mutation or dereference. -class MemAlloc - : MemoryEffect<"MemoryEffects::Allocate", resourceName>; -def MemAlloc : MemAlloc<"">; +class MemAlloc + : MemoryEffect<"MemoryEffects::Allocate", resource>; +def MemAlloc : MemAlloc; // The following effect indicates that the operation frees some resource that // has been allocated. A 'free' effect implies only de-allocation of the // resource, and not any visible allocation, mutation or dereference. -class MemFree - : MemoryEffect<"MemoryEffects::Free", resourceName>; -def MemFree : MemFree<"">; +class MemFree + : MemoryEffect<"MemoryEffects::Free", resource>; +def MemFree : MemFree; // The following effect indicates that the operation reads from some // resource. A 'read' effect implies only dereferencing of the resource, and // not any visible mutation. -class MemRead - : MemoryEffect<"MemoryEffects::Read", resourceName>; -def MemRead : MemRead<"">; +class MemRead + : MemoryEffect<"MemoryEffects::Read", resource>; +def MemRead : MemRead; // The following effect indicates that the operation writes to some // resource. A 'write' effect implies only mutating a resource, and not any // visible dereference or read. -class MemWrite - : MemoryEffect<"MemoryEffects::Write", resourceName>; -def MemWrite : MemWrite<"">; +class MemWrite + : MemoryEffect<"MemoryEffects::Write", resource>; +def MemWrite : MemWrite; //===----------------------------------------------------------------------===// // Effect Traits diff --git a/mlir/lib/TableGen/SideEffects.cpp b/mlir/lib/TableGen/SideEffects.cpp --- a/mlir/lib/TableGen/SideEffects.cpp +++ b/mlir/lib/TableGen/SideEffects.cpp @@ -29,8 +29,7 @@ } StringRef SideEffect::getResource() const { - auto value = def->getValueAsString("resource"); - return value.empty() ? "::mlir::SideEffects::DefaultResource" : value; + return def->getValueAsString("resource"); } bool SideEffect::classof(const Operator::VariableDecorator *var) { diff --git a/mlir/test/mlir-tblgen/op-side-effects.td b/mlir/test/mlir-tblgen/op-side-effects.td --- a/mlir/test/mlir-tblgen/op-side-effects.td +++ b/mlir/test/mlir-tblgen/op-side-effects.td @@ -8,13 +8,15 @@ class TEST_Op traits = []> : Op; +def CustomResource : Resource<"CustomResource">; + def SideEffectOpA : TEST_Op<"side_effect_op_a"> { let arguments = (ins Arg, "", [MemRead]>); - let results = (outs Res]>); + let results = (outs Res]>); } def SideEffectOpB : TEST_Op<"side_effect_op_b", - [MemoryEffects<[MemWrite<"CustomResource">]>]>; + [MemoryEffects<[MemWrite]>]>; // CHECK: void SideEffectOpA::getEffects // CHECK: for (Value value : getODSOperands(0))