LLVM  13.0.0git
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  ArrayRef<uint8_t> Data) {
89  uint8_t *Stable = Alloc.Allocate<uint8_t>(Data.size());
90  memcpy(Stable, Data.data(), Data.size());
91  return makeArrayRef(Stable, Data.size());
92 }
93 
95  GloballyHashedType GHT =
96  GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
97  return insertRecordAs(GHT, Record.size(),
99  assert(Data.size() == Record.size());
100  ::memcpy(Data.data(), Record.data(), Record.size());
101  return Data;
102  });
103 }
104 
105 TypeIndex
107  TypeIndex TI;
108  auto Fragments = Builder.end(nextTypeIndex());
109  assert(!Fragments.empty());
110  for (auto C : Fragments)
111  TI = insertRecordBytes(C.RecordData);
112  return TI;
113 }
114 
116  bool Stabilize) {
117  assert(Index.toArrayIndex() < SeenRecords.size() &&
118  "This function cannot be used to insert records!");
119 
120  ArrayRef<uint8_t> Record = Data.data();
121  assert(Record.size() < UINT32_MAX && "Record too big");
122  assert(Record.size() % 4 == 0 &&
123  "The type record size is not a multiple of 4 bytes which will cause "
124  "misalignment in the output TPI stream!");
125 
126  GloballyHashedType Hash =
127  GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
128  auto Result = HashedRecords.try_emplace(Hash, Index.toArrayIndex());
129  if (!Result.second) {
130  Index = Result.first->second;
131  return false; // The record is already there, at a different location
132  }
133 
134  if (Stabilize)
135  Record = stabilize(RecordStorage, Record);
136 
137  SeenRecords[Index.toArrayIndex()] = Record;
138  SeenHashes[Index.toArrayIndex()] = Hash;
139  return true;
140 }
GlobalTypeTableBuilder.h
llvm
Definition: AllocatorList.h:23
RecordSerialization.h
llvm::codeview::TypeIndex::FirstNonSimpleIndex
static const uint32_t FirstNonSimpleIndex
Definition: TypeIndex.h:97
BinaryByteStream.h
llvm::codeview::TypeIndex::fromArrayIndex
static TypeIndex fromArrayIndex(uint32_t Index)
Definition: TypeIndex.h:122
Allocator.h
Error.h
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:46
llvm::Optional
Definition: APInt.h:33
STLExtras.h
llvm::Data
@ Data
Definition: SIMachineScheduler.h:56
stabilize
static ArrayRef< uint8_t > stabilize(BumpPtrAllocator &Alloc, ArrayRef< uint8_t > Data)
Definition: GlobalTypeTableBuilder.cpp:87
llvm::MutableArrayRef< uint8_t >
llvm::BumpPtrAllocatorImpl::Allocate
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:145
llvm::codeview::GlobalTypeTableBuilder::replaceType
bool replaceType(TypeIndex &Index, CVType Data, bool Stabilize) override
Definition: GlobalTypeTableBuilder.cpp:115
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::codeview::GlobalTypeTableBuilder::GlobalTypeTableBuilder
GlobalTypeTableBuilder(BumpPtrAllocator &Storage)
Definition: GlobalTypeTableBuilder.cpp:34
DenseSet.h
llvm::codeview::GloballyHashedType::hashType
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
CodeView.h
llvm::None
const NoneType None
Definition: None.h:23
llvm::codeview::GloballyHashedType
A globally hashed type represents a hash value that is sufficient to uniquely identify a record acros...
Definition: TypeHashing.h:77
llvm::codeview::GlobalTypeTableBuilder::capacity
uint32_t capacity() override
Definition: GlobalTypeTableBuilder.cpp:72
llvm::codeview::GlobalTypeTableBuilder::hashes
ArrayRef< GloballyHashedType > hashes() const
Definition: GlobalTypeTableBuilder.cpp:78
llvm::codeview::GlobalTypeTableBuilder::size
uint32_t size() override
Definition: GlobalTypeTableBuilder.cpp:70
llvm::codeview::ContinuationRecordBuilder
Definition: ContinuationRecordBuilder.h:33
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::codeview::GlobalTypeTableBuilder::getType
CVType getType(TypeIndex Index) override
Definition: GlobalTypeTableBuilder.cpp:54
llvm::codeview::GlobalTypeTableBuilder::~GlobalTypeTableBuilder
~GlobalTypeTableBuilder()
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
llvm::codeview::GlobalTypeTableBuilder::insertRecordAs
TypeIndex insertRecordAs(GloballyHashedType Hash, size_t RecordSize, CreateFunc Create)
Definition: GlobalTypeTableBuilder.h:71
ArrayRef.h
llvm::codeview::TypeCollection::empty
bool empty()
Definition: TypeCollection.h:22
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
memcpy
<%struct.s * > cast struct s *S to sbyte *< sbyte * > sbyte uint cast struct s *agg result to sbyte *< sbyte * > sbyte uint cast struct s *memtmp to sbyte *< sbyte * > sbyte uint ret void llc ends up issuing two memcpy or custom lower memcpy(of small size) to be ldmia/stmia. I think option 2 is better but the current register allocator cannot allocate a chunk of registers at a time. A feasible temporary solution is to use specific physical registers at the lowering time for small(<
llvm::Record
Definition: Record.h:1472
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
llvm::codeview::GlobalTypeTableBuilder::getTypeName
StringRef getTypeName(TypeIndex Index) override
Definition: GlobalTypeTableBuilder.cpp:59
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::codeview::GlobalTypeTableBuilder::getFirst
Optional< TypeIndex > getFirst() override
Definition: GlobalTypeTableBuilder.cpp:41
llvm::codeview::CVRecord< TypeLeafKind >
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
uint32_t
llvm::codeview::GlobalTypeTableBuilder::insertRecord
TypeIndex insertRecord(ContinuationRecordBuilder &Builder)
Definition: GlobalTypeTableBuilder.cpp:106
llvm::codeview::GlobalTypeTableBuilder::getNext
Optional< TypeIndex > getNext(TypeIndex Prev) override
Definition: GlobalTypeTableBuilder.cpp:48
llvm::codeview::GlobalTypeTableBuilder::insertRecordBytes
TypeIndex insertRecordBytes(ArrayRef< uint8_t > Data)
Definition: GlobalTypeTableBuilder.cpp:94
TypeIndex.h
ContinuationRecordBuilder.h
llvm::codeview
Definition: AppendingTypeTableBuilder.h:22
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:476
llvm::codeview::GlobalTypeTableBuilder::records
ArrayRef< ArrayRef< uint8_t > > records() const
Definition: GlobalTypeTableBuilder.cpp:74
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:95
BinaryStreamWriter.h
llvm::codeview::GlobalTypeTableBuilder::contains
bool contains(TypeIndex Index) override
Definition: GlobalTypeTableBuilder.cpp:63
Endian.h
llvm::codeview::GlobalTypeTableBuilder::nextTypeIndex
TypeIndex nextTypeIndex() const
Definition: GlobalTypeTableBuilder.cpp:30
llvm::codeview::GlobalTypeTableBuilder::reset
void reset()
Definition: GlobalTypeTableBuilder.cpp:82