32 : Msf(Msf), Allocator(Msf.getAllocator()), Header(nullptr), Idx(StreamIdx) {
44 size_t NewSize = TypeRecordBytes +
Size;
45 constexpr size_t EightKB = 8 * 1024;
46 if (NewSize / EightKB > TypeRecordBytes / EightKB || TypeRecordCount == 0) {
47 TypeIndexOffsets.push_back(
53 TypeRecordBytes = NewSize;
59 "The type record's size is not a multiple of 4 bytes which will "
60 "cause misalignment in the output TPI stream!");
63 updateTypeIndexOffsets(
ArrayRef(&OneSize, 1));
65 TypeRecBuffers.push_back(
Record);
66 TypeHashes.push_back(Hash);
78 assert(((Types.size() & 3) == 0) &&
79 "The type record's size is not a multiple of 4 bytes which will "
80 "cause misalignment in the output TPI stream!");
81 assert(Sizes.size() == Hashes.
size() &&
"sizes and hashes should be in sync");
82 assert(std::accumulate(Sizes.begin(), Sizes.end(), 0U) == Types.size() &&
83 "sizes of type records should sum to the size of the types");
84 updateTypeIndexOffsets(Sizes);
86 TypeRecBuffers.push_back(Types);
90Error TpiStreamBuilder::finalize() {
96 H->Version = VerHeader;
99 H->TypeIndexEnd =
H->TypeIndexBegin + TypeRecordCount;
100 H->TypeRecordBytes = TypeRecordBytes;
102 H->HashStreamIndex = HashStreamIndex;
110 H->HashValueBuffer.Off = 0;
111 H->HashValueBuffer.Length = calculateHashBufferSize();
115 H->HashAdjBuffer.Off =
H->HashValueBuffer.Off +
H->HashValueBuffer.Length;
116 H->HashAdjBuffer.Length = 0;
118 H->IndexOffsetBuffer.Off =
H->HashAdjBuffer.Off +
H->HashAdjBuffer.Length;
119 H->IndexOffsetBuffer.Length = calculateIndexOffsetSize();
129uint32_t TpiStreamBuilder::calculateHashBufferSize()
const {
130 assert((TypeRecordCount == TypeHashes.size() || TypeHashes.empty()) &&
131 "either all or no type records should have hashes");
135uint32_t TpiStreamBuilder::calculateIndexOffsetSize()
const {
141 if (
auto EC = Msf.setStreamSize(Idx,
Length))
145 calculateHashBufferSize() + calculateIndexOffsetSize();
147 if (HashStreamSize == 0)
150 auto ExpectedIndex = Msf.addStream(HashStreamSize);
152 return ExpectedIndex.takeError();
153 HashStreamIndex = *ExpectedIndex;
154 if (!TypeHashes.empty()) {
161 reinterpret_cast<const uint8_t *
>(HashBuffer.
data()),
162 calculateHashBufferSize());
182 for (
auto Rec : TypeRecBuffers) {
183 assert(!Rec.empty() &&
"Attempting to write an empty type record shifts "
184 "all offsets in the TPI stream!");
185 assert(((Rec.size() & 3) == 0) &&
186 "The type record's size is not a multiple of 4 bytes which will "
187 "cause misalignment in the output TPI stream!");
194 Layout, Buffer, HashStreamIndex, Allocator);
196 if (HashValueStream) {
201 for (
auto &IndexOffset : TypeIndexOffsets) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the BumpPtrAllocator interface.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
Provides write only access to a subclass of WritableBinaryStream.
LLVM_ABI Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
LLVM_ABI Error writeBytes(ArrayRef< uint8_t > Buffer)
Write the bytes specified in Buffer to the underlying stream.
Error writeObject(const T &Obj)
Writes the object Obj to the underlying stream, as if by using memcpy.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
static const uint32_t FirstNonSimpleIndex
static std::unique_ptr< WritableMappedBlockStream > createIndexedStream(const MSFLayout &Layout, WritableBinaryStreamRef MsfData, uint32_t StreamIndex, BumpPtrAllocator &Allocator)
LLVM_ABI void addTypeRecord(ArrayRef< uint8_t > Type, uint32_t Hash)
LLVM_ABI Error finalizeMsfLayout()
LLVM_ABI Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer)
LLVM_ABI void addTypeRecords(ArrayRef< uint8_t > Types, ArrayRef< uint16_t > Sizes, ArrayRef< uint32_t > Hashes)
LLVM_ABI TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx)
LLVM_ABI uint32_t calculateSerializedLength()
LLVM_ABI ~TpiStreamBuilder()
LLVM_ABI void setVersionHeader(PdbRaw_TpiVer Version)
const uint16_t kInvalidStreamIndex
const uint32_t MaxTpiHashBuckets
detail::packed_endian_specific_integral< uint32_t, llvm::endianness::little, unaligned > ulittle32_t
This is an optimization pass for GlobalISel generic memory operations.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
FunctionAddr VTableAddr uintptr_t uintptr_t Version
ArrayRef(const T &OneElt) -> ArrayRef< T >