2121#include " llvm/ADT/StringRef.h"
2222#include " llvm/CodeGen/MachineBasicBlock.h"
2323#include " llvm/IR/Module.h"
24+ #include " llvm/IR/PassManager.h"
2425#include " llvm/InitializePasses.h"
2526#include " llvm/Pass.h"
2627#include " llvm/Support/Error.h"
2728#include " llvm/Support/LineIterator.h"
2829#include " llvm/Support/MemoryBuffer.h"
30+ #include " llvm/Target/TargetMachine.h"
31+
2932using namespace llvm ;
3033
3134namespace llvm {
@@ -72,25 +75,13 @@ template <> struct DenseMapInfo<UniqueBBID> {
7275 }
7376};
7477
75- class BasicBlockSectionsProfileReader : public ImmutablePass {
78+ class BasicBlockSectionsProfileReader {
7679public:
77- static char ID;
78-
80+ friend class BasicBlockSectionsProfileReaderWrapperPass ;
7981 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=*/ ' #' ){};
8583
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 (){};
9485
9586 // Returns true if basic block sections profile exist for function \p
9687 // FuncName.
@@ -109,10 +100,6 @@ class BasicBlockSectionsProfileReader : public ImmutablePass {
109100 SmallVector<SmallVector<unsigned >>
110101 getClonePathsForFunction (StringRef FuncName) const ;
111102
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-
116103private:
117104 StringRef getAliasName (StringRef FuncName) const {
118105 auto R = FuncAliasMap.find (FuncName);
@@ -170,7 +157,61 @@ class BasicBlockSectionsProfileReader : public ImmutablePass {
170157// sections profile. \p Buf is a memory buffer that contains the list of
171158// functions and basic block ids to selectively enable basic block sections.
172159ImmutablePass *
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+ };
174215
175216} // namespace llvm
176217#endif // LLVM_CODEGEN_BASICBLOCKSECTIONSPROFILEREADER_H
0 commit comments