LLVM: lib/DebugInfo/CodeView/LazyRandomTypeCollection.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
17#include
18#include
19#include
20#include
21
22using namespace llvm;
24
30
33 PartialOffsetArray()) {}
34
37 PartialOffsetArray PartialOffsets)
38 : NameStorage(Allocator), Types(Types), PartialOffsets(PartialOffsets) {
39 Records.resize(RecordCountHint);
40}
41
46
51
55
58 Count = 0;
59 PartialOffsets = PartialOffsetArray();
60
62
63
64 Records.clear();
65 Records.resize(RecordCountHint);
66}
67
70 reset(Reader, RecordCountHint);
71}
72
76 reset(Reader, RecordCountHint);
77}
78
80 error(ensureTypeExists(Index));
82
83 return Records[Index.toArrayIndex()].Offset;
84}
85
87 assert(!Index.isSimple());
88
89 auto EC = ensureTypeExists(Index);
92
93 return Records[Index.toArrayIndex()].Type;
94}
95
97 if (Index.isSimple())
98 return std::nullopt;
99
100 if (auto EC = ensureTypeExists(Index)) {
102 return std::nullopt;
103 }
104
106 return std::nullopt;
107 return Records[Index.toArrayIndex()].Type;
108}
109
111 if (Index.isNoneType() || Index.isSimple())
113
114
115
116
117
118 if (auto EC = ensureTypeExists(Index)) {
120 return "";
121 }
122
123 uint32_t I = Index.toArrayIndex();
124 ensureCapacityFor(Index);
125 if (Records[I].Name.data() == nullptr) {
127 Records[I].Name = Result;
128 }
129 return Records[I].Name;
130}
131
133 if (Index.isSimple() || Index.isNoneType())
134 return false;
135
136 if (Records.size() <= Index.toArrayIndex())
137 return false;
138 if (!Records[Index.toArrayIndex()].Type.valid())
139 return false;
140 return true;
141}
142
144
146
147Error LazyRandomTypeCollection::ensureTypeExists(TypeIndex TI) {
150
151 return visitRangeForType(TI);
152}
153
154void LazyRandomTypeCollection::ensureCapacityFor(TypeIndex Index) {
155 assert(!Index.isSimple());
156 uint32_t MinSize = Index.toArrayIndex() + 1;
157
159 return;
160
161 uint32_t NewCapacity = MinSize * 3 / 2;
162
164 Records.resize(NewCapacity);
165}
166
167Error LazyRandomTypeCollection::visitRangeForType(TypeIndex TI) {
169 if (PartialOffsets.empty())
170 return fullScanForType(TI);
171
175 });
176
177 assert(Next != PartialOffsets.begin());
178 auto Prev = std::prev(Next);
179
180 TypeIndex TIB = Prev->Type;
182
183
184
185
186
188 }
189
190 TypeIndex TIE;
191 if (Next == PartialOffsets.end()) {
193 } else {
194 TIE = Next->Type;
195 }
196
197 visitRange(TIB, Prev->Offset, TIE);
199}
200
203 if (auto EC = ensureTypeExists(TI)) {
205 return std::nullopt;
206 }
207 return TI;
208}
209
211
212
213
214 if (auto EC = ensureTypeExists(Prev + 1)) {
216 return std::nullopt;
217 }
218
219 return Prev + 1;
220}
221
222Error LazyRandomTypeCollection::fullScanForType(TypeIndex TI) {
225
227 auto Begin = Types.begin();
228
230
231
232
233
234
235
236
237
239 CurrentTI = LargestTypeIndex + 1;
240 Begin = Types.at(Offset);
241 ++Begin;
242 }
243
244 auto End = Types.end();
245 while (Begin != End) {
246 ensureCapacityFor(CurrentTI);
247 LargestTypeIndex = std::max(LargestTypeIndex, CurrentTI);
249 Records[Idx].Type = *Begin;
250 Records[Idx].Offset = Begin.offset();
252 ++Begin;
253 ++CurrentTI;
254 }
255 if (CurrentTI <= TI) {
257 }
259}
260
261void LazyRandomTypeCollection::visitRange(TypeIndex Begin, uint32_t BeginOffset,
263 auto RI = Types.at(BeginOffset);
264 assert(RI != Types.end());
265
266 ensureCapacityFor(End);
267 while (Begin != End) {
268 LargestTypeIndex = std::max(LargestTypeIndex, Begin);
270 Records[Idx].Type = *RI;
271 Records[Idx].Offset = RI.offset();
272 ++Count;
273 ++Begin;
274 ++RI;
275 }
276}
277
279 bool Stabilize) {
281}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Provides read only access to a subclass of BinaryStream.
uint64_t bytesRemaining() const
Error readArray(ArrayRef< T > &Array, uint32_t NumElements)
Get a reference to a NumElements element array of objects of type T from the underlying stream as if ...
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
StringRef - Represent a constant reference to a string, i.e.
LLVM Value Representation.
std::optional< TypeIndex > getNext(TypeIndex Prev) override
Definition LazyRandomTypeCollection.cpp:210
std::optional< CVType > tryGetType(TypeIndex Index)
Definition LazyRandomTypeCollection.cpp:96
CVType getType(TypeIndex Index) override
Definition LazyRandomTypeCollection.cpp:86
uint32_t size() override
Definition LazyRandomTypeCollection.cpp:143
uint32_t getOffsetOfType(TypeIndex Index)
Definition LazyRandomTypeCollection.cpp:79
uint32_t capacity() override
Definition LazyRandomTypeCollection.cpp:145
bool replaceType(TypeIndex &Index, CVType Data, bool Stabilize) override
Definition LazyRandomTypeCollection.cpp:278
StringRef getTypeName(TypeIndex Index) override
Definition LazyRandomTypeCollection.cpp:110
bool contains(TypeIndex Index) override
Definition LazyRandomTypeCollection.cpp:132
std::optional< TypeIndex > getFirst() override
Definition LazyRandomTypeCollection.cpp:201
void reset(ArrayRef< uint8_t > Data, uint32_t RecordCountHint)
Definition LazyRandomTypeCollection.cpp:73
LazyRandomTypeCollection(uint32_t RecordCountHint)
Definition LazyRandomTypeCollection.cpp:31
static TypeIndex fromArrayIndex(uint32_t Index)
uint32_t toArrayIndex() const
static LLVM_ABI StringRef simpleTypeName(TypeIndex TI)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
CVRecord< TypeLeafKind > CVType
VarStreamArray< CVType > CVTypeArray
LLVM_ABI std::string computeTypeName(TypeCollection &Types, TypeIndex Index)
This is an optimization pass for GlobalISel generic memory operations.
auto upper_bound(R &&Range, T &&Value)
Provide wrappers to std::upper_bound which take ranges instead of having to pass begin/end explicitly...
FunctionAddr VTableAddr Count
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
FunctionAddr VTableAddr Next
void consumeError(Error Err)
Consume a Error without doing anything.