diff options
| author | River Riddle <riverriddle@google.com> | 2019-11-13 10:27:21 -0800 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-11-13 10:27:53 -0800 |
| commit | d985c7488393a181f30b0faeb3083ec0c27983eb (patch) | |
| tree | 6d772ec663a965645858879b92f15dfc0260c96f /mlir/test/lib/TestDialect | |
| parent | f45852be6c152efc377419e3c8bead5d80544223 (diff) | |
| download | bcm5719-llvm-d985c7488393a181f30b0faeb3083ec0c27983eb.tar.gz bcm5719-llvm-d985c7488393a181f30b0faeb3083ec0c27983eb.zip | |
NFC: Refactor block signature conversion to not erase the original arguments.
This refactors the implementation of block signature(type) conversion to not insert fake cast operations to perform the type conversion, but to instead create a new block containing the proper signature. This has the benefit of enabling the use of pre-computed analyses that rely on mapping values. It also leads to a much cleaner implementation overall. The major user facing change is that applySignatureConversion will now replace the entry block of the region, meaning that blocks generally shouldn't be cached over calls to applySignatureConversion.
PiperOrigin-RevId: 280226936
Diffstat (limited to 'mlir/test/lib/TestDialect')
| -rw-r--r-- | mlir/test/lib/TestDialect/TestPatterns.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/mlir/test/lib/TestDialect/TestPatterns.cpp b/mlir/test/lib/TestDialect/TestPatterns.cpp index cc935c71c28..936d7632967 100644 --- a/mlir/test/lib/TestDialect/TestPatterns.cpp +++ b/mlir/test/lib/TestDialect/TestPatterns.cpp @@ -162,15 +162,32 @@ struct TestRegionRewriteUndo : public RewritePattern { //===----------------------------------------------------------------------===// // Type-Conversion Rewrite Testing -/// This pattern simply erases the given operation. -struct TestDropOp : public ConversionPattern { - TestDropOp(MLIRContext *ctx) : ConversionPattern("test.drop_op", 1, ctx) {} +/// This patterns erases a region operation that has had a type conversion. +struct TestDropOpSignatureConversion : public ConversionPattern { + TestDropOpSignatureConversion(MLIRContext *ctx, TypeConverter &converter) + : ConversionPattern("test.drop_region_op", 1, ctx), converter(converter) { + } PatternMatchResult matchAndRewrite(Operation *op, ArrayRef<Value *> operands, - ConversionPatternRewriter &rewriter) const final { + ConversionPatternRewriter &rewriter) const override { + Region ®ion = op->getRegion(0); + Block *entry = ®ion.front(); + + // Convert the original entry arguments. + TypeConverter::SignatureConversion result(entry->getNumArguments()); + for (unsigned i = 0, e = entry->getNumArguments(); i != e; ++i) + if (failed(converter.convertSignatureArg( + i, entry->getArgument(i)->getType(), result))) + return matchFailure(); + + // Convert the region signature and just drop the operation. + rewriter.applySignatureConversion(®ion, result); rewriter.eraseOp(op); return matchSuccess(); } + + /// The type converter to use when rewriting the signature. + TypeConverter &converter; }; /// This pattern simply updates the operands of the given operation. struct TestPassthroughInvalidOp : public ConversionPattern { @@ -334,10 +351,11 @@ struct TestLegalizePatternDriver populateWithGenerated(&getContext(), &patterns); patterns .insert<TestRegionRewriteBlockMovement, TestRegionRewriteUndo, - TestDropOp, TestPassthroughInvalidOp, TestSplitReturnType, + TestPassthroughInvalidOp, TestSplitReturnType, TestChangeProducerTypeI32ToF32, TestChangeProducerTypeF32ToF64, TestChangeProducerTypeF32ToInvalid, TestUpdateConsumerType, TestNonRootReplacement>(&getContext()); + patterns.insert<TestDropOpSignatureConversion>(&getContext(), converter); mlir::populateFuncOpTypeConversionPattern(patterns, &getContext(), converter); |

