summaryrefslogtreecommitdiffstats
path: root/mlir/test/lib/TestDialect
diff options
context:
space:
mode:
authorJacques Pienaar <jpienaar@google.com>2019-12-06 10:52:38 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-12-06 10:53:06 -0800
commit398f04aa49109fd5d1eff2c1946a2956dc6b29c6 (patch)
tree20c0b758574c11999f3d0c670fe5d0dc7a765b97 /mlir/test/lib/TestDialect
parente216a72ab8587c443e4c5c06aabc71c36712ce7e (diff)
downloadbcm5719-llvm-398f04aa49109fd5d1eff2c1946a2956dc6b29c6.tar.gz
bcm5719-llvm-398f04aa49109fd5d1eff2c1946a2956dc6b29c6.zip
Generate builder for ops that use InferTypeOpInterface trait in ODS
For ops with infer type op interface defined, generate version that calls the inferal method on build. This is intermediate step to removing special casing of SameOperandsAndResultType & FirstAttrDereivedResultType. After that would be generating the inference code, with the initial focus on shaped container types. In between I plan to refactor these a bit to reuse generated paths. The intention would not be to add the type inference trait in multiple places, but rather to take advantage of the current modelling in ODS where possible to emit it instead. Switch the `inferReturnTypes` method to be static. Skipping ops with regions here as I don't like the Region vs unique_ptr<Region> difference at the moment, and I want the infer return type trait to be useful for verification too. So instead, just skip it for now to avoid churn. PiperOrigin-RevId: 284217913
Diffstat (limited to 'mlir/test/lib/TestDialect')
-rw-r--r--mlir/test/lib/TestDialect/TestPatterns.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/mlir/test/lib/TestDialect/TestPatterns.cpp b/mlir/test/lib/TestDialect/TestPatterns.cpp
index 92f132613b1..7b835c5e61d 100644
--- a/mlir/test/lib/TestDialect/TestPatterns.cpp
+++ b/mlir/test/lib/TestDialect/TestPatterns.cpp
@@ -73,10 +73,7 @@ struct ReturnTypeOpMatch : public RewritePattern {
PatternMatchResult matchAndRewrite(Operation *op,
PatternRewriter &rewriter) const final {
if (auto retTypeFn = dyn_cast<InferTypeOpInterface>(op)) {
- SmallVector<Value *, 4> values;
- values.reserve(op->getNumOperands());
- for (auto &operand : op->getOpOperands())
- values.push_back(operand.get());
+ SmallVector<Value *, 4> values(op->getOperands());
auto res = retTypeFn.inferReturnTypes(op->getLoc(), values,
op->getAttrs(), op->getRegions());
SmallVector<Type, 1> result_types(op->getResultTypes());
@@ -84,6 +81,20 @@ struct ReturnTypeOpMatch : public RewritePattern {
return op->emitOpError(
"inferred type incompatible with return type of operation"),
matchFailure();
+
+ // TODO(jpienaar): Split this out to make the test more focused.
+ // Create new op with unknown location to verify building with
+ // InferTypeOpInterface is triggered.
+ auto fop = op->getParentOfType<FuncOp>();
+ if (values[0] == fop.getArgument(0)) {
+ // Use the 2nd function argument if the first function argument is used
+ // when constructing the new op so that a new return type is inferred.
+ values[0] = fop.getArgument(1);
+ values[1] = fop.getArgument(1);
+ // TODO(jpienaar): Expand to regions.
+ rewriter.create<OpWithInferTypeInterfaceOp>(
+ UnknownLoc::get(op->getContext()), values, op->getAttrs());
+ }
}
return matchFailure();
}
OpenPOWER on IntegriCloud