41
41
#include < algorithm>
42
42
using namespace llvm ;
43
43
44
- char LiveVariables::ID = 0 ;
45
- char &llvm::LiveVariablesID = LiveVariables::ID;
46
- INITIALIZE_PASS_BEGIN (LiveVariables, " livevars" ,
47
- " Live Variable Analysis" , false , false )
48
- INITIALIZE_PASS_DEPENDENCY(UnreachableMachineBlockElim)
49
- INITIALIZE_PASS_END(LiveVariables, " livevars" ,
50
- " Live Variable Analysis" , false , false )
44
+ AnalysisKey LiveVariablesAnalysis::Key;
45
+
46
+ LiveVariablesAnalysis::Result
47
+ LiveVariablesAnalysis::run (MachineFunction &MF,
48
+ MachineFunctionAnalysisManager &) {
49
+ return Result (MF);
50
+ }
51
+
52
+ PreservedAnalyses
53
+ LiveVariablesPrinterPass::run (MachineFunction &MF,
54
+ MachineFunctionAnalysisManager &MFAM) {
55
+ OS << " Live variables in machine function: " << MF.getName () << ' \n ' ;
56
+ MFAM.getResult <LiveVariablesAnalysis>(MF).print (OS);
57
+ return PreservedAnalyses::all ();
58
+ }
51
59
60
+ char LiveVariablesWrapperPass::ID = 0 ;
61
+ char &llvm::LiveVariablesID = LiveVariablesWrapperPass::ID;
62
+ INITIALIZE_PASS_BEGIN (LiveVariablesWrapperPass, " livevars" ,
63
+ " Live Variable Analysis" , false , false )
64
+ INITIALIZE_PASS_DEPENDENCY(UnreachableMachineBlockElim)
65
+ INITIALIZE_PASS_END(LiveVariablesWrapperPass, " livevars" ,
66
+ " Live Variable Analysis" , false , false )
52
67
53
- void LiveVariables ::getAnalysisUsage(AnalysisUsage &AU) const {
68
+ void LiveVariablesWrapperPass ::getAnalysisUsage(AnalysisUsage &AU) const {
54
69
AU.addRequiredID (UnreachableMachineBlockElimID);
55
70
AU.setPreservesAll ();
56
71
MachineFunctionPass::getAnalysisUsage (AU);
57
72
}
58
73
74
+ LiveVariables::LiveVariables (MachineFunction &MF)
75
+ : MF(&MF), MRI(&MF.getRegInfo()), TRI(MF.getSubtarget().getRegisterInfo()) {
76
+ analyze (MF);
77
+ }
78
+
79
+ void LiveVariables::print (raw_ostream &OS) const {
80
+ for (size_t I = 0 , E = VirtRegInfo.size (); I != E; ++I) {
81
+ const Register Reg = Register::index2VirtReg (I);
82
+ OS << " Virtual register '%" << I << " ':\n " ;
83
+ VirtRegInfo[Reg].print (OS);
84
+ }
85
+ }
86
+
59
87
MachineInstr *
60
88
LiveVariables::VarInfo::findKill (const MachineBasicBlock *MBB) const {
61
89
for (MachineInstr *MI : Kills)
@@ -64,20 +92,22 @@ LiveVariables::VarInfo::findKill(const MachineBasicBlock *MBB) const {
64
92
return nullptr ;
65
93
}
66
94
67
- #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
68
- LLVM_DUMP_METHOD void LiveVariables::VarInfo::dump () const {
69
- dbgs () << " Alive in blocks: " ;
95
+ void LiveVariables::VarInfo::print (raw_ostream &OS) const {
96
+ OS << " Alive in blocks: " ;
70
97
for (unsigned AB : AliveBlocks)
71
- dbgs () << AB << " , " ;
72
- dbgs () << " \n Killed by:" ;
98
+ OS << AB << " , " ;
99
+ OS << " \n Killed by:" ;
73
100
if (Kills.empty ())
74
- dbgs () << " No instructions.\n " ;
101
+ OS << " No instructions.\n \n" ;
75
102
else {
76
103
for (unsigned i = 0 , e = Kills.size (); i != e; ++i)
77
- dbgs () << " \n #" << i << " : " << *Kills[i];
78
- dbgs () << " \n " ;
104
+ OS << " \n #" << i << " : " << *Kills[i];
105
+ OS << " \n " ;
79
106
}
80
107
}
108
+
109
+ #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
110
+ LLVM_DUMP_METHOD void LiveVariables::VarInfo::dump () const { print (dbgs ()); }
81
111
#endif
82
112
83
113
// / getVarInfo - Get (possibly creating) a VarInfo object for the given vreg.
@@ -595,7 +625,7 @@ void LiveVariables::runOnBlock(MachineBasicBlock *MBB, unsigned NumRegs) {
595
625
HandlePhysRegDef (i, nullptr , Defs);
596
626
}
597
627
598
- bool LiveVariables::runOnMachineFunction (MachineFunction &mf) {
628
+ void LiveVariables::analyze (MachineFunction &mf) {
599
629
MF = &mf;
600
630
MRI = &mf.getRegInfo ();
601
631
TRI = MF->getSubtarget ().getRegisterInfo ();
@@ -649,8 +679,6 @@ bool LiveVariables::runOnMachineFunction(MachineFunction &mf) {
649
679
PhysRegDef.clear ();
650
680
PhysRegUse.clear ();
651
681
PHIVarInfo.clear ();
652
-
653
- return false ;
654
682
}
655
683
656
684
void LiveVariables::recomputeForSingleDefVirtReg (Register Reg) {
0 commit comments