diff options
author | River Riddle <riverriddle@google.com> | 2019-07-18 18:20:03 -0700 |
---|---|---|
committer | Mehdi Amini <joker.eph@gmail.com> | 2019-07-19 11:40:19 -0700 |
commit | 28057ff3daa241f79417817a9d9ee821cffc83fd (patch) | |
tree | 0df8f33118626981b1ae8d273c70517075a28ef0 /mlir/test/lib | |
parent | 36a26e00334446abfc4a03f30c58a36914d33235 (diff) | |
download | bcm5719-llvm-28057ff3daa241f79417817a9d9ee821cffc83fd.tar.gz bcm5719-llvm-28057ff3daa241f79417817a9d9ee821cffc83fd.zip |
Add support for providing a legality callback for dynamic legality in DialectConversion.
This allows for providing specific handling for dynamically legal operations/dialects without overriding the general 'isDynamicallyLegal' hook. This also means that a derived ConversionTarget class need not always be defined when some operations are dynamically legal.
Example usage:
ConversionTarget target(...);
target.addDynamicallyLegalOp<ReturnOp>([](ReturnOp op) {
return ...
};
target.addDynamicallyLegalDialect<StandardOpsDialect>([](Operation *op) {
return ...
};
PiperOrigin-RevId: 258884753
Diffstat (limited to 'mlir/test/lib')
-rw-r--r-- | mlir/test/lib/TestDialect/TestPatterns.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/mlir/test/lib/TestDialect/TestPatterns.cpp b/mlir/test/lib/TestDialect/TestPatterns.cpp index 410536c2882..d452edb71eb 100644 --- a/mlir/test/lib/TestDialect/TestPatterns.cpp +++ b/mlir/test/lib/TestDialect/TestPatterns.cpp @@ -182,19 +182,6 @@ struct TestTypeConverter : public TypeConverter { } }; -struct TestConversionTarget : public ConversionTarget { - TestConversionTarget(MLIRContext &ctx) : ConversionTarget(ctx) { - addLegalOp<LegalOpA, TestValidOp>(); - addDynamicallyLegalOp<TestReturnOp>(); - addIllegalOp<ILLegalOpF, TestRegionBuilderOp>(); - } - bool isDynamicallyLegal(Operation *op) const final { - // Don't allow F32 operands. - return llvm::none_of(op->getOperandTypes(), - [](Type type) { return type.isF32(); }); - } -}; - struct TestLegalizePatternDriver : public ModulePass<TestLegalizePatternDriver> { void runOnModule() override { @@ -204,8 +191,17 @@ struct TestLegalizePatternDriver TestDropOp, TestPassthroughInvalidOp, TestSplitReturnType>::build(patterns, &getContext()); + // Define the conversion target used for the test. + ConversionTarget target(getContext()); + target.addLegalOp<LegalOpA, TestValidOp>(); + target.addIllegalOp<ILLegalOpF, TestRegionBuilderOp>(); + target.addDynamicallyLegalOp<TestReturnOp>([](TestReturnOp op) { + // Don't allow F32 operands. + return llvm::none_of(op.getOperandTypes(), + [](Type type) { return type.isF32(); }); + }); + TestTypeConverter converter; - TestConversionTarget target(getContext()); (void)applyPartialConversion(getModule(), target, std::move(patterns), &converter); } |