Coverage Report

Created: 2019-02-21 13:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h
Line
Count
Source (jump to first uncovered line)
1
//===- GlobalTypeTableBuilder.h ----------------------------------*- C++-*-===//
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
#ifndef LLVM_DEBUGINFO_CODEVIEW_GLOBALTYPETABLEBUILDER_H
10
#define LLVM_DEBUGINFO_CODEVIEW_GLOBALTYPETABLEBUILDER_H
11
12
#include "llvm/ADT/ArrayRef.h"
13
#include "llvm/ADT/DenseSet.h"
14
#include "llvm/ADT/SmallVector.h"
15
#include "llvm/DebugInfo/CodeView/CodeView.h"
16
#include "llvm/DebugInfo/CodeView/SimpleTypeSerializer.h"
17
#include "llvm/DebugInfo/CodeView/TypeCollection.h"
18
#include "llvm/DebugInfo/CodeView/TypeHashing.h"
19
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
20
#include "llvm/Support/Allocator.h"
21
#include <cassert>
22
#include <cstdint>
23
#include <memory>
24
#include <vector>
25
26
namespace llvm {
27
namespace codeview {
28
29
class ContinuationRecordBuilder;
30
31
class GlobalTypeTableBuilder : public TypeCollection {
32
  /// Storage for records.  These need to outlive the TypeTableBuilder.
33
  BumpPtrAllocator &RecordStorage;
34
35
  /// A serializer that can write non-continuation leaf types.  Only used as
36
  /// a convenience function so that we can provide an interface method to
37
  /// write an unserialized record.
38
  SimpleTypeSerializer SimpleSerializer;
39
40
  /// Hash table.
41
  DenseMap<GloballyHashedType, TypeIndex> HashedRecords;
42
43
  /// Contains a list of all records indexed by TypeIndex.toArrayIndex().
44
  SmallVector<ArrayRef<uint8_t>, 2> SeenRecords;
45
46
  /// Contains a list of all hash values inexed by TypeIndex.toArrayIndex().
47
  SmallVector<GloballyHashedType, 2> SeenHashes;
48
49
public:
50
  explicit GlobalTypeTableBuilder(BumpPtrAllocator &Storage);
51
  ~GlobalTypeTableBuilder();
52
53
  // TypeTableCollection overrides
54
  Optional<TypeIndex> getFirst() override;
55
  Optional<TypeIndex> getNext(TypeIndex Prev) override;
56
  CVType getType(TypeIndex Index) override;
57
  StringRef getTypeName(TypeIndex Index) override;
58
  bool contains(TypeIndex Index) override;
59
  uint32_t size() override;
60
  uint32_t capacity() override;
61
62
  // public interface
63
  void reset();
64
  TypeIndex nextTypeIndex() const;
65
66
0
  BumpPtrAllocator &getAllocator() { return RecordStorage; }
67
68
  ArrayRef<ArrayRef<uint8_t>> records() const;
69
  ArrayRef<GloballyHashedType> hashes() const;
70
71
  template <typename CreateFunc>
72
  TypeIndex insertRecordAs(GloballyHashedType Hash, size_t RecordSize,
73
2.05k
                           CreateFunc Create) {
74
2.05k
    auto Result = HashedRecords.try_emplace(Hash, nextTypeIndex());
75
2.05k
76
2.05k
    if (LLVM_UNLIKELY(Result.second /*inserted*/ ||
77
2.05k
                      Result.first->second.isSimple())) {
78
1.84k
      uint8_t *Stable = RecordStorage.Allocate<uint8_t>(RecordSize);
79
1.84k
      MutableArrayRef<uint8_t> Data(Stable, RecordSize);
80
1.84k
      ArrayRef<uint8_t> StableRecord = Create(Data);
81
1.84k
      if (StableRecord.empty()) {
82
0
        // Records with forward references into the Type stream will be deferred
83
0
        // for insertion at a later time, on the second pass.
84
0
        Result.first->getSecond() = TypeIndex(SimpleTypeKind::NotTranslated);
85
0
        return TypeIndex(SimpleTypeKind::NotTranslated);
86
0
      }
87
1.84k
      if (Result.first->second.isSimple()) {
88
0
        assert(Result.first->second.getIndex() ==
89
0
               (uint32_t)SimpleTypeKind::NotTranslated);
90
0
        // On the second pass, update with index to remapped record. The
91
0
        // (initially misbehaved) record will now come *after* other records
92
0
        // resolved in the first pass, with proper *back* references in the
93
0
        // stream.
94
0
        Result.first->second = nextTypeIndex();
95
0
      }
96
1.84k
      SeenRecords.push_back(StableRecord);
97
1.84k
      SeenHashes.push_back(Hash);
98
1.84k
    }
99
2.05k
100
2.05k
    return Result.first->second;
101
2.05k
  }
102
103
  TypeIndex insertRecordBytes(ArrayRef<uint8_t> Data);
104
  TypeIndex insertRecord(ContinuationRecordBuilder &Builder);
105
106
1.93k
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
1.93k
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
1.93k
    return insertRecordBytes(Data);
109
1.93k
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::StringIdRecord>(llvm::codeview::StringIdRecord&)
Line
Count
Source
106
396
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
396
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
396
    return insertRecordBytes(Data);
109
396
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::MemberFuncIdRecord>(llvm::codeview::MemberFuncIdRecord&)
Line
Count
Source
106
45
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
45
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
45
    return insertRecordBytes(Data);
109
45
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::FuncIdRecord>(llvm::codeview::FuncIdRecord&)
Line
Count
Source
106
215
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
215
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
215
    return insertRecordBytes(Data);
109
215
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::BuildInfoRecord>(llvm::codeview::BuildInfoRecord&)
Line
Count
Source
106
139
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
139
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
139
    return insertRecordBytes(Data);
109
139
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ArrayRecord>(llvm::codeview::ArrayRecord&)
Line
Count
Source
106
19
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
19
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
19
    return insertRecordBytes(Data);
109
19
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::PointerRecord>(llvm::codeview::PointerRecord&)
Line
Count
Source
106
179
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
179
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
179
    return insertRecordBytes(Data);
109
179
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ModifierRecord>(llvm::codeview::ModifierRecord&)
Line
Count
Source
106
26
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
26
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
26
    return insertRecordBytes(Data);
109
26
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ArgListRecord>(llvm::codeview::ArgListRecord&)
Line
Count
Source
106
274
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
274
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
274
    return insertRecordBytes(Data);
109
274
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ProcedureRecord>(llvm::codeview::ProcedureRecord&)
Line
Count
Source
106
172
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
172
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
172
    return insertRecordBytes(Data);
109
172
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::MemberFunctionRecord>(llvm::codeview::MemberFunctionRecord&)
Line
Count
Source
106
102
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
102
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
102
    return insertRecordBytes(Data);
109
102
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::VFTableShapeRecord>(llvm::codeview::VFTableShapeRecord&)
Line
Count
Source
106
9
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
9
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
9
    return insertRecordBytes(Data);
109
9
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::UdtSourceLineRecord>(llvm::codeview::UdtSourceLineRecord&)
Line
Count
Source
106
116
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
116
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
116
    return insertRecordBytes(Data);
109
116
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::EnumRecord>(llvm::codeview::EnumRecord&)
Line
Count
Source
106
8
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
8
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
8
    return insertRecordBytes(Data);
109
8
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ClassRecord>(llvm::codeview::ClassRecord&)
Line
Count
Source
106
209
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
209
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
209
    return insertRecordBytes(Data);
109
209
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::UnionRecord>(llvm::codeview::UnionRecord&)
Line
Count
Source
106
15
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
15
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
15
    return insertRecordBytes(Data);
109
15
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::BitFieldRecord>(llvm::codeview::BitFieldRecord&)
Line
Count
Source
106
8
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
8
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
8
    return insertRecordBytes(Data);
109
8
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::MethodOverloadListRecord>(llvm::codeview::MethodOverloadListRecord&)
Line
Count
Source
106
2
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
2
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
2
    return insertRecordBytes(Data);
109
2
  }
110
};
111
112
} // end namespace codeview
113
} // end namespace llvm
114
115
#endif // LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H