Coverage Report

Created: 2018-09-23 16:00

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/MachinePassRegistry.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/CodeGen/MachinePassRegistry.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
// This file contains the mechanics for machine function pass registries.  A
11
// function pass registry (MachinePassRegistry) is auto filled by the static
12
// constructors of MachinePassRegistryNode.  Further there is a command line
13
// parser (RegisterPassParser) which listens to each registry for additions
14
// and deletions, so that the appropriate command option is updated.
15
//
16
//===----------------------------------------------------------------------===//
17
18
#ifndef LLVM_CODEGEN_MACHINEPASSREGISTRY_H
19
#define LLVM_CODEGEN_MACHINEPASSREGISTRY_H
20
21
#include "llvm/ADT/StringRef.h"
22
#include "llvm/CodeGen/Passes.h"
23
#include "llvm/Support/CommandLine.h"
24
25
namespace llvm {
26
27
using MachinePassCtor = void *(*)();
28
29
//===----------------------------------------------------------------------===//
30
///
31
/// MachinePassRegistryListener - Listener to adds and removals of nodes in
32
/// registration list.
33
///
34
//===----------------------------------------------------------------------===//
35
class MachinePassRegistryListener {
36
  virtual void anchor();
37
38
public:
39
279k
  MachinePassRegistryListener() = default;
40
279k
  virtual ~MachinePassRegistryListener() = default;
41
42
  virtual void NotifyAdd(StringRef N, MachinePassCtor C, StringRef D) = 0;
43
  virtual void NotifyRemove(StringRef N) = 0;
44
};
45
46
//===----------------------------------------------------------------------===//
47
///
48
/// MachinePassRegistryNode - Machine pass node stored in registration list.
49
///
50
//===----------------------------------------------------------------------===//
51
class MachinePassRegistryNode {
52
private:
53
  MachinePassRegistryNode *Next = nullptr; // Next function pass in list.
54
  StringRef Name;                       // Name of function pass.
55
  StringRef Description;                // Description string.
56
  MachinePassCtor Ctor;                 // Function pass creator.
57
58
public:
59
  MachinePassRegistryNode(const char *N, const char *D, MachinePassCtor C)
60
2.08M
      : Name(N), Description(D), Ctor(C) {}
61
62
  // Accessors
63
3.61M
  MachinePassRegistryNode *getNext()      const { return Next; }
64
0
  MachinePassRegistryNode **getNextAddress()    { return &Next; }
65
2.64M
  StringRef getName()                   const { return Name; }
66
2.08M
  StringRef getDescription()            const { return Description; }
67
2.08M
  MachinePassCtor getCtor()               const { return Ctor; }
68
2.08M
  void setNext(MachinePassRegistryNode *N)      { Next = N; }
69
};
70
71
//===----------------------------------------------------------------------===//
72
///
73
/// MachinePassRegistry - Track the registration of machine passes.
74
///
75
//===----------------------------------------------------------------------===//
76
class MachinePassRegistry {
77
private:
78
  MachinePassRegistryNode *List;        // List of registry nodes.
79
  MachinePassCtor Default;              // Default function pass creator.
80
  MachinePassRegistryListener *Listener; // Listener for list adds are removes.
81
82
public:
83
  // NO CONSTRUCTOR - we don't want static constructor ordering to mess
84
  // with the registry.
85
86
  // Accessors.
87
  //
88
279k
  MachinePassRegistryNode *getList()                    { return List; }
89
65.7k
  MachinePassCtor getDefault()                          { return Default; }
90
32.7k
  void setDefault(MachinePassCtor C)                    { Default = C; }
91
  void setDefault(StringRef Name);
92
559k
  void setListener(MachinePassRegistryListener *L)      { Listener = L; }
93
94
  /// Add - Adds a function pass to the registration list.
95
  ///
96
  void Add(MachinePassRegistryNode *Node);
97
98
  /// Remove - Removes a function pass from the registration list.
99
  ///
100
  void Remove(MachinePassRegistryNode *Node);
101
};
102
103
//===----------------------------------------------------------------------===//
104
///
105
/// RegisterPassParser class - Handle the addition of new machine passes.
106
///
107
//===----------------------------------------------------------------------===//
108
template<class RegistryClass>
109
class RegisterPassParser : public MachinePassRegistryListener,
110
                   public cl::parser<typename RegistryClass::FunctionPassCtor> {
111
public:
112
  RegisterPassParser(cl::Option &O)
113
279k
      : cl::parser<typename RegistryClass::FunctionPassCtor>(O) {}
llvm::RegisterPassParser<llvm::MachineSchedRegistry>::RegisterPassParser(llvm::cl::Option&)
Line
Count
Source
113
93.1k
      : cl::parser<typename RegistryClass::FunctionPassCtor>(O) {}
llvm::RegisterPassParser<llvm::RegisterRegAlloc>::RegisterPassParser(llvm::cl::Option&)
Line
Count
Source
113
93.1k
      : cl::parser<typename RegistryClass::FunctionPassCtor>(O) {}
llvm::RegisterPassParser<llvm::RegisterScheduler>::RegisterPassParser(llvm::cl::Option&)
Line
Count
Source
113
93.1k
      : cl::parser<typename RegistryClass::FunctionPassCtor>(O) {}
114
279k
  ~RegisterPassParser() override { RegistryClass::setListener(nullptr); }
llvm::RegisterPassParser<llvm::MachineSchedRegistry>::~RegisterPassParser()
Line
Count
Source
114
93.1k
  ~RegisterPassParser() override { RegistryClass::setListener(nullptr); }
llvm::RegisterPassParser<llvm::RegisterRegAlloc>::~RegisterPassParser()
Line
Count
Source
114
93.1k
  ~RegisterPassParser() override { RegistryClass::setListener(nullptr); }
llvm::RegisterPassParser<llvm::RegisterScheduler>::~RegisterPassParser()
Line
Count
Source
114
93.1k
  ~RegisterPassParser() override { RegistryClass::setListener(nullptr); }
115
116
279k
  void initialize() {
117
279k
    cl::parser<typename RegistryClass::FunctionPassCtor>::initialize();
118
279k
119
279k
    // Add existing passes to option.
120
279k
    for (RegistryClass *Node = RegistryClass::getList();
121
1.80M
         Node; 
Node = Node->getNext()1.53M
) {
122
1.53M
      this->addLiteralOption(Node->getName(),
123
1.53M
                      (typename RegistryClass::FunctionPassCtor)Node->getCtor(),
124
1.53M
                             Node->getDescription());
125
1.53M
    }
126
279k
127
279k
    // Make sure we listen for list changes.
128
279k
    RegistryClass::setListener(this);
129
279k
  }
llvm::RegisterPassParser<llvm::MachineSchedRegistry>::initialize()
Line
Count
Source
116
93.1k
  void initialize() {
117
93.1k
    cl::parser<typename RegistryClass::FunctionPassCtor>::initialize();
118
93.1k
119
93.1k
    // Add existing passes to option.
120
93.1k
    for (RegistryClass *Node = RegistryClass::getList();
121
743k
         Node; 
Node = Node->getNext()649k
) {
122
649k
      this->addLiteralOption(Node->getName(),
123
649k
                      (typename RegistryClass::FunctionPassCtor)Node->getCtor(),
124
649k
                             Node->getDescription());
125
649k
    }
126
93.1k
127
93.1k
    // Make sure we listen for list changes.
128
93.1k
    RegistryClass::setListener(this);
129
93.1k
  }
llvm::RegisterPassParser<llvm::RegisterRegAlloc>::initialize()
Line
Count
Source
116
93.1k
  void initialize() {
117
93.1k
    cl::parser<typename RegistryClass::FunctionPassCtor>::initialize();
118
93.1k
119
93.1k
    // Add existing passes to option.
120
93.1k
    for (RegistryClass *Node = RegistryClass::getList();
121
465k
         Node; 
Node = Node->getNext()372k
) {
122
372k
      this->addLiteralOption(Node->getName(),
123
372k
                      (typename RegistryClass::FunctionPassCtor)Node->getCtor(),
124
372k
                             Node->getDescription());
125
372k
    }
126
93.1k
127
93.1k
    // Make sure we listen for list changes.
128
93.1k
    RegistryClass::setListener(this);
129
93.1k
  }
llvm::RegisterPassParser<llvm::RegisterScheduler>::initialize()
Line
Count
Source
116
93.1k
  void initialize() {
117
93.1k
    cl::parser<typename RegistryClass::FunctionPassCtor>::initialize();
118
93.1k
119
93.1k
    // Add existing passes to option.
120
93.1k
    for (RegistryClass *Node = RegistryClass::getList();
121
600k
         Node; 
Node = Node->getNext()507k
) {
122
507k
      this->addLiteralOption(Node->getName(),
123
507k
                      (typename RegistryClass::FunctionPassCtor)Node->getCtor(),
124
507k
                             Node->getDescription());
125
507k
    }
126
93.1k
127
93.1k
    // Make sure we listen for list changes.
128
93.1k
    RegistryClass::setListener(this);
129
93.1k
  }
130
131
  // Implement the MachinePassRegistryListener callbacks.
132
559k
  void NotifyAdd(StringRef N, MachinePassCtor C, StringRef D) override {
133
559k
    this->addLiteralOption(N, (typename RegistryClass::FunctionPassCtor)C, D);
134
559k
  }
llvm::RegisterPassParser<llvm::MachineSchedRegistry>::NotifyAdd(llvm::StringRef, void* (*)(), llvm::StringRef)
Line
Count
Source
132
372k
  void NotifyAdd(StringRef N, MachinePassCtor C, StringRef D) override {
133
372k
    this->addLiteralOption(N, (typename RegistryClass::FunctionPassCtor)C, D);
134
372k
  }
llvm::RegisterPassParser<llvm::RegisterRegAlloc>::NotifyAdd(llvm::StringRef, void* (*)(), llvm::StringRef)
Line
Count
Source
132
93.1k
  void NotifyAdd(StringRef N, MachinePassCtor C, StringRef D) override {
133
93.1k
    this->addLiteralOption(N, (typename RegistryClass::FunctionPassCtor)C, D);
134
93.1k
  }
llvm::RegisterPassParser<llvm::RegisterScheduler>::NotifyAdd(llvm::StringRef, void* (*)(), llvm::StringRef)
Line
Count
Source
132
93.1k
  void NotifyAdd(StringRef N, MachinePassCtor C, StringRef D) override {
133
93.1k
    this->addLiteralOption(N, (typename RegistryClass::FunctionPassCtor)C, D);
134
93.1k
  }
135
559k
  void NotifyRemove(StringRef N) override {
136
559k
    this->removeLiteralOption(N);
137
559k
  }
llvm::RegisterPassParser<llvm::MachineSchedRegistry>::NotifyRemove(llvm::StringRef)
Line
Count
Source
135
372k
  void NotifyRemove(StringRef N) override {
136
372k
    this->removeLiteralOption(N);
137
372k
  }
llvm::RegisterPassParser<llvm::RegisterRegAlloc>::NotifyRemove(llvm::StringRef)
Line
Count
Source
135
93.1k
  void NotifyRemove(StringRef N) override {
136
93.1k
    this->removeLiteralOption(N);
137
93.1k
  }
llvm::RegisterPassParser<llvm::RegisterScheduler>::NotifyRemove(llvm::StringRef)
Line
Count
Source
135
93.1k
  void NotifyRemove(StringRef N) override {
136
93.1k
    this->removeLiteralOption(N);
137
93.1k
  }
138
};
139
140
} // end namespace llvm
141
142
#endif // LLVM_CODEGEN_MACHINEPASSREGISTRY_H