38 uint32_t calculateSerializedLength()
const;
39 uint32_t calculateRecordByteSize()
const;
41 void finalizeBuckets(
uint32_t RecordZeroOffset);
45 Records.push_back(SymbolSerializer::writeOneSymbol(Copy, Msf.
getAllocator(),
46 CodeViewContainer::Pdb));
51 uint32_t GSIHashStreamBuilder::calculateSerializedLength()
const {
54 Size += HashBitmap.size() *
sizeof(
uint32_t);
55 Size += HashBuckets.size() *
sizeof(
uint32_t);
59 uint32_t GSIHashStreamBuilder::calculateRecordByteSize()
const {
61 for (
const auto &Sym : Records)
69 Header.
VerHdr = GSIHashHeader::HdrVersion;
71 Header.
NumBuckets = HashBitmap.size() * 4 + HashBuckets.size() * 4;
92 size_t RS = S2.
size();
105 void GSIHashStreamBuilder::finalizeBuckets(
uint32_t RecordZeroOffset) {
106 std::array<std::vector<std::pair<StringRef, PSHashRecord>>,
IPHR_HASH + 1>
108 uint32_t SymOffset = RecordZeroOffset;
109 for (
const CVSymbol &Sym : Records) {
112 HR.
Off = SymOffset + 1;
118 TmpBuckets[BucketIdx].push_back(std::make_pair(Name, HR));
119 SymOffset += Sym.length();
124 HashRecords.reserve(Records.size());
127 for (
size_t BucketIdx = 0; BucketIdx <
IPHR_HASH + 1; ++BucketIdx) {
128 auto &Bucket = TmpBuckets[BucketIdx];
131 HashBitmap[BucketIdx / 32] |= 1U << (BucketIdx % 32);
136 const int SizeOfHROffsetCalc = 12;
138 ulittle32_t(HashRecords.size() * SizeOfHROffsetCalc);
139 HashBuckets.push_back(ChainStartOff);
148 [](
const std::pair<StringRef, PSHashRecord> &
Left,
149 const std::pair<StringRef, PSHashRecord> &
Right) {
153 for (
const auto &Entry : Bucket)
154 HashRecords.push_back(Entry.second);
164 uint32_t GSIStreamBuilder::calculatePublicsHashStreamSize()
const {
167 Size += PSH->calculateSerializedLength();
168 Size += PSH->Records.size() *
sizeof(
uint32_t);
174 uint32_t GSIStreamBuilder::calculateGlobalsHashStreamSize()
const {
175 return GSH->calculateSerializedLength();
181 uint32_t GSHZero = PSH->calculateRecordByteSize();
183 PSH->finalizeBuckets(PSHZero);
184 GSH->finalizeBuckets(GSHZero);
189 GSH->StreamIndex = *Idx;
190 Idx = Msf.
addStream(calculatePublicsHashStreamSize());
193 PSH->StreamIndex = *Idx;
196 GSH->calculateRecordByteSize() + PSH->calculateRecordByteSize();
201 RecordStreamIdx = *Idx;
206 const std::pair<const CVSymbol *, const PublicSym32 *> &
LS,
207 const std::pair<const CVSymbol *, const PublicSym32 *> &RS) {
208 if (LS.second->Segment != RS.second->Segment)
209 return LS.second->Segment < RS.second->Segment;
210 if (LS.second->Offset != RS.second->Offset)
211 return LS.second->Offset < RS.second->Offset;
213 return LS.second->Name < RS.second->Name;
222 std::vector<PublicSym32> DeserializedPublics;
223 std::vector<std::pair<const CVSymbol *, const PublicSym32 *>> PublicsByAddr;
224 std::vector<uint32_t> SymOffsets;
225 DeserializedPublics.reserve(Records.
size());
226 PublicsByAddr.reserve(Records.
size());
227 SymOffsets.reserve(Records.
size());
230 for (
const CVSymbol &Sym : Records) {
231 assert(Sym.kind() == SymbolKind::S_PUB32);
232 DeserializedPublics.push_back(
233 cantFail(SymbolDeserializer::deserializeAs<PublicSym32>(Sym)));
234 PublicsByAddr.emplace_back(&Sym, &DeserializedPublics.back());
235 SymOffsets.push_back(SymOffset);
236 SymOffset += Sym.length();
238 std::stable_sort(PublicsByAddr.begin(), PublicsByAddr.end(),
242 std::vector<ulittle32_t> AddrMap;
243 AddrMap.reserve(Records.size());
244 for (
auto &Sym : PublicsByAddr) {
245 ptrdiff_t Idx = std::distance(Records.data(), Sym.first);
246 assert(Idx >= 0 &&
size_t(Idx) < Records.size());
253 return PSH->StreamIndex;
257 return GSH->StreamIndex;
261 PSH->addSymbol(Pub, Msf);
265 GSH->addSymbol(Sym, Msf);
269 GSH->addSymbol(Sym, Msf);
273 GSH->addSymbol(Sym, Msf);
277 GSH->addSymbol(Sym, Msf);
292 Error GSIStreamBuilder::commitSymbolRecordStream(
307 Error GSIStreamBuilder::commitPublicsHashStream(
318 Header.
SymHash = PSH->calculateSerializedLength();
319 Header.
AddrMap = PSH->Records.size() * 4;
323 if (
auto EC = PSH->commit(Writer))
333 Error GSIStreamBuilder::commitGlobalsHashStream(
336 return GSH->commit(Writer);
341 auto GS = WritableMappedBlockStream::createIndexedStream(
343 auto PS = WritableMappedBlockStream::createIndexedStream(
345 auto PRS = WritableMappedBlockStream::createIndexedStream(
348 if (
auto EC = commitSymbolRecordStream(*PRS))
350 if (
auto EC = commitGlobalsHashStream(*GS))
352 if (
auto EC = commitPublicsHashStream(*PS))
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
std::vector< CVSymbol > Records
Compute iterated dominance frontiers using a linear time algorithm.
static bool isAsciiString(StringRef S)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
static std::vector< ulittle32_t > computeAddrMap(ArrayRef< CVSymbol > Records)
Compute the address map.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&... args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
Error takeError()
Take ownership of the stored error.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
std::vector< PSHashRecord > HashRecords
uint32_t getPublicsStreamIndex() const
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
support::ulittle32_t CRef
support::ulittle32_t Word
Tagged union holding either a T or a Error.
uint32_t getRecordStreamIdx() const
static Error writeRecords(BinaryStreamWriter &Writer, ArrayRef< CVSymbol > Records)
void addSymbol(const CVSymbol &Symbol)
void addSymbol(const T &Symbol, MSFBuilder &Msf)
static bool comparePubSymByAddrAndName(const std::pair< const CVSymbol *, const PublicSym32 *> &LS, const std::pair< const CVSymbol *, const PublicSym32 *> &RS)
uint32_t getGlobalsStreamIndex() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Error writeArray(ArrayRef< T > Array)
Writes an array of objects of type T to the underlying stream, as if by using memcpy.
static bool gsiRecordLess(StringRef S1, StringRef S2)
uint32_t hashStringV1(StringRef Str)
detail::packed_endian_specific_integral< uint32_t, little, unaligned > ulittle32_t
size_t size() const
size - Get the array size.
Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
Error finalizeMsfLayout()
Provides write only access to a subclass of WritableBinaryStream.
#define LLVM_UNLIKELY(EXPR)
void sort(IteratorTy Start, IteratorTy End)
LLVM_NODISCARD int compare_lower(StringRef RHS) const
compare_lower - Compare two strings, ignoring case.
static ErrorSuccess success()
Create a success value.
std::vector< support::ulittle32_t > HashBuckets
BinaryStreamRef is to BinaryStream what ArrayRef is to an Array.
Expected< uint32_t > addStream(uint32_t Size, ArrayRef< uint32_t > Blocks)
Add a stream to the MSF file with the given size, occupying the given list of blocks.
void addGlobalSymbol(const codeview::ProcRefSym &Sym)
void addPublicSymbol(const codeview::PublicSym32 &Pub)
Merge contiguous icmps into a memcmp
Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
BinaryItemStream represents a sequence of objects stored in some kind of external container but for w...
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
Lightweight error class with error context and mandatory checking.
void setItems(ArrayRef< T > ItemArray)
StringRef - Represent a constant reference to a string, i.e.
BumpPtrAllocator & getAllocator()
StringRef getSymbolName(CVSymbol Sym)