1818// /
1919// ===----------------------------------------------------------------------===//
2020
21+ #include " llvm/CodeGen/RegUsageInfoPropagate.h"
2122#include " llvm/CodeGen/MachineBasicBlock.h"
2223#include " llvm/CodeGen/MachineFrameInfo.h"
2324#include " llvm/CodeGen/MachineFunctionPass.h"
2425#include " llvm/CodeGen/MachineInstr.h"
2526#include " llvm/CodeGen/MachineRegisterInfo.h"
2627#include " llvm/CodeGen/Passes.h"
2728#include " llvm/CodeGen/RegisterUsageInfo.h"
29+ #include " llvm/IR/Analysis.h"
2830#include " llvm/IR/Module.h"
2931#include " llvm/Pass.h"
32+ #include " llvm/Passes/CodeGenPassBuilder.h"
3033#include " llvm/Support/Debug.h"
3134#include " llvm/Support/raw_ostream.h"
3235
@@ -38,26 +41,16 @@ using namespace llvm;
3841
3942namespace {
4043
41- class RegUsageInfoPropagation : public MachineFunctionPass {
44+ class RegUsageInfoPropagation {
4245public:
43- RegUsageInfoPropagation () : MachineFunctionPass(ID) {
44- PassRegistry &Registry = *PassRegistry::getPassRegistry ();
45- initializeRegUsageInfoPropagationPass (Registry);
46- }
46+ explicit RegUsageInfoPropagation (PhysicalRegisterUsageInfo *PRUI)
47+ : PRUI(PRUI) {}
4748
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);
5950
6051private:
52+ PhysicalRegisterUsageInfo *PRUI;
53+
6154 static void setRegMask (MachineInstr &MI, ArrayRef<uint32_t > RegMask) {
6255 assert (RegMask.size () ==
6356 MachineOperand::getRegMaskSize (MI.getParent ()->getParent ()
@@ -71,15 +64,34 @@ class RegUsageInfoPropagation : public MachineFunctionPass {
7164 }
7265};
7366
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+
7486} // end of anonymous namespace
7587
76- INITIALIZE_PASS_BEGIN (RegUsageInfoPropagation , " reg-usage-propagation" ,
88+ INITIALIZE_PASS_BEGIN (RegUsageInfoPropagationLegacy , " reg-usage-propagation" ,
7789 RUIP_NAME, false , false )
7890INITIALIZE_PASS_DEPENDENCY(PhysicalRegisterUsageInfoWrapperLegacy)
79- INITIALIZE_PASS_END(RegUsageInfoPropagation , " reg-usage-propagation" ,
91+ INITIALIZE_PASS_END(RegUsageInfoPropagationLegacy , " reg-usage-propagation" ,
8092 RUIP_NAME, false , false )
8193
82- char RegUsageInfoPropagation ::ID = 0;
94+ char RegUsageInfoPropagationLegacy ::ID = 0;
8395
8496// Assumes call instructions have a single reference to a function.
8597static const Function *findCalledFunction (const Module &M,
@@ -95,12 +107,29 @@ static const Function *findCalledFunction(const Module &M,
95107 return nullptr ;
96108}
97109
98- bool RegUsageInfoPropagation::runOnMachineFunction (MachineFunction &MF) {
99- const Module &M = *MF.getFunction ().getParent ();
110+ bool RegUsageInfoPropagationLegacy::runOnMachineFunction (MachineFunction &MF) {
100111 PhysicalRegisterUsageInfo *PRUI =
101112 &getAnalysis<PhysicalRegisterUsageInfoWrapperLegacy>().getPRUI ();
102113
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
104133 << " ++++++++++++++++++++ \n " );
105134 LLVM_DEBUG (dbgs () << " MachineFunction : " << MF.getName () << " \n " );
106135
@@ -151,5 +180,5 @@ bool RegUsageInfoPropagation::runOnMachineFunction(MachineFunction &MF) {
151180}
152181
153182FunctionPass *llvm::createRegUsageInfoPropPass () {
154- return new RegUsageInfoPropagation ();
183+ return new RegUsageInfoPropagationLegacy ();
155184}
0 commit comments