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"
15#include <cassert>
16#include <cstdint>
17#include <cstring>
18
19using namespace llvm;
20using namespace llvm::codeview;
21
23 return TypeIndex::fromArrayIndex(SeenRecords.size());
24}
25
27 : RecordStorage(Storage) {
28 SeenRecords.reserve(4096);
29}
30
32
33std::optional<TypeIndex> GlobalTypeTableBuilder::getFirst() {
34 if (empty())
35 return std::nullopt;
36
38}
39
40std::optional<TypeIndex> GlobalTypeTableBuilder::getNext(TypeIndex Prev) {
41 if (++Prev == nextTypeIndex())
42 return std::nullopt;
43 return Prev;
44}
45
47 CVType Type(SeenRecords[Index.toArrayIndex()]);
48 return Type;
49}
50
52 llvm_unreachable("Method not implemented");
53}
54
56 if (Index.isSimple() || Index.isNoneType())
57 return false;
58
59 return Index.toArrayIndex() < SeenRecords.size();
60}
61
62uint32_t GlobalTypeTableBuilder::size() { return SeenRecords.size(); }
63
64uint32_t GlobalTypeTableBuilder::capacity() { return SeenRecords.size(); }
65
67 return SeenRecords;
68}
69
71 return SeenHashes;
72}
73
75 HashedRecords.clear();
76 SeenRecords.clear();
77}
78
81 uint8_t *Stable = Alloc.Allocate<uint8_t>(Data.size());
82 memcpy(Stable, Data.data(), Data.size());
83 return ArrayRef(Stable, Data.size());
84}
85
88 GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
89 return insertRecordAs(GHT, Record.size(),
91 assert(Data.size() == Record.size());
92 ::memcpy(Data.data(), Record.data(), Record.size());
93 return Data;
94 });
95}
96
99 TypeIndex TI;
100 auto Fragments = Builder.end(nextTypeIndex());
101 assert(!Fragments.empty());
102 for (auto C : Fragments)
103 TI = insertRecordBytes(C.RecordData);
104 return TI;
105}
106
108 bool Stabilize) {
109 assert(Index.toArrayIndex() < SeenRecords.size() &&
110 "This function cannot be used to insert records!");
111
113 assert(Record.size() < UINT32_MAX && "Record too big");
114 assert(Record.size() % 4 == 0 &&
115 "The type record size is not a multiple of 4 bytes which will cause "
116 "misalignment in the output TPI stream!");
117
118 GloballyHashedType Hash =
119 GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
120 auto Result = HashedRecords.try_emplace(Hash, Index.toArrayIndex());
121 if (!Result.second) {
122 Index = Result.first->second;
123 return false; // The record is already there, at a different location
124 }
125
126 if (Stabilize)
127 Record = stabilize(RecordStorage, Record);
128
129 SeenRecords[Index.toArrayIndex()] = Record;
130 SeenHashes[Index.toArrayIndex()] = Hash;
131 return true;
132}
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:310
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
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