@@ -35,27 +35,33 @@ using namespace llvm;
3535STATISTIC (NumAssigned , " Number of registers assigned" );
3636STATISTIC (NumUnassigned , " Number of registers unassigned" );
3737
38- char LiveRegMatrix ::ID = 0 ;
39- INITIALIZE_PASS_BEGIN (LiveRegMatrix , " liveregmatrix" ,
38+ char LiveRegMatrixWrapperPass ::ID = 0 ;
39+ INITIALIZE_PASS_BEGIN (LiveRegMatrixWrapperPass , " liveregmatrix" ,
4040 " Live Register Matrix" , false , false )
4141INITIALIZE_PASS_DEPENDENCY(LiveIntervalsWrapperPass)
4242INITIALIZE_PASS_DEPENDENCY(VirtRegMapWrapperPass)
43- INITIALIZE_PASS_END(LiveRegMatrix , " liveregmatrix" ,
43+ INITIALIZE_PASS_END(LiveRegMatrixWrapperPass , " liveregmatrix" ,
4444 " Live Register Matrix" , false , false )
4545
46- LiveRegMatrix::LiveRegMatrix() : MachineFunctionPass(ID) {}
47-
48- void LiveRegMatrix::getAnalysisUsage (AnalysisUsage &AU) const {
46+ void LiveRegMatrixWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
4947 AU.setPreservesAll ();
5048 AU.addRequiredTransitive <LiveIntervalsWrapperPass>();
5149 AU.addRequiredTransitive <VirtRegMapWrapperPass>();
5250 MachineFunctionPass::getAnalysisUsage (AU);
5351}
5452
55- bool LiveRegMatrix::runOnMachineFunction (MachineFunction &MF) {
53+ bool LiveRegMatrixWrapperPass::runOnMachineFunction (MachineFunction &MF) {
54+ auto *LIS = &getAnalysis<LiveIntervalsWrapperPass>().getLIS ();
55+ auto *VRM = &getAnalysis<VirtRegMapWrapperPass>().getVRM ();
56+ LRM.init (MF, LIS, VRM);
57+ return false ;
58+ }
59+
60+ void LiveRegMatrix::init (MachineFunction &MF, LiveIntervals *pLIS,
61+ VirtRegMap *pVRM) {
5662 TRI = MF.getSubtarget ().getRegisterInfo ();
57- LIS = &getAnalysis<LiveIntervalsWrapperPass>(). getLIS () ;
58- VRM = &getAnalysis<VirtRegMapWrapperPass>(). getVRM () ;
63+ LIS = pLIS ;
64+ VRM = pVRM ;
5965
6066 unsigned NumRegUnits = TRI->getNumRegUnits ();
6167 if (NumRegUnits != Matrix.size ())
@@ -64,9 +70,10 @@ bool LiveRegMatrix::runOnMachineFunction(MachineFunction &MF) {
6470
6571 // Make sure no stale queries get reused.
6672 invalidateVirtRegs ();
67- return false ;
6873}
6974
75+ void LiveRegMatrixWrapperPass::releaseMemory () { LRM.releaseMemory (); }
76+
7077void LiveRegMatrix::releaseMemory () {
7178 for (unsigned i = 0 , e = Matrix.size (); i != e; ++i) {
7279 Matrix[i].clear ();
@@ -246,3 +253,14 @@ Register LiveRegMatrix::getOneVReg(unsigned PhysReg) const {
246253
247254 return MCRegister::NoRegister;
248255}
256+
257+ AnalysisKey LiveRegMatrixAnalysis::Key;
258+
259+ LiveRegMatrix LiveRegMatrixAnalysis::run (MachineFunction &MF,
260+ MachineFunctionAnalysisManager &MFAM) {
261+ auto &LIS = MFAM.getResult <LiveIntervalsAnalysis>(MF);
262+ auto &VRM = MFAM.getResult <VirtRegMapAnalysis>(MF);
263+ LiveRegMatrix LRM;
264+ LRM.init (MF, &LIS, &VRM);
265+ return LRM;
266+ }
0 commit comments