LLVM  8.0.1
GlobalTypeTableBuilder.cpp
Go to the documentation of this file.
1 //===- GlobalTypeTableBuilder.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  if (!Type.RecordData.empty()) {
59  assert(Type.RecordData.size() >= sizeof(RecordPrefix));
60  const RecordPrefix *P =
61  reinterpret_cast<const RecordPrefix *>(Type.RecordData.data());
62  Type.Type = static_cast<TypeLeafKind>(uint16_t(P->RecordKind));
63  }
64  return Type;
65 }
66 
68  llvm_unreachable("Method not implemented");
69 }
70 
72  if (Index.isSimple() || Index.isNoneType())
73  return false;
74 
75  return Index.toArrayIndex() < SeenRecords.size();
76 }
77 
78 uint32_t GlobalTypeTableBuilder::size() { return SeenRecords.size(); }
79 
80 uint32_t GlobalTypeTableBuilder::capacity() { return SeenRecords.size(); }
81 
83  return SeenRecords;
84 }
85 
87  return SeenHashes;
88 }
89 
91  HashedRecords.clear();
92  SeenRecords.clear();
93 }
94 
96  GloballyHashedType GHT =
97  GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
98  return insertRecordAs(GHT, Record.size(),
99  [Record](MutableArrayRef<uint8_t> Data) {
100  assert(Data.size() == Record.size());
101  ::memcpy(Data.data(), Record.data(), Record.size());
102  return Data;
103  });
104 }
105 
106 TypeIndex
108  TypeIndex TI;
109  auto Fragments = Builder.end(nextTypeIndex());
110  assert(!Fragments.empty());
111  for (auto C : Fragments)
112  TI = insertRecordBytes(C.RecordData);
113  return TI;
114 }
CVType getType(TypeIndex Index) override
Optional< TypeIndex > getFirst() override
This class represents lattice values for constants.
Definition: AllocatorList.h:24
TypeLeafKind
Duplicate copy of the above enum, but using the official CV names.
Definition: CodeView.h:34
Optional< TypeIndex > getNext(TypeIndex Prev) override
GlobalTypeTableBuilder(BumpPtrAllocator &Storage)
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
bool isNoneType() const
Definition: TypeIndex.h:116
TypeIndex insertRecord(ContinuationRecordBuilder &Builder)
ArrayRef< GloballyHashedType > hashes() const
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
A globally hashed type represents a hash value that is sufficient to uniquely identify a record acros...
Definition: TypeHashing.h:78
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
ArrayRef< ArrayRef< uint8_t > > records() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const T * data() const
Definition: ArrayRef.h:146
static GloballyHashedType hashType(ArrayRef< uint8_t > RecordData, ArrayRef< GloballyHashedType > PreviousTypes, ArrayRef< GloballyHashedType > PreviousIds)
Given a sequence of bytes representing a record, compute a global hash for this record.
Definition: TypeHashing.cpp:34
std::vector< CVType > end(TypeIndex Index)
ArrayRef< uint8_t > RecordData
Definition: CVRecord.h:49
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
StringRef getTypeName(TypeIndex Index) override
TypeIndex insertRecordAs(GloballyHashedType Hash, size_t RecordSize, CreateFunc Create)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
TypeIndex insertRecordBytes(ArrayRef< uint8_t > Data)
bool empty() const
empty - Check if the array is empty.
Definition: ArrayRef.h:144