33 : Msf(Msf),
Allocator(Msf.getAllocator()), Header(nullptr),
Idx(StreamIdx) {
45 size_t NewSize = TypeRecordBytes +
Size;
46 constexpr size_t EightKB = 8 * 1024;
47 if (NewSize / EightKB > TypeRecordBytes / EightKB || TypeRecordCount == 0) {
48 TypeIndexOffsets.push_back(
54 TypeRecordBytes = NewSize;
59 std::optional<uint32_t> Hash) {
61 "The type record's size is not a multiple of 4 bytes which will "
62 "cause misalignment in the output TPI stream!");
65 updateTypeIndexOffsets(
ArrayRef(&OneSize, 1));
67 TypeRecBuffers.push_back(
Record);
70 TypeHashes.push_back(*Hash);
82 assert(((Types.size() & 3) == 0) &&
83 "The type record's size is not a multiple of 4 bytes which will "
84 "cause misalignment in the output TPI stream!");
85 assert(Sizes.size() == Hashes.
size() &&
"sizes and hashes should be in sync");
86 assert(std::accumulate(Sizes.begin(), Sizes.end(), 0U) == Types.size() &&
87 "sizes of type records should sum to the size of the types");
88 updateTypeIndexOffsets(Sizes);
90 TypeRecBuffers.push_back(Types);
94Error TpiStreamBuilder::finalize() {
100 H->Version = VerHeader;
103 H->TypeIndexEnd =
H->TypeIndexBegin + TypeRecordCount;
104 H->TypeRecordBytes = TypeRecordBytes;
106 H->HashStreamIndex = HashStreamIndex;
114 H->HashValueBuffer.Off = 0;
115 H->HashValueBuffer.Length = calculateHashBufferSize();
119 H->HashAdjBuffer.Off =
H->HashValueBuffer.Off +
H->HashValueBuffer.Length;
120 H->HashAdjBuffer.Length = 0;
122 H->IndexOffsetBuffer.Off =
H->HashAdjBuffer.Off +
H->HashAdjBuffer.Length;
123 H->IndexOffsetBuffer.Length = calculateIndexOffsetSize();
133uint32_t TpiStreamBuilder::calculateHashBufferSize()
const {
134 assert((TypeRecordCount == TypeHashes.size() || TypeHashes.empty()) &&
135 "either all or no type records should have hashes");
139uint32_t TpiStreamBuilder::calculateIndexOffsetSize()
const {
149 calculateHashBufferSize() + calculateIndexOffsetSize();
151 if (HashStreamSize == 0)
154 auto ExpectedIndex = Msf.
addStream(HashStreamSize);
156 return ExpectedIndex.takeError();
157 HashStreamIndex = *ExpectedIndex;
158 if (!TypeHashes.empty()) {
165 reinterpret_cast<const uint8_t *
>(HashBuffer.data()),
166 calculateHashBufferSize());
176 if (
auto EC = finalize())
186 for (
auto Rec : TypeRecBuffers) {
187 assert(!Rec.empty() &&
"Attempting to write an empty type record shifts "
188 "all offsets in the TPI stream!");
189 assert(((Rec.size() & 3) == 0) &&
190 "The type record's size is not a multiple of 4 bytes which will "
191 "cause misalignment in the output TPI stream!");
198 Layout, Buffer, HashStreamIndex, Allocator);
200 if (HashValueStream) {
205 for (
auto &IndexOffset : TypeIndexOffsets) {
This file defines the BumpPtrAllocator interface.
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
Error writeStreamRef(BinaryStreamRef Ref)
Efficiently reads all data from Ref, and writes it to this stream.
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.
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
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
Error setStreamSize(uint32_t Idx, uint32_t Size)
Update the size of an existing stream.
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.
static std::unique_ptr< WritableMappedBlockStream > createIndexedStream(const MSFLayout &Layout, WritableBinaryStreamRef MsfData, uint32_t StreamIndex, BumpPtrAllocator &Allocator)
Error finalizeMsfLayout()
void addTypeRecord(ArrayRef< uint8_t > Type, std::optional< uint32_t > Hash)
Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer)
void addTypeRecords(ArrayRef< uint8_t > Types, ArrayRef< uint16_t > Sizes, ArrayRef< uint32_t > Hashes)
TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx)
uint32_t calculateSerializedLength()
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.