diff options
| author | River Riddle <riverriddle@google.com> | 2019-12-18 11:02:35 -0800 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-12-18 11:09:11 -0800 |
| commit | 29807ff5e4636b0300cd5a3182eb54254e2714d3 (patch) | |
| tree | 4abf59b00b068ad56b87a19001fdf8d7d620213e /mlir/include | |
| parent | d7e2cc9bd1d17cbc7182bd904a9173817745525a (diff) | |
| download | bcm5719-llvm-29807ff5e4636b0300cd5a3182eb54254e2714d3.tar.gz bcm5719-llvm-29807ff5e4636b0300cd5a3182eb54254e2714d3.zip | |
Add support for providing a default implementation for an interface method.
This enables providing a default implementation of an interface method. This method is defined on the Trait that is attached to the operation, and thus has all of the same constraints and properties as any other interface method. This allows for interface authors to provide a conservative default implementation for certain methods, without requiring that all users explicitly define it. The default implementation can be specified via the argument directly after the interface method body:
StaticInterfaceMethod<
/*desc=*/"Returns whether two array of types are compatible result types for an op.",
/*retTy=*/"bool",
/*methodName=*/"isCompatibleReturnTypes",
/*args=*/(ins "ArrayRef<Type>":$lhs, "ArrayRef<Type>":$rhs),
/*methodBody=*/[{
return ConcreteOp::isCompatibleReturnTypes(lhs, rhs);
}],
/*defaultImplementation=*/[{
/// Returns whether two arrays are equal as strongest check for
/// compatibility by default.
return lhs == rhs;
}]
PiperOrigin-RevId: 286226054
Diffstat (limited to 'mlir/include')
| -rw-r--r-- | mlir/include/mlir/Analysis/InferTypeOpInterface.td | 11 | ||||
| -rw-r--r-- | mlir/include/mlir/IR/OpBase.td | 12 | ||||
| -rw-r--r-- | mlir/include/mlir/TableGen/OpInterfaces.h | 3 |
3 files changed, 18 insertions, 8 deletions
diff --git a/mlir/include/mlir/Analysis/InferTypeOpInterface.td b/mlir/include/mlir/Analysis/InferTypeOpInterface.td index aae6e83cf0e..14d580962e1 100644 --- a/mlir/include/mlir/Analysis/InferTypeOpInterface.td +++ b/mlir/include/mlir/Analysis/InferTypeOpInterface.td @@ -59,15 +59,16 @@ def InferTypeOpInterface : OpInterface<"InferTypeOpInterface"> { /*retTy=*/"bool", /*methodName=*/"isCompatibleReturnTypes", /*args=*/(ins "ArrayRef<Type>":$lhs, "ArrayRef<Type>":$rhs), - [{ + /*methodBody=*/[{ return ConcreteOp::isCompatibleReturnTypes(lhs, rhs); + }], + /*defaultImplementation=*/[{ + /// Returns whether two arrays are equal as strongest check for + /// compatibility by default. + return lhs == rhs; }] >, ]; } -// Default implementations for some of the interface methods above: -// - compatibleReturnTypes returns whether strictly true. -def InferTypeOpInterfaceDefault : NativeOpTrait<"TypeOpInterfaceDefault">; - #endif // MLIR_INFERTYPEOPINTERFACE diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index 4d5d1fe766f..8f6770f297e 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -1425,7 +1425,8 @@ class OpInterfaceTrait<string name> : NativeOpTrait<""> { // Note: non-static interface methods have an implicit 'op' parameter // corresponding to an instance of the derived operation. class InterfaceMethod<string desc, string retTy, string methodName, - dag args = (ins), code methodBody = [{}]> { + dag args = (ins), code methodBody = [{}], + code defaultImplementation = [{}]> { // A human-readable description of what this method does. string description = desc; @@ -1440,12 +1441,17 @@ class InterfaceMethod<string desc, string retTy, string methodName, // An optional body to the method. code body = methodBody; + + // An optional default implementation of the method. + code defaultBody = defaultImplementation; } // This class represents a single static interface method. class StaticInterfaceMethod<string desc, string retTy, string methodName, - dag args = (ins), code methodBody = [{}]> - : InterfaceMethod<desc, retTy, methodName, args, methodBody>; + dag args = (ins), code methodBody = [{}], + code defaultImplementation = [{}]> + : InterfaceMethod<desc, retTy, methodName, args, methodBody, + defaultImplementation>; // OpInterface represents an interface regarding an op. class OpInterface<string name> : OpInterfaceTrait<name> { diff --git a/mlir/include/mlir/TableGen/OpInterfaces.h b/mlir/include/mlir/TableGen/OpInterfaces.h index 4a87876d5e8..0959f6be9bb 100644 --- a/mlir/include/mlir/TableGen/OpInterfaces.h +++ b/mlir/include/mlir/TableGen/OpInterfaces.h @@ -58,6 +58,9 @@ public: // Return the body for this method if it has one. llvm::Optional<StringRef> getBody() const; + // Return the default implementation for this method if it has one. + llvm::Optional<StringRef> getDefaultImplementation() const; + // Return the description of this method if it has one. llvm::Optional<StringRef> getDescription() const; |

