63 class TypeStreamMerger {
66 : IndexMap(SourceToDest) {
72 CurIndex += SourceToDest.
size();
110 inline bool remapTypeIndex(
TypeIndex &Idx) {
116 if (!hasTypeStream())
117 return remapIndex(Idx, TypeLookup);
119 assert(TypeLookup.empty());
120 return remapIndex(Idx, IndexMap);
122 inline bool remapItemIndex(
TypeIndex &Idx) {
124 return remapIndex(Idx, IndexMap);
127 bool hasTypeStream()
const {
128 return (UseGlobalHashes) ? (!!DestGlobalTypeStream) : (!!DestTypeStream);
131 bool hasIdStream()
const {
132 return (UseGlobalHashes) ? (!!DestGlobalIdStream) : (!!DestIdStream);
142 return remapIndexFallback(Idx, Map);
163 Error errorCorruptRecord()
const {
171 bool UseGlobalHashes =
false;
173 bool IsSecondPass =
false;
175 unsigned NumBadIndices = 0;
206 void TypeStreamMerger::addMapping(
TypeIndex Idx) {
209 "visitKnownRecord should add one index map entry");
210 IndexMap.push_back(Idx);
217 bool TypeStreamMerger::remapIndexFallback(
TypeIndex &Idx,
223 if (IsSecondPass && MapPos >= Map.
size()) {
227 LastError =
joinErrors(std::move(*LastError), errorCorruptRecord());
229 LastError = errorCorruptRecord();
243 DestTypeStream = &Dest;
244 UseGlobalHashes =
false;
252 DestIdStream = &Dest;
253 TypeLookup = TypeSourceToDest;
254 UseGlobalHashes =
false;
263 DestIdStream = &DestIds;
264 DestTypeStream = &DestTypes;
265 UseGlobalHashes =
false;
266 auto Err = doit(IdsAndTypes);
276 DestGlobalTypeStream = &Dest;
277 UseGlobalHashes =
true;
278 GlobalHashes = Hashes;
279 auto Err = doit(Types);
288 DestGlobalIdStream = &Dest;
289 TypeLookup = TypeSourceToDest;
290 UseGlobalHashes =
true;
291 GlobalHashes = Hashes;
301 DestGlobalIdStream = &DestIds;
302 DestGlobalTypeStream = &DestTypes;
303 UseGlobalHashes =
true;
304 GlobalHashes = Hashes;
305 auto Err = doit(IdsAndTypes);
311 if (
auto EC = remapAllTypes(Types))
321 while (!LastError && NumBadIndices > 0) {
322 unsigned BadIndicesRemaining = NumBadIndices;
327 if (
auto EC = remapAllTypes(Types))
330 assert(NumBadIndices <= BadIndicesRemaining &&
331 "second pass found more bad indices");
332 if (!LastError && NumBadIndices == BadIndicesRemaining) {
333 return llvm::make_error<CodeViewError>(
339 return std::move(*LastError);
348 return forEachCodeViewRecord<CVType>(
349 Buffer, [
this](
const CVType &
T) {
return remapType(
T); });
353 auto R = shouldRemapType(Type);
355 return R.takeError();
361 return remapIndices(Type, Storage);
365 isIdRecord(Type.
kind()) ? *DestGlobalIdStream : *DestGlobalTypeStream;
382 "visitKnownRecord should add one index map entry");
387 TypeStreamMerger::remapIndices(
const CVType &OriginalType,
399 for (
auto &
Ref : Refs) {
401 reinterpret_cast<TypeIndex *
>(DestContent +
Ref.Offset);
403 for (
size_t I = 0;
I <
Ref.Count; ++
I) {
406 : remapTypeIndex(TI);
417 TypeStreamMerger M(SourceToDest);
418 return M.mergeTypeRecords(Dest, Types);
425 TypeStreamMerger M(SourceToDest);
426 return M.mergeIdRecords(Dest, TypeSourceToDest, Ids);
433 TypeStreamMerger M(SourceToDest);
434 return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes, PCHSignature);
441 TypeStreamMerger M(SourceToDest);
442 return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes, Hashes,
451 TypeStreamMerger M(SourceToDest);
452 return M.mergeTypeRecords(Dest, Types, Hashes, PCHSignature);
460 TypeStreamMerger M(SourceToDest);
461 return M.mergeIdRecords(Dest, Types, Ids, Hashes);
468 if (Type.
kind() == LF_ENDPRECOMP) {
473 if (PCHSignature.hasValue())
474 return errorCorruptRecord();
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
void discoverTypeIndices(ArrayRef< uint8_t > RecordData, SmallVectorImpl< TiReference > &Refs)
This class represents lattice values for constants.
#define LLVM_UNLIKELY(EXPR)
#define LLVM_LIKELY(EXPR)
BinaryStreamRef getUnderlyingStream() const
Error mergeTypeRecords(MergingTypeTableBuilder &Dest, SmallVectorImpl< TypeIndex > &SourceToDest, const CVTypeArray &Types)
Merge one set of type records into another.
Error mergeTypeAndIdRecords(MergingTypeTableBuilder &DestIds, MergingTypeTableBuilder &DestTypes, SmallVectorImpl< TypeIndex > &SourceToDest, const CVTypeArray &IdsAndTypes, Optional< uint32_t > &PCHSignature)
Merge a unified set of type and id records, splitting them into separate output streams.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
The access may reference the value stored in memory.
Tagged union holding either a T or a Error.
static const uint32_t FirstNonSimpleIndex
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
A globally hashed type represents a hash value that is sufficient to uniquely identify a record acros...
Error readBytes(uint32_t Offset, uint32_t Size, ArrayRef< uint8_t > &Buffer) const
Given an Offset into this StreamRef and a Size, return a reference to a buffer owned by the stream...
The instances of the Type class are immutable: once they are created, they are never changed...
size_t size() const
size - Get the array size.
static Error deserializeAs(CVType &CVT, T &Record)
uint32_t getIndex() const
uint32_t getLength() const
static ErrorSuccess success()
Create a success value.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
static size_t slotForIndex(TypeIndex Idx)
ArrayRef< uint8_t > RecordData
LLVM_NODISCARD bool empty() const
Error joinErrors(Error E1, Error E2)
Concatenate errors.
TypeIndex insertRecordBytes(ArrayRef< uint8_t > &Record)
Error mergeIdRecords(MergingTypeTableBuilder &Dest, ArrayRef< TypeIndex > Types, SmallVectorImpl< TypeIndex > &SourceToDest, const CVTypeArray &Ids)
Merge one set of id records into another.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
TypeIndex insertRecordAs(GloballyHashedType Hash, size_t RecordSize, CreateFunc Create)
Lightweight error class with error context and mandatory checking.
bool isIdRecord(TypeLeafKind K)
Return true if this record should be in the IPI stream of a PDB.
uint32_t getSignature() const
bool empty() const
empty - Check if the array is empty.