diff options
| author | River Riddle <riverriddle@google.com> | 2019-10-28 10:03:57 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-10-28 10:04:34 -0700 |
| commit | 2f4d0c085a9849fb48b8b55e10f013ac851e470e (patch) | |
| tree | 1b1c286a9aba000227a3f0f4c9cf4184d7e9f8fe /mlir/test/lib/TestDialect | |
| parent | e38fe4a7af03f504b1a51b39fba2a3f07aad46f6 (diff) | |
| download | bcm5719-llvm-2f4d0c085a9849fb48b8b55e10f013ac851e470e.tar.gz bcm5719-llvm-2f4d0c085a9849fb48b8b55e10f013ac851e470e.zip | |
Add support for marking an operation as recursively legal.
In some cases, it may be desirable to mark entire regions of operations as legal. This provides an additional granularity of context to the concept of "legal". The `ConversionTarget` supports marking operations, that were previously added as `Legal` or `Dynamic`, as `recursively` legal. Recursive legality means that if an operation instance is legal, either statically or dynamically, all of the operations nested within are also considered legal. An operation can be marked via `markOpRecursivelyLegal<>`:
```c++
ConversionTarget &target = ...;
/// The operation must first be marked as `Legal` or `Dynamic`.
target.addLegalOp<MyOp>(...);
target.addDynamicallyLegalOp<MySecondOp>(...);
/// Mark the operation as always recursively legal.
target.markOpRecursivelyLegal<MyOp>();
/// Mark optionally with a callback to allow selective marking.
target.markOpRecursivelyLegal<MyOp, MySecondOp>([](Operation *op) { ... });
/// Mark optionally with a callback to allow selective marking.
target.markOpRecursivelyLegal<MyOp>([](MyOp op) { ... });
```
PiperOrigin-RevId: 277086382
Diffstat (limited to 'mlir/test/lib/TestDialect')
| -rw-r--r-- | mlir/test/lib/TestDialect/TestPatterns.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/mlir/test/lib/TestDialect/TestPatterns.cpp b/mlir/test/lib/TestDialect/TestPatterns.cpp index 052d7b9b721..dfde4f8bc99 100644 --- a/mlir/test/lib/TestDialect/TestPatterns.cpp +++ b/mlir/test/lib/TestDialect/TestPatterns.cpp @@ -356,6 +356,12 @@ struct TestLegalizePatternDriver return op.getOperand()->getType().isF64(); }); + // Check support for marking certain operations as recursively legal. + target.markOpRecursivelyLegal<FuncOp, ModuleOp>([](Operation *op) { + return static_cast<bool>( + op->getAttrOfType<UnitAttr>("test.recursively_legal")); + }); + // Handle a partial conversion. if (mode == ConversionMode::Partial) { (void)applyPartialConversion(getModule(), target, patterns, &converter); |

