Change derived type storage objects to be constructed with an instance of the

KeyTy. This will simplify the cases where a type can be constructed, and need to be verified, in multiple ways.

PiperOrigin-RevId: 229279000
This commit is contained in:
River Riddle 2019-01-14 16:29:30 -08:00 committed by jpienaar
parent 8b0ad6f579
commit b9c791b96d
3 changed files with 33 additions and 43 deletions

View File

@ -189,7 +189,7 @@ public:
// Otherwise, construct and initialize the derived storage for this type // Otherwise, construct and initialize the derived storage for this type
// instance. // instance.
TypeStorageAllocator allocator(ctx); TypeStorageAllocator allocator(ctx);
storage = ImplType::construct(allocator, args...); storage = ImplType::construct(allocator, derivedKey);
storage->initializeTypeInfo(dialect, kind); storage->initializeTypeInfo(dialect, kind);
// Insert the new type storage instance into the context. // Insert the new type storage instance into the context.

View File

@ -88,10 +88,10 @@ struct UnknownTypeStorage;
/// from an existing storage instance. /// from an existing storage instance.
/// ///
/// - Provide a construction method: /// - Provide a construction method:
/// 'DerivedStorage *construct(TypeStorageAllocator &, ...)' /// 'DerivedStorage *construct(TypeStorageAllocator &, const KeyTy &key)'
/// that builds a unique instance of the derived storage. The arguments /// that builds a unique instance of the derived storage. The arguments to
/// after the TypeStorageAllocator must correspond with the values passed /// this function are an allocator to store any uniqued data within the
/// into the detail::TypeUniquer::get call after the type kind. /// context and the key type for this storage.
class Type { class Type {
public: public:
/// Integer identifier for all the concrete type kinds. /// Integer identifier for all the concrete type kinds.

View File

@ -45,11 +45,10 @@ struct UnknownTypeStorage : public TypeStorage {
KeyTy getKey() const { return std::make_pair(dialectNamespace, typeData); } KeyTy getKey() const { return std::make_pair(dialectNamespace, typeData); }
static UnknownTypeStorage *construct(TypeStorageAllocator &allocator, static UnknownTypeStorage *construct(TypeStorageAllocator &allocator,
Identifier dialectName, const KeyTy &key) {
StringRef tyData) { StringRef tyData = allocator.copyInto(key.second);
auto *instance = allocator.allocate<UnknownTypeStorage>(); return new (allocator.allocate<UnknownTypeStorage>())
tyData = allocator.copyInto(tyData); UnknownTypeStorage(key.first, tyData);
return new (instance) UnknownTypeStorage(dialectName, tyData);
} }
// The unknown dialect namespace. // The unknown dialect namespace.
@ -70,9 +69,9 @@ struct IntegerTypeStorage : public TypeStorage {
KeyTy getKey() const { return width; } KeyTy getKey() const { return width; }
static IntegerTypeStorage *construct(TypeStorageAllocator &allocator, static IntegerTypeStorage *construct(TypeStorageAllocator &allocator,
unsigned bitwidth) { KeyTy bitwidth) {
auto *instance = allocator.allocate<IntegerTypeStorage>(); return new (allocator.allocate<IntegerTypeStorage>())
return new (instance) IntegerTypeStorage(bitwidth); IntegerTypeStorage(bitwidth);
} }
unsigned width; unsigned width;
@ -93,9 +92,9 @@ struct FunctionTypeStorage : public TypeStorage {
/// Construction. /// Construction.
static FunctionTypeStorage *construct(TypeStorageAllocator &allocator, static FunctionTypeStorage *construct(TypeStorageAllocator &allocator,
ArrayRef<Type> inputs, const KeyTy &key) {
ArrayRef<Type> results) { ArrayRef<Type> inputs, results;
auto *result = allocator.allocate<FunctionTypeStorage>(); std::tie(inputs, results) = key;
// Copy the inputs and results into the bump pointer. // Copy the inputs and results into the bump pointer.
SmallVector<Type, 16> types; SmallVector<Type, 16> types;
@ -105,9 +104,8 @@ struct FunctionTypeStorage : public TypeStorage {
auto typesList = allocator.copyInto(ArrayRef<Type>(types)); auto typesList = allocator.copyInto(ArrayRef<Type>(types));
// Initialize the memory using placement new. // Initialize the memory using placement new.
return new (result) FunctionTypeStorage( return new (allocator.allocate<FunctionTypeStorage>())
static_cast<unsigned int>(inputs.size()), FunctionTypeStorage(inputs.size(), results.size(), typesList.data());
static_cast<unsigned int>(results.size()), typesList.data());
} }
ArrayRef<Type> getInputs() const { ArrayRef<Type> getInputs() const {
@ -150,15 +148,13 @@ struct VectorTypeStorage : public VectorOrTensorTypeStorage {
/// Construction. /// Construction.
static VectorTypeStorage *construct(TypeStorageAllocator &allocator, static VectorTypeStorage *construct(TypeStorageAllocator &allocator,
ArrayRef<int> shape, Type elementTy) { const KeyTy &key) {
auto *result = allocator.allocate<VectorTypeStorage>();
// Copy the shape into the bump pointer. // Copy the shape into the bump pointer.
shape = allocator.copyInto(shape); ArrayRef<int> shape = allocator.copyInto(key.first);
// Initialize the memory using placement new. // Initialize the memory using placement new.
return new (result) VectorTypeStorage( return new (allocator.allocate<VectorTypeStorage>())
static_cast<unsigned int>(shape.size()), elementTy, shape.data()); VectorTypeStorage(shape.size(), key.second, shape.data());
} }
ArrayRef<int> getShape() const { ArrayRef<int> getShape() const {
@ -182,16 +178,13 @@ struct RankedTensorTypeStorage : public VectorOrTensorTypeStorage {
/// Construction. /// Construction.
static RankedTensorTypeStorage *construct(TypeStorageAllocator &allocator, static RankedTensorTypeStorage *construct(TypeStorageAllocator &allocator,
ArrayRef<int> shape, const KeyTy &key) {
Type elementTy) {
auto *result = allocator.allocate<RankedTensorTypeStorage>();
// Copy the shape into the bump pointer. // Copy the shape into the bump pointer.
shape = allocator.copyInto(shape); ArrayRef<int> shape = allocator.copyInto(key.first);
// Initialize the memory using placement new. // Initialize the memory using placement new.
return new (result) RankedTensorTypeStorage( return new (allocator.allocate<RankedTensorTypeStorage>())
static_cast<unsigned int>(shape.size()), elementTy, shape.data()); RankedTensorTypeStorage(shape.size(), key.second, shape.data());
} }
ArrayRef<int> getShape() const { ArrayRef<int> getShape() const {
@ -233,22 +226,19 @@ struct MemRefTypeStorage : public TypeStorage {
/// Construction. /// Construction.
static MemRefTypeStorage *construct(TypeStorageAllocator &allocator, static MemRefTypeStorage *construct(TypeStorageAllocator &allocator,
ArrayRef<int> shape, Type elementType, const KeyTy &key) {
ArrayRef<AffineMap> affineMapComposition,
unsigned memorySpace) {
auto *result = allocator.allocate<MemRefTypeStorage>();
// Copy the shape into the bump pointer. // Copy the shape into the bump pointer.
shape = allocator.copyInto(shape); ArrayRef<int> shape = allocator.copyInto(std::get<0>(key));
// Copy the affine map composition into the bump pointer. // Copy the affine map composition into the bump pointer.
affineMapComposition = allocator.copyInto(affineMapComposition); ArrayRef<AffineMap> affineMapComposition =
allocator.copyInto(std::get<2>(key));
// Initialize the memory using placement new. // Initialize the memory using placement new.
return new (result) MemRefTypeStorage( return new (allocator.allocate<MemRefTypeStorage>())
static_cast<unsigned int>(shape.size()), elementType, shape.data(), MemRefTypeStorage(shape.size(), std::get<1>(key), shape.data(),
static_cast<unsigned int>(affineMapComposition.size()), affineMapComposition.size(),
affineMapComposition.data(), memorySpace); affineMapComposition.data(), std::get<3>(key));
} }
ArrayRef<int> getShape() const { ArrayRef<int> getShape() const {