Shape inference is currently tested alongside type inference by
`TestReturnTypeDriver` in the test dialect. This driver performs two checks:
-1. Verification that the return types specified matches the infered types. This
+1. Verification that the return types specified matches the inferred types. This
explicit check will be removed and made part of Op verification instead.
2. Test the creation of Ops without specifying the return type explicitly in
function `testCreateFunctions` by creating new binary Ops (Op classes
componentTypeFn,
MLIRContext *context, Optional<Location> location, ValueRange operands,
ArrayRef<NamedAttribute> attributes, RegionRange regions,
- SmallVectorImpl<Type> &inferedReturnTypes);
+ SmallVectorImpl<Type> &inferredReturnTypes);
/// Verifies that the inferred result types match the actual result types for
/// the op. Precondition: op implements InferTypeOpInterface.
namespace OpTrait {
-/// Tensor type inference trait that constructs a tensor from the infered
+/// Tensor type inference trait that constructs a tensor from the inferred
/// shape and elemental types.
/// Requires: Op implements functions of InferShapedTypeOpInterface.
template <typename ConcreteType>
inferReturnTypes(MLIRContext *context, Optional<Location> location,
ValueRange operands, ArrayRef<NamedAttribute> attributes,
RegionRange regions,
- SmallVectorImpl<Type> &inferedReturnTypes) {
+ SmallVectorImpl<Type> &inferredReturnTypes) {
return ::mlir::detail::inferReturnTensorTypes(
ConcreteType::inferReturnTypeComponents, context, location, operands,
- attributes, regions, inferedReturnTypes);
+ attributes, regions, inferredReturnTypes);
}
};
"ValueRange":$operands,
"ArrayRef<NamedAttribute>":$attributes,
"RegionRange":$regions,
- "SmallVectorImpl<Type>&":$inferedReturnTypes)
+ "SmallVectorImpl<Type>&":$inferredReturnTypes)
>,
StaticInterfaceMethod<
/*desc=*/"Returns whether two array of types are compatible result types"
"ArrayRef<NamedAttribute>":$attributes,
"RegionRange":$regions,
"SmallVectorImpl<ShapedTypeComponents>&":
- $inferedReturnShapes)
+ $inferredReturnShapes)
>,
InterfaceMethod<
/*desc=*/[{Reify the shape computation for the operation.
componentTypeFn,
MLIRContext *context, Optional<Location> location, ValueRange operands,
ArrayRef<NamedAttribute> attributes, RegionRange regions,
- SmallVectorImpl<Type> &inferedReturnTypes) {
+ SmallVectorImpl<Type> &inferredReturnTypes) {
SmallVector<ShapedTypeComponents, 2> retComponents;
if (failed(componentTypeFn(context, location, operands, attributes, regions,
retComponents)))
for (auto shapeAndType : retComponents) {
assert(shapeAndType.getAttribute() == nullptr && "attribute not supported");
if (shapeAndType.hasRank())
- inferedReturnTypes.push_back(RankedTensorType::get(
+ inferredReturnTypes.push_back(RankedTensorType::get(
shapeAndType.getDims(), shapeAndType.getElementType()));
else
- inferedReturnTypes.push_back(
+ inferredReturnTypes.push_back(
UnrankedTensorType::get(shapeAndType.getElementType()));
}
return success();
}
LogicalResult mlir::detail::verifyInferredResultTypes(Operation *op) {
- SmallVector<Type, 4> inferedReturnTypes;
+ SmallVector<Type, 4> inferredReturnTypes;
auto retTypeFn = cast<InferTypeOpInterface>(op);
if (failed(retTypeFn.inferReturnTypes(op->getContext(), op->getLoc(),
op->getOperands(), op->getAttrs(),
- op->getRegions(), inferedReturnTypes)))
+ op->getRegions(), inferredReturnTypes)))
return failure();
- if (!retTypeFn.isCompatibleReturnTypes(inferedReturnTypes,
+ if (!retTypeFn.isCompatibleReturnTypes(inferredReturnTypes,
op->getResultTypes()))
return op->emitOpError(
"inferred type incompatible with return type of operation");
LogicalResult mlir::OpWithInferTypeInterfaceOp::inferReturnTypes(
MLIRContext *, Optional<Location> location, ValueRange operands,
ArrayRef<NamedAttribute> attributes, RegionRange regions,
- SmallVectorImpl<Type> &inferedReturnTypes) {
+ SmallVectorImpl<Type> &inferredReturnTypes) {
if (operands[0].getType() != operands[1].getType()) {
return emitOptionalError(location, "operand type mismatch ",
operands[0].getType(), " vs ",
operands[1].getType());
}
- inferedReturnTypes.assign({operands[0].getType()});
+ inferredReturnTypes.assign({operands[0].getType()});
return success();
}
LogicalResult OpWithShapedTypeInferTypeInterfaceOp::inferReturnTypeComponents(
MLIRContext *context, Optional<Location> location, ValueRange operands,
ArrayRef<NamedAttribute> attributes, RegionRange regions,
- SmallVectorImpl<ShapedTypeComponents> &inferedReturnShapes) {
+ SmallVectorImpl<ShapedTypeComponents> &inferredReturnShapes) {
// Create return type consisting of the last element of the first operand.
auto operandType = *operands.getTypes().begin();
auto sval = operandType.dyn_cast<ShapedType>();
int64_t dim =
sval.hasRank() ? sval.getShape().front() : ShapedType::kDynamicSize;
auto type = IntegerType::get(17, context);
- inferedReturnShapes.push_back(ShapedTypeComponents({dim}, type));
+ inferredReturnShapes.push_back(ShapedTypeComponents({dim}, type));
return success();
}
//===----------------------------------------------------------------------===//
namespace {
-// Generate ops for each instance where the type can be successfully infered.
+// Generate ops for each instance where the type can be successfully inferred.
template <typename OpTy>
-static void invokeCreateWithInferedReturnType(Operation *op) {
+static void invokeCreateWithInferredReturnType(Operation *op) {
auto *context = op->getContext();
auto fop = op->getParentOfType<FuncOp>();
auto location = UnknownLoc::get(context);
for (int i = 0, e = fop.getNumArguments(); i < e; ++i) {
for (int j = 0; j < e; ++j) {
std::array<Value, 2> values = {{fop.getArgument(i), fop.getArgument(j)}};
- SmallVector<Type, 2> inferedReturnTypes;
+ SmallVector<Type, 2> inferredReturnTypes;
if (succeeded(OpTy::inferReturnTypes(context, llvm::None, values,
op->getAttrs(), op->getRegions(),
- inferedReturnTypes))) {
+ inferredReturnTypes))) {
OperationState state(location, OpTy::getOperationName());
// TODO(jpienaar): Expand to regions.
OpTy::build(&b, state, values, op->getAttrs());
// Test create method of each of the Op classes below. The resultant
// output would be in reverse order underneath `op` from which
// the attributes and regions are used.
- invokeCreateWithInferedReturnType<OpWithInferTypeInterfaceOp>(op);
- invokeCreateWithInferedReturnType<OpWithShapedTypeInferTypeInterfaceOp>(
- op);
+ invokeCreateWithInferredReturnType<OpWithInferTypeInterfaceOp>(op);
+ invokeCreateWithInferredReturnType<
+ OpWithShapedTypeInferTypeInterfaceOp>(op);
};
return;
}
// Generates the build() method that takes aggregate operands/attributes
// parameters. This build() method uses inferred types as result types.
// Requires: The type needs to be inferable via InferTypeOpInterface.
- void genInferedTypeCollectiveParamBuilder();
+ void genInferredTypeCollectiveParamBuilder();
// Generates the build() method that takes each operand/attribute as a
// stand-alone parameter. The generated build() method uses first attribute's
if (inferType) {
// Generate builder that infers type too.
// TODO(jpienaar): Subsume this with general checking if type can be
- // infered automatically.
+ // inferred automatically.
// TODO(jpienaar): Expand to handle regions.
body << formatv(R"(
- SmallVector<Type, 2> inferedReturnTypes;
+ SmallVector<Type, 2> inferredReturnTypes;
if (succeeded({0}::inferReturnTypes(odsBuilder->getContext(),
{1}.location, {1}.operands, {1}.attributes,
- /*regions=*/{{}, inferedReturnTypes)))
- {1}.addTypes(inferedReturnTypes);
+ /*regions=*/{{}, inferredReturnTypes)))
+ {1}.addTypes(inferredReturnTypes);
else
llvm::report_fatal_error("Failed to infer result type(s).");)",
opClass.getClassName(), builderOpState);
<< llvm::join(resultTypes, ", ") << "});\n\n";
}
-void OpEmitter::genInferedTypeCollectiveParamBuilder() {
+void OpEmitter::genInferredTypeCollectiveParamBuilder() {
// TODO(jpienaar): Expand to support regions.
const char *params =
"Builder *odsBuilder, OperationState &{0}, "
OpMethod::MP_Static);
auto &body = m.body();
body << formatv(R"(
- SmallVector<Type, 2> inferedReturnTypes;
+ SmallVector<Type, 2> inferredReturnTypes;
if (succeeded({0}::inferReturnTypes(odsBuilder->getContext(),
{1}.location, operands, attributes,
- /*regions=*/{{}, inferedReturnTypes)))
- build(odsBuilder, odsState, inferedReturnTypes, operands, attributes);
+ /*regions=*/{{}, inferredReturnTypes)))
+ build(odsBuilder, odsState, inferredReturnTypes, operands, attributes);
else
llvm::report_fatal_error("Failed to infer result type(s).");)",
opClass.getClassName(), builderOpState);
body << " " << builderOpState << ".addTypes(resultTypes);\n";
// Generate builder that infers type too.
- // TODO(jpienaar): Subsume this with general checking if type can be infered
+ // TODO(jpienaar): Subsume this with general checking if type can be inferred
// automatically.
// TODO(jpienaar): Expand to handle regions and successors.
if (op.getTrait("InferTypeOpInterface::Trait") && op.getNumRegions() == 0 &&
op.getNumSuccessors() == 0)
- genInferedTypeCollectiveParamBuilder();
+ genInferredTypeCollectiveParamBuilder();
}
void OpEmitter::buildParamList(std::string ¶mList,