LLVM  16.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/None.h"
16 #include "llvm/Support/Allocator.h"
18 #include <cassert>
19 #include <cstdint>
20 #include <cstring>
21 
22 using namespace llvm;
23 using namespace llvm::codeview;
24 
26  return TypeIndex::fromArrayIndex(SeenRecords.size());
27 }
28 
30  : RecordStorage(Storage) {
31  SeenRecords.reserve(4096);
32 }
33 
35 
37  if (empty())
38  return None;
39 
41 }
42 
44  if (++Prev == nextTypeIndex())
45  return None;
46  return Prev;
47 }
48 
50  CVType Type(SeenRecords[Index.toArrayIndex()]);
51  return Type;
52 }
53 
55  llvm_unreachable("Method not implemented");
56 }
57 
59  if (Index.isSimple() || Index.isNoneType())
60  return false;
61 
62  return Index.toArrayIndex() < SeenRecords.size();
63 }
64 
65 uint32_t MergingTypeTableBuilder::size() { return SeenRecords.size(); }
66 
67 uint32_t MergingTypeTableBuilder::capacity() { return SeenRecords.size(); }
68 
70  return SeenRecords;
71 }
72 
74  HashedRecords.clear();
75  SeenRecords.clear();
76 }
77 
79  ArrayRef<uint8_t> Data) {
80  uint8_t *Stable = Alloc.Allocate<uint8_t>(Data.size());
81  memcpy(Stable, Data.data(), Data.size());
82  return makeArrayRef(Stable, Data.size());
83 }
84 
87  assert(Record.size() < UINT32_MAX && "Record too big");
88  assert(Record.size() % 4 == 0 &&
89  "The type record size is not a multiple of 4 bytes which will cause "
90  "misalignment in the output TPI stream!");
91 
92  LocallyHashedType WeakHash{Hash, Record};
93  auto Result = HashedRecords.try_emplace(WeakHash, nextTypeIndex());
94 
95  if (Result.second) {
96  ArrayRef<uint8_t> RecordData = stabilize(RecordStorage, Record);
97  Result.first->first.RecordData = RecordData;
98  SeenRecords.push_back(RecordData);
99  }
100 
101  // Update the caller's copy of Record to point a stable copy.
102  TypeIndex ActualTI = Result.first->second;
103  Record = SeenRecords[ActualTI.toArrayIndex()];
104  return ActualTI;
105 }
106 
107 TypeIndex
110 }
111 
112 TypeIndex
114  TypeIndex TI;
115  auto Fragments = Builder.end(nextTypeIndex());
116  assert(!Fragments.empty());
117  for (auto C : Fragments)
118  TI = insertRecordBytes(C.RecordData);
119  return TI;
120 }
121 
123  bool Stabilize) {
124  assert(Index.toArrayIndex() < SeenRecords.size() &&
125  "This function cannot be used to insert records!");
126 
127  ArrayRef<uint8_t> Record = Data.data();
128  assert(Record.size() < UINT32_MAX && "Record too big");
129  assert(Record.size() % 4 == 0 &&
130  "The type record size is not a multiple of 4 bytes which will cause "
131  "misalignment in the output TPI stream!");
132 
134  auto Result = HashedRecords.try_emplace(WeakHash, Index.toArrayIndex());
135  if (!Result.second) {
136  Index = Result.first->second;
137  return false; // The record is already there, at a different location
138  }
139 
140  if (Stabilize) {
141  Record = stabilize(RecordStorage, Record);
142  Result.first->first.RecordData = Record;
143  }
144 
145  SeenRecords[Index.toArrayIndex()] = Record;
146  return true;
147 }
llvm::codeview::MergingTypeTableBuilder::size
uint32_t size() override
Definition: MergingTypeTableBuilder.cpp:65
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::codeview::TypeIndex::FirstNonSimpleIndex
static const uint32_t FirstNonSimpleIndex
Definition: TypeIndex.h:98
llvm::codeview::MergingTypeTableBuilder::capacity
uint32_t capacity() override
Definition: MergingTypeTableBuilder.cpp:67
llvm::codeview::TypeIndex::fromArrayIndex
static TypeIndex fromArrayIndex(uint32_t Index)
Definition: TypeIndex.h:123
ErrorHandling.h
Allocator.h
llvm::codeview::MergingTypeTableBuilder::getType
CVType getType(TypeIndex Index) override
Definition: MergingTypeTableBuilder.cpp:49
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
llvm::codeview::MergingTypeTableBuilder::replaceType
bool replaceType(TypeIndex &Index, CVType Data, bool Stabilize) override
Definition: MergingTypeTableBuilder.cpp:122
llvm::codeview::LocallyHashedType
A locally hashed type represents a straightforward hash code of a serialized record.
Definition: TypeHashing.h:34
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::codeview::MergingTypeTableBuilder::~MergingTypeTableBuilder
~MergingTypeTableBuilder()
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::codeview::MergingTypeTableBuilder::nextTypeIndex
TypeIndex nextTypeIndex() const
Definition: MergingTypeTableBuilder.cpp:25
MergingTypeTableBuilder.h
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
CodeView.h
llvm::codeview::MergingTypeTableBuilder::insertRecordBytes
TypeIndex insertRecordBytes(ArrayRef< uint8_t > &Record)
Definition: MergingTypeTableBuilder.cpp:108
stabilize
static ArrayRef< uint8_t > stabilize(BumpPtrAllocator &Alloc, ArrayRef< uint8_t > Data)
Definition: MergingTypeTableBuilder.cpp:78
llvm::codeview::MergingTypeTableBuilder::getNext
Optional< TypeIndex > getNext(TypeIndex Prev) override
Definition: MergingTypeTableBuilder.cpp:43
llvm::codeview::ContinuationRecordBuilder
Definition: ContinuationRecordBuilder.h:27
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
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:1573
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
TypeHashing.h
None.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
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:143
uint32_t
llvm::codeview::MergingTypeTableBuilder::contains
bool contains(TypeIndex Index) override
Definition: MergingTypeTableBuilder.cpp:58
llvm::codeview::MergingTypeTableBuilder::getTypeName
StringRef getTypeName(TypeIndex Index) override
Definition: MergingTypeTableBuilder.cpp:54
llvm::None
constexpr std::nullopt_t None
Definition: None.h:27
llvm::BumpPtrAllocatorImpl::Allocate
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, Align Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:148
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:475
llvm::hash_value
hash_code hash_value(const FixedPointSemantics &Val)
Definition: APFixedPoint.h:127
llvm::codeview::MergingTypeTableBuilder::insertRecordAs
TypeIndex insertRecordAs(hash_code Hash, ArrayRef< uint8_t > &Record)
Definition: MergingTypeTableBuilder.cpp:85
llvm::codeview::MergingTypeTableBuilder::getFirst
Optional< TypeIndex > getFirst() override
Definition: MergingTypeTableBuilder.cpp:36
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:96
llvm::codeview::MergingTypeTableBuilder::insertRecord
TypeIndex insertRecord(ContinuationRecordBuilder &Builder)
Definition: MergingTypeTableBuilder.cpp:113
llvm::codeview::MergingTypeTableBuilder::records
ArrayRef< ArrayRef< uint8_t > > records() const
Definition: MergingTypeTableBuilder.cpp:69
llvm::codeview::MergingTypeTableBuilder::reset
void reset()
Definition: MergingTypeTableBuilder.cpp:73
llvm::hash_code
An opaque object representing a hash code.
Definition: Hashing.h:73
llvm::codeview::MergingTypeTableBuilder::MergingTypeTableBuilder
MergingTypeTableBuilder(BumpPtrAllocator &Storage)
Definition: MergingTypeTableBuilder.cpp:29