Coverage Report

Created: 2018-07-19 03:59

/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
274k
  MachinePassRegistryListener() = default;
40
274k
  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.04M
      : Name(N), Description(D), Ctor(C) {}
61
62
  // Accessors
63
3.54M
  MachinePassRegistryNode *getNext()      const { return Next; }
64
0
  MachinePassRegistryNode **getNextAddress()    { return &Next; }
65
2.59M
  StringRef getName()                   const { return Name; }
66
2.04M
  StringRef getDescription()            const { return Description; }
67
2.04M
  MachinePassCtor getCtor()               const { return Ctor; }
68
2.04M
  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
274k
  MachinePassRegistryNode *getList()                    { return List; }
89
64.4k
  MachinePassCtor getDefault()                          { return Default; }
90
32.0k
  void setDefault(MachinePassCtor C)                    { Default = C; }
91
  void setDefault(StringRef Name);
92
548k
  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
274k
      : cl::parser<typename RegistryClass::FunctionPassCtor>(O) {}
llvm::RegisterPassParser<llvm::MachineSchedRegistry>::RegisterPassParser(llvm::cl::Option&)
Line
Count
Source
113
91.3k
      : cl::parser<typename RegistryClass::FunctionPassCtor>(O) {}
llvm::RegisterPassParser<llvm::RegisterRegAlloc>::RegisterPassParser(llvm::cl::Option&)
Line
Count
Source
113
91.3k
      : cl::parser<typename RegistryClass::FunctionPassCtor>(O) {}
llvm::RegisterPassParser<llvm::RegisterScheduler>::RegisterPassParser(llvm::cl::Option&)
Line
Count
Source
113
91.3k
      : cl::parser<typename RegistryClass::FunctionPassCtor>(O) {}
114
274k
  ~RegisterPassParser() override { RegistryClass::setListener(nullptr); }
llvm::RegisterPassParser<llvm::MachineSchedRegistry>::~RegisterPassParser()
Line
Count
Source
114
91.3k
  ~RegisterPassParser() override { RegistryClass::setListener(nullptr); }
llvm::RegisterPassParser<llvm::RegisterRegAlloc>::~RegisterPassParser()
Line
Count
Source
114
91.3k
  ~RegisterPassParser() override { RegistryClass::setListener(nullptr); }
llvm::RegisterPassParser<llvm::RegisterScheduler>::~RegisterPassParser()
Line
Count
Source
114
91.3k
  ~RegisterPassParser() override { RegistryClass::setListener(nullptr); }
115
116
274k
  void initialize() {
117
274k
    cl::parser<typename RegistryClass::FunctionPassCtor>::initialize();
118
274k
119
274k
    // Add existing passes to option.
120
274k
    for (RegistryClass *Node = RegistryClass::getList();
121
1.77M
         Node; 
Node = Node->getNext()1.49M
) {
122
1.49M
      this->addLiteralOption(Node->getName(),
123
1.49M
                      (typename RegistryClass::FunctionPassCtor)Node->getCtor(),
124
1.49M
                             Node->getDescription());
125
1.49M
    }
126
274k
127
274k
    // Make sure we listen for list changes.
128
274k
    RegistryClass::setListener(this);
129
274k
  }
llvm::RegisterPassParser<llvm::MachineSchedRegistry>::initialize()
Line
Count
Source
116
91.3k
  void initialize() {
117
91.3k
    cl::parser<typename RegistryClass::FunctionPassCtor>::initialize();
118
91.3k
119
91.3k
    // Add existing passes to option.
120
91.3k
    for (RegistryClass *Node = RegistryClass::getList();
121
728k
         Node; 
Node = Node->getNext()636k
) {
122
636k
      this->addLiteralOption(Node->getName(),
123
636k
                      (typename RegistryClass::FunctionPassCtor)Node->getCtor(),
124
636k
                             Node->getDescription());
125
636k
    }
126
91.3k
127
91.3k
    // Make sure we listen for list changes.
128
91.3k
    RegistryClass::setListener(this);
129
91.3k
  }
llvm::RegisterPassParser<llvm::RegisterRegAlloc>::initialize()
Line
Count
Source
116
91.3k
  void initialize() {
117
91.3k
    cl::parser<typename RegistryClass::FunctionPassCtor>::initialize();
118
91.3k
119
91.3k
    // Add existing passes to option.
120
91.3k
    for (RegistryClass *Node = RegistryClass::getList();
121
456k
         Node; 
Node = Node->getNext()365k
) {
122
365k
      this->addLiteralOption(Node->getName(),
123
365k
                      (typename RegistryClass::FunctionPassCtor)Node->getCtor(),
124
365k
                             Node->getDescription());
125
365k
    }
126
91.3k
127
91.3k
    // Make sure we listen for list changes.
128
91.3k
    RegistryClass::setListener(this);
129
91.3k
  }
llvm::RegisterPassParser<llvm::RegisterScheduler>::initialize()
Line
Count
Source
116
91.3k
  void initialize() {
117
91.3k
    cl::parser<typename RegistryClass::FunctionPassCtor>::initialize();
118
91.3k
119
91.3k
    // Add existing passes to option.
120
91.3k
    for (RegistryClass *Node = RegistryClass::getList();
121
588k
         Node; 
Node = Node->getNext()497k
) {
122
497k
      this->addLiteralOption(Node->getName(),
123
497k
                      (typename RegistryClass::FunctionPassCtor)Node->getCtor(),
124
497k
                             Node->getDescription());
125
497k
    }
126
91.3k
127
91.3k
    // Make sure we listen for list changes.
128
91.3k
    RegistryClass::setListener(this);
129
91.3k
  }
130
131
  // Implement the MachinePassRegistryListener callbacks.
132
548k
  void NotifyAdd(StringRef N, MachinePassCtor C, StringRef D) override {
133
548k
    this->addLiteralOption(N, (typename RegistryClass::FunctionPassCtor)C, D);
134
548k
  }
llvm::RegisterPassParser<llvm::MachineSchedRegistry>::NotifyAdd(llvm::StringRef, void* (*)(), llvm::StringRef)
Line
Count
Source
132
365k
  void NotifyAdd(StringRef N, MachinePassCtor C, StringRef D) override {
133
365k
    this->addLiteralOption(N, (typename RegistryClass::FunctionPassCtor)C, D);
134
365k
  }
llvm::RegisterPassParser<llvm::RegisterRegAlloc>::NotifyAdd(llvm::StringRef, void* (*)(), llvm::StringRef)
Line
Count
Source
132
91.3k
  void NotifyAdd(StringRef N, MachinePassCtor C, StringRef D) override {
133
91.3k
    this->addLiteralOption(N, (typename RegistryClass::FunctionPassCtor)C, D);
134
91.3k
  }
llvm::RegisterPassParser<llvm::RegisterScheduler>::NotifyAdd(llvm::StringRef, void* (*)(), llvm::StringRef)
Line
Count
Source
132
91.3k
  void NotifyAdd(StringRef N, MachinePassCtor C, StringRef D) override {
133
91.3k
    this->addLiteralOption(N, (typename RegistryClass::FunctionPassCtor)C, D);
134
91.3k
  }
135
548k
  void NotifyRemove(StringRef N) override {
136
548k
    this->removeLiteralOption(N);
137
548k
  }
llvm::RegisterPassParser<llvm::MachineSchedRegistry>::NotifyRemove(llvm::StringRef)
Line
Count
Source
135
365k
  void NotifyRemove(StringRef N) override {
136
365k
    this->removeLiteralOption(N);
137
365k
  }
llvm::RegisterPassParser<llvm::RegisterRegAlloc>::NotifyRemove(llvm::StringRef)
Line
Count
Source
135
91.3k
  void NotifyRemove(StringRef N) override {
136
91.3k
    this->removeLiteralOption(N);
137
91.3k
  }
llvm::RegisterPassParser<llvm::RegisterScheduler>::NotifyRemove(llvm::StringRef)
Line
Count
Source
135
91.3k
  void NotifyRemove(StringRef N) override {
136
91.3k
    this->removeLiteralOption(N);
137
91.3k
  }
138
};
139
140
} // end namespace llvm
141
142
#endif // LLVM_CODEGEN_MACHINEPASSREGISTRY_H