Coverage Report

Created: 2019-07-24 05:18

/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
3.56k
                           CreateFunc Create) {
74
3.56k
    auto Result = HashedRecords.try_emplace(Hash, nextTypeIndex());
75
3.56k
76
3.56k
    if (LLVM_UNLIKELY(Result.second /*inserted*/ ||
77
3.56k
                      Result.first->second.isSimple())) {
78
3.11k
      uint8_t *Stable = RecordStorage.Allocate<uint8_t>(RecordSize);
79
3.11k
      MutableArrayRef<uint8_t> Data(Stable, RecordSize);
80
3.11k
      ArrayRef<uint8_t> StableRecord = Create(Data);
81
3.11k
      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
3.11k
      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
3.11k
      SeenRecords.push_back(StableRecord);
97
3.11k
      SeenHashes.push_back(Hash);
98
3.11k
    }
99
3.56k
100
3.56k
    return Result.first->second;
101
3.56k
  }
102
103
  TypeIndex insertRecordBytes(ArrayRef<uint8_t> Data);
104
  TypeIndex insertRecord(ContinuationRecordBuilder &Builder);
105
106
3.31k
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
3.31k
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
3.31k
    return insertRecordBytes(Data);
109
3.31k
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::StringIdRecord>(llvm::codeview::StringIdRecord&)
Line
Count
Source
106
623
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
623
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
623
    return insertRecordBytes(Data);
109
623
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::MemberFuncIdRecord>(llvm::codeview::MemberFuncIdRecord&)
Line
Count
Source
106
69
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
69
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
69
    return insertRecordBytes(Data);
109
69
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::FuncIdRecord>(llvm::codeview::FuncIdRecord&)
Line
Count
Source
106
322
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
322
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
322
    return insertRecordBytes(Data);
109
322
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::BuildInfoRecord>(llvm::codeview::BuildInfoRecord&)
Line
Count
Source
106
190
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
190
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
190
    return insertRecordBytes(Data);
109
190
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ArrayRecord>(llvm::codeview::ArrayRecord&)
Line
Count
Source
106
30
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
30
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
30
    return insertRecordBytes(Data);
109
30
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::PointerRecord>(llvm::codeview::PointerRecord&)
Line
Count
Source
106
361
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
361
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
361
    return insertRecordBytes(Data);
109
361
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ModifierRecord>(llvm::codeview::ModifierRecord&)
Line
Count
Source
106
50
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
50
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
50
    return insertRecordBytes(Data);
109
50
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ArgListRecord>(llvm::codeview::ArgListRecord&)
Line
Count
Source
106
462
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
462
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
462
    return insertRecordBytes(Data);
109
462
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ProcedureRecord>(llvm::codeview::ProcedureRecord&)
Line
Count
Source
106
267
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
267
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
267
    return insertRecordBytes(Data);
109
267
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::MemberFunctionRecord>(llvm::codeview::MemberFunctionRecord&)
Line
Count
Source
106
195
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
195
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
195
    return insertRecordBytes(Data);
109
195
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::VFTableShapeRecord>(llvm::codeview::VFTableShapeRecord&)
Line
Count
Source
106
17
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
17
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
17
    return insertRecordBytes(Data);
109
17
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::UdtSourceLineRecord>(llvm::codeview::UdtSourceLineRecord&)
Line
Count
Source
106
240
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
240
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
240
    return insertRecordBytes(Data);
109
240
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::EnumRecord>(llvm::codeview::EnumRecord&)
Line
Count
Source
106
20
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
20
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
20
    return insertRecordBytes(Data);
109
20
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ClassRecord>(llvm::codeview::ClassRecord&)
Line
Count
Source
106
409
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
409
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
409
    return insertRecordBytes(Data);
109
409
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::UnionRecord>(llvm::codeview::UnionRecord&)
Line
Count
Source
106
44
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
44
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
44
    return insertRecordBytes(Data);
109
44
  }
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
8
  template <typename T> TypeIndex writeLeafType(T &Record) {
107
8
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
108
8
    return insertRecordBytes(Data);
109
8
  }
110
};
111
112
} // end namespace codeview
113
} // end namespace llvm
114
115
#endif // LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H