|
26 | 26 | #include "clang/Serialization/SourceLocationEncoding.h"
|
27 | 27 | #include "llvm/ADT/DenseMapInfo.h"
|
28 | 28 | #include "llvm/Bitstream/BitCodes.h"
|
| 29 | +#include "llvm/Support/MathExtras.h" |
29 | 30 | #include <cassert>
|
30 | 31 | #include <cstdint>
|
31 | 32 |
|
@@ -70,41 +71,64 @@ using DeclID = DeclIDBase::DeclID;
|
70 | 71 |
|
71 | 72 | /// An ID number that refers to a type in an AST file.
|
72 | 73 | ///
|
73 |
| -/// The ID of a type is partitioned into two parts: the lower |
74 |
| -/// three bits are used to store the const/volatile/restrict |
75 |
| -/// qualifiers (as with QualType) and the upper bits provide a |
76 |
| -/// type index. The type index values are partitioned into two |
| 74 | +/// The ID of a type is partitioned into three parts: |
| 75 | +/// - the lower three bits are used to store the const/volatile/restrict |
| 76 | +/// qualifiers (as with QualType). |
| 77 | +/// - the next 29 bits provide a type index in the corresponding |
| 78 | +/// module file. |
| 79 | +/// - the upper 32 bits provide a module file index. |
| 80 | +/// |
| 81 | +/// The type index values are partitioned into two |
77 | 82 | /// sets. The values below NUM_PREDEF_TYPE_IDs are predefined type
|
78 | 83 | /// IDs (based on the PREDEF_TYPE_*_ID constants), with 0 as a
|
79 |
| -/// placeholder for "no type". Values from NUM_PREDEF_TYPE_IDs are |
80 |
| -/// other types that have serialized representations. |
81 |
| -using TypeID = uint32_t; |
| 84 | +/// placeholder for "no type". The module file index for predefined |
| 85 | +/// types are always 0 since they don't belong to any modules. |
| 86 | +/// Values from NUM_PREDEF_TYPE_IDs are other types that have |
| 87 | +/// serialized representations. |
| 88 | +using TypeID = uint64_t; |
| 89 | +/// Same with TypeID except that the LocalTypeID is only meaningful |
| 90 | +/// with the corresponding ModuleFile. |
| 91 | +/// |
| 92 | +/// FIXME: Make TypeID and LocalTypeID a class to improve the type |
| 93 | +/// safety. |
| 94 | +using LocalTypeID = TypeID; |
82 | 95 |
|
83 | 96 | /// A type index; the type ID with the qualifier bits removed.
|
| 97 | +/// Keep structure alignment 32-bit since the blob is assumed as 32-bit |
| 98 | +/// aligned. |
84 | 99 | class TypeIdx {
|
| 100 | + uint32_t ModuleFileIndex = 0; |
85 | 101 | uint32_t Idx = 0;
|
86 | 102 |
|
87 | 103 | public:
|
88 | 104 | TypeIdx() = default;
|
89 |
| - explicit TypeIdx(uint32_t index) : Idx(index) {} |
90 | 105 |
|
91 |
| - uint32_t getIndex() const { return Idx; } |
| 106 | + explicit TypeIdx(uint32_t ModuleFileIdx, uint32_t Idx) |
| 107 | + : ModuleFileIndex(ModuleFileIdx), Idx(Idx) {} |
| 108 | + |
| 109 | + uint32_t getModuleFileIndex() const { return ModuleFileIndex; } |
| 110 | + |
| 111 | + uint64_t getValue() const { return ((uint64_t)ModuleFileIndex << 32) | Idx; } |
92 | 112 |
|
93 | 113 | TypeID asTypeID(unsigned FastQuals) const {
|
94 | 114 | if (Idx == uint32_t(-1))
|
95 | 115 | return TypeID(-1);
|
96 | 116 |
|
97 |
| - return (Idx << Qualifiers::FastWidth) | FastQuals; |
| 117 | + unsigned Index = (Idx << Qualifiers::FastWidth) | FastQuals; |
| 118 | + return ((uint64_t)ModuleFileIndex << 32) | Index; |
98 | 119 | }
|
99 | 120 |
|
100 | 121 | static TypeIdx fromTypeID(TypeID ID) {
|
101 | 122 | if (ID == TypeID(-1))
|
102 |
| - return TypeIdx(-1); |
| 123 | + return TypeIdx(0, -1); |
103 | 124 |
|
104 |
| - return TypeIdx(ID >> Qualifiers::FastWidth); |
| 125 | + return TypeIdx(ID >> 32, (ID & llvm::maskTrailingOnes<TypeID>(32)) >> |
| 126 | + Qualifiers::FastWidth); |
105 | 127 | }
|
106 | 128 | };
|
107 | 129 |
|
| 130 | +static_assert(alignof(TypeIdx) == 4); |
| 131 | + |
108 | 132 | /// A structure for putting "fast"-unqualified QualTypes into a
|
109 | 133 | /// DenseMap. This uses the standard pointer hash function.
|
110 | 134 | struct UnsafeQualTypeDenseMapInfo {
|
|
0 commit comments