[MIPS GlobalISel] Select MSA vector generic and builtin add
[llvm-complete.git] / lib / DebugInfo / CodeView / GlobalTypeTableBuilder.cpp
bloba7ad1d045f0474029050d9de0c71ea5ae3ee58d9
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 //===----------------------------------------------------------------------===//
9 #include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h"
10 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/ADT/DenseSet.h"
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/DebugInfo/CodeView/CodeView.h"
14 #include "llvm/DebugInfo/CodeView/ContinuationRecordBuilder.h"
15 #include "llvm/DebugInfo/CodeView/RecordSerialization.h"
16 #include "llvm/DebugInfo/CodeView/TypeIndex.h"
17 #include "llvm/Support/Allocator.h"
18 #include "llvm/Support/BinaryByteStream.h"
19 #include "llvm/Support/BinaryStreamWriter.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>
27 using namespace llvm;
28 using namespace llvm::codeview;
30 TypeIndex GlobalTypeTableBuilder::nextTypeIndex() const {
31 return TypeIndex::fromArrayIndex(SeenRecords.size());
34 GlobalTypeTableBuilder::GlobalTypeTableBuilder(BumpPtrAllocator &Storage)
35 : RecordStorage(Storage) {
36 SeenRecords.reserve(4096);
39 GlobalTypeTableBuilder::~GlobalTypeTableBuilder() = default;
41 Optional<TypeIndex> GlobalTypeTableBuilder::getFirst() {
42 if (empty())
43 return None;
45 return TypeIndex(TypeIndex::FirstNonSimpleIndex);
48 Optional<TypeIndex> GlobalTypeTableBuilder::getNext(TypeIndex Prev) {
49 if (++Prev == nextTypeIndex())
50 return None;
51 return Prev;
54 CVType GlobalTypeTableBuilder::getType(TypeIndex Index) {
55 CVType Type(SeenRecords[Index.toArrayIndex()]);
56 return Type;
59 StringRef GlobalTypeTableBuilder::getTypeName(TypeIndex Index) {
60 llvm_unreachable("Method not implemented");
63 bool GlobalTypeTableBuilder::contains(TypeIndex Index) {
64 if (Index.isSimple() || Index.isNoneType())
65 return false;
67 return Index.toArrayIndex() < SeenRecords.size();
70 uint32_t GlobalTypeTableBuilder::size() { return SeenRecords.size(); }
72 uint32_t GlobalTypeTableBuilder::capacity() { return SeenRecords.size(); }
74 ArrayRef<ArrayRef<uint8_t>> GlobalTypeTableBuilder::records() const {
75 return SeenRecords;
78 ArrayRef<GloballyHashedType> GlobalTypeTableBuilder::hashes() const {
79 return SeenHashes;
82 void GlobalTypeTableBuilder::reset() {
83 HashedRecords.clear();
84 SeenRecords.clear();
87 TypeIndex GlobalTypeTableBuilder::insertRecordBytes(ArrayRef<uint8_t> Record) {
88 GloballyHashedType GHT =
89 GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
90 return insertRecordAs(GHT, Record.size(),
91 [Record](MutableArrayRef<uint8_t> Data) {
92 assert(Data.size() == Record.size());
93 ::memcpy(Data.data(), Record.data(), Record.size());
94 return Data;
95 });
98 TypeIndex
99 GlobalTypeTableBuilder::insertRecord(ContinuationRecordBuilder &Builder) {
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;