Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/DebugInfo/CodeView/GlobalTypeTableBuilder.cpp
Line
Count
Source (jump to first uncovered line)
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
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>
26
27
using namespace llvm;
28
using namespace llvm::codeview;
29
30
3.93k
TypeIndex GlobalTypeTableBuilder::nextTypeIndex() const {
31
3.93k
  return TypeIndex::fromArrayIndex(SeenRecords.size());
32
3.93k
}
33
34
GlobalTypeTableBuilder::GlobalTypeTableBuilder(BumpPtrAllocator &Storage)
35
8.46k
    : RecordStorage(Storage) {
36
8.46k
  SeenRecords.reserve(4096);
37
8.46k
}
38
39
8.45k
GlobalTypeTableBuilder::~GlobalTypeTableBuilder() = default;
40
41
4
Optional<TypeIndex> GlobalTypeTableBuilder::getFirst() {
42
4
  if (empty())
43
0
    return None;
44
4
45
4
  return TypeIndex(TypeIndex::FirstNonSimpleIndex);
46
4
}
47
48
38
Optional<TypeIndex> GlobalTypeTableBuilder::getNext(TypeIndex Prev) {
49
38
  if (++Prev == nextTypeIndex())
50
4
    return None;
51
34
  return Prev;
52
34
}
53
54
44
CVType GlobalTypeTableBuilder::getType(TypeIndex Index) {
55
44
  CVType Type(SeenRecords[Index.toArrayIndex()]);
56
44
  return Type;
57
44
}
58
59
0
StringRef GlobalTypeTableBuilder::getTypeName(TypeIndex Index) {
60
0
  llvm_unreachable("Method not implemented");
61
0
}
62
63
0
bool GlobalTypeTableBuilder::contains(TypeIndex Index) {
64
0
  if (Index.isSimple() || Index.isNoneType())
65
0
    return false;
66
0
67
0
  return Index.toArrayIndex() < SeenRecords.size();
68
0
}
69
70
196
uint32_t GlobalTypeTableBuilder::size() { return SeenRecords.size(); }
71
72
0
uint32_t GlobalTypeTableBuilder::capacity() { return SeenRecords.size(); }
73
74
192
ArrayRef<ArrayRef<uint8_t>> GlobalTypeTableBuilder::records() const {
75
192
  return SeenRecords;
76
192
}
77
78
2
ArrayRef<GloballyHashedType> GlobalTypeTableBuilder::hashes() const {
79
2
  return SeenHashes;
80
2
}
81
82
0
void GlobalTypeTableBuilder::reset() {
83
0
  HashedRecords.clear();
84
0
  SeenRecords.clear();
85
0
}
86
87
3.56k
TypeIndex GlobalTypeTableBuilder::insertRecordBytes(ArrayRef<uint8_t> Record) {
88
3.56k
  GloballyHashedType GHT =
89
3.56k
      GloballyHashedType::hashType(Record, SeenHashes, SeenHashes);
90
3.56k
  return insertRecordAs(GHT, Record.size(),
91
3.56k
                        [Record](MutableArrayRef<uint8_t> Data) {
92
3.11k
                          assert(Data.size() == Record.size());
93
3.11k
                          ::memcpy(Data.data(), Record.data(), Record.size());
94
3.11k
                          return Data;
95
3.11k
                        });
96
3.56k
}
97
98
TypeIndex
99
242
GlobalTypeTableBuilder::insertRecord(ContinuationRecordBuilder &Builder) {
100
242
  TypeIndex TI;
101
242
  auto Fragments = Builder.end(nextTypeIndex());
102
242
  assert(!Fragments.empty());
103
242
  for (auto C : Fragments)
104
250
    TI = insertRecordBytes(C.RecordData);
105
242
  return TI;
106
242
}