Coverage Report

Created: 2018-09-19 08:35

/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.36k
                           CreateFunc Create) {
75
1.36k
    auto Result = HashedRecords.try_emplace(Hash, nextTypeIndex());
76
1.36k
77
1.36k
    if (LLVM_UNLIKELY(Result.second)) {
78
1.16k
      uint8_t *Stable = RecordStorage.Allocate<uint8_t>(RecordSize);
79
1.16k
      MutableArrayRef<uint8_t> Data(Stable, RecordSize);
80
1.16k
      SeenRecords.push_back(Create(Data));
81
1.16k
      SeenHashes.push_back(Hash);
82
1.16k
    }
83
1.36k
84
1.36k
    // Update the caller's copy of Record to point a stable copy.
85
1.36k
    return Result.first->second;
86
1.36k
  }
87
88
  TypeIndex insertRecordBytes(ArrayRef<uint8_t> Data);
89
  TypeIndex insertRecord(ContinuationRecordBuilder &Builder);
90
91
1.26k
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
1.26k
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
1.26k
    return insertRecordBytes(Data);
94
1.26k
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::StringIdRecord>(llvm::codeview::StringIdRecord&)
Line
Count
Source
91
95
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
95
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
95
    return insertRecordBytes(Data);
94
95
  }
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
182
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
182
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
182
    return insertRecordBytes(Data);
94
182
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ArrayRecord>(llvm::codeview::ArrayRecord&)
Line
Count
Source
91
16
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
16
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
16
    return insertRecordBytes(Data);
94
16
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::PointerRecord>(llvm::codeview::PointerRecord&)
Line
Count
Source
91
141
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
141
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
141
    return insertRecordBytes(Data);
94
141
  }
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
233
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
233
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
233
    return insertRecordBytes(Data);
94
233
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ProcedureRecord>(llvm::codeview::ProcedureRecord&)
Line
Count
Source
91
145
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
145
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
145
    return insertRecordBytes(Data);
94
145
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::MemberFunctionRecord>(llvm::codeview::MemberFunctionRecord&)
Line
Count
Source
91
88
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
88
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
88
    return insertRecordBytes(Data);
94
88
  }
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
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::EnumRecord>(llvm::codeview::EnumRecord&)
Line
Count
Source
91
4
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
4
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
4
    return insertRecordBytes(Data);
94
4
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::ClassRecord>(llvm::codeview::ClassRecord&)
Line
Count
Source
91
177
  template <typename T> TypeIndex writeLeafType(T &Record) {
92
177
    ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93
177
    return insertRecordBytes(Data);
94
177
  }
llvm::codeview::TypeIndex llvm::codeview::GlobalTypeTableBuilder::writeLeafType<llvm::codeview::UnionRecord>(llvm::codeview::UnionRecord&)
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::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