Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Support/Registry.h
Line
Count
Source
1
//=== Registry.h - Linker-supported plugin registries -----------*- 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
// Defines a registry template for discovering pluggable modules.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_SUPPORT_REGISTRY_H
14
#define LLVM_SUPPORT_REGISTRY_H
15
16
#include "llvm/ADT/STLExtras.h"
17
#include "llvm/ADT/StringRef.h"
18
#include "llvm/ADT/iterator_range.h"
19
#include "llvm/Support/Compiler.h"
20
#include "llvm/Support/DynamicLibrary.h"
21
#include <memory>
22
23
namespace llvm {
24
  /// A simple registry entry which provides only a name, description, and
25
  /// no-argument constructor.
26
  template <typename T>
27
  class SimpleRegistryEntry {
28
    StringRef Name, Desc;
29
    std::unique_ptr<T> (*Ctor)();
30
31
  public:
32
    SimpleRegistryEntry(StringRef N, StringRef D, std::unique_ptr<T> (*C)())
33
175k
        : Name(N), Desc(D), Ctor(C) {}
llvm::SimpleRegistryEntry<llvm::GCMetadataPrinter>::SimpleRegistryEntry(llvm::StringRef, llvm::StringRef, std::__1::unique_ptr<llvm::GCMetadataPrinter, std::__1::default_delete<llvm::GCMetadataPrinter> > (*)())
Line
Count
Source
33
49.9k
        : Name(N), Desc(D), Ctor(C) {}
llvm::SimpleRegistryEntry<llvm::GCStrategy>::SimpleRegistryEntry(llvm::StringRef, llvm::StringRef, std::__1::unique_ptr<llvm::GCStrategy, std::__1::default_delete<llvm::GCStrategy> > (*)())
Line
Count
Source
33
125k
        : Name(N), Desc(D), Ctor(C) {}
34
35
98
    StringRef getName() const { return Name; }
llvm::SimpleRegistryEntry<llvm::GCStrategy>::getName() const
Line
Count
Source
35
89
    StringRef getName() const { return Name; }
Unexecuted instantiation: llvm::SimpleRegistryEntry<clang::PluginASTAction>::getName() const
llvm::SimpleRegistryEntry<llvm::GCMetadataPrinter>::getName() const
Line
Count
Source
35
9
    StringRef getName() const { return Name; }
36
    StringRef getDesc() const { return Desc; }
37
3.87k
    std::unique_ptr<T> instantiate() const { return Ctor(); }
llvm::SimpleRegistryEntry<llvm::GCStrategy>::instantiate() const
Line
Count
Source
37
26
    std::unique_ptr<T> instantiate() const { return Ctor(); }
llvm::SimpleRegistryEntry<clang::PluginASTAction>::instantiate() const
Line
Count
Source
37
3.84k
    std::unique_ptr<T> instantiate() const { return Ctor(); }
llvm::SimpleRegistryEntry<llvm::GCMetadataPrinter>::instantiate() const
Line
Count
Source
37
6
    std::unique_ptr<T> instantiate() const { return Ctor(); }
Unexecuted instantiation: llvm::SimpleRegistryEntry<clang::PragmaHandler>::instantiate() const
38
  };
39
40
  /// A global registry used in conjunction with static constructors to make
41
  /// pluggable components (like targets or garbage collectors) "just work" when
42
  /// linked with an executable.
43
  template <typename T>
44
  class Registry {
45
  public:
46
    typedef T type;
47
    typedef SimpleRegistryEntry<T> entry;
48
49
    class node;
50
    class iterator;
51
52
  private:
53
    Registry() = delete;
54
55
    friend class node;
56
    static node *Head, *Tail;
57
58
  public:
59
    /// Node in linked list of entries.
60
    ///
61
    class node {
62
      friend class iterator;
63
      friend Registry<T>;
64
65
      node *Next;
66
      const entry& Val;
67
68
    public:
69
175k
      node(const entry &V) : Next(nullptr), Val(V) {}
llvm::Registry<llvm::GCMetadataPrinter>::node::node(llvm::SimpleRegistryEntry<llvm::GCMetadataPrinter> const&)
Line
Count
Source
69
49.9k
      node(const entry &V) : Next(nullptr), Val(V) {}
llvm::Registry<llvm::GCStrategy>::node::node(llvm::SimpleRegistryEntry<llvm::GCStrategy> const&)
Line
Count
Source
69
125k
      node(const entry &V) : Next(nullptr), Val(V) {}
70
    };
71
72
    /// Add a node to the Registry: this is the interface between the plugin and
73
    /// the executable.
74
    ///
75
    /// This function is exported by the executable and called by the plugin to
76
    /// add a node to the executable's registry. Therefore it's not defined here
77
    /// to avoid it being instantiated in the plugin and is instead defined in
78
    /// the executable (see LLVM_INSTANTIATE_REGISTRY below).
79
    static void add_node(node *N);
80
81
    /// Iterators for registry entries.
82
    ///
83
    class iterator
84
        : public llvm::iterator_facade_base<iterator, std::forward_iterator_tag,
85
                                            const entry> {
86
      const node *Cur;
87
88
    public:
89
249k
      explicit iterator(const node *N) : Cur(N) {}
llvm::Registry<llvm::GCStrategy>::iterator::iterator(llvm::Registry<llvm::GCStrategy>::node const*)
Line
Count
Source
89
52
      explicit iterator(const node *N) : Cur(N) {}
llvm::Registry<llvm::GCMetadataPrinter>::iterator::iterator(llvm::Registry<llvm::GCMetadataPrinter>::node const*)
Line
Count
Source
89
12
      explicit iterator(const node *N) : Cur(N) {}
llvm::Registry<clang::PluginASTAction>::iterator::iterator(llvm::Registry<clang::PluginASTAction>::node const*)
Line
Count
Source
89
160k
      explicit iterator(const node *N) : Cur(N) {}
llvm::Registry<clang::PragmaHandler>::iterator::iterator(llvm::Registry<clang::PragmaHandler>::node const*)
Line
Count
Source
89
88.4k
      explicit iterator(const node *N) : Cur(N) {}
90
91
128k
      bool operator==(const iterator &That) const { return Cur == That.Cur; }
llvm::Registry<llvm::GCStrategy>::iterator::operator==(llvm::Registry<llvm::GCStrategy>::iterator const&) const
Line
Count
Source
91
89
      bool operator==(const iterator &That) const { return Cur == That.Cur; }
llvm::Registry<clang::PluginASTAction>::iterator::operator==(llvm::Registry<clang::PluginASTAction>::iterator const&) const
Line
Count
Source
91
84.2k
      bool operator==(const iterator &That) const { return Cur == That.Cur; }
llvm::Registry<llvm::GCMetadataPrinter>::iterator::operator==(llvm::Registry<llvm::GCMetadataPrinter>::iterator const&) const
Line
Count
Source
91
9
      bool operator==(const iterator &That) const { return Cur == That.Cur; }
llvm::Registry<clang::PragmaHandler>::iterator::operator==(llvm::Registry<clang::PragmaHandler>::iterator const&) const
Line
Count
Source
91
44.2k
      bool operator==(const iterator &That) const { return Cur == That.Cur; }
92
3.91k
      iterator &operator++() { Cur = Cur->Next; return *this; }
llvm::Registry<llvm::GCStrategy>::iterator::operator++()
Line
Count
Source
92
63
      iterator &operator++() { Cur = Cur->Next; return *this; }
llvm::Registry<clang::PluginASTAction>::iterator::operator++()
Line
Count
Source
92
3.84k
      iterator &operator++() { Cur = Cur->Next; return *this; }
llvm::Registry<llvm::GCMetadataPrinter>::iterator::operator++()
Line
Count
Source
92
3
      iterator &operator++() { Cur = Cur->Next; return *this; }
Unexecuted instantiation: llvm::Registry<clang::PragmaHandler>::iterator::operator++()
93
3.94k
      const entry &operator*() const { return Cur->Val; }
llvm::Registry<llvm::GCStrategy>::iterator::operator*() const
Line
Count
Source
93
89
      const entry &operator*() const { return Cur->Val; }
llvm::Registry<clang::PluginASTAction>::iterator::operator*() const
Line
Count
Source
93
3.84k
      const entry &operator*() const { return Cur->Val; }
llvm::Registry<llvm::GCMetadataPrinter>::iterator::operator*() const
Line
Count
Source
93
15
      const entry &operator*() const { return Cur->Val; }
Unexecuted instantiation: llvm::Registry<clang::PragmaHandler>::iterator::operator*() const
94
    };
95
96
    // begin is not defined here in order to avoid usage of an undefined static
97
    // data member, instead it's instantiated by LLVM_INSTANTIATE_REGISTRY.
98
    static iterator begin();
99
124k
    static iterator end()   { return iterator(nullptr); }
llvm::Registry<llvm::GCStrategy>::end()
Line
Count
Source
99
26
    static iterator end()   { return iterator(nullptr); }
llvm::Registry<clang::PluginASTAction>::end()
Line
Count
Source
99
80.4k
    static iterator end()   { return iterator(nullptr); }
llvm::Registry<llvm::GCMetadataPrinter>::end()
Line
Count
Source
99
6
    static iterator end()   { return iterator(nullptr); }
llvm::Registry<clang::PragmaHandler>::end()
Line
Count
Source
99
44.2k
    static iterator end()   { return iterator(nullptr); }
100
101
26
    static iterator_range<iterator> entries() {
102
26
      return make_range(begin(), end());
103
26
    }
104
105
    /// A static registration template. Use like such:
106
    ///
107
    ///   Registry<Collector>::Add<FancyGC>
108
    ///   X("fancy-gc", "Newfangled garbage collector.");
109
    ///
110
    /// Use of this template requires that:
111
    ///
112
    ///  1. The registered subclass has a default constructor.
113
    template <typename V>
114
    class Add {
115
      entry Entry;
116
      node Node;
117
118
32
      static std::unique_ptr<T> CtorFn() { return make_unique<V>(); }
ErlangGCPrinter.cpp:llvm::Registry<llvm::GCMetadataPrinter>::Add<(anonymous namespace)::ErlangGCPrinter>::CtorFn()
Line
Count
Source
118
3
      static std::unique_ptr<T> CtorFn() { return make_unique<V>(); }
OcamlGCPrinter.cpp:llvm::Registry<llvm::GCMetadataPrinter>::Add<(anonymous namespace)::OcamlGCMetadataPrinter>::CtorFn()
Line
Count
Source
118
3
      static std::unique_ptr<T> CtorFn() { return make_unique<V>(); }
BuiltinGCs.cpp:llvm::Registry<llvm::GCStrategy>::Add<(anonymous namespace)::ErlangGC>::CtorFn()
Line
Count
Source
118
3
      static std::unique_ptr<T> CtorFn() { return make_unique<V>(); }
BuiltinGCs.cpp:llvm::Registry<llvm::GCStrategy>::Add<(anonymous namespace)::OcamlGC>::CtorFn()
Line
Count
Source
118
3
      static std::unique_ptr<T> CtorFn() { return make_unique<V>(); }
BuiltinGCs.cpp:llvm::Registry<llvm::GCStrategy>::Add<(anonymous namespace)::ShadowStackGC>::CtorFn()
Line
Count
Source
118
2
      static std::unique_ptr<T> CtorFn() { return make_unique<V>(); }
BuiltinGCs.cpp:llvm::Registry<llvm::GCStrategy>::Add<(anonymous namespace)::StatepointGC>::CtorFn()
Line
Count
Source
118
16
      static std::unique_ptr<T> CtorFn() { return make_unique<V>(); }
BuiltinGCs.cpp:llvm::Registry<llvm::GCStrategy>::Add<(anonymous namespace)::CoreCLRGC>::CtorFn()
Line
Count
Source
118
2
      static std::unique_ptr<T> CtorFn() { return make_unique<V>(); }
119
120
    public:
121
      Add(StringRef Name, StringRef Desc)
122
175k
          : Entry(Name, Desc, CtorFn), Node(Entry) {
123
175k
        add_node(&Node);
124
175k
      }
ErlangGCPrinter.cpp:llvm::Registry<llvm::GCMetadataPrinter>::Add<(anonymous namespace)::ErlangGCPrinter>::Add(llvm::StringRef, llvm::StringRef)
Line
Count
Source
122
24.9k
          : Entry(Name, Desc, CtorFn), Node(Entry) {
123
24.9k
        add_node(&Node);
124
24.9k
      }
OcamlGCPrinter.cpp:llvm::Registry<llvm::GCMetadataPrinter>::Add<(anonymous namespace)::OcamlGCMetadataPrinter>::Add(llvm::StringRef, llvm::StringRef)
Line
Count
Source
122
24.9k
          : Entry(Name, Desc, CtorFn), Node(Entry) {
123
24.9k
        add_node(&Node);
124
24.9k
      }
BuiltinGCs.cpp:llvm::Registry<llvm::GCStrategy>::Add<(anonymous namespace)::ErlangGC>::Add(llvm::StringRef, llvm::StringRef)
Line
Count
Source
122
25.1k
          : Entry(Name, Desc, CtorFn), Node(Entry) {
123
25.1k
        add_node(&Node);
124
25.1k
      }
BuiltinGCs.cpp:llvm::Registry<llvm::GCStrategy>::Add<(anonymous namespace)::OcamlGC>::Add(llvm::StringRef, llvm::StringRef)
Line
Count
Source
122
25.1k
          : Entry(Name, Desc, CtorFn), Node(Entry) {
123
25.1k
        add_node(&Node);
124
25.1k
      }
BuiltinGCs.cpp:llvm::Registry<llvm::GCStrategy>::Add<(anonymous namespace)::ShadowStackGC>::Add(llvm::StringRef, llvm::StringRef)
Line
Count
Source
122
25.1k
          : Entry(Name, Desc, CtorFn), Node(Entry) {
123
25.1k
        add_node(&Node);
124
25.1k
      }
BuiltinGCs.cpp:llvm::Registry<llvm::GCStrategy>::Add<(anonymous namespace)::StatepointGC>::Add(llvm::StringRef, llvm::StringRef)
Line
Count
Source
122
25.1k
          : Entry(Name, Desc, CtorFn), Node(Entry) {
123
25.1k
        add_node(&Node);
124
25.1k
      }
BuiltinGCs.cpp:llvm::Registry<llvm::GCStrategy>::Add<(anonymous namespace)::CoreCLRGC>::Add(llvm::StringRef, llvm::StringRef)
Line
Count
Source
122
25.1k
          : Entry(Name, Desc, CtorFn), Node(Entry) {
123
25.1k
        add_node(&Node);
124
25.1k
      }
125
    };
126
  };
127
} // end namespace llvm
128
129
/// Instantiate a registry class.
130
///
131
/// This provides template definitions of add_node, begin, and the Head and Tail
132
/// pointers, then explicitly instantiates them. We could explicitly specialize
133
/// them, instead of the two-step process of define then instantiate, but
134
/// strictly speaking that's not allowed by the C++ standard (we would need to
135
/// have explicit specialization declarations in all translation units where the
136
/// specialization is used) so we don't.
137
#define LLVM_INSTANTIATE_REGISTRY(REGISTRY_CLASS) \
138
  namespace llvm { \
139
  template<typename T> typename Registry<T>::node *Registry<T>::Head = nullptr;\
140
  template<typename T> typename Registry<T>::node *Registry<T>::Tail = nullptr;\
141
  template<typename T> \
142
178k
  void Registry<T>::add_node(typename Registry<T>::node *N) { \
143
178k
    if (Tail) \
144
178k
      
Tail->Next = N126k
; \
145
178k
    else \
146
178k
      
Head = N51.2k
; \
147
178k
    Tail = N; \
148
178k
  } \
llvm::Registry<llvm::GCMetadataPrinter>::add_node(llvm::Registry<llvm::GCMetadataPrinter>::node*)
Line
Count
Source
142
49.9k
  void Registry<T>::add_node(typename Registry<T>::node *N) { \
143
49.9k
    if (Tail) \
144
49.9k
      
Tail->Next = N24.9k
; \
145
49.9k
    else \
146
49.9k
      
Head = N24.9k
; \
147
49.9k
    Tail = N; \
148
49.9k
  } \
llvm::Registry<llvm::GCStrategy>::add_node(llvm::Registry<llvm::GCStrategy>::node*)
Line
Count
Source
142
125k
  void Registry<T>::add_node(typename Registry<T>::node *N) { \
143
125k
    if (Tail) \
144
125k
      
Tail->Next = N100k
; \
145
125k
    else \
146
125k
      
Head = N25.1k
; \
147
125k
    Tail = N; \
148
125k
  } \
llvm::Registry<clang::PluginASTAction>::add_node(llvm::Registry<clang::PluginASTAction>::node*)
Line
Count
Source
142
2.22k
  void Registry<T>::add_node(typename Registry<T>::node *N) { \
143
2.22k
    if (Tail) \
144
2.22k
      
Tail->Next = N1.11k
; \
145
2.22k
    else \
146
2.22k
      
Head = N1.11k
; \
147
2.22k
    Tail = N; \
148
2.22k
  } \
Unexecuted instantiation: llvm::Registry<clang::PragmaHandler>::add_node(llvm::Registry<clang::PragmaHandler>::node*)
149
124k
  template<typename T> typename Registry<T>::iterator Registry<T>::begin() { \
150
124k
    return iterator(Head); \
151
124k
  } \
llvm::Registry<llvm::GCMetadataPrinter>::begin()
Line
Count
Source
149
6
  template<typename T> typename Registry<T>::iterator Registry<T>::begin() { \
150
6
    return iterator(Head); \
151
6
  } \
llvm::Registry<llvm::GCStrategy>::begin()
Line
Count
Source
149
26
  template<typename T> typename Registry<T>::iterator Registry<T>::begin() { \
150
26
    return iterator(Head); \
151
26
  } \
llvm::Registry<clang::PluginASTAction>::begin()
Line
Count
Source
149
80.4k
  template<typename T> typename Registry<T>::iterator Registry<T>::begin() { \
150
80.4k
    return iterator(Head); \
151
80.4k
  } \
llvm::Registry<clang::PragmaHandler>::begin()
Line
Count
Source
149
44.2k
  template<typename T> typename Registry<T>::iterator Registry<T>::begin() { \
150
44.2k
    return iterator(Head); \
151
44.2k
  } \
152
  template REGISTRY_CLASS::node *Registry<REGISTRY_CLASS::type>::Head; \
153
  template REGISTRY_CLASS::node *Registry<REGISTRY_CLASS::type>::Tail; \
154
  template \
155
  void Registry<REGISTRY_CLASS::type>::add_node(REGISTRY_CLASS::node*); \
156
  template REGISTRY_CLASS::iterator Registry<REGISTRY_CLASS::type>::begin(); \
157
  }
158
159
#endif // LLVM_SUPPORT_REGISTRY_H