xref: /freebsd/contrib/llvm-project/llvm/include/llvm/DebugInfo/CodeView/TypeStreamMerger.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
1 //===- TypeStreamMerger.h ---------------------------------------*- 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_CODEVIEW_TYPESTREAMMERGER_H
10 #define LLVM_DEBUGINFO_CODEVIEW_TYPESTREAMMERGER_H
11 
12 #include "llvm/ADT/ArrayRef.h"
13 #include "llvm/DebugInfo/CodeView/CVRecord.h"
14 #include "llvm/Support/Compiler.h"
15 #include "llvm/Support/Error.h"
16 
17 namespace llvm {
18 template <typename T> class SmallVectorImpl;
19 namespace codeview {
20 
21 class TypeIndex;
22 struct GloballyHashedType;
23 class GlobalTypeTableBuilder;
24 class MergingTypeTableBuilder;
25 
26 /// Used to forward information about PCH.OBJ (precompiled) files, when
27 /// applicable.
28 struct PCHMergerInfo {
29   uint32_t PCHSignature{};
30   uint32_t EndPrecompIndex = ~0U;
31 };
32 
33 /// Merge one set of type records into another.  This method assumes
34 /// that all records are type records, and there are no Id records present.
35 ///
36 /// \param Dest The table to store the re-written type records into.
37 ///
38 /// \param SourceToDest A vector, indexed by the TypeIndex in the source
39 /// type stream, that contains the index of the corresponding type record
40 /// in the destination stream.
41 ///
42 /// \param Types The collection of types to merge in.
43 ///
44 /// \returns Error::success() if the operation succeeded, otherwise an
45 /// appropriate error code.
46 LLVM_ABI Error mergeTypeRecords(MergingTypeTableBuilder &Dest,
47                                 SmallVectorImpl<TypeIndex> &SourceToDest,
48                                 const CVTypeArray &Types);
49 
50 /// Merge one set of id records into another.  This method assumes
51 /// that all records are id records, and there are no Type records present.
52 /// However, since Id records can refer back to Type records, this method
53 /// assumes that the referenced type records have also been merged into
54 /// another type stream (for example using the above method), and accepts
55 /// the mapping from source to dest for that stream so that it can re-write
56 /// the type record mappings accordingly.
57 ///
58 /// \param Dest The table to store the re-written id records into.
59 ///
60 /// \param Types The mapping to use for the type records that these id
61 /// records refer to.
62 ///
63 /// \param SourceToDest A vector, indexed by the TypeIndex in the source
64 /// id stream, that contains the index of the corresponding id record
65 /// in the destination stream.
66 ///
67 /// \param Ids The collection of id records to merge in.
68 ///
69 /// \returns Error::success() if the operation succeeded, otherwise an
70 /// appropriate error code.
71 LLVM_ABI Error mergeIdRecords(MergingTypeTableBuilder &Dest,
72                               ArrayRef<TypeIndex> Types,
73                               SmallVectorImpl<TypeIndex> &SourceToDest,
74                               const CVTypeArray &Ids);
75 
76 /// Merge a unified set of type and id records, splitting them into
77 /// separate output streams.
78 ///
79 /// \param DestIds The table to store the re-written id records into.
80 ///
81 /// \param DestTypes the table to store the re-written type records into.
82 ///
83 /// \param SourceToDest A vector, indexed by the TypeIndex in the source
84 /// id stream, that contains the index of the corresponding id record
85 /// in the destination stream.
86 ///
87 /// \param IdsAndTypes The collection of id records to merge in.
88 ///
89 /// \returns Error::success() if the operation succeeded, otherwise an
90 /// appropriate error code.
91 LLVM_ABI Error mergeTypeAndIdRecords(MergingTypeTableBuilder &DestIds,
92                                      MergingTypeTableBuilder &DestTypes,
93                                      SmallVectorImpl<TypeIndex> &SourceToDest,
94                                      const CVTypeArray &IdsAndTypes,
95                                      std::optional<PCHMergerInfo> &PCHInfo);
96 
97 LLVM_ABI Error mergeTypeAndIdRecords(GlobalTypeTableBuilder &DestIds,
98                                      GlobalTypeTableBuilder &DestTypes,
99                                      SmallVectorImpl<TypeIndex> &SourceToDest,
100                                      const CVTypeArray &IdsAndTypes,
101                                      ArrayRef<GloballyHashedType> Hashes,
102                                      std::optional<PCHMergerInfo> &PCHInfo);
103 
104 LLVM_ABI Error mergeTypeRecords(GlobalTypeTableBuilder &Dest,
105                                 SmallVectorImpl<TypeIndex> &SourceToDest,
106                                 const CVTypeArray &Types,
107                                 ArrayRef<GloballyHashedType> Hashes,
108                                 std::optional<PCHMergerInfo> &PCHInfo);
109 
110 LLVM_ABI Error mergeIdRecords(GlobalTypeTableBuilder &Dest,
111                               ArrayRef<TypeIndex> Types,
112                               SmallVectorImpl<TypeIndex> &SourceToDest,
113                               const CVTypeArray &Ids,
114                               ArrayRef<GloballyHashedType> Hashes);
115 
116 } // end namespace codeview
117 } // end namespace llvm
118 
119 #endif // LLVM_DEBUGINFO_CODEVIEW_TYPESTREAMMERGER_H
120