LLVM  14.0.0git
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 &&
94  "The type record size is not a multiple of 4 bytes which will cause "
95  "misalignment in the output TPI stream!");
96 
97  LocallyHashedType WeakHash{Hash, Record};
98  auto Result = HashedRecords.try_emplace(WeakHash, nextTypeIndex());
99 
100  if (Result.second) {
101  ArrayRef<uint8_t> RecordData = stabilize(RecordStorage, Record);
102  Result.first->first.RecordData = RecordData;
103  SeenRecords.push_back(RecordData);
104  }
105 
106  // Update the caller's copy of Record to point a stable copy.
107  TypeIndex ActualTI = Result.first->second;
108  Record = SeenRecords[ActualTI.toArrayIndex()];
109  return ActualTI;
110 }
111 
112 TypeIndex
115 }
116 
117 TypeIndex
119  TypeIndex TI;
120  auto Fragments = Builder.end(nextTypeIndex());
121  assert(!Fragments.empty());
122  for (auto C : Fragments)
123  TI = insertRecordBytes(C.RecordData);
124  return TI;
125 }
126 
128  bool Stabilize) {
129  assert(Index.toArrayIndex() < SeenRecords.size() &&
130  "This function cannot be used to insert records!");
131 
132  ArrayRef<uint8_t> Record = Data.data();
133  assert(Record.size() < UINT32_MAX && "Record too big");
134  assert(Record.size() % 4 == 0 &&
135  "The type record size is not a multiple of 4 bytes which will cause "
136  "misalignment in the output TPI stream!");
137 
139  auto Result = HashedRecords.try_emplace(WeakHash, Index.toArrayIndex());
140  if (!Result.second) {
141  Index = Result.first->second;
142  return false; // The record is already there, at a different location
143  }
144 
145  if (Stabilize) {
146  Record = stabilize(RecordStorage, Record);
147  Result.first->first.RecordData = Record;
148  }
149 
150  SeenRecords[Index.toArrayIndex()] = Record;
151  return true;
152 }
llvm::codeview::MergingTypeTableBuilder::size
uint32_t size() override
Definition: MergingTypeTableBuilder.cpp:70
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
RecordSerialization.h
llvm::codeview::TypeIndex::FirstNonSimpleIndex
static const uint32_t FirstNonSimpleIndex
Definition: TypeIndex.h:98
BinaryByteStream.h
llvm::codeview::MergingTypeTableBuilder::capacity
uint32_t capacity() override
Definition: MergingTypeTableBuilder.cpp:72
llvm::codeview::TypeIndex::fromArrayIndex
static TypeIndex fromArrayIndex(uint32_t Index)
Definition: TypeIndex.h:123
Allocator.h
Error.h
llvm::codeview::MergingTypeTableBuilder::getType
CVType getType(TypeIndex Index) override
Definition: MergingTypeTableBuilder.cpp:54
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::Optional
Definition: APInt.h:33
STLExtras.h
llvm::codeview::MergingTypeTableBuilder::replaceType
bool replaceType(TypeIndex &Index, CVType Data, bool Stabilize) override
Definition: MergingTypeTableBuilder.cpp:127
llvm::hash_value
hash_code hash_value(const APFloat &Arg)
See friend declarations above.
Definition: APFloat.cpp:4821
llvm::codeview::LocallyHashedType
A locally hashed type represents a straightforward hash code of a serialized record.
Definition: TypeHashing.h:32
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::codeview::MergingTypeTableBuilder::~MergingTypeTableBuilder
~MergingTypeTableBuilder()
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
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::codeview::MergingTypeTableBuilder::nextTypeIndex
TypeIndex nextTypeIndex() const
Definition: MergingTypeTableBuilder.cpp:30
MergingTypeTableBuilder.h
DenseSet.h
CodeView.h
llvm::codeview::MergingTypeTableBuilder::insertRecordBytes
TypeIndex insertRecordBytes(ArrayRef< uint8_t > &Record)
Definition: MergingTypeTableBuilder.cpp:113
llvm::None
const NoneType None
Definition: None.h:23
stabilize
static ArrayRef< uint8_t > stabilize(BumpPtrAllocator &Alloc, ArrayRef< uint8_t > Data)
Definition: MergingTypeTableBuilder.cpp:83
llvm::codeview::MergingTypeTableBuilder::getNext
Optional< TypeIndex > getNext(TypeIndex Prev) override
Definition: MergingTypeTableBuilder.cpp:48
llvm::codeview::ContinuationRecordBuilder
Definition: ContinuationRecordBuilder.h:33
Index
uint32_t Index
Definition: ELFObjHandler.cpp:84
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
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:1486
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:650
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:57
llvm::codeview::TypeIndex::toArrayIndex
uint32_t toArrayIndex() const
Definition: TypeIndex.h:118
llvm::codeview::CVRecord< TypeLeafKind >
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
uint32_t
llvm::codeview::MergingTypeTableBuilder::contains
bool contains(TypeIndex Index) override
Definition: MergingTypeTableBuilder.cpp:63
llvm::codeview::MergingTypeTableBuilder::getTypeName
StringRef getTypeName(TypeIndex Index) override
Definition: MergingTypeTableBuilder.cpp:59
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:474
llvm::codeview::MergingTypeTableBuilder::insertRecordAs
TypeIndex insertRecordAs(hash_code Hash, ArrayRef< uint8_t > &Record)
Definition: MergingTypeTableBuilder.cpp:90
llvm::codeview::MergingTypeTableBuilder::getFirst
Optional< TypeIndex > getFirst() override
Definition: MergingTypeTableBuilder.cpp:41
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:96
BinaryStreamWriter.h
llvm::codeview::MergingTypeTableBuilder::insertRecord
TypeIndex insertRecord(ContinuationRecordBuilder &Builder)
Definition: MergingTypeTableBuilder.cpp:118
llvm::codeview::MergingTypeTableBuilder::records
ArrayRef< ArrayRef< uint8_t > > records() const
Definition: MergingTypeTableBuilder.cpp:74
llvm::codeview::MergingTypeTableBuilder::reset
void reset()
Definition: MergingTypeTableBuilder.cpp:78
Endian.h
llvm::hash_code
An opaque object representing a hash code.
Definition: Hashing.h:73
llvm::codeview::MergingTypeTableBuilder::MergingTypeTableBuilder
MergingTypeTableBuilder(BumpPtrAllocator &Storage)
Definition: MergingTypeTableBuilder.cpp:34