LLVM 20.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"
16#include <cassert>
17#include <cstdint>
18#include <cstring>
19
20using namespace llvm;
21using namespace llvm::codeview;
22
24 return TypeIndex::fromArrayIndex(SeenRecords.size());
25}
26
28 : RecordStorage(Storage) {
29 SeenRecords.reserve(4096);
30}
31
33
34std::optional<TypeIndex> GlobalTypeTableBuilder::getFirst() {
35 if (empty())
36 return std::nullopt;
37
39}
40
41std::optional<TypeIndex> GlobalTypeTableBuilder::getNext(TypeIndex Prev) {
42 if (++Prev == nextTypeIndex())
43 return std::nullopt;
44 return Prev;
45}
46
48 CVType Type(SeenRecords[Index.toArrayIndex()]);
49 return Type;
50}
51
53 llvm_unreachable("Method not implemented");
54}
55
57 if (Index.isSimple() || Index.isNoneType())
58 return false;
59
60 return Index.toArrayIndex() < SeenRecords.size();
61}
62
63uint32_t GlobalTypeTableBuilder::size() { return SeenRecords.size(); }
64
65uint32_t GlobalTypeTableBuilder::capacity() { return SeenRecords.size(); }
66
68 return SeenRecords;
69}
70
72 return SeenHashes;
73}
74
76 HashedRecords.clear();
77 SeenRecords.clear();
78}
79
82 uint8_t *Stable = Alloc.Allocate<uint8_t>(Data.size());
83 memcpy(Stable, Data.data(), Data.size());
84 return ArrayRef(Stable, Data.size());
85}
86
89 GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
90 return insertRecordAs(GHT, Record.size(),
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}
107
109 bool Stabilize) {
110 assert(Index.toArrayIndex() < SeenRecords.size() &&
111 "This function cannot be used to insert records!");
112
114 assert(Record.size() < UINT32_MAX && "Record too big");
115 assert(Record.size() % 4 == 0 &&
116 "The type record size is not a multiple of 4 bytes which will cause "
117 "misalignment in the output TPI stream!");
118
119 GloballyHashedType Hash =
120 GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
121 auto Result = HashedRecords.try_emplace(Hash, Index.toArrayIndex());
122 if (!Result.second) {
123 Index = Result.first->second;
124 return false; // The record is already there, at a different location
125 }
126
127 if (Stabilize)
128 Record = stabilize(RecordStorage, Record);
129
130 SeenRecords[Index.toArrayIndex()] = Record;
131 SeenHashes[Index.toArrayIndex()] = Hash;
132 return true;
133}
This file defines the BumpPtrAllocator interface.
static ArrayRef< uint8_t > stabilize(BumpPtrAllocator &RecordStorage, ArrayRef< uint8_t > Record)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:66
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
std::vector< CVType > end(TypeIndex Index)
StringRef getTypeName(TypeIndex Index) override
std::optional< TypeIndex > getNext(TypeIndex Prev) override
ArrayRef< ArrayRef< uint8_t > > records() const
TypeIndex insertRecord(ContinuationRecordBuilder &Builder)
CVType getType(TypeIndex Index) override
TypeIndex insertRecordBytes(ArrayRef< uint8_t > Data)
TypeIndex insertRecordAs(GloballyHashedType Hash, size_t RecordSize, CreateFunc Create)
GlobalTypeTableBuilder(BumpPtrAllocator &Storage)
bool replaceType(TypeIndex &Index, CVType Data, bool Stabilize) override
ArrayRef< GloballyHashedType > hashes() const
std::optional< TypeIndex > getFirst() override
A 32-bit type reference.
Definition: TypeIndex.h:96
static TypeIndex fromArrayIndex(uint32_t Index)
Definition: TypeIndex.h:123
static const uint32_t FirstNonSimpleIndex
Definition: TypeIndex.h:98
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
A globally hashed type represents a hash value that is sufficient to uniquely identify a record acros...
Definition: TypeHashing.h:80
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