[Mlir-commits] [mlir] 568787f - [mlir] Updated SideEffect interface definitions to use tablegen Resource objects.
Marcel Koester
llvmlistbot at llvm.org
Fri May 8 01:01:06 PDT 2020
Author: Marcel Koester
Date: 2020-05-08T09:55:08+02:00
New Revision: 568787f81e07d82cf0f1ad1c9cb61eb04a12dcfb
URL: https://github.com/llvm/llvm-project/commit/568787f81e07d82cf0f1ad1c9cb61eb04a12dcfb
DIFF: https://github.com/llvm/llvm-project/commit/568787f81e07d82cf0f1ad1c9cb61eb04a12dcfb.diff
LOG: [mlir] Updated SideEffect interface definitions to use tablegen Resource objects.
The SideEffect interface definitions currently use string expressions to
reference custom resource objects. This CL introduces Resource objects in
tablegen definitions to simplify linking of resource reference to resource
objects.
Differential Revision: https://reviews.llvm.org/D78917
Added:
Modified:
mlir/include/mlir/Interfaces/SideEffects.td
mlir/lib/TableGen/SideEffects.cpp
mlir/test/mlir-tblgen/op-side-effects.td
Removed:
################################################################################
diff --git a/mlir/include/mlir/Interfaces/SideEffects.td b/mlir/include/mlir/Interfaces/SideEffects.td
index 4433f46706f4..ab9c97b4c9f7 100644
--- 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<string resourceName> {
+ /// 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<string resourceName> :
+ Resource<!strconcat("::mlir::SideEffects::", resourceName)> {
+}
+
+// A link to the DefaultResource class.
+def DefaultResource : IntrinsicResource<"DefaultResource">;
+
//===----------------------------------------------------------------------===//
// EffectOpInterface
//===----------------------------------------------------------------------===//
@@ -114,7 +132,7 @@ class EffectOpInterfaceBase<string name, string baseEffect>
// This class is the general base side effect class. This is used by derived
// effect interfaces to define their effects.
class SideEffect<EffectOpInterfaceBase interface, string effectName,
- string resourceName> : OpVariableDecorator {
+ Resource resourceReference> : OpVariableDecorator {
/// The name of the base effects class.
string baseEffectName = interface.baseEffectName;
@@ -125,7 +143,7 @@ class SideEffect<EffectOpInterfaceBase interface, string effectName,
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 @@ def MemoryEffectsOpInterface
}
// The base class for defining specific memory effects.
-class MemoryEffect<string effectName, string resourceName>
- : SideEffect<MemoryEffectsOpInterface, effectName, resourceName>;
+class MemoryEffect<string effectName, Resource resource>
+ : SideEffect<MemoryEffectsOpInterface, effectName, resource>;
// This class represents the trait for memory effects that may be placed on
// operations.
@@ -173,30 +191,30 @@ class MemoryEffects<list<MemoryEffect> effects = []>
// 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<string resourceName>
- : MemoryEffect<"MemoryEffects::Allocate", resourceName>;
-def MemAlloc : MemAlloc<"">;
+class MemAlloc<Resource resource>
+ : MemoryEffect<"MemoryEffects::Allocate", resource>;
+def MemAlloc : MemAlloc<DefaultResource>;
// 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<string resourceName>
- : MemoryEffect<"MemoryEffects::Free", resourceName>;
-def MemFree : MemFree<"">;
+class MemFree<Resource resource>
+ : MemoryEffect<"MemoryEffects::Free", resource>;
+def MemFree : MemFree<DefaultResource>;
// 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<string resourceName>
- : MemoryEffect<"MemoryEffects::Read", resourceName>;
-def MemRead : MemRead<"">;
+class MemRead<Resource resource>
+ : MemoryEffect<"MemoryEffects::Read", resource>;
+def MemRead : MemRead<DefaultResource>;
// 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<string resourceName>
- : MemoryEffect<"MemoryEffects::Write", resourceName>;
-def MemWrite : MemWrite<"">;
+class MemWrite<Resource resource>
+ : MemoryEffect<"MemoryEffects::Write", resource>;
+def MemWrite : MemWrite<DefaultResource>;
//===----------------------------------------------------------------------===//
// Effect Traits
diff --git a/mlir/lib/TableGen/SideEffects.cpp b/mlir/lib/TableGen/SideEffects.cpp
index 5d4f68581cca..a2116ba3c37b 100644
--- a/mlir/lib/TableGen/SideEffects.cpp
+++ b/mlir/lib/TableGen/SideEffects.cpp
@@ -29,8 +29,7 @@ StringRef SideEffect::getInterfaceTrait() const {
}
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
index e1dd7035127d..29b56df59094 100644
--- a/mlir/test/mlir-tblgen/op-side-effects.td
+++ b/mlir/test/mlir-tblgen/op-side-effects.td
@@ -8,13 +8,15 @@ def TEST_Dialect : Dialect {
class TEST_Op<string mnemonic, list<OpTrait> traits = []> :
Op<TEST_Dialect, mnemonic, traits>;
+def CustomResource : Resource<"CustomResource">;
+
def SideEffectOpA : TEST_Op<"side_effect_op_a"> {
let arguments = (ins Arg<Variadic<AnyMemRef>, "", [MemRead]>);
- let results = (outs Res<AnyMemRef, "", [MemAlloc<"CustomResource">]>);
+ let results = (outs Res<AnyMemRef, "", [MemAlloc<CustomResource>]>);
}
def SideEffectOpB : TEST_Op<"side_effect_op_b",
- [MemoryEffects<[MemWrite<"CustomResource">]>]>;
+ [MemoryEffects<[MemWrite<CustomResource>]>]>;
// CHECK: void SideEffectOpA::getEffects
// CHECK: for (Value value : getODSOperands(0))
More information about the Mlir-commits
mailing list