|
|
@@ -42,7 +42,7 @@ class InstStore {
|
|
|
auto size() const -> int { return values_.size(); }
|
|
|
|
|
|
private:
|
|
|
- ValueStore<InstId, Inst> values_;
|
|
|
+ ValueStore<InstId> values_;
|
|
|
};
|
|
|
|
|
|
// Provides storage for instructions representing global constants.
|
|
|
@@ -121,7 +121,7 @@ class NameScopeStore {
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
- ValueStore<NameScopeId, llvm::DenseMap<NameId, InstId>> values_;
|
|
|
+ ValueStore<NameScopeId> values_;
|
|
|
};
|
|
|
|
|
|
// Provides a block-based ValueStore, which uses slab allocation of added
|
|
|
@@ -130,22 +130,33 @@ class NameScopeStore {
|
|
|
//
|
|
|
// BlockValueStore is used as-is, but there are also children that expose the
|
|
|
// protected members for type-specific functionality.
|
|
|
-template <typename IdT, typename ValueT>
|
|
|
-class BlockValueStore : public Yaml::Printable<BlockValueStore<IdT, ValueT>> {
|
|
|
+//
|
|
|
+// On IdT, this requires:
|
|
|
+// - IdT::ElementType to represent the underlying type in the block.
|
|
|
+// - IdT::ValueType to be llvm::MutableArrayRef<IdT::ElementType> for
|
|
|
+// compatibility with ValueStore.
|
|
|
+template <typename IdT>
|
|
|
+class BlockValueStore : public Yaml::Printable<BlockValueStore<IdT>> {
|
|
|
public:
|
|
|
+ using ElementType = typename IdT::ElementType;
|
|
|
+
|
|
|
explicit BlockValueStore(llvm::BumpPtrAllocator& allocator)
|
|
|
: allocator_(&allocator) {}
|
|
|
|
|
|
// Adds a block with the given content, returning an ID to reference it.
|
|
|
- auto Add(llvm::ArrayRef<ValueT> content) -> IdT {
|
|
|
+ auto Add(llvm::ArrayRef<ElementType> content) -> IdT {
|
|
|
return values_.Add(AllocateCopy(content));
|
|
|
}
|
|
|
|
|
|
// Returns the requested block.
|
|
|
- auto Get(IdT id) const -> llvm::ArrayRef<ValueT> { return values_.Get(id); }
|
|
|
+ auto Get(IdT id) const -> llvm::ArrayRef<ElementType> {
|
|
|
+ return values_.Get(id);
|
|
|
+ }
|
|
|
|
|
|
// Returns the requested block.
|
|
|
- auto Get(IdT id) -> llvm::MutableArrayRef<ValueT> { return values_.Get(id); }
|
|
|
+ auto Get(IdT id) -> llvm::MutableArrayRef<ElementType> {
|
|
|
+ return values_.Get(id);
|
|
|
+ }
|
|
|
|
|
|
auto OutputYaml() const -> Yaml::OutputMapping {
|
|
|
return Yaml::OutputMapping([&](Yaml::OutputMapping::Map map) {
|
|
|
@@ -184,31 +195,31 @@ class BlockValueStore : public Yaml::Printable<BlockValueStore<IdT, ValueT>> {
|
|
|
private:
|
|
|
// Allocates an uninitialized array using our slab allocator.
|
|
|
auto AllocateUninitialized(std::size_t size)
|
|
|
- -> llvm::MutableArrayRef<ValueT> {
|
|
|
+ -> llvm::MutableArrayRef<ElementType> {
|
|
|
// We're not going to run a destructor, so ensure that's OK.
|
|
|
- static_assert(std::is_trivially_destructible_v<ValueT>);
|
|
|
+ static_assert(std::is_trivially_destructible_v<ElementType>);
|
|
|
|
|
|
- auto storage = static_cast<ValueT*>(
|
|
|
- allocator_->Allocate(size * sizeof(ValueT), alignof(ValueT)));
|
|
|
- return llvm::MutableArrayRef<ValueT>(storage, size);
|
|
|
+ auto storage = static_cast<ElementType*>(
|
|
|
+ allocator_->Allocate(size * sizeof(ElementType), alignof(ElementType)));
|
|
|
+ return llvm::MutableArrayRef<ElementType>(storage, size);
|
|
|
}
|
|
|
|
|
|
// Allocates a copy of the given data using our slab allocator.
|
|
|
- auto AllocateCopy(llvm::ArrayRef<ValueT> data)
|
|
|
- -> llvm::MutableArrayRef<ValueT> {
|
|
|
+ auto AllocateCopy(llvm::ArrayRef<ElementType> data)
|
|
|
+ -> llvm::MutableArrayRef<ElementType> {
|
|
|
auto result = AllocateUninitialized(data.size());
|
|
|
std::uninitialized_copy(data.begin(), data.end(), result.begin());
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
llvm::BumpPtrAllocator* allocator_;
|
|
|
- ValueStore<IdT, llvm::MutableArrayRef<ValueT>> values_;
|
|
|
+ ValueStore<IdT> values_;
|
|
|
};
|
|
|
|
|
|
// Adapts BlockValueStore for instruction blocks.
|
|
|
-class InstBlockStore : public BlockValueStore<InstBlockId, InstId> {
|
|
|
+class InstBlockStore : public BlockValueStore<InstBlockId> {
|
|
|
public:
|
|
|
- using BaseType = BlockValueStore<InstBlockId, InstId>;
|
|
|
+ using BaseType = BlockValueStore<InstBlockId>;
|
|
|
|
|
|
using BaseType::AddDefaultValue;
|
|
|
using BaseType::AddUninitialized;
|
|
|
@@ -216,7 +227,7 @@ class InstBlockStore : public BlockValueStore<InstBlockId, InstId> {
|
|
|
|
|
|
auto Set(InstBlockId block_id, llvm::ArrayRef<InstId> content) -> void {
|
|
|
CARBON_CHECK(block_id != InstBlockId::Unreachable);
|
|
|
- BlockValueStore<InstBlockId, InstId>::Set(block_id, content);
|
|
|
+ BlockValueStore<InstBlockId>::Set(block_id, content);
|
|
|
}
|
|
|
};
|
|
|
|