summaryrefslogtreecommitdiff
path: root/mlir/lib/TableGen
diff options
context:
space:
mode:
authorRiver Riddle <riddleriver@gmail.com>2022-04-26 11:12:45 -0700
committerRiver Riddle <riddleriver@gmail.com>2022-04-28 12:57:59 -0700
commit92a836da07596a9e409c3b4231fe727e0924d0e4 (patch)
treef15144ffd6a8fd8298bbbe5bea13f72523127705 /mlir/lib/TableGen
parent1bd1edaf4006ff66a88ac59e0931f22105003a26 (diff)
downloadllvm-92a836da07596a9e409c3b4231fe727e0924d0e4.tar.gz
[mlir] Attach InferTypeOpInterface on SameOperandsAndResultType operations when possible
This allows for inferring the result types of operations in certain situations by using the type of an operand. This commit allowed for automatically supporting type inference for many more operations with no additional effort, e.g. nearly all Arithmetic operations now support result type inferrence with no additional changes. Differential Revision: https://reviews.llvm.org/D124581
Diffstat (limited to 'mlir/lib/TableGen')
-rw-r--r--mlir/lib/TableGen/Operator.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/mlir/lib/TableGen/Operator.cpp b/mlir/lib/TableGen/Operator.cpp
index 35afb8d7f694..b3b6d36ee397 100644
--- a/mlir/lib/TableGen/Operator.cpp
+++ b/mlir/lib/TableGen/Operator.cpp
@@ -333,8 +333,25 @@ void Operator::populateTypeInferenceInfo(
// Skip cases currently being custom generated.
// TODO: Remove special cases.
- if (getTrait("::mlir::OpTrait::SameOperandsAndResultType"))
+ if (getTrait("::mlir::OpTrait::SameOperandsAndResultType")) {
+ // Check for a non-variable length operand to use as the type anchor.
+ auto *operandI = llvm::find_if(arguments, [](const Argument &arg) {
+ NamedTypeConstraint *operand = arg.dyn_cast<NamedTypeConstraint *>();
+ return operand && !operand->isVariableLength();
+ });
+ if (operandI == arguments.end())
+ return;
+
+ // Map each of the result types to the anchor operation.
+ int operandIdx = operandI - arguments.begin();
+ resultTypeMapping.resize(getNumResults());
+ for (int i = 0; i < getNumResults(); ++i)
+ resultTypeMapping[i].emplace_back(operandIdx);
+
+ allResultsHaveKnownTypes = true;
+ traits.push_back(Trait::create(inferTrait->getDefInit()));
return;
+ }
// We create equivalence classes of argument/result types where arguments
// and results are mapped into the same index space and indices corresponding