LLVM 20.0.0git
MergingTypeTableBuilder.cpp
Go to the documentation of this file.
1//===- MergingTypeTableBuilder.cpp ----------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "llvm/ADT/ArrayRef.h"
16#include <cassert>
17#include <cstdint>
18#include <cstring>
19
20using namespace llvm;
21using namespace llvm::codeview;
22
24 return TypeIndex::fromArrayIndex(SeenRecords.size());
25}
26
28 : RecordStorage(Storage) {
29 SeenRecords.reserve(4096);
30}
31
33
34std::optional<TypeIndex> MergingTypeTableBuilder::getFirst() {
35 if (empty())
36 return std::nullopt;
37
39}
40
41std::optional<TypeIndex> MergingTypeTableBuilder::getNext(TypeIndex Prev) {
42 if (++Prev == nextTypeIndex())
43 return std::nullopt;
44 return Prev;
45}
46
48 CVType Type(SeenRecords[Index.toArrayIndex()]);
49 return Type;
50}
51
53 llvm_unreachable("Method not implemented");
54}
55
57 if (Index.isSimple() || Index.isNoneType())
58 return false;
59
60 return Index.toArrayIndex() < SeenRecords.size();
61}
62
63uint32_t MergingTypeTableBuilder::size() { return SeenRecords.size(); }
64
65uint32_t MergingTypeTableBuilder::capacity() { return SeenRecords.size(); }
66
68 return SeenRecords;
69}
70
72 HashedRecords.clear();
73 SeenRecords.clear();
74}
75
78 uint8_t *Stable = Alloc.Allocate<uint8_t>(Data.size());
79 memcpy(Stable, Data.data(), Data.size());
80 return ArrayRef(Stable, Data.size());
81}
82
85 assert(Record.size() < UINT32_MAX && "Record too big");
86 assert(Record.size() % 4 == 0 &&
87 "The type record size is not a multiple of 4 bytes which will cause "
88 "misalignment in the output TPI stream!");
89
90 LocallyHashedType WeakHash{Hash, Record};
91 auto Result = HashedRecords.try_emplace(WeakHash, nextTypeIndex());
92
93 if (Result.second) {
94 ArrayRef<uint8_t> RecordData = stabilize(RecordStorage, Record);
95 Result.first->first.RecordData = RecordData;
96 SeenRecords.push_back(RecordData);
97 }
98
99 // Update the caller's copy of Record to point a stable copy.
100 TypeIndex ActualTI = Result.first->second;
101 Record = SeenRecords[ActualTI.toArrayIndex()];
102 return ActualTI;
103}
104
108}
109
112 TypeIndex TI;
113 auto Fragments = Builder.end(nextTypeIndex());
114 assert(!Fragments.empty());
115 for (auto C : Fragments)
116 TI = insertRecordBytes(C.RecordData);
117 return TI;
118}
119
121 bool Stabilize) {
122 assert(Index.toArrayIndex() < SeenRecords.size() &&
123 "This function cannot be used to insert records!");
124
126 assert(Record.size() < UINT32_MAX && "Record too big");
127 assert(Record.size() % 4 == 0 &&
128 "The type record size is not a multiple of 4 bytes which will cause "
129 "misalignment in the output TPI stream!");
130
132 auto Result = HashedRecords.try_emplace(WeakHash, Index.toArrayIndex());
133 if (!Result.second) {
134 Index = Result.first->second;
135 return false; // The record is already there, at a different location
136 }
137
138 if (Stabilize) {
139 Record = stabilize(RecordStorage, Record);
140 Result.first->first.RecordData = Record;
141 }
142
143 SeenRecords[Index.toArrayIndex()] = Record;
144 return true;
145}
This file defines the BumpPtrAllocator interface.
static ArrayRef< uint8_t > stabilize(BumpPtrAllocator &RecordStorage, ArrayRef< uint8_t > Record)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
std::vector< CVType > end(TypeIndex Index)
CVType getType(TypeIndex Index) override
ArrayRef< ArrayRef< uint8_t > > records() const
std::optional< TypeIndex > getFirst() override
std::optional< TypeIndex > getNext(TypeIndex Prev) override
StringRef getTypeName(TypeIndex Index) override
TypeIndex insertRecordAs(hash_code Hash, ArrayRef< uint8_t > &Record)
bool replaceType(TypeIndex &Index, CVType Data, bool Stabilize) override
TypeIndex insertRecord(ContinuationRecordBuilder &Builder)
TypeIndex insertRecordBytes(ArrayRef< uint8_t > &Record)
A 32-bit type reference.
Definition: TypeIndex.h:96
static TypeIndex fromArrayIndex(uint32_t Index)
Definition: TypeIndex.h:123
uint32_t toArrayIndex() const
Definition: TypeIndex.h:118
static const uint32_t FirstNonSimpleIndex
Definition: TypeIndex.h:98
An opaque object representing a hash code.
Definition: Hashing.h:75
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
hash_code hash_value(const FixedPointSemantics &Val)
Definition: APFixedPoint.h:136
A locally hashed type represents a straightforward hash code of a serialized record.
Definition: TypeHashing.h:34