21
21
#include " llvm/ADT/StringRef.h"
22
22
#include " llvm/CodeGen/MachineBasicBlock.h"
23
23
#include " llvm/IR/Module.h"
24
+ #include " llvm/IR/PassManager.h"
24
25
#include " llvm/InitializePasses.h"
25
26
#include " llvm/Pass.h"
26
27
#include " llvm/Support/Error.h"
27
28
#include " llvm/Support/LineIterator.h"
28
29
#include " llvm/Support/MemoryBuffer.h"
30
+ #include " llvm/Target/TargetMachine.h"
31
+
29
32
using namespace llvm ;
30
33
31
34
namespace llvm {
@@ -72,25 +75,13 @@ template <> struct DenseMapInfo<UniqueBBID> {
72
75
}
73
76
};
74
77
75
- class BasicBlockSectionsProfileReader : public ImmutablePass {
78
+ class BasicBlockSectionsProfileReader {
76
79
public:
77
- static char ID;
78
-
80
+ friend class BasicBlockSectionsProfileReaderWrapperPass ;
79
81
BasicBlockSectionsProfileReader (const MemoryBuffer *Buf)
80
- : ImmutablePass(ID), MBuf(Buf),
81
- LineIt (*Buf, /* SkipBlanks=*/ true , /* CommentMarker=*/ ' #' ) {
82
- initializeBasicBlockSectionsProfileReaderPass (
83
- *PassRegistry::getPassRegistry ());
84
- };
82
+ : MBuf(Buf), LineIt(*Buf, /* SkipBlanks=*/ true , /* CommentMarker=*/ ' #' ){};
85
83
86
- BasicBlockSectionsProfileReader () : ImmutablePass(ID) {
87
- initializeBasicBlockSectionsProfileReaderPass (
88
- *PassRegistry::getPassRegistry ());
89
- }
90
-
91
- StringRef getPassName () const override {
92
- return " Basic Block Sections Profile Reader" ;
93
- }
84
+ BasicBlockSectionsProfileReader (){};
94
85
95
86
// Returns true if basic block sections profile exist for function \p
96
87
// FuncName.
@@ -109,10 +100,6 @@ class BasicBlockSectionsProfileReader : public ImmutablePass {
109
100
SmallVector<SmallVector<unsigned >>
110
101
getClonePathsForFunction (StringRef FuncName) const ;
111
102
112
- // Initializes the FunctionNameToDIFilename map for the current module and
113
- // then reads the profile for the matching functions.
114
- bool doInitialization (Module &M) override ;
115
-
116
103
private:
117
104
StringRef getAliasName (StringRef FuncName) const {
118
105
auto R = FuncAliasMap.find (FuncName);
@@ -170,7 +157,61 @@ class BasicBlockSectionsProfileReader : public ImmutablePass {
170
157
// sections profile. \p Buf is a memory buffer that contains the list of
171
158
// functions and basic block ids to selectively enable basic block sections.
172
159
ImmutablePass *
173
- createBasicBlockSectionsProfileReaderPass (const MemoryBuffer *Buf);
160
+ createBasicBlockSectionsProfileReaderWrapperPass (const MemoryBuffer *Buf);
161
+
162
+ // / Analysis pass providing the \c BasicBlockSectionsProfileReader.
163
+ // /
164
+ // / Note that this pass's result cannot be invalidated, it is immutable for the
165
+ // / life of the module.
166
+ class BasicBlockSectionsProfileReaderAnalysis
167
+ : public AnalysisInfoMixin<BasicBlockSectionsProfileReaderAnalysis> {
168
+
169
+ public:
170
+ static AnalysisKey Key;
171
+ typedef BasicBlockSectionsProfileReader Result;
172
+ BasicBlockSectionsProfileReaderAnalysis (const TargetMachine *TM) : TM(TM) {}
173
+
174
+ Result run (Function &F, FunctionAnalysisManager &AM);
175
+
176
+ private:
177
+ const TargetMachine *TM;
178
+ };
179
+
180
+ class BasicBlockSectionsProfileReaderWrapperPass : public ImmutablePass {
181
+ public:
182
+ static char ID;
183
+ BasicBlockSectionsProfileReader BBSPR;
184
+
185
+ BasicBlockSectionsProfileReaderWrapperPass (const MemoryBuffer *Buf)
186
+ : ImmutablePass(ID), BBSPR(BasicBlockSectionsProfileReader(Buf)) {
187
+ initializeBasicBlockSectionsProfileReaderWrapperPassPass (
188
+ *PassRegistry::getPassRegistry ());
189
+ };
190
+
191
+ BasicBlockSectionsProfileReaderWrapperPass ()
192
+ : ImmutablePass(ID), BBSPR(BasicBlockSectionsProfileReader()) {
193
+ initializeBasicBlockSectionsProfileReaderWrapperPassPass (
194
+ *PassRegistry::getPassRegistry ());
195
+ }
196
+
197
+ StringRef getPassName () const override {
198
+ return " Basic Block Sections Profile Reader" ;
199
+ }
200
+
201
+ bool isFunctionHot (StringRef FuncName) const ;
202
+
203
+ std::pair<bool , SmallVector<BBClusterInfo>>
204
+ getClusterInfoForFunction (StringRef FuncName) const ;
205
+
206
+ SmallVector<SmallVector<unsigned >>
207
+ getClonePathsForFunction (StringRef FuncName) const ;
208
+
209
+ // Initializes the FunctionNameToDIFilename map for the current module and
210
+ // then reads the profile for the matching functions.
211
+ bool doInitialization (Module &M) override ;
212
+
213
+ BasicBlockSectionsProfileReader &getBBSPR ();
214
+ };
174
215
175
216
} // namespace llvm
176
217
#endif // LLVM_CODEGEN_BASICBLOCKSECTIONSPROFILEREADER_H
0 commit comments