Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Analysis/RegionPass.h
Line
Count
Source (jump to first uncovered line)
1
//===- RegionPass.h - RegionPass class --------------------------*- 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 defines the RegionPass class. All region based analysis,
11
// optimization and transformation passes are derived from RegionPass.
12
// This class is implemented following the some ideas of the LoopPass.h class.
13
//
14
//===----------------------------------------------------------------------===//
15
16
#ifndef LLVM_ANALYSIS_REGIONPASS_H
17
#define LLVM_ANALYSIS_REGIONPASS_H
18
19
#include "llvm/Analysis/RegionInfo.h"
20
#include "llvm/IR/Function.h"
21
#include "llvm/IR/LegacyPassManagers.h"
22
#include "llvm/Pass.h"
23
#include <deque>
24
25
namespace llvm {
26
27
class RGPassManager;
28
class Function;
29
30
//===----------------------------------------------------------------------===//
31
/// A pass that runs on each Region in a function.
32
///
33
/// RegionPass is managed by RGPassManager.
34
class RegionPass : public Pass {
35
public:
36
6.02k
  explicit RegionPass(char &pid) : Pass(PT_Region, pid) {}
37
38
  //===--------------------------------------------------------------------===//
39
  /// @name To be implemented by every RegionPass
40
  ///
41
  //@{
42
  /// Run the pass on a specific Region
43
  ///
44
  /// Accessing regions not contained in the current region is not allowed.
45
  ///
46
  /// @param R The region this pass is run on.
47
  /// @param RGM The RegionPassManager that manages this Pass.
48
  ///
49
  /// @return True if the pass modifies this Region.
50
  virtual bool runOnRegion(Region *R, RGPassManager &RGM) = 0;
51
52
  /// Get a pass to print the LLVM IR in the region.
53
  ///
54
  /// @param O      The output stream to print the Region.
55
  /// @param Banner The banner to separate different printed passes.
56
  ///
57
  /// @return The pass to print the LLVM IR in the region.
58
  Pass *createPrinterPass(raw_ostream &O,
59
                          const std::string &Banner) const override;
60
61
  using llvm::Pass::doInitialization;
62
  using llvm::Pass::doFinalization;
63
64
14.3k
  virtual bool doInitialization(Region *R, RGPassManager &RGM) { return false; }
65
26.1k
  virtual bool doFinalization() { return false; }
66
  //@}
67
68
  //===--------------------------------------------------------------------===//
69
  /// @name PassManager API
70
  ///
71
  //@{
72
  void preparePassManager(PMStack &PMS) override;
73
74
  void assignPassManager(PMStack &PMS,
75
                         PassManagerType PMT = PMT_RegionPassManager) override;
76
77
29.7k
  PassManagerType getPotentialPassManagerType() const override {
78
29.7k
    return PMT_RegionPassManager;
79
29.7k
  }
80
  //@}
81
82
protected:
83
  /// Optional passes call this function to check whether the pass should be
84
  /// skipped. This is the case when optimization bisect is over the limit.
85
  bool skipRegion(Region &R) const;
86
};
87
88
/// The pass manager to schedule RegionPasses.
89
class RGPassManager : public FunctionPass, public PMDataManager {
90
  std::deque<Region*> RQ;
91
  bool skipThisRegion;
92
  bool redoThisRegion;
93
  RegionInfo *RI;
94
  Region *CurrentRegion;
95
96
public:
97
  static char ID;
98
  explicit RGPassManager();
99
100
  /// Execute all of the passes scheduled for execution.
101
  ///
102
  /// @return True if any of the passes modifies the function.
103
  bool runOnFunction(Function &F) override;
104
105
  /// Pass Manager itself does not invalidate any analysis info.
106
  /// RGPassManager needs RegionInfo.
107
  void getAnalysisUsage(AnalysisUsage &Info) const override;
108
109
0
  StringRef getPassName() const override { return "Region Pass Manager"; }
110
111
3.41k
  PMDataManager *getAsPMDataManager() override { return this; }
112
10.7k
  Pass *getAsPass() override { return this; }
113
114
  /// Print passes managed by this manager.
115
  void dumpPassStructure(unsigned Offset) override;
116
117
  /// Get passes contained by this manager.
118
101k
  Pass *getContainedPass(unsigned N) {
119
101k
    assert(N < PassVector.size() && "Pass number out of range!");
120
101k
    Pass *FP = static_cast<Pass *>(PassVector[N]);
121
101k
    return FP;
122
101k
  }
123
124
12.4k
  PassManagerType getPassManagerType() const override {
125
12.4k
    return PMT_RegionPassManager;
126
12.4k
  }
127
};
128
129
} // End llvm namespace
130
131
#endif