62 class TypeStreamMerger {
65 : IndexMap(SourceToDest) {
102 inline bool remapTypeIndex(
TypeIndex &Idx) {
108 if (!hasTypeStream())
109 return remapIndex(Idx, TypeLookup);
111 assert(TypeLookup.empty());
112 return remapIndex(Idx, IndexMap);
114 inline bool remapItemIndex(
TypeIndex &Idx) {
116 return remapIndex(Idx, IndexMap);
119 bool hasTypeStream()
const {
120 return (UseGlobalHashes) ? (!!DestGlobalTypeStream) : (!!DestTypeStream);
123 bool hasIdStream()
const {
124 return (UseGlobalHashes) ? (!!DestGlobalIdStream) : (!!DestIdStream);
134 return remapIndexFallback(Idx, Map);
155 Error errorCorruptRecord()
const {
161 bool UseGlobalHashes =
false;
163 bool IsSecondPass =
false;
165 unsigned NumBadIndices = 0;
196 case TypeLeafKind::LF_FUNC_ID:
197 case TypeLeafKind::LF_MFUNC_ID:
198 case TypeLeafKind::LF_STRING_ID:
199 case TypeLeafKind::LF_SUBSTR_LIST:
200 case TypeLeafKind::LF_BUILDINFO:
201 case TypeLeafKind::LF_UDT_SRC_LINE:
202 case TypeLeafKind::LF_UDT_MOD_SRC_LINE:
209 void TypeStreamMerger::addMapping(
TypeIndex Idx) {
212 "visitKnownRecord should add one index map entry");
213 IndexMap.push_back(Idx);
220 bool TypeStreamMerger::remapIndexFallback(
TypeIndex &Idx,
226 if (IsSecondPass && MapPos >= Map.
size()) {
230 LastError =
joinErrors(std::move(*LastError), errorCorruptRecord());
232 LastError = errorCorruptRecord();
246 DestTypeStream = &Dest;
247 UseGlobalHashes =
false;
255 DestIdStream = &Dest;
256 TypeLookup = TypeSourceToDest;
257 UseGlobalHashes =
false;
265 DestIdStream = &DestIds;
266 DestTypeStream = &DestTypes;
267 UseGlobalHashes =
false;
268 return doit(IdsAndTypes);
275 DestGlobalTypeStream = &Dest;
276 UseGlobalHashes =
true;
277 GlobalHashes = Hashes;
286 DestGlobalIdStream = &Dest;
287 TypeLookup = TypeSourceToDest;
288 UseGlobalHashes =
true;
289 GlobalHashes = Hashes;
298 DestGlobalIdStream = &DestIds;
299 DestGlobalTypeStream = &DestTypes;
300 UseGlobalHashes =
true;
301 GlobalHashes = Hashes;
302 return doit(IdsAndTypes);
306 if (
auto EC = remapAllTypes(Types))
316 while (!LastError && NumBadIndices > 0) {
317 unsigned BadIndicesRemaining = NumBadIndices;
322 if (
auto EC = remapAllTypes(Types))
325 assert(NumBadIndices <= BadIndicesRemaining &&
326 "second pass found more bad indices");
327 if (!LastError && NumBadIndices == BadIndicesRemaining) {
328 return llvm::make_error<CodeViewError>(
334 return std::move(*LastError);
343 return forEachCodeViewRecord<CVType>(
344 Buffer, [
this](
const CVType &
T) {
return remapType(
T); });
350 return remapIndices(Type, Storage);
356 isIdRecord(Type.
kind()) ? *DestGlobalIdStream : *DestGlobalTypeStream;
372 "visitKnownRecord should add one index map entry");
377 TypeStreamMerger::remapIndices(
const CVType &OriginalType,
389 for (
auto &
Ref : Refs) {
391 reinterpret_cast<TypeIndex *
>(DestContent +
Ref.Offset);
393 for (
size_t I = 0;
I <
Ref.Count; ++
I) {
396 : remapTypeIndex(TI);
407 TypeStreamMerger M(SourceToDest);
408 return M.mergeTypeRecords(Dest, Types);
415 TypeStreamMerger M(SourceToDest);
416 return M.mergeIdRecords(Dest, TypeSourceToDest, Ids);
422 TypeStreamMerger M(SourceToDest);
423 return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes);
430 TypeStreamMerger M(SourceToDest);
431 return M.mergeTypesAndIds(DestIds, DestTypes, IdsAndTypes, Hashes);
438 TypeStreamMerger M(SourceToDest);
439 return M.mergeTypeRecords(Dest, Types, Hashes);
447 TypeStreamMerger M(SourceToDest);
448 return M.mergeIdRecords(Dest, Types, Ids, Hashes);
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)
Compute iterated dominance frontiers using a linear time algorithm.
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Error mergeTypeAndIdRecords(MergingTypeTableBuilder &DestIds, MergingTypeTableBuilder &DestTypes, SmallVectorImpl< TypeIndex > &SourceToDest, const CVTypeArray &IdsAndTypes)
Merge a unified set of type and id records, splitting them into separate output streams.
BinaryStreamRef getUnderlyingStream() const
Error mergeTypeRecords(MergingTypeTableBuilder &Dest, SmallVectorImpl< TypeIndex > &SourceToDest, const CVTypeArray &Types)
Merge one set of type records into another.
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.
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.
#define LLVM_LIKELY(EXPR)
#define LLVM_UNLIKELY(EXPR)
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 bool isIdRecord(TypeLeafKind K)
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 empty() const
empty - Check if the array is empty.