Coverage Report

Created: 2018-11-16 02:38

/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
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLVM_DEBUGINFO_CODEVIEW_GLOBALTYPETABLEBUILDER_H
11
#define LLVM_DEBUGINFO_CODEVIEW_GLOBALTYPETABLEBUILDER_H
12
13
#include "llvm/ADT/ArrayRef.h"
14
#include "llvm/ADT/DenseSet.h"
15
#include "llvm/ADT/SmallVector.h"
16
#include "llvm/DebugInfo/CodeView/CodeView.h"
17
#include "llvm/DebugInfo/CodeView/SimpleTypeSerializer.h"
18
#include "llvm/DebugInfo/CodeView/TypeCollection.h"
19
#include "llvm/DebugInfo/CodeView/TypeHashing.h"
20
#include "llvm/DebugInfo/CodeView/TypeIndex.h"
21
#include "llvm/Support/Allocator.h"
22
#include <cassert>
23
#include <cstdint>
24
#include <memory>
25
#include <vector>
26
27
namespace llvm {
28
namespace codeview {
29
30
class ContinuationRecordBuilder;
31
32
class GlobalTypeTableBuilder : public TypeCollection {
33
  /// Storage for records.  These need to outlive the TypeTableBuilder.
34
  BumpPtrAllocator &RecordStorage;
35
36
  /// A serializer that can write non-continuation leaf types.  Only used as
37
  /// a convenience function so that we can provide an interface method to
38
  /// write an unserialized record.
39
  SimpleTypeSerializer SimpleSerializer;
40
41
  /// Hash table.
42
  DenseMap<GloballyHashedType, TypeIndex> HashedRecords;
43
44
  /// Contains a list of all records indexed by TypeIndex.toArrayIndex().
45
  SmallVector<ArrayRef<uint8_t>, 2> SeenRecords;
46
47
  /// Contains a list of all hash values inexed by TypeIndex.toArrayIndex().
48
  SmallVector<GloballyHashedType, 2> SeenHashes;
49
50
public:
51
  explicit GlobalTypeTableBuilder(BumpPtrAllocator &Storage);
52
  ~GlobalTypeTableBuilder();
53
54
  // TypeTableCollection overrides
55
  Optional<TypeIndex> getFirst() override;
56
  Optional<TypeIndex> getNext(TypeIndex Prev) override;
57
  CVType getType(TypeIndex Index) override;
58
  StringRef getTypeName(TypeIndex Index) override;
59
  bool contains(TypeIndex Index) override;
60
  uint32_t size() override;
61
  uint32_t capacity() override;
62
63
  // public interface
64
  void reset();
65
  TypeIndex nextTypeIndex() const;
66
67
0
  BumpPtrAllocator &getAllocator() { return RecordStorage; }
68
69
  ArrayRef<ArrayRef<uint8_t>> records() const;
70
  ArrayRef<GloballyHashedType> hashes() const;
71
72
  template <typename CreateFunc>
73
  TypeIndex insertRecordAs(GloballyHashedType Hash, size_t RecordSize,
74
1.96k
                           CreateFunc Create) {
75
1.96k
    auto Result = HashedRecords.try_emplace(Hash, nextTypeIndex());
76
1.96k
77
1.96k
    if (LLVM_UNLIKELY(Result.second)) {
78
1.74k
      uint8_t *Stable = RecordStorage.Allocate<uint8_t>(RecordSize);
79
1.74k
      MutableArrayRef<uint8_t> Data(Stable, RecordSize);
80
1.74k
      SeenRecords.push_back(Create(Data));
81
1.74k
      SeenHashes.push_back(Hash);
82
1.74k
    }
83
1.96k
84
1.96k
    // Update the caller's copy of Record to point a stable copy.
85
1.96k
    return Result.first->second;
86
1.96k
  }
87
88
  TypeIndex insertRecordBytes(ArrayRef<uint8_t> Data);
89
  TypeIndex insertRecord(ContinuationRecordBuilder &Builder);
90
91
1.84k
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
1.84k
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
1.84k
    return insertRecordBytes(Data);
94
1.84k
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::StringIdRecord>(llvm::codeview::StringIdRecord&)
Line
Count
Source
91
380
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
380
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
380
    return insertRecordBytes(Data);
94
380
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::MemberFuncIdRecord>(llvm::codeview::MemberFuncIdRecord&)
Line
Count
Source
91
42
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
42
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
42
    return insertRecordBytes(Data);
94
42
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::FuncIdRecord>(llvm::codeview::FuncIdRecord&)
Line
Count
Source
91
212
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
212
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
212
    return insertRecordBytes(Data);
94
212
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::BuildInfoRecord>(llvm::codeview::BuildInfoRecord&)
Line
Count
Source
91
134
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
134
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
134
    return insertRecordBytes(Data);
94
134
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ArrayRecord>(llvm::codeview::ArrayRecord&)
Line
Count
Source
91
19
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
19
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
19
    return insertRecordBytes(Data);
94
19
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::PointerRecord>(llvm::codeview::PointerRecord&)
Line
Count
Source
91
159
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
159
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
159
    return insertRecordBytes(Data);
94
159
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ModifierRecord>(llvm::codeview::ModifierRecord&)
Line
Count
Source
91
26
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
26
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
26
    return insertRecordBytes(Data);
94
26
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ArgListRecord>(llvm::codeview::ArgListRecord&)
Line
Count
Source
91
263
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
263
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
263
    return insertRecordBytes(Data);
94
263
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ProcedureRecord>(llvm::codeview::ProcedureRecord&)
Line
Count
Source
91
170
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
170
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
170
    return insertRecordBytes(Data);
94
170
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::MemberFunctionRecord>(llvm::codeview::MemberFunctionRecord&)
Line
Count
Source
91
93
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
93
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
93
    return insertRecordBytes(Data);
94
93
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::VFTableShapeRecord>(llvm::codeview::VFTableShapeRecord&)
Line
Count
Source
91
9
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
9
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
9
    return insertRecordBytes(Data);
94
9
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::UdtSourceLineRecord>(llvm::codeview::UdtSourceLineRecord&)
Line
Count
Source
91
110
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
110
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
110
    return insertRecordBytes(Data);
94
110
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::EnumRecord>(llvm::codeview::EnumRecord&)
Line
Count
Source
91
8
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
8
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
8
    return insertRecordBytes(Data);
94
8
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ClassRecord>(llvm::codeview::ClassRecord&)
Line
Count
Source
91
197
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
197
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
197
    return insertRecordBytes(Data);
94
197
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::UnionRecord>(llvm::codeview::UnionRecord&)
Line
Count
Source
91
15
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
15
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
15
    return insertRecordBytes(Data);
94
15
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::BitFieldRecord>(llvm::codeview::BitFieldRecord&)
Line
Count
Source
91
8
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
8
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
8
    return insertRecordBytes(Data);
94
8
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::MethodOverloadListRecord>(llvm::codeview::MethodOverloadListRecord&)
Line
Count
Source
91
1
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
1
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
1
    return insertRecordBytes(Data);
94
1
  }
95
};
96
97
} // end namespace codeview
98
} // end namespace llvm
99
100
#endif // LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H