LLVM  17.0.0git
TpiStreamBuilder.h
Go to the documentation of this file.
1 //===- TpiStreamBuilder.h - PDB Tpi Stream Creation -------------*- C++ -*-===//
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 
9 #ifndef LLVM_DEBUGINFO_PDB_NATIVE_TPISTREAMBUILDER_H
10 #define LLVM_DEBUGINFO_PDB_NATIVE_TPISTREAMBUILDER_H
11 
15 #include "llvm/Support/Allocator.h"
17 #include "llvm/Support/Error.h"
18 
19 #include <vector>
20 
21 namespace llvm {
22 class BinaryByteStream;
23 template <typename T> struct BinaryItemTraits;
24 
25 template <> struct BinaryItemTraits<llvm::codeview::CVType> {
26  static size_t length(const codeview::CVType &Item) { return Item.length(); }
28  return Item.data();
29  }
30 };
31 
32 namespace msf {
33 class MSFBuilder;
34 struct MSFLayout;
35 }
36 namespace pdb {
37 struct TpiStreamHeader;
38 
40 public:
41  explicit TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx);
43 
44  TpiStreamBuilder(const TpiStreamBuilder &) = delete;
45  TpiStreamBuilder &operator=(const TpiStreamBuilder &) = delete;
46 
48  void addTypeRecord(ArrayRef<uint8_t> Type, std::optional<uint32_t> Hash);
50  ArrayRef<uint32_t> Hashes);
51 
53 
54  uint32_t getRecordCount() const { return TypeRecordCount; }
55 
56  Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer);
57 
59 
60 private:
61  void updateTypeIndexOffsets(ArrayRef<uint16_t> Sizes);
62 
63  uint32_t calculateHashBufferSize() const;
64  uint32_t calculateIndexOffsetSize() const;
65  Error finalize();
66 
67  msf::MSFBuilder &Msf;
68  BumpPtrAllocator &Allocator;
69 
70  uint32_t TypeRecordCount = 0;
71  size_t TypeRecordBytes = 0;
72 
74  std::vector<ArrayRef<uint8_t>> TypeRecBuffers;
75  std::vector<uint32_t> TypeHashes;
76  std::vector<codeview::TypeIndexOffset> TypeIndexOffsets;
77  uint32_t HashStreamIndex = kInvalidStreamIndex;
78  std::unique_ptr<BinaryByteStream> HashValueStream;
79 
80  const TpiStreamHeader *Header;
81  uint32_t Idx;
82 };
83 } // namespace pdb
84 }
85 
86 #endif
RawConstants.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::pdb::TpiStreamBuilder::addTypeRecords
void addTypeRecords(ArrayRef< uint8_t > Types, ArrayRef< uint16_t > Sizes, ArrayRef< uint32_t > Hashes)
Definition: TpiStreamBuilder.cpp:72
Allocator.h
llvm::pdb::kInvalidStreamIndex
const uint16_t kInvalidStreamIndex
Definition: RawConstants.h:19
Error.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::pdb::TpiStreamBuilder::~TpiStreamBuilder
~TpiStreamBuilder()
llvm::BinaryItemTraits< llvm::codeview::CVType >::bytes
static ArrayRef< uint8_t > bytes(const codeview::CVType &Item)
Definition: TpiStreamBuilder.h:27
llvm::pdb::PdbTpiV80
@ PdbTpiV80
Definition: RawConstants.h:64
llvm::msf::MSFBuilder
Definition: MSFBuilder.h:27
llvm::msf::MSFLayout
Definition: MSFCommon.h:51
llvm::pdb::TpiStreamBuilder::finalizeMsfLayout
Error finalizeMsfLayout()
Definition: TpiStreamBuilder.cpp:142
llvm::pdb::PdbRaw_TpiVer
PdbRaw_TpiVer
Definition: RawConstants.h:59
llvm::IndexedInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:1058
llvm::pdb::TpiStreamBuilder::getRecordCount
uint32_t getRecordCount() const
Definition: TpiStreamBuilder.h:54
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
llvm::pdb::TpiStreamBuilder::calculateSerializedLength
uint32_t calculateSerializedLength()
Definition: TpiStreamBuilder.cpp:128
llvm::pdb::TpiStreamBuilder
Definition: TpiStreamBuilder.h:39
llvm::BinaryItemTraits< llvm::codeview::CVType >::length
static size_t length(const codeview::CVType &Item)
Definition: TpiStreamBuilder.h:26
llvm::ArrayRef< uint8_t >
BinaryStreamRef.h
llvm::codeview::CVRecord< TypeLeafKind >
uint32_t
llvm::pdb::TpiStreamBuilder::setVersionHeader
void setVersionHeader(PdbRaw_TpiVer Version)
Definition: TpiStreamBuilder.cpp:37
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
llvm::codeview::CVRecord::data
ArrayRef< uint8_t > data() const
Definition: CVRecord.h:49
CVRecord.h
TypeIndex.h
llvm::pdb::TpiStreamBuilder::commit
Error commit(const msf::MSFLayout &Layout, WritableBinaryStreamRef Buffer)
Definition: TpiStreamBuilder.cpp:172
llvm::pdb::TpiStreamHeader
Definition: RawTypes.h:277
llvm::pdb::TpiStreamBuilder::addTypeRecord
void addTypeRecord(ArrayRef< uint8_t > Type, std::optional< uint32_t > Hash)
Definition: TpiStreamBuilder.cpp:57
llvm::pdb::TpiStreamBuilder::operator=
TpiStreamBuilder & operator=(const TpiStreamBuilder &)=delete
llvm::BinaryItemTraits
Definition: GSIStreamBuilder.h:26
llvm::WritableBinaryStreamRef
Definition: BinaryStreamRef.h:220
llvm::pdb::TpiStreamBuilder::TpiStreamBuilder
TpiStreamBuilder(msf::MSFBuilder &Msf, uint32_t StreamIdx)
Definition: TpiStreamBuilder.cpp:31
llvm::codeview::CVRecord::length
uint32_t length() const
Definition: CVRecord.h:40