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