LLVM  8.0.1
MergingTypeTableBuilder.cpp
Go to the documentation of this file.
1 //===- MergingTypeTableBuilder.cpp ----------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/ADT/ArrayRef.h"
12 #include "llvm/ADT/DenseSet.h"
13 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/Support/Allocator.h"
21 #include "llvm/Support/Endian.h"
22 #include "llvm/Support/Error.h"
23 #include <algorithm>
24 #include <cassert>
25 #include <cstdint>
26 #include <cstring>
27 
28 using namespace llvm;
29 using namespace llvm::codeview;
30 
32  return TypeIndex::fromArrayIndex(SeenRecords.size());
33 }
34 
36  : RecordStorage(Storage) {
37  SeenRecords.reserve(4096);
38 }
39 
41 
43  if (empty())
44  return None;
45 
47 }
48 
50  if (++Prev == nextTypeIndex())
51  return None;
52  return Prev;
53 }
54 
56  CVType Type;
57  Type.RecordData = SeenRecords[Index.toArrayIndex()];
58  const RecordPrefix *P =
59  reinterpret_cast<const RecordPrefix *>(Type.RecordData.data());
60  Type.Type = static_cast<TypeLeafKind>(uint16_t(P->RecordKind));
61  return Type;
62 }
63 
65  llvm_unreachable("Method not implemented");
66 }
67 
69  if (Index.isSimple() || Index.isNoneType())
70  return false;
71 
72  return Index.toArrayIndex() < SeenRecords.size();
73 }
74 
75 uint32_t MergingTypeTableBuilder::size() { return SeenRecords.size(); }
76 
77 uint32_t MergingTypeTableBuilder::capacity() { return SeenRecords.size(); }
78 
80  return SeenRecords;
81 }
82 
84  HashedRecords.clear();
85  SeenRecords.clear();
86 }
87 
89  ArrayRef<uint8_t> Data) {
90  uint8_t *Stable = Alloc.Allocate<uint8_t>(Data.size());
91  memcpy(Stable, Data.data(), Data.size());
92  return makeArrayRef(Stable, Data.size());
93 }
94 
97  assert(Record.size() < UINT32_MAX && "Record too big");
98  assert(Record.size() % 4 == 0 && "Record is not aligned to 4 bytes!");
99 
100  LocallyHashedType WeakHash{Hash, Record};
101  auto Result = HashedRecords.try_emplace(WeakHash, nextTypeIndex());
102 
103  if (Result.second) {
104  ArrayRef<uint8_t> RecordData = stabilize(RecordStorage, Record);
105  Result.first->first.RecordData = RecordData;
106  SeenRecords.push_back(RecordData);
107  }
108 
109  // Update the caller's copy of Record to point a stable copy.
110  TypeIndex ActualTI = Result.first->second;
111  Record = SeenRecords[ActualTI.toArrayIndex()];
112  return ActualTI;
113 }
114 
115 TypeIndex
117  return insertRecordAs(hash_value(Record), Record);
118 }
119 
120 TypeIndex
122  TypeIndex TI;
123  auto Fragments = Builder.end(nextTypeIndex());
124  assert(!Fragments.empty());
125  for (auto C : Fragments)
126  TI = insertRecordBytes(C.RecordData);
127  return TI;
128 }
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A locally hashed type represents a straightforward hash code of a serialized record.
Definition: TypeHashing.h:33
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:34
Optional< TypeIndex > getNext(TypeIndex Prev) override
TypeIndex insertRecord(ContinuationRecordBuilder &Builder)
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
CVType getType(TypeIndex Index) override
StringRef getTypeName(TypeIndex Index) override
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
bool isNoneType() const
Definition: TypeIndex.h:116
static const uint32_t FirstNonSimpleIndex
Definition: TypeIndex.h:98
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
A 32-bit type reference.
Definition: TypeIndex.h:96
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition: APFloat.cpp:4431
uint32_t toArrayIndex() const
Definition: TypeIndex.h:118
static TypeIndex fromArrayIndex(uint32_t Index)
Definition: TypeIndex.h:123
#define P(N)
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:141
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:149
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:215
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const T * data() const
Definition: ArrayRef.h:146
static ArrayRef< uint8_t > stabilize(BumpPtrAllocator &Alloc, ArrayRef< uint8_t > Data)
An opaque object representing a hash code.
Definition: Hashing.h:72
std::vector< CVType > end(TypeIndex Index)
ArrayRef< uint8_t > RecordData
Definition: CVRecord.h:49
Optional< TypeIndex > getFirst() override
TypeIndex insertRecordBytes(ArrayRef< uint8_t > &Record)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
TypeIndex insertRecordAs(hash_code Hash, ArrayRef< uint8_t > &Record)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
ArrayRef< ArrayRef< uint8_t > > records() const