LLVM  8.0.1
GlobalTypeTableBuilder.h
Go to the documentation of this file.
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"
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 
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.
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().
49 
50 public:
51  explicit GlobalTypeTableBuilder(BumpPtrAllocator &Storage);
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  BumpPtrAllocator &getAllocator() { return RecordStorage; }
68 
71 
72  template <typename CreateFunc>
73  TypeIndex insertRecordAs(GloballyHashedType Hash, size_t RecordSize,
74  CreateFunc Create) {
75  auto Result = HashedRecords.try_emplace(Hash, nextTypeIndex());
76 
77  if (LLVM_UNLIKELY(Result.second)) {
78  uint8_t *Stable = RecordStorage.Allocate<uint8_t>(RecordSize);
79  MutableArrayRef<uint8_t> Data(Stable, RecordSize);
80  SeenRecords.push_back(Create(Data));
81  SeenHashes.push_back(Hash);
82  }
83 
84  // Update the caller's copy of Record to point a stable copy.
85  return Result.first->second;
86  }
87 
90 
91  template <typename T> TypeIndex writeLeafType(T &Record) {
92  ArrayRef<uint8_t> Data = SimpleSerializer.serialize(Record);
93  return insertRecordBytes(Data);
94  }
95 };
96 
97 } // end namespace codeview
98 } // end namespace llvm
99 
100 #endif // LLVM_DEBUGINFO_CODEVIEW_MERGINGTYPETABLEBUILDER_H
CVType getType(TypeIndex Index) override
Optional< TypeIndex > getFirst() override
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Optional< TypeIndex > getNext(TypeIndex Prev) override
GlobalTypeTableBuilder(BumpPtrAllocator &Storage)
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
#define LLVM_UNLIKELY(EXPR)
Definition: Compiler.h:192
TypeIndex insertRecord(ContinuationRecordBuilder &Builder)
ArrayRef< GloballyHashedType > hashes() const
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
A 32-bit type reference.
Definition: TypeIndex.h:96
A globally hashed type represents a hash value that is sufficient to uniquely identify a record acros...
Definition: TypeHashing.h:78
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:141
ArrayRef< uint8_t > serialize(T &Record)
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * Allocate(size_t Size, size_t Alignment)
Allocate space at the specified alignment.
Definition: Allocator.h:215
ArrayRef< ArrayRef< uint8_t > > records() const
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
StringRef getTypeName(TypeIndex Index) override
TypeIndex insertRecordAs(GloballyHashedType Hash, size_t RecordSize, CreateFunc Create)
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
TypeIndex insertRecordBytes(ArrayRef< uint8_t > Data)