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 TargetMachine ;
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 TargetMachine &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,10 @@ 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 ;
53+
54+ bool invalidate (Module &M, const PreservedAnalyses &PA,
55+ ModuleAnalysisManager::Invalidator &Inv);
5956
6057private:
6158 // / A Dense map from Function * to RegMask.
@@ -66,6 +63,52 @@ class PhysicalRegisterUsageInfo : public ImmutablePass {
6663 const TargetMachine *TM = nullptr ;
6764};
6865
66+ class PhysicalRegisterUsageInfoWrapperLegacy : public ImmutablePass {
67+ std::unique_ptr<PhysicalRegisterUsageInfo> PRUI;
68+
69+ public:
70+ static char ID;
71+ PhysicalRegisterUsageInfoWrapperLegacy () : ImmutablePass(ID) {
72+ initializePhysicalRegisterUsageInfoWrapperLegacyPass (
73+ *PassRegistry::getPassRegistry ());
74+ }
75+
76+ PhysicalRegisterUsageInfo &getPRUI () { return *PRUI; }
77+ const PhysicalRegisterUsageInfo &getPRUI () const { return *PRUI; }
78+
79+ bool doInitialization (Module &M) override {
80+ PRUI.reset (new PhysicalRegisterUsageInfo ());
81+ return PRUI->doInitialization (M);
82+ }
83+
84+ bool doFinalization (Module &M) override { return PRUI->doFinalization (M); }
85+
86+ void print (raw_ostream &OS, const Module *M = nullptr ) const override {
87+ PRUI->print (OS, M);
88+ }
89+ };
90+
91+ class PhysicalRegisterUsageAnalysis
92+ : public AnalysisInfoMixin<PhysicalRegisterUsageAnalysis> {
93+ friend AnalysisInfoMixin<PhysicalRegisterUsageAnalysis>;
94+ static AnalysisKey Key;
95+
96+ public:
97+ using Result = PhysicalRegisterUsageInfo;
98+
99+ PhysicalRegisterUsageInfo run (Module &M, ModuleAnalysisManager &);
100+ };
101+
102+ class PhysicalRegisterUsageInfoPrinterPass
103+ : public PassInfoMixin<PhysicalRegisterUsageInfoPrinterPass> {
104+ raw_ostream &OS;
105+
106+ public:
107+ explicit PhysicalRegisterUsageInfoPrinterPass (raw_ostream &OS) : OS(OS) {}
108+ PreservedAnalyses run (Module &M, ModuleAnalysisManager &AM);
109+ static bool isRequired () { return true ; }
110+ };
111+
69112} // end namespace llvm
70113
71114#endif // LLVM_CODEGEN_REGISTERUSAGEINFO_H
0 commit comments