}
typeName += ">";
}
- return mlir::UnknownType::get(mlir::Identifier::get("toy", &context),
- typeName, &context);
+ return mlir::OpaqueType::get(mlir::Identifier::get("toy", &context),
+ typeName, &context);
}
/// Build an MLIR type from a Toy AST variable type
MLIR supports unregistered operations in generic assembly form. MLIR also
supports a similar concept for types. When parsing, if the dialect for dialect
-type has not been registered the type is modeled as an 'UnknownType'. This
-allows for types to be round-tripped without needing to link in the dialect
-library that defined them. No additional information about unknown types,
-outside of parsing/printing, will be available.
+type has not been registered the type is modeled as an 'OpaqueType'. This allows
+for types to be round-tripped without needing to link in the dialect library
+that defined them. No additional information about opaque types, outside of
+parsing/printing, will be available.
#### Dialect type syntax
```c++
// The return type for the operation: `!another_dialect<"other_type">`
auto another_dialect_prefix = mlir::Identifier::get("another_dialect", &context);
-auto returnType = mlir::UnknownType::get(another_dialect_prefix,
+auto returnType = mlir::OpaqueType::get(another_dialect_prefix,
"custom_type", &context);
// Creation of the state defining the operation:
mlir::OperationState state(&context, location, "custom.operation");
// We bundle our custom type in a `toy` dialect.
auto toyDialect = mlir::Identifier::get("toy", builder->getContext());
// Create a custom type, in the MLIR assembly it is: !toy<"array<2, 2>">
- auto type = mlir::UnknownType::get(toyDialect, "array<2, 2>", builder->getContext());
+ auto type = mlir::OpaqueType::get(toyDialect, "array<2, 2>", builder->getContext());
// Fill the `OperationState` with the required fields
mlir::OperationState result(builder->getContext(), location, "toy.transpose");
// types. Dialects are expected to verify that tensor types have a valid
// element type within that dialect.
return type.isIntOrFloat() || type.isa<VectorType>() ||
- type.isa<UnknownType>() ||
+ type.isa<OpaqueType>() ||
(type.getKind() > Type::Kind::LAST_STANDARD_TYPE);
}
namespace detail {
struct FunctionTypeStorage;
-struct UnknownTypeStorage;
+struct OpaqueTypeStorage;
} // namespace detail
/// Instances of the Type class are immutable and uniqued. They wrap a pointer
enum Kind {
// Builtin types.
Function,
- Unknown,
- LAST_BUILTIN_TYPE = Unknown,
+ Opaque,
+ LAST_BUILTIN_TYPE = Opaque,
// Reserve type kinds for dialect specific type system extensions.
#define DEFINE_TYPE_KIND_RANGE(Dialect) \
static bool kindof(unsigned kind) { return kind == Kind::Function; }
};
-/// Unknown types represent types of non-registered dialects. These are types
+/// Opaque types represent types of non-registered dialects. These are types
/// represented in their raw string form, and can only usefully be tested for
/// type equality.
-class UnknownType
- : public Type::TypeBase<UnknownType, Type, detail::UnknownTypeStorage> {
+class OpaqueType
+ : public Type::TypeBase<OpaqueType, Type, detail::OpaqueTypeStorage> {
public:
using Base::Base;
- /// Get or create a new UnknownType with the provided dialect and string data.
- static UnknownType get(Identifier dialect, StringRef typeData,
- MLIRContext *context);
+ /// Get or create a new OpaqueType with the provided dialect and string data.
+ static OpaqueType get(Identifier dialect, StringRef typeData,
+ MLIRContext *context);
- /// Get or create a new UnknownType with the provided dialect and string data.
+ /// Get or create a new OpaqueType with the provided dialect and string data.
/// If the given identifier is not a valid namespace for a dialect, then a
/// null type is returned.
- static UnknownType getChecked(Identifier dialect, StringRef typeData,
- MLIRContext *context, Location location);
+ static OpaqueType getChecked(Identifier dialect, StringRef typeData,
+ MLIRContext *context, Location location);
- /// Returns the dialect namespace of the unknown type.
+ /// Returns the dialect namespace of the opaque type.
Identifier getDialectNamespace() const;
- /// Returns the raw type data of the unknown type.
+ /// Returns the raw type data of the opaque type.
StringRef getTypeData() const;
- /// Verify the construction of an unknown type.
+ /// Verify the construction of an opaque type.
static LogicalResult
verifyConstructionInvariants(llvm::Optional<Location> loc,
MLIRContext *context, Identifier dialect,
StringRef typeData);
- static bool kindof(unsigned kind) { return kind == Kind::Unknown; }
+ static bool kindof(unsigned kind) { return kind == Kind::Opaque; }
};
// Make Type hashable.
os << "\">";
return;
}
- case Type::Kind::Unknown: {
- auto unknownTy = type.cast<UnknownType>();
- os << '!' << unknownTy.getDialectNamespace() << "<\""
- << unknownTy.getTypeData() << "\">";
+ case Type::Kind::Opaque: {
+ auto opaqueTy = type.cast<OpaqueType>();
+ os << '!' << opaqueTy.getDialectNamespace() << "<\""
+ << opaqueTy.getTypeData() << "\">";
return;
}
case StandardTypes::Index:
/// validity of the IR.
struct BuiltinDialect : public Dialect {
BuiltinDialect(MLIRContext *context) : Dialect(/*name=*/"", context) {
- addTypes<FunctionType, UnknownType, FloatType, IndexType, IntegerType,
+ addTypes<FunctionType, OpaqueType, FloatType, IndexType, IntegerType,
VectorType, RankedTensorType, UnrankedTensorType, MemRefType,
ComplexType, TupleType>();
}
namespace detail {
-/// Unknown Type Storage and Uniquing.
-struct UnknownTypeStorage : public TypeStorage {
- UnknownTypeStorage(Identifier dialectNamespace, StringRef typeData)
+/// Opaque Type Storage and Uniquing.
+struct OpaqueTypeStorage : public TypeStorage {
+ OpaqueTypeStorage(Identifier dialectNamespace, StringRef typeData)
: dialectNamespace(dialectNamespace), typeData(typeData) {}
/// The hash key used for uniquing.
return key == KeyTy(dialectNamespace, typeData);
}
- static UnknownTypeStorage *construct(TypeStorageAllocator &allocator,
- const KeyTy &key) {
+ static OpaqueTypeStorage *construct(TypeStorageAllocator &allocator,
+ const KeyTy &key) {
StringRef tyData = allocator.copyInto(key.second);
- return new (allocator.allocate<UnknownTypeStorage>())
- UnknownTypeStorage(key.first, tyData);
+ return new (allocator.allocate<OpaqueTypeStorage>())
+ OpaqueTypeStorage(key.first, tyData);
}
// The unknown dialect namespace.
Identifier dialectNamespace;
- // The parser type data for this unknown type.
+ // The parser type data for this opaque type.
StringRef typeData;
};
return getImpl()->getResults();
}
-/// UnknownType
+/// OpaqueType
-UnknownType UnknownType::get(Identifier dialect, StringRef typeData,
- MLIRContext *context) {
- return Base::get(context, Type::Kind::Unknown, dialect, typeData);
+OpaqueType OpaqueType::get(Identifier dialect, StringRef typeData,
+ MLIRContext *context) {
+ return Base::get(context, Type::Kind::Opaque, dialect, typeData);
}
-UnknownType UnknownType::getChecked(Identifier dialect, StringRef typeData,
- MLIRContext *context, Location location) {
- return Base::getChecked(location, context, Kind::Unknown, dialect, typeData);
+OpaqueType OpaqueType::getChecked(Identifier dialect, StringRef typeData,
+ MLIRContext *context, Location location) {
+ return Base::getChecked(location, context, Kind::Opaque, dialect, typeData);
}
-/// Returns the dialect namespace of the unknown type.
-Identifier UnknownType::getDialectNamespace() const {
+/// Returns the dialect namespace of the opaque type.
+Identifier OpaqueType::getDialectNamespace() const {
return getImpl()->dialectNamespace;
}
-/// Returns the raw type data of the unknown type.
-StringRef UnknownType::getTypeData() const { return getImpl()->typeData; }
+/// Returns the raw type data of the opaque type.
+StringRef OpaqueType::getTypeData() const { return getImpl()->typeData; }
-/// Verify the construction of an unknown type.
-LogicalResult UnknownType::verifyConstructionInvariants(
+/// Verify the construction of an opaque type.
+LogicalResult OpaqueType::verifyConstructionInvariants(
llvm::Optional<Location> loc, MLIRContext *context, Identifier dialect,
StringRef typeData) {
if (!Dialect::isValidNamespace(dialect.strref())) {
if (!result)
return nullptr;
} else {
- // Otherwise, form a new unknown type.
- result = UnknownType::getChecked(Identifier::get(identifier, state.context),
- typeData, state.context, loc);
+ // Otherwise, form a new opaque type.
+ result = OpaqueType::getChecked(Identifier::get(identifier, state.context),
+ typeData, state.context, loc);
}
// Consume the '>'.
// RUN: mlir-opt %s -split-input-file -verify
// -----
-// Unknown type.
+// Invalid type.
// expected-error@+1 {{unknown quantized type foobar}}
!qalias = type !quant<"foobar">