LLVM  10.0.0svn
GlobalTypeTableBuilder.cpp
Go to the documentation of this file.
1 //===- GlobalTypeTableBuilder.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 GlobalTypeTableBuilder::size() { return SeenRecords.size(); }
71 
72 uint32_t GlobalTypeTableBuilder::capacity() { return SeenRecords.size(); }
73 
75  return SeenRecords;
76 }
77 
79  return SeenHashes;
80 }
81 
83  HashedRecords.clear();
84  SeenRecords.clear();
85 }
86 
88  GloballyHashedType GHT =
89  GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
90  return insertRecordAs(GHT, Record.size(),
91  [Record](MutableArrayRef<uint8_t> Data) {
92  assert(Data.size() == Record.size());
93  ::memcpy(Data.data(), Record.data(), Record.size());
94  return Data;
95  });
96 }
97 
100  TypeIndex TI;
101  auto Fragments = Builder.end(nextTypeIndex());
102  assert(!Fragments.empty());
103  for (auto C : Fragments)
104  TI = insertRecordBytes(C.RecordData);
105  return TI;
106 }
CVType getType(TypeIndex Index) override
Optional< TypeIndex > getFirst() override
This class represents lattice values for constants.
Definition: AllocatorList.h:23
Optional< TypeIndex > getNext(TypeIndex Prev) override
GlobalTypeTableBuilder(BumpPtrAllocator &Storage)
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
bool isNoneType() const
Definition: TypeIndex.h:115
TypeIndex insertRecord(ContinuationRecordBuilder &Builder)
ArrayRef< GloballyHashedType > hashes() const
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
A globally hashed type represents a hash value that is sufficient to uniquely identify a record acros...
Definition: TypeHashing.h:77
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
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:145
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:33
std::vector< CVType > end(TypeIndex Index)
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:48
TypeIndex insertRecordBytes(ArrayRef< uint8_t > Data)