Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/PassInfo.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/PassInfo.h - Pass Info class ------------------------*- 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
// This file defines and implements the PassInfo class.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_PASSINFO_H
14
#define LLVM_PASSINFO_H
15
16
#include "llvm/ADT/StringRef.h"
17
#include <cassert>
18
#include <vector>
19
20
namespace llvm {
21
22
class Pass;
23
24
//===---------------------------------------------------------------------------
25
/// PassInfo class - An instance of this class exists for every pass known by
26
/// the system, and can be obtained from a live Pass by calling its
27
/// getPassInfo() method.  These objects are set up by the RegisterPass<>
28
/// template.
29
///
30
class PassInfo {
31
public:
32
  using NormalCtor_t = Pass* (*)();
33
34
private:
35
  StringRef PassName;     // Nice name for Pass
36
  StringRef PassArgument; // Command Line argument to run this pass
37
  const void *PassID;
38
  const bool IsCFGOnlyPass = false;      // Pass only looks at the CFG.
39
  const bool IsAnalysis;                 // True if an analysis pass.
40
  const bool IsAnalysisGroup;            // True if an analysis group.
41
  std::vector<const PassInfo *> ItfImpl; // Interfaces implemented by this pass
42
  NormalCtor_t NormalCtor = nullptr;
43
44
public:
45
  /// PassInfo ctor - Do not call this directly, this should only be invoked
46
  /// through RegisterPass.
47
  PassInfo(StringRef name, StringRef arg, const void *pi, NormalCtor_t normal,
48
           bool isCFGOnly, bool is_analysis)
49
      : PassName(name), PassArgument(arg), PassID(pi), IsCFGOnlyPass(isCFGOnly),
50
32.8M
        IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal) {}
51
52
  /// PassInfo ctor - Do not call this directly, this should only be invoked
53
  /// through RegisterPass. This version is for use by analysis groups; it
54
  /// does not auto-register the pass.
55
  PassInfo(StringRef name, const void *pi)
56
0
      : PassName(name), PassID(pi), IsAnalysis(false), IsAnalysisGroup(true) {}
57
58
  PassInfo(const PassInfo &) = delete;
59
  PassInfo &operator=(const PassInfo &) = delete;
60
61
  /// getPassName - Return the friendly name for the pass, never returns null
62
217M
  StringRef getPassName() const { return PassName; }
63
64
  /// getPassArgument - Return the command line option that may be passed to
65
  /// 'opt' that will cause this pass to be run.  This will return null if there
66
  /// is no argument.
67
256M
  StringRef getPassArgument() const { return PassArgument; }
68
69
  /// getTypeInfo - Return the id object for the pass...
70
  /// TODO : Rename
71
66.6M
  const void *getTypeInfo() const { return PassID; }
72
73
  /// Return true if this PassID implements the specified ID pointer.
74
0
  bool isPassID(const void *IDPtr) const { return PassID == IDPtr; }
75
76
  /// isAnalysisGroup - Return true if this is an analysis group, not a normal
77
  /// pass.
78
17.2k
  bool isAnalysisGroup() const { return IsAnalysisGroup; }
79
27.4M
  bool isAnalysis() const { return IsAnalysis; }
80
81
  /// isCFGOnlyPass - return true if this pass only looks at the CFG for the
82
  /// function.
83
665M
  bool isCFGOnlyPass() const { return IsCFGOnlyPass; }
84
85
  /// getNormalCtor - Return a pointer to a function, that when called, creates
86
  /// an instance of the pass and returns it.  This pointer may be null if there
87
  /// is no default constructor for the pass.
88
71.1M
  NormalCtor_t getNormalCtor() const {
89
71.1M
    return NormalCtor;
90
71.1M
  }
91
0
  void setNormalCtor(NormalCtor_t Ctor) {
92
0
    NormalCtor = Ctor;
93
0
  }
94
95
  /// createPass() - Use this method to create an instance of this pass.
96
6.32M
  Pass *createPass() const {
97
6.32M
    assert((!isAnalysisGroup() || NormalCtor) &&
98
6.32M
           "No default implementation found for analysis group!");
99
6.32M
    assert(NormalCtor &&
100
6.32M
           "Cannot call createPass on PassInfo without default ctor!");
101
6.32M
    return NormalCtor();
102
6.32M
  }
103
104
  /// addInterfaceImplemented - This method is called when this pass is
105
  /// registered as a member of an analysis group with the RegisterAnalysisGroup
106
  /// template.
107
0
  void addInterfaceImplemented(const PassInfo *ItfPI) {
108
0
    ItfImpl.push_back(ItfPI);
109
0
  }
110
111
  /// getInterfacesImplemented - Return a list of all of the analysis group
112
  /// interfaces implemented by this pass.
113
343M
  const std::vector<const PassInfo*> &getInterfacesImplemented() const {
114
343M
    return ItfImpl;
115
343M
  }
116
};
117
118
} // end namespace llvm
119
120
#endif // LLVM_PASSINFO_H