LLVM  16.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/None.h"
15 #include "llvm/Support/Allocator.h"
17 #include <cassert>
18 #include <cstdint>
19 #include <cstring>
20 
21 using namespace llvm;
22 using namespace llvm::codeview;
23 
25  return TypeIndex::fromArrayIndex(SeenRecords.size());
26 }
27 
29  : RecordStorage(Storage) {
30  SeenRecords.reserve(4096);
31 }
32 
34 
36  if (empty())
37  return None;
38 
40 }
41 
43  if (++Prev == nextTypeIndex())
44  return None;
45  return Prev;
46 }
47 
49  CVType Type(SeenRecords[Index.toArrayIndex()]);
50  return Type;
51 }
52 
54  llvm_unreachable("Method not implemented");
55 }
56 
58  if (Index.isSimple() || Index.isNoneType())
59  return false;
60 
61  return Index.toArrayIndex() < SeenRecords.size();
62 }
63 
64 uint32_t GlobalTypeTableBuilder::size() { return SeenRecords.size(); }
65 
66 uint32_t GlobalTypeTableBuilder::capacity() { return SeenRecords.size(); }
67 
69  return SeenRecords;
70 }
71 
73  return SeenHashes;
74 }
75 
77  HashedRecords.clear();
78  SeenRecords.clear();
79 }
80 
82  ArrayRef<uint8_t> Data) {
83  uint8_t *Stable = Alloc.Allocate<uint8_t>(Data.size());
84  memcpy(Stable, Data.data(), Data.size());
85  return makeArrayRef(Stable, Data.size());
86 }
87 
89  GloballyHashedType GHT =
90  GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
91  return insertRecordAs(GHT, Record.size(),
93  assert(Data.size() == Record.size());
94  ::memcpy(Data.data(), Record.data(), Record.size());
95  return Data;
96  });
97 }
98 
101  TypeIndex TI;
102  auto Fragments = Builder.end(nextTypeIndex());
103  assert(!Fragments.empty());
104  for (auto C : Fragments)
105  TI = insertRecordBytes(C.RecordData);
106  return TI;
107 }
108 
110  bool Stabilize) {
111  assert(Index.toArrayIndex() < SeenRecords.size() &&
112  "This function cannot be used to insert records!");
113 
114  ArrayRef<uint8_t> Record = Data.data();
115  assert(Record.size() < UINT32_MAX && "Record too big");
116  assert(Record.size() % 4 == 0 &&
117  "The type record size is not a multiple of 4 bytes which will cause "
118  "misalignment in the output TPI stream!");
119 
120  GloballyHashedType Hash =
121  GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
122  auto Result = HashedRecords.try_emplace(Hash, Index.toArrayIndex());
123  if (!Result.second) {
124  Index = Result.first->second;
125  return false; // The record is already there, at a different location
126  }
127 
128  if (Stabilize)
129  Record = stabilize(RecordStorage, Record);
130 
131  SeenRecords[Index.toArrayIndex()] = Record;
132  SeenHashes[Index.toArrayIndex()] = Hash;
133  return true;
134 }
GlobalTypeTableBuilder.h
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::TypeIndex::fromArrayIndex
static TypeIndex fromArrayIndex(uint32_t Index)
Definition: TypeIndex.h:123
ErrorHandling.h
Allocator.h
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::Data
@ Data
Definition: SIMachineScheduler.h:55
stabilize
static ArrayRef< uint8_t > stabilize(BumpPtrAllocator &Alloc, ArrayRef< uint8_t > Data)
Definition: GlobalTypeTableBuilder.cpp:81
llvm::MutableArrayRef< uint8_t >
llvm::codeview::GlobalTypeTableBuilder::replaceType
bool replaceType(TypeIndex &Index, CVType Data, bool Stabilize) override
Definition: GlobalTypeTableBuilder.cpp:109
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::codeview::GlobalTypeTableBuilder::GlobalTypeTableBuilder
GlobalTypeTableBuilder(BumpPtrAllocator &Storage)
Definition: GlobalTypeTableBuilder.cpp:28
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
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
CodeView.h
llvm::codeview::GloballyHashedType
A globally hashed type represents a hash value that is sufficient to uniquely identify a record acros...
Definition: TypeHashing.h:80
llvm::codeview::GlobalTypeTableBuilder::capacity
uint32_t capacity() override
Definition: GlobalTypeTableBuilder.cpp:66
llvm::codeview::GlobalTypeTableBuilder::hashes
ArrayRef< GloballyHashedType > hashes() const
Definition: GlobalTypeTableBuilder.cpp:72
llvm::codeview::GlobalTypeTableBuilder::size
uint32_t size() override
Definition: GlobalTypeTableBuilder.cpp:64
llvm::codeview::ContinuationRecordBuilder
Definition: ContinuationRecordBuilder.h:27
llvm::codeview::GlobalTypeTableBuilder::getType
CVType getType(TypeIndex Index) override
Definition: GlobalTypeTableBuilder.cpp:48
llvm::codeview::GlobalTypeTableBuilder::~GlobalTypeTableBuilder
~GlobalTypeTableBuilder()
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
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:1573
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
llvm::codeview::GlobalTypeTableBuilder::getTypeName
StringRef getTypeName(TypeIndex Index) override
Definition: GlobalTypeTableBuilder.cpp:53
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
None.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::codeview::GlobalTypeTableBuilder::getFirst
Optional< TypeIndex > getFirst() override
Definition: GlobalTypeTableBuilder.cpp:35
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::GlobalTypeTableBuilder::insertRecord
TypeIndex insertRecord(ContinuationRecordBuilder &Builder)
Definition: GlobalTypeTableBuilder.cpp:100
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
llvm::codeview::GlobalTypeTableBuilder::getNext
Optional< TypeIndex > getNext(TypeIndex Prev) override
Definition: GlobalTypeTableBuilder.cpp:42
llvm::codeview::GlobalTypeTableBuilder::insertRecordBytes
TypeIndex insertRecordBytes(ArrayRef< uint8_t > Data)
Definition: GlobalTypeTableBuilder.cpp:88
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::codeview::GlobalTypeTableBuilder::records
ArrayRef< ArrayRef< uint8_t > > records() const
Definition: GlobalTypeTableBuilder.cpp:68
llvm::codeview::TypeIndex
A 32-bit type reference.
Definition: TypeIndex.h:96
llvm::codeview::GlobalTypeTableBuilder::contains
bool contains(TypeIndex Index) override
Definition: GlobalTypeTableBuilder.cpp:57
llvm::codeview::GlobalTypeTableBuilder::nextTypeIndex
TypeIndex nextTypeIndex() const
Definition: GlobalTypeTableBuilder.cpp:24
llvm::codeview::GlobalTypeTableBuilder::reset
void reset()
Definition: GlobalTypeTableBuilder.cpp:76