18
18
// /
19
19
// ===----------------------------------------------------------------------===//
20
20
21
+ #include " llvm/CodeGen/RegUsageInfoPropagate.h"
21
22
#include " llvm/CodeGen/MachineBasicBlock.h"
22
23
#include " llvm/CodeGen/MachineFrameInfo.h"
23
24
#include " llvm/CodeGen/MachineFunctionPass.h"
24
25
#include " llvm/CodeGen/MachineInstr.h"
25
26
#include " llvm/CodeGen/MachineRegisterInfo.h"
26
27
#include " llvm/CodeGen/Passes.h"
27
28
#include " llvm/CodeGen/RegisterUsageInfo.h"
29
+ #include " llvm/IR/Analysis.h"
28
30
#include " llvm/IR/Module.h"
29
31
#include " llvm/Pass.h"
32
+ #include " llvm/Passes/CodeGenPassBuilder.h"
30
33
#include " llvm/Support/Debug.h"
31
34
#include " llvm/Support/raw_ostream.h"
32
35
@@ -38,26 +41,16 @@ using namespace llvm;
38
41
39
42
namespace {
40
43
41
- class RegUsageInfoPropagation : public MachineFunctionPass {
44
+ class RegUsageInfoPropagation {
42
45
public:
43
- RegUsageInfoPropagation () : MachineFunctionPass(ID) {
44
- PassRegistry &Registry = *PassRegistry::getPassRegistry ();
45
- initializeRegUsageInfoPropagationPass (Registry);
46
- }
46
+ explicit RegUsageInfoPropagation (PhysicalRegisterUsageInfo *PRUI)
47
+ : PRUI(PRUI) {}
47
48
48
- StringRef getPassName () const override { return RUIP_NAME; }
49
-
50
- bool runOnMachineFunction (MachineFunction &MF) override ;
51
-
52
- void getAnalysisUsage (AnalysisUsage &AU) const override {
53
- AU.addRequired <PhysicalRegisterUsageInfoWrapperLegacy>();
54
- AU.setPreservesAll ();
55
- MachineFunctionPass::getAnalysisUsage (AU);
56
- }
57
-
58
- static char ID;
49
+ bool run (MachineFunction &MF);
59
50
60
51
private:
52
+ PhysicalRegisterUsageInfo *PRUI;
53
+
61
54
static void setRegMask (MachineInstr &MI, ArrayRef<uint32_t > RegMask) {
62
55
assert (RegMask.size () ==
63
56
MachineOperand::getRegMaskSize (MI.getParent ()->getParent ()
@@ -71,15 +64,34 @@ class RegUsageInfoPropagation : public MachineFunctionPass {
71
64
}
72
65
};
73
66
67
+ class RegUsageInfoPropagationLegacy : public MachineFunctionPass {
68
+ public:
69
+ static char ID;
70
+ RegUsageInfoPropagationLegacy () : MachineFunctionPass(ID) {
71
+ PassRegistry &Registry = *PassRegistry::getPassRegistry ();
72
+ initializeRegUsageInfoPropagationLegacyPass (Registry);
73
+ }
74
+
75
+ StringRef getPassName () const override { return RUIP_NAME; }
76
+
77
+ bool runOnMachineFunction (MachineFunction &MF) override ;
78
+
79
+ void getAnalysisUsage (AnalysisUsage &AU) const override {
80
+ AU.addRequired <PhysicalRegisterUsageInfoWrapperLegacy>();
81
+ AU.setPreservesAll ();
82
+ MachineFunctionPass::getAnalysisUsage (AU);
83
+ }
84
+ };
85
+
74
86
} // end of anonymous namespace
75
87
76
- INITIALIZE_PASS_BEGIN (RegUsageInfoPropagation , " reg-usage-propagation" ,
88
+ INITIALIZE_PASS_BEGIN (RegUsageInfoPropagationLegacy , " reg-usage-propagation" ,
77
89
RUIP_NAME, false , false )
78
90
INITIALIZE_PASS_DEPENDENCY(PhysicalRegisterUsageInfoWrapperLegacy)
79
- INITIALIZE_PASS_END(RegUsageInfoPropagation , " reg-usage-propagation" ,
91
+ INITIALIZE_PASS_END(RegUsageInfoPropagationLegacy , " reg-usage-propagation" ,
80
92
RUIP_NAME, false , false )
81
93
82
- char RegUsageInfoPropagation ::ID = 0;
94
+ char RegUsageInfoPropagationLegacy ::ID = 0;
83
95
84
96
// Assumes call instructions have a single reference to a function.
85
97
static const Function *findCalledFunction (const Module &M,
@@ -95,12 +107,29 @@ static const Function *findCalledFunction(const Module &M,
95
107
return nullptr ;
96
108
}
97
109
98
- bool RegUsageInfoPropagation::runOnMachineFunction (MachineFunction &MF) {
99
- const Module &M = *MF.getFunction ().getParent ();
110
+ bool RegUsageInfoPropagationLegacy::runOnMachineFunction (MachineFunction &MF) {
100
111
PhysicalRegisterUsageInfo *PRUI =
101
112
&getAnalysis<PhysicalRegisterUsageInfoWrapperLegacy>().getPRUI ();
102
113
103
- LLVM_DEBUG (dbgs () << " ++++++++++++++++++++ " << getPassName ()
114
+ RegUsageInfoPropagation RUIP (PRUI);
115
+ return RUIP.run (MF);
116
+ }
117
+
118
+ PreservedAnalyses
119
+ RegUsageInfoPropagationPass::run (MachineFunction &MF,
120
+ MachineFunctionAnalysisManager &MFAM) {
121
+ Module &MFA = *MF.getFunction ().getParent ();
122
+ auto *PRUI = MFAM.getResult <ModuleAnalysisManagerMachineFunctionProxy>(MF)
123
+ .getCachedResult <PhysicalRegisterUsageAnalysis>(MFA);
124
+ assert (PRUI && " PhysicalRegisterUsageAnalysis not available" );
125
+ RegUsageInfoPropagation (PRUI).run (MF);
126
+ return PreservedAnalyses::all ();
127
+ }
128
+
129
+ bool RegUsageInfoPropagation::run (MachineFunction &MF) {
130
+ const Module &M = *MF.getFunction ().getParent ();
131
+
132
+ LLVM_DEBUG (dbgs () << " ++++++++++++++++++++ " << RUIP_NAME
104
133
<< " ++++++++++++++++++++ \n " );
105
134
LLVM_DEBUG (dbgs () << " MachineFunction : " << MF.getName () << " \n " );
106
135
@@ -151,5 +180,5 @@ bool RegUsageInfoPropagation::runOnMachineFunction(MachineFunction &MF) {
151
180
}
152
181
153
182
FunctionPass *llvm::createRegUsageInfoPropPass () {
154
- return new RegUsageInfoPropagation ();
183
+ return new RegUsageInfoPropagationLegacy ();
155
184
}
0 commit comments