blob: 2f1ab4d43377ef3b46c2b2bee9219834eb0c4c51 [file] [log] [blame]
Zachary Turner070d5322014-06-12 16:06:51 +00001//===- 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 Zelenko9797e4a2017-09-06 23:05:38 +000013
Zachary Turner070d5322014-06-12 16:06:51 +000014#ifndef LLVM_PASSINFO_H
15#define LLVM_PASSINFO_H
16
Mehdi Amini67f335d2016-10-01 02:56:57 +000017#include "llvm/ADT/StringRef.h"
Zachary Turner070d5322014-06-12 16:06:51 +000018#include <cassert>
19#include <vector>
20
21namespace llvm {
22
23class Pass;
Zachary Turner070d5322014-06-12 16:06:51 +000024
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///
31class PassInfo {
32public:
Eugene Zelenko9797e4a2017-09-06 23:05:38 +000033 using NormalCtor_t = Pass* (*)();
Zachary Turner070d5322014-06-12 16:06:51 +000034
35private:
Mehdi Amini67f335d2016-10-01 02:56:57 +000036 StringRef PassName; // Nice name for Pass
37 StringRef PassArgument; // Command Line argument to run this pass
NAKAMURA Takumideb80b52015-10-05 04:46:30 +000038 const void *PassID;
Eugene Zelenko9797e4a2017-09-06 23:05:38 +000039 const bool IsCFGOnlyPass = false; // Pass only looks at the CFG.
NAKAMURA Takumideb80b52015-10-05 04:46:30 +000040 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 Zelenko9797e4a2017-09-06 23:05:38 +000043 NormalCtor_t NormalCtor = nullptr;
Zachary Turner070d5322014-06-12 16:06:51 +000044
45public:
46 /// PassInfo ctor - Do not call this directly, this should only be invoked
47 /// through RegisterPass.
Mehdi Amini67f335d2016-10-01 02:56:57 +000048 PassInfo(StringRef name, StringRef arg, const void *pi, NormalCtor_t normal,
Francis Visoiu Mistrihae1c8532017-05-18 17:21:13 +000049 bool isCFGOnly, bool is_analysis)
NAKAMURA Takumideb80b52015-10-05 04:46:30 +000050 : PassName(name), PassArgument(arg), PassID(pi), IsCFGOnlyPass(isCFGOnly),
Francis Visoiu Mistrihae1c8532017-05-18 17:21:13 +000051 IsAnalysis(is_analysis), IsAnalysisGroup(false), NormalCtor(normal) {}
Eugene Zelenko9797e4a2017-09-06 23:05:38 +000052
Zachary Turner070d5322014-06-12 16:06:51 +000053 /// 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 Amini6bd185b2016-10-01 04:03:30 +000056 PassInfo(StringRef name, const void *pi)
Eugene Zelenko9797e4a2017-09-06 23:05:38 +000057 : PassName(name), PassID(pi), IsAnalysis(false), IsAnalysisGroup(true) {}
58
59 PassInfo(const PassInfo &) = delete;
60 PassInfo &operator=(const PassInfo &) = delete;
Zachary Turner070d5322014-06-12 16:06:51 +000061
62 /// getPassName - Return the friendly name for the pass, never returns null
Mehdi Amini67f335d2016-10-01 02:56:57 +000063 StringRef getPassName() const { return PassName; }
Zachary Turner070d5322014-06-12 16:06:51 +000064
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 Amini67f335d2016-10-01 02:56:57 +000068 StringRef getPassArgument() const { return PassArgument; }
Zachary Turner070d5322014-06-12 16:06:51 +000069
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 Takumideb80b52015-10-05 04:46:30 +000075 bool isPassID(const void *IDPtr) const { return PassID == IDPtr; }
76
Zachary Turner070d5322014-06-12 16:06:51 +000077 /// isAnalysisGroup - Return true if this is an analysis group, not a normal
78 /// pass.
Zachary Turner070d5322014-06-12 16:06:51 +000079 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 Takumidc0de222015-10-05 04:43:48 +000085
Zachary Turner070d5322014-06-12 16:06:51 +000086 /// 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 Turner070d5322014-06-12 16:06:51 +000089 NormalCtor_t getNormalCtor() const {
90 return NormalCtor;
91 }
92 void setNormalCtor(NormalCtor_t Ctor) {
93 NormalCtor = Ctor;
94 }
95
Zachary Turner070d5322014-06-12 16:06:51 +000096 /// 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 Turner070d5322014-06-12 16:06:51 +0000108 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 Turner070d5322014-06-12 16:06:51 +0000114 const std::vector<const PassInfo*> &getInterfacesImplemented() const {
115 return ItfImpl;
116 }
Zachary Turner070d5322014-06-12 16:06:51 +0000117};
118
Eugene Zelenko9797e4a2017-09-06 23:05:38 +0000119} // end namespace llvm
Zachary Turner070d5322014-06-12 16:06:51 +0000120
Eugene Zelenko9797e4a2017-09-06 23:05:38 +0000121#endif // LLVM_PASSINFO_H