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"
17#include <cassert>
18#include <cstdint>
19#include <cstring>
20
21using namespace llvm;
22using namespace llvm::codeview;
23
25 return TypeIndex::fromArrayIndex(SeenRecords.size());
26}
27
29 : RecordStorage(Storage) {
30 SeenRecords.reserve(4096);
31}
32
34
35std::optional<TypeIndex> MergingTypeTableBuilder::getFirst() {
36 if (empty())
37 return std::nullopt;
38
40}
41
42std::optional<TypeIndex> MergingTypeTableBuilder::getNext(TypeIndex Prev) {
43 if (++Prev == nextTypeIndex())
44 return std::nullopt;
45 return Prev;
46}
47
49 CVType Type(SeenRecords[Index.toArrayIndex()]);
50 return Type;
51}
52
54 llvm_unreachable("Method not implemented");
55}
56
58 if (Index.isSimple() || Index.isNoneType())
59 return false;
60
61 return Index.toArrayIndex() < SeenRecords.size();
62}
63
64uint32_t MergingTypeTableBuilder::size() { return SeenRecords.size(); }
65
66uint32_t MergingTypeTableBuilder::capacity() { return SeenRecords.size(); }
67
69 return SeenRecords;
70}
71
73 HashedRecords.clear();
74 SeenRecords.clear();
75}
76
79 uint8_t *Stable = Alloc.Allocate<uint8_t>(Data.size());
80 memcpy(Stable, Data.data(), Data.size());
81 return ArrayRef(Stable, Data.size());
82}
83
86 assert(Record.size() < UINT32_MAX && "Record too big");
87 assert(Record.size() % 4 == 0 &&
88 "The type record size is not a multiple of 4 bytes which will cause "
89 "misalignment in the output TPI stream!");
90
91 LocallyHashedType WeakHash{Hash, Record};
92 auto Result = HashedRecords.try_emplace(WeakHash, nextTypeIndex());
93
94 if (Result.second) {
95 ArrayRef<uint8_t> RecordData = stabilize(RecordStorage, Record);
96 Result.first->first.RecordData = RecordData;
97 SeenRecords.push_back(RecordData);
98 }
99
100 // Update the caller's copy of Record to point a stable copy.
101 TypeIndex ActualTI = Result.first->second;
102 Record = SeenRecords[ActualTI.toArrayIndex()];
103 return ActualTI;
104}
105
109}
110
113 TypeIndex TI;
114 auto Fragments = Builder.end(nextTypeIndex());
115 assert(!Fragments.empty());
116 for (auto C : Fragments)
117 TI = insertRecordBytes(C.RecordData);
118 return TI;
119}
120
122 bool Stabilize) {
123 assert(Index.toArrayIndex() < SeenRecords.size() &&
124 "This function cannot be used to insert records!");
125
127 assert(Record.size() < UINT32_MAX && "Record too big");
128 assert(Record.size() % 4 == 0 &&
129 "The type record size is not a multiple of 4 bytes which will cause "
130 "misalignment in the output TPI stream!");
131
133 auto Result = HashedRecords.try_emplace(WeakHash, Index.toArrayIndex());
134 if (!Result.second) {
135 Index = Result.first->second;
136 return false; // The record is already there, at a different location
137 }
138
139 if (Stabilize) {
140 Record = stabilize(RecordStorage, Record);
141 Result.first->first.RecordData = Record;
142 }
143
144 SeenRecords[Index.toArrayIndex()] = Record;
145 return true;
146}
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:50
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:127
A locally hashed type represents a straightforward hash code of a serialized record.
Definition: TypeHashing.h:34