LLVM  10.0.0svn
MergingTypeTableBuilder.cpp
Go to the documentation of this file.
1 //===- MergingTypeTableBuilder.cpp ----------------------------------------===//
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 
10 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/ADT/DenseSet.h"
12 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/Support/Allocator.h"
20 #include "llvm/Support/Endian.h"
21 #include "llvm/Support/Error.h"
22 #include <algorithm>
23 #include <cassert>
24 #include <cstdint>
25 #include <cstring>
26 
27 using namespace llvm;
28 using namespace llvm::codeview;
29 
31  return TypeIndex::fromArrayIndex(SeenRecords.size());
32 }
33 
35  : RecordStorage(Storage) {
36  SeenRecords.reserve(4096);
37 }
38 
40 
42  if (empty())
43  return None;
44 
46 }
47 
49  if (++Prev == nextTypeIndex())
50  return None;
51  return Prev;
52 }
53 
55  CVType Type(SeenRecords[Index.toArrayIndex()]);
56  return Type;
57 }
58 
60  llvm_unreachable("Method not implemented");
61 }
62 
64  if (Index.isSimple() || Index.isNoneType())
65  return false;
66 
67  return Index.toArrayIndex() < SeenRecords.size();
68 }
69 
70 uint32_t MergingTypeTableBuilder::size() { return SeenRecords.size(); }
71 
72 uint32_t MergingTypeTableBuilder::capacity() { return SeenRecords.size(); }
73 
75  return SeenRecords;
76 }
77 
79  HashedRecords.clear();
80  SeenRecords.clear();
81 }
82 
84  ArrayRef<uint8_t> Data) {
85  uint8_t *Stable = Alloc.Allocate<uint8_t>(Data.size());
86  memcpy(Stable, Data.data(), Data.size());
87  return makeArrayRef(Stable, Data.size());
88 }
89 
92  assert(Record.size() < UINT32_MAX && "Record too big");
93  assert(Record.size() % 4 == 0 && "Record is not aligned to 4 bytes!");
94 
95  LocallyHashedType WeakHash{Hash, Record};
96  auto Result = HashedRecords.try_emplace(WeakHash, nextTypeIndex());
97 
98  if (Result.second) {
99  ArrayRef<uint8_t> RecordData = stabilize(RecordStorage, Record);
100  Result.first->first.RecordData = RecordData;
101  SeenRecords.push_back(RecordData);
102  }
103 
104  // Update the caller's copy of Record to point a stable copy.
105  TypeIndex ActualTI = Result.first->second;
106  Record = SeenRecords[ActualTI.toArrayIndex()];
107  return ActualTI;
108 }
109 
110 TypeIndex
112  return insertRecordAs(hash_value(Record), Record);
113 }
114 
115 TypeIndex
117  TypeIndex TI;
118  auto Fragments = Builder.end(nextTypeIndex());
119  assert(!Fragments.empty());
120  for (auto C : Fragments)
121  TI = insertRecordBytes(C.RecordData);
122  return TI;
123 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A locally hashed type represents a straightforward hash code of a serialized record.
Definition: TypeHashing.h:32
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:450
bool isNoneType() const
Definition: TypeIndex.h:115
static const uint32_t FirstNonSimpleIndex
Definition: TypeIndex.h:97
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
A 32-bit type reference.
Definition: TypeIndex.h:95
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition: APFloat.cpp:4470
uint32_t toArrayIndex() const
Definition: TypeIndex.h:117
static TypeIndex fromArrayIndex(uint32_t Index)
Definition: TypeIndex.h:122
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:140
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:148
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:214
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const T * data() const
Definition: ArrayRef.h:145
static ArrayRef< uint8_t > stabilize(BumpPtrAllocator &Alloc, ArrayRef< uint8_t > Data)
An opaque object representing a hash code.
Definition: Hashing.h:71
std::vector< CVType > end(TypeIndex Index)
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:48
ArrayRef< ArrayRef< uint8_t > > records() const