2020
2121#include " llvm/ADT/ArrayRef.h"
2222#include " llvm/ADT/DenseMap.h"
23+ #include " llvm/IR/PassManager.h"
2324#include " llvm/InitializePasses.h"
2425#include " llvm/Pass.h"
2526#include " llvm/PassRegistry.h"
@@ -31,21 +32,14 @@ namespace llvm {
3132class Function ;
3233class LLVMTargetMachine ;
3334
34- class PhysicalRegisterUsageInfo : public ImmutablePass {
35+ class PhysicalRegisterUsageInfo {
3536public:
36- static char ID;
37-
38- PhysicalRegisterUsageInfo () : ImmutablePass(ID) {
39- PassRegistry &Registry = *PassRegistry::getPassRegistry ();
40- initializePhysicalRegisterUsageInfoPass (Registry);
41- }
42-
4337 // / Set TargetMachine which is used to print analysis.
4438 void setTargetMachine (const LLVMTargetMachine &TM);
4539
46- bool doInitialization (Module &M) override ;
40+ bool doInitialization (Module &M);
4741
48- bool doFinalization (Module &M) override ;
42+ bool doFinalization (Module &M);
4943
5044 // / To store RegMask for given Function *.
5145 void storeUpdateRegUsageInfo (const Function &FP,
@@ -55,7 +49,7 @@ class PhysicalRegisterUsageInfo : public ImmutablePass {
5549 // / array if function is not known.
5650 ArrayRef<uint32_t > getRegUsageInfo (const Function &FP);
5751
58- void print (raw_ostream &OS, const Module *M = nullptr ) const override ;
52+ void print (raw_ostream &OS, const Module *M = nullptr ) const ;
5953
6054private:
6155 // / A Dense map from Function * to RegMask.
@@ -66,6 +60,52 @@ class PhysicalRegisterUsageInfo : public ImmutablePass {
6660 const LLVMTargetMachine *TM = nullptr ;
6761};
6862
63+ class PhysicalRegisterUsageInfoWrapperLegacy : public ImmutablePass {
64+ std::unique_ptr<PhysicalRegisterUsageInfo> PRUI;
65+
66+ public:
67+ static char ID;
68+ PhysicalRegisterUsageInfoWrapperLegacy () : ImmutablePass(ID) {
69+ initializePhysicalRegisterUsageInfoWrapperLegacyPass (
70+ *PassRegistry::getPassRegistry ());
71+ }
72+
73+ PhysicalRegisterUsageInfo &getPRUI () { return *PRUI; }
74+ const PhysicalRegisterUsageInfo &getPRUI () const { return *PRUI; }
75+
76+ bool doInitialization (Module &M) override {
77+ PRUI.reset (new PhysicalRegisterUsageInfo ());
78+ return PRUI->doInitialization (M);
79+ }
80+
81+ bool doFinalization (Module &M) override { return PRUI->doFinalization (M); }
82+
83+ void print (raw_ostream &OS, const Module *M = nullptr ) const override {
84+ PRUI->print (OS, M);
85+ }
86+ };
87+
88+ class PhysicalRegisterUsageInfoAnalysis
89+ : public AnalysisInfoMixin<PhysicalRegisterUsageInfoAnalysis> {
90+ friend AnalysisInfoMixin<PhysicalRegisterUsageInfoAnalysis>;
91+ static AnalysisKey Key;
92+
93+ public:
94+ using Result = PhysicalRegisterUsageInfo;
95+
96+ PhysicalRegisterUsageInfo run (Module &M, ModuleAnalysisManager &);
97+ };
98+
99+ class PhysicalRegisterUsageInfoPrinterPass
100+ : public PassInfoMixin<PhysicalRegisterUsageInfoPrinterPass> {
101+ raw_ostream &OS;
102+
103+ public:
104+ explicit PhysicalRegisterUsageInfoPrinterPass (raw_ostream &OS) : OS(OS) {}
105+ PreservedAnalyses run (Module &M, ModuleAnalysisManager &AM);
106+ static bool isRequired () { return true ; }
107+ };
108+
69109} // end namespace llvm
70110
71111#endif // LLVM_CODEGEN_REGISTERUSAGEINFO_H
0 commit comments