Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 1 | //===-- LiveVariables.cpp - Live Variable Analysis for Machine Code -------===// |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 5cdfbad | 2003-05-07 20:08:36 +0000 | [diff] [blame] | 10 | // This file implements the LiveVariable analysis pass. For each machine |
| 11 | // instruction in the function, this pass calculates the set of registers that |
| 12 | // are immediately dead after the instruction (i.e., the instruction calculates |
| 13 | // the value, but it is never used) and the set of registers that are used by |
| 14 | // the instruction, but are never used after the instruction (i.e., they are |
| 15 | // killed). |
| 16 | // |
| 17 | // This class computes live variables using are sparse implementation based on |
| 18 | // the machine code SSA form. This class computes live variable information for |
| 19 | // each virtual and _register allocatable_ physical register in a function. It |
| 20 | // uses the dominance properties of SSA form to efficiently compute live |
| 21 | // variables for virtual registers, and assumes that physical registers are only |
| 22 | // live within a single basic block (allowing it to do a single local analysis |
| 23 | // to resolve physical register lifetimes in each basic block). If a physical |
| 24 | // register is not register allocatable, it is not tracked. This is useful for |
| 25 | // things like the stack pointer and condition codes. |
| 26 | // |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 27 | //===----------------------------------------------------------------------===// |
| 28 | |
| 29 | #include "llvm/CodeGen/LiveVariables.h" |
| 30 | #include "llvm/CodeGen/MachineInstr.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Owen Anderson | bd3ba46 | 2008-08-04 23:54:43 +0000 | [diff] [blame] | 32 | #include "llvm/CodeGen/Passes.h" |
David Greene | 1d44df6 | 2010-01-04 23:02:10 +0000 | [diff] [blame] | 33 | #include "llvm/Support/Debug.h" |
Chris Lattner | 3501fea | 2003-01-14 22:00:31 +0000 | [diff] [blame] | 34 | #include "llvm/Target/TargetInstrInfo.h" |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 35 | #include "llvm/Target/TargetMachine.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 36 | #include "llvm/ADT/DepthFirstIterator.h" |
Evan Cheng | 0410407 | 2007-06-27 05:23:00 +0000 | [diff] [blame] | 37 | #include "llvm/ADT/SmallPtrSet.h" |
Owen Anderson | bffdf66 | 2008-06-27 07:05:59 +0000 | [diff] [blame] | 38 | #include "llvm/ADT/SmallSet.h" |
Reid Spencer | 551ccae | 2004-09-01 22:55:40 +0000 | [diff] [blame] | 39 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | 657b4d1 | 2005-08-24 00:09:33 +0000 | [diff] [blame] | 40 | #include <algorithm> |
Chris Lattner | 49a5aaa | 2004-01-30 22:08:53 +0000 | [diff] [blame] | 41 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 42 | |
Devang Patel | 1997473 | 2007-05-03 01:11:54 +0000 | [diff] [blame] | 43 | char LiveVariables::ID = 0; |
Owen Anderson | 2ab36d3 | 2010-10-12 19:48:12 +0000 | [diff] [blame] | 44 | INITIALIZE_PASS_BEGIN(LiveVariables, "livevars", |
| 45 | "Live Variable Analysis", false, false) |
| 46 | INITIALIZE_PASS_DEPENDENCY(UnreachableMachineBlockElim) |
| 47 | INITIALIZE_PASS_END(LiveVariables, "livevars", |
Owen Anderson | ce665bd | 2010-10-07 22:25:06 +0000 | [diff] [blame] | 48 | "Live Variable Analysis", false, false) |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 49 | |
Owen Anderson | bd3ba46 | 2008-08-04 23:54:43 +0000 | [diff] [blame] | 50 | |
| 51 | void LiveVariables::getAnalysisUsage(AnalysisUsage &AU) const { |
| 52 | AU.addRequiredID(UnreachableMachineBlockElimID); |
| 53 | AU.setPreservesAll(); |
Dan Gohman | ad2afc2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 54 | MachineFunctionPass::getAnalysisUsage(AU); |
Owen Anderson | bd3ba46 | 2008-08-04 23:54:43 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Jakob Stoklund Olesen | f235f13 | 2009-11-10 22:01:05 +0000 | [diff] [blame] | 57 | MachineInstr * |
| 58 | LiveVariables::VarInfo::findKill(const MachineBasicBlock *MBB) const { |
| 59 | for (unsigned i = 0, e = Kills.size(); i != e; ++i) |
| 60 | if (Kills[i]->getParent() == MBB) |
| 61 | return Kills[i]; |
| 62 | return NULL; |
| 63 | } |
| 64 | |
Chris Lattner | dacceef | 2006-01-04 05:40:30 +0000 | [diff] [blame] | 65 | void LiveVariables::VarInfo::dump() const { |
David Greene | 1d44df6 | 2010-01-04 23:02:10 +0000 | [diff] [blame] | 66 | dbgs() << " Alive in blocks: "; |
Jeffrey Yasskin | 493a3d0 | 2009-05-26 18:27:15 +0000 | [diff] [blame] | 67 | for (SparseBitVector<>::iterator I = AliveBlocks.begin(), |
| 68 | E = AliveBlocks.end(); I != E; ++I) |
David Greene | 1d44df6 | 2010-01-04 23:02:10 +0000 | [diff] [blame] | 69 | dbgs() << *I << ", "; |
| 70 | dbgs() << "\n Killed by:"; |
Chris Lattner | dacceef | 2006-01-04 05:40:30 +0000 | [diff] [blame] | 71 | if (Kills.empty()) |
David Greene | 1d44df6 | 2010-01-04 23:02:10 +0000 | [diff] [blame] | 72 | dbgs() << " No instructions.\n"; |
Chris Lattner | dacceef | 2006-01-04 05:40:30 +0000 | [diff] [blame] | 73 | else { |
| 74 | for (unsigned i = 0, e = Kills.size(); i != e; ++i) |
David Greene | 1d44df6 | 2010-01-04 23:02:10 +0000 | [diff] [blame] | 75 | dbgs() << "\n #" << i << ": " << *Kills[i]; |
| 76 | dbgs() << "\n"; |
Chris Lattner | dacceef | 2006-01-04 05:40:30 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
Bill Wendling | 90a3868 | 2008-02-20 06:10:21 +0000 | [diff] [blame] | 80 | /// getVarInfo - Get (possibly creating) a VarInfo object for the given vreg. |
Chris Lattner | fb2cb69 | 2003-05-12 14:24:00 +0000 | [diff] [blame] | 81 | LiveVariables::VarInfo &LiveVariables::getVarInfo(unsigned RegIdx) { |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 82 | assert(TargetRegisterInfo::isVirtualRegister(RegIdx) && |
Chris Lattner | fb2cb69 | 2003-05-12 14:24:00 +0000 | [diff] [blame] | 83 | "getVarInfo: not a virtual register!"); |
Jakob Stoklund Olesen | b421c56 | 2011-01-08 23:10:57 +0000 | [diff] [blame] | 84 | VirtRegInfo.grow(RegIdx); |
Jeffrey Yasskin | 493a3d0 | 2009-05-26 18:27:15 +0000 | [diff] [blame] | 85 | return VirtRegInfo[RegIdx]; |
Chris Lattner | fb2cb69 | 2003-05-12 14:24:00 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Owen Anderson | 40a627d | 2008-01-15 22:58:11 +0000 | [diff] [blame] | 88 | void LiveVariables::MarkVirtRegAliveInBlock(VarInfo& VRInfo, |
| 89 | MachineBasicBlock *DefBlock, |
Evan Cheng | 5618490 | 2007-05-08 19:00:00 +0000 | [diff] [blame] | 90 | MachineBasicBlock *MBB, |
| 91 | std::vector<MachineBasicBlock*> &WorkList) { |
Chris Lattner | 8ba9771 | 2004-07-01 04:29:47 +0000 | [diff] [blame] | 92 | unsigned BBNum = MBB->getNumber(); |
Owen Anderson | 7047dd4 | 2008-01-15 22:02:46 +0000 | [diff] [blame] | 93 | |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 94 | // Check to see if this basic block is one of the killing blocks. If so, |
Bill Wendling | 90a3868 | 2008-02-20 06:10:21 +0000 | [diff] [blame] | 95 | // remove it. |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 96 | for (unsigned i = 0, e = VRInfo.Kills.size(); i != e; ++i) |
Chris Lattner | 74de8b1 | 2004-07-19 07:04:55 +0000 | [diff] [blame] | 97 | if (VRInfo.Kills[i]->getParent() == MBB) { |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 98 | VRInfo.Kills.erase(VRInfo.Kills.begin()+i); // Erase entry |
| 99 | break; |
| 100 | } |
Owen Anderson | 7047dd4 | 2008-01-15 22:02:46 +0000 | [diff] [blame] | 101 | |
Owen Anderson | 40a627d | 2008-01-15 22:58:11 +0000 | [diff] [blame] | 102 | if (MBB == DefBlock) return; // Terminate recursion |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 103 | |
Jeffrey Yasskin | 493a3d0 | 2009-05-26 18:27:15 +0000 | [diff] [blame] | 104 | if (VRInfo.AliveBlocks.test(BBNum)) |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 105 | return; // We already know the block is live |
| 106 | |
| 107 | // Mark the variable known alive in this bb |
Jeffrey Yasskin | 493a3d0 | 2009-05-26 18:27:15 +0000 | [diff] [blame] | 108 | VRInfo.AliveBlocks.set(BBNum); |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 109 | |
Evan Cheng | 5618490 | 2007-05-08 19:00:00 +0000 | [diff] [blame] | 110 | for (MachineBasicBlock::const_pred_reverse_iterator PI = MBB->pred_rbegin(), |
| 111 | E = MBB->pred_rend(); PI != E; ++PI) |
| 112 | WorkList.push_back(*PI); |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Bill Wendling | 420cdeb | 2008-02-20 07:36:31 +0000 | [diff] [blame] | 115 | void LiveVariables::MarkVirtRegAliveInBlock(VarInfo &VRInfo, |
Owen Anderson | 40a627d | 2008-01-15 22:58:11 +0000 | [diff] [blame] | 116 | MachineBasicBlock *DefBlock, |
Evan Cheng | 5618490 | 2007-05-08 19:00:00 +0000 | [diff] [blame] | 117 | MachineBasicBlock *MBB) { |
| 118 | std::vector<MachineBasicBlock*> WorkList; |
Owen Anderson | 40a627d | 2008-01-15 22:58:11 +0000 | [diff] [blame] | 119 | MarkVirtRegAliveInBlock(VRInfo, DefBlock, MBB, WorkList); |
Bill Wendling | 420cdeb | 2008-02-20 07:36:31 +0000 | [diff] [blame] | 120 | |
Evan Cheng | 5618490 | 2007-05-08 19:00:00 +0000 | [diff] [blame] | 121 | while (!WorkList.empty()) { |
| 122 | MachineBasicBlock *Pred = WorkList.back(); |
| 123 | WorkList.pop_back(); |
Owen Anderson | 40a627d | 2008-01-15 22:58:11 +0000 | [diff] [blame] | 124 | MarkVirtRegAliveInBlock(VRInfo, DefBlock, Pred, WorkList); |
Evan Cheng | 5618490 | 2007-05-08 19:00:00 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Owen Anderson | 7047dd4 | 2008-01-15 22:02:46 +0000 | [diff] [blame] | 128 | void LiveVariables::HandleVirtRegUse(unsigned reg, MachineBasicBlock *MBB, |
Misha Brukman | 09ba906 | 2004-06-24 21:31:16 +0000 | [diff] [blame] | 129 | MachineInstr *MI) { |
Evan Cheng | ea1d9cd | 2008-04-02 18:04:08 +0000 | [diff] [blame] | 130 | assert(MRI->getVRegDef(reg) && "Register use before def!"); |
Alkis Evlogimenos | 2e58a41 | 2004-09-01 22:34:52 +0000 | [diff] [blame] | 131 | |
Owen Anderson | a018540 | 2007-11-08 01:20:48 +0000 | [diff] [blame] | 132 | unsigned BBNum = MBB->getNumber(); |
| 133 | |
Owen Anderson | 7047dd4 | 2008-01-15 22:02:46 +0000 | [diff] [blame] | 134 | VarInfo& VRInfo = getVarInfo(reg); |
Evan Cheng | 38b7ca6 | 2007-04-17 20:22:11 +0000 | [diff] [blame] | 135 | VRInfo.NumUses++; |
Evan Cheng | c6a2410 | 2007-03-17 09:29:54 +0000 | [diff] [blame] | 136 | |
Bill Wendling | 90a3868 | 2008-02-20 06:10:21 +0000 | [diff] [blame] | 137 | // Check to see if this basic block is already a kill block. |
Chris Lattner | 74de8b1 | 2004-07-19 07:04:55 +0000 | [diff] [blame] | 138 | if (!VRInfo.Kills.empty() && VRInfo.Kills.back()->getParent() == MBB) { |
Bill Wendling | 90a3868 | 2008-02-20 06:10:21 +0000 | [diff] [blame] | 139 | // Yes, this register is killed in this basic block already. Increase the |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 140 | // live range by updating the kill instruction. |
Chris Lattner | 74de8b1 | 2004-07-19 07:04:55 +0000 | [diff] [blame] | 141 | VRInfo.Kills.back() = MI; |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 142 | return; |
| 143 | } |
| 144 | |
| 145 | #ifndef NDEBUG |
| 146 | for (unsigned i = 0, e = VRInfo.Kills.size(); i != e; ++i) |
Chris Lattner | 74de8b1 | 2004-07-19 07:04:55 +0000 | [diff] [blame] | 147 | assert(VRInfo.Kills[i]->getParent() != MBB && "entry should be at end!"); |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 148 | #endif |
| 149 | |
Bill Wendling | ebcba61 | 2008-06-23 23:41:14 +0000 | [diff] [blame] | 150 | // This situation can occur: |
| 151 | // |
| 152 | // ,------. |
| 153 | // | | |
| 154 | // | v |
| 155 | // | t2 = phi ... t1 ... |
| 156 | // | | |
| 157 | // | v |
| 158 | // | t1 = ... |
| 159 | // | ... = ... t1 ... |
| 160 | // | | |
| 161 | // `------' |
| 162 | // |
| 163 | // where there is a use in a PHI node that's a predecessor to the defining |
| 164 | // block. We don't want to mark all predecessors as having the value "alive" |
| 165 | // in this case. |
| 166 | if (MBB == MRI->getVRegDef(reg)->getParent()) return; |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 167 | |
Bill Wendling | 90a3868 | 2008-02-20 06:10:21 +0000 | [diff] [blame] | 168 | // Add a new kill entry for this basic block. If this virtual register is |
| 169 | // already marked as alive in this basic block, that means it is alive in at |
| 170 | // least one of the successor blocks, it's not a kill. |
Jeffrey Yasskin | 493a3d0 | 2009-05-26 18:27:15 +0000 | [diff] [blame] | 171 | if (!VRInfo.AliveBlocks.test(BBNum)) |
Evan Cheng | e2ee996 | 2007-03-09 09:48:56 +0000 | [diff] [blame] | 172 | VRInfo.Kills.push_back(MI); |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 173 | |
Bill Wendling | 420cdeb | 2008-02-20 07:36:31 +0000 | [diff] [blame] | 174 | // Update all dominating blocks to mark them as "known live". |
Chris Lattner | f25fb4b | 2004-05-01 21:24:24 +0000 | [diff] [blame] | 175 | for (MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(), |
| 176 | E = MBB->pred_end(); PI != E; ++PI) |
Evan Cheng | ea1d9cd | 2008-04-02 18:04:08 +0000 | [diff] [blame] | 177 | MarkVirtRegAliveInBlock(VRInfo, MRI->getVRegDef(reg)->getParent(), *PI); |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Dan Gohman | 3bdf5fe | 2008-09-21 21:11:41 +0000 | [diff] [blame] | 180 | void LiveVariables::HandleVirtRegDef(unsigned Reg, MachineInstr *MI) { |
| 181 | VarInfo &VRInfo = getVarInfo(Reg); |
| 182 | |
Jeffrey Yasskin | 493a3d0 | 2009-05-26 18:27:15 +0000 | [diff] [blame] | 183 | if (VRInfo.AliveBlocks.empty()) |
Dan Gohman | 3bdf5fe | 2008-09-21 21:11:41 +0000 | [diff] [blame] | 184 | // If vr is not alive in any block, then defaults to dead. |
| 185 | VRInfo.Kills.push_back(MI); |
| 186 | } |
| 187 | |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 188 | /// FindLastPartialDef - Return the last partial def of the specified register. |
Evan Cheng | 60c7df2 | 2009-09-22 08:34:46 +0000 | [diff] [blame] | 189 | /// Also returns the sub-registers that're defined by the instruction. |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 190 | MachineInstr *LiveVariables::FindLastPartialDef(unsigned Reg, |
Evan Cheng | 60c7df2 | 2009-09-22 08:34:46 +0000 | [diff] [blame] | 191 | SmallSet<unsigned,4> &PartDefRegs) { |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 192 | unsigned LastDefReg = 0; |
| 193 | unsigned LastDefDist = 0; |
| 194 | MachineInstr *LastDef = NULL; |
| 195 | for (const unsigned *SubRegs = TRI->getSubRegisters(Reg); |
| 196 | unsigned SubReg = *SubRegs; ++SubRegs) { |
| 197 | MachineInstr *Def = PhysRegDef[SubReg]; |
| 198 | if (!Def) |
| 199 | continue; |
| 200 | unsigned Dist = DistanceMap[Def]; |
| 201 | if (Dist > LastDefDist) { |
| 202 | LastDefReg = SubReg; |
| 203 | LastDef = Def; |
| 204 | LastDefDist = Dist; |
| 205 | } |
| 206 | } |
Evan Cheng | 60c7df2 | 2009-09-22 08:34:46 +0000 | [diff] [blame] | 207 | |
| 208 | if (!LastDef) |
| 209 | return 0; |
| 210 | |
| 211 | PartDefRegs.insert(LastDefReg); |
| 212 | for (unsigned i = 0, e = LastDef->getNumOperands(); i != e; ++i) { |
| 213 | MachineOperand &MO = LastDef->getOperand(i); |
| 214 | if (!MO.isReg() || !MO.isDef() || MO.getReg() == 0) |
| 215 | continue; |
| 216 | unsigned DefReg = MO.getReg(); |
| 217 | if (TRI->isSubRegister(Reg, DefReg)) { |
| 218 | PartDefRegs.insert(DefReg); |
| 219 | for (const unsigned *SubRegs = TRI->getSubRegisters(DefReg); |
| 220 | unsigned SubReg = *SubRegs; ++SubRegs) |
| 221 | PartDefRegs.insert(SubReg); |
| 222 | } |
| 223 | } |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 224 | return LastDef; |
| 225 | } |
| 226 | |
Bill Wendling | 6d79474 | 2008-02-20 09:15:16 +0000 | [diff] [blame] | 227 | /// HandlePhysRegUse - Turn previous partial def's into read/mod/writes. Add |
| 228 | /// implicit defs to a machine instruction if there was an earlier def of its |
| 229 | /// super-register. |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 230 | void LiveVariables::HandlePhysRegUse(unsigned Reg, MachineInstr *MI) { |
Evan Cheng | 236490d | 2009-11-13 20:36:40 +0000 | [diff] [blame] | 231 | MachineInstr *LastDef = PhysRegDef[Reg]; |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 232 | // If there was a previous use or a "full" def all is well. |
Evan Cheng | 236490d | 2009-11-13 20:36:40 +0000 | [diff] [blame] | 233 | if (!LastDef && !PhysRegUse[Reg]) { |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 234 | // Otherwise, the last sub-register def implicitly defines this register. |
| 235 | // e.g. |
| 236 | // AH = |
| 237 | // AL = ... <imp-def EAX>, <imp-kill AH> |
| 238 | // = AH |
| 239 | // ... |
| 240 | // = EAX |
| 241 | // All of the sub-registers must have been defined before the use of Reg! |
Evan Cheng | 60c7df2 | 2009-09-22 08:34:46 +0000 | [diff] [blame] | 242 | SmallSet<unsigned, 4> PartDefRegs; |
| 243 | MachineInstr *LastPartialDef = FindLastPartialDef(Reg, PartDefRegs); |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 244 | // If LastPartialDef is NULL, it must be using a livein register. |
| 245 | if (LastPartialDef) { |
| 246 | LastPartialDef->addOperand(MachineOperand::CreateReg(Reg, true/*IsDef*/, |
| 247 | true/*IsImp*/)); |
| 248 | PhysRegDef[Reg] = LastPartialDef; |
Owen Anderson | bbf5583 | 2008-08-14 23:41:38 +0000 | [diff] [blame] | 249 | SmallSet<unsigned, 8> Processed; |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 250 | for (const unsigned *SubRegs = TRI->getSubRegisters(Reg); |
| 251 | unsigned SubReg = *SubRegs; ++SubRegs) { |
| 252 | if (Processed.count(SubReg)) |
| 253 | continue; |
Evan Cheng | 60c7df2 | 2009-09-22 08:34:46 +0000 | [diff] [blame] | 254 | if (PartDefRegs.count(SubReg)) |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 255 | continue; |
| 256 | // This part of Reg was defined before the last partial def. It's killed |
| 257 | // here. |
| 258 | LastPartialDef->addOperand(MachineOperand::CreateReg(SubReg, |
| 259 | false/*IsDef*/, |
| 260 | true/*IsImp*/)); |
| 261 | PhysRegDef[SubReg] = LastPartialDef; |
| 262 | for (const unsigned *SS = TRI->getSubRegisters(SubReg); *SS; ++SS) |
| 263 | Processed.insert(*SS); |
| 264 | } |
| 265 | } |
Evan Cheng | 24a3cc4 | 2007-04-25 07:30:23 +0000 | [diff] [blame] | 266 | } |
Evan Cheng | 236490d | 2009-11-13 20:36:40 +0000 | [diff] [blame] | 267 | else if (LastDef && !PhysRegUse[Reg] && |
| 268 | !LastDef->findRegisterDefOperand(Reg)) |
| 269 | // Last def defines the super register, add an implicit def of reg. |
| 270 | LastDef->addOperand(MachineOperand::CreateReg(Reg, |
| 271 | true/*IsDef*/, true/*IsImp*/)); |
Bill Wendling | 90a3868 | 2008-02-20 06:10:21 +0000 | [diff] [blame] | 272 | |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 273 | // Remember this use. |
| 274 | PhysRegUse[Reg] = MI; |
Evan Cheng | 6130f66 | 2008-03-05 00:59:57 +0000 | [diff] [blame] | 275 | for (const unsigned *SubRegs = TRI->getSubRegisters(Reg); |
Bill Wendling | 420cdeb | 2008-02-20 07:36:31 +0000 | [diff] [blame] | 276 | unsigned SubReg = *SubRegs; ++SubRegs) |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 277 | PhysRegUse[SubReg] = MI; |
Evan Cheng | 4efe741 | 2007-06-26 21:03:35 +0000 | [diff] [blame] | 278 | } |
| 279 | |
Evan Cheng | a4025df | 2009-12-01 00:44:45 +0000 | [diff] [blame] | 280 | /// FindLastRefOrPartRef - Return the last reference or partial reference of |
| 281 | /// the specified register. |
| 282 | MachineInstr *LiveVariables::FindLastRefOrPartRef(unsigned Reg) { |
| 283 | MachineInstr *LastDef = PhysRegDef[Reg]; |
| 284 | MachineInstr *LastUse = PhysRegUse[Reg]; |
| 285 | if (!LastDef && !LastUse) |
Chris Lattner | 98cdfc7 | 2010-06-14 18:28:34 +0000 | [diff] [blame] | 286 | return 0; |
Evan Cheng | a4025df | 2009-12-01 00:44:45 +0000 | [diff] [blame] | 287 | |
| 288 | MachineInstr *LastRefOrPartRef = LastUse ? LastUse : LastDef; |
| 289 | unsigned LastRefOrPartRefDist = DistanceMap[LastRefOrPartRef]; |
Evan Cheng | a4025df | 2009-12-01 00:44:45 +0000 | [diff] [blame] | 290 | unsigned LastPartDefDist = 0; |
| 291 | for (const unsigned *SubRegs = TRI->getSubRegisters(Reg); |
| 292 | unsigned SubReg = *SubRegs; ++SubRegs) { |
| 293 | MachineInstr *Def = PhysRegDef[SubReg]; |
| 294 | if (Def && Def != LastDef) { |
| 295 | // There was a def of this sub-register in between. This is a partial |
| 296 | // def, keep track of the last one. |
| 297 | unsigned Dist = DistanceMap[Def]; |
Benjamin Kramer | e7078ae | 2010-01-07 17:29:08 +0000 | [diff] [blame] | 298 | if (Dist > LastPartDefDist) |
Evan Cheng | a4025df | 2009-12-01 00:44:45 +0000 | [diff] [blame] | 299 | LastPartDefDist = Dist; |
Benjamin Kramer | e7078ae | 2010-01-07 17:29:08 +0000 | [diff] [blame] | 300 | } else if (MachineInstr *Use = PhysRegUse[SubReg]) { |
Evan Cheng | a4025df | 2009-12-01 00:44:45 +0000 | [diff] [blame] | 301 | unsigned Dist = DistanceMap[Use]; |
| 302 | if (Dist > LastRefOrPartRefDist) { |
| 303 | LastRefOrPartRefDist = Dist; |
| 304 | LastRefOrPartRef = Use; |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | return LastRefOrPartRef; |
| 310 | } |
| 311 | |
Evan Cheng | a894ae1 | 2009-01-20 21:25:12 +0000 | [diff] [blame] | 312 | bool LiveVariables::HandlePhysRegKill(unsigned Reg, MachineInstr *MI) { |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 313 | MachineInstr *LastDef = PhysRegDef[Reg]; |
| 314 | MachineInstr *LastUse = PhysRegUse[Reg]; |
| 315 | if (!LastDef && !LastUse) |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 316 | return false; |
| 317 | |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 318 | MachineInstr *LastRefOrPartRef = LastUse ? LastUse : LastDef; |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 319 | unsigned LastRefOrPartRefDist = DistanceMap[LastRefOrPartRef]; |
| 320 | // The whole register is used. |
| 321 | // AL = |
| 322 | // AH = |
| 323 | // |
| 324 | // = AX |
| 325 | // = AL, AX<imp-use, kill> |
| 326 | // AX = |
| 327 | // |
| 328 | // Or whole register is defined, but not used at all. |
| 329 | // AX<dead> = |
| 330 | // ... |
| 331 | // AX = |
| 332 | // |
| 333 | // Or whole register is defined, but only partly used. |
| 334 | // AX<dead> = AL<imp-def> |
| 335 | // = AL<kill> |
| 336 | // AX = |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 337 | MachineInstr *LastPartDef = 0; |
| 338 | unsigned LastPartDefDist = 0; |
Owen Anderson | bbf5583 | 2008-08-14 23:41:38 +0000 | [diff] [blame] | 339 | SmallSet<unsigned, 8> PartUses; |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 340 | for (const unsigned *SubRegs = TRI->getSubRegisters(Reg); |
| 341 | unsigned SubReg = *SubRegs; ++SubRegs) { |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 342 | MachineInstr *Def = PhysRegDef[SubReg]; |
| 343 | if (Def && Def != LastDef) { |
| 344 | // There was a def of this sub-register in between. This is a partial |
| 345 | // def, keep track of the last one. |
| 346 | unsigned Dist = DistanceMap[Def]; |
| 347 | if (Dist > LastPartDefDist) { |
| 348 | LastPartDefDist = Dist; |
| 349 | LastPartDef = Def; |
| 350 | } |
| 351 | continue; |
| 352 | } |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 353 | if (MachineInstr *Use = PhysRegUse[SubReg]) { |
| 354 | PartUses.insert(SubReg); |
| 355 | for (const unsigned *SS = TRI->getSubRegisters(SubReg); *SS; ++SS) |
| 356 | PartUses.insert(*SS); |
| 357 | unsigned Dist = DistanceMap[Use]; |
| 358 | if (Dist > LastRefOrPartRefDist) { |
| 359 | LastRefOrPartRefDist = Dist; |
| 360 | LastRefOrPartRef = Use; |
Evan Cheng | 4efe741 | 2007-06-26 21:03:35 +0000 | [diff] [blame] | 361 | } |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 362 | } |
| 363 | } |
Evan Cheng | a894ae1 | 2009-01-20 21:25:12 +0000 | [diff] [blame] | 364 | |
Jakob Stoklund Olesen | 53e000b | 2010-03-05 21:49:17 +0000 | [diff] [blame] | 365 | if (!PhysRegUse[Reg]) { |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 366 | // Partial uses. Mark register def dead and add implicit def of |
| 367 | // sub-registers which are used. |
| 368 | // EAX<dead> = op AL<imp-def> |
| 369 | // That is, EAX def is dead but AL def extends pass it. |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 370 | PhysRegDef[Reg]->addRegisterDead(Reg, TRI, true); |
| 371 | for (const unsigned *SubRegs = TRI->getSubRegisters(Reg); |
| 372 | unsigned SubReg = *SubRegs; ++SubRegs) { |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 373 | if (!PartUses.count(SubReg)) |
| 374 | continue; |
| 375 | bool NeedDef = true; |
| 376 | if (PhysRegDef[Reg] == PhysRegDef[SubReg]) { |
| 377 | MachineOperand *MO = PhysRegDef[Reg]->findRegisterDefOperand(SubReg); |
| 378 | if (MO) { |
| 379 | NeedDef = false; |
| 380 | assert(!MO->isDead()); |
Evan Cheng | 2c4d96d | 2009-07-06 21:34:05 +0000 | [diff] [blame] | 381 | } |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 382 | } |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 383 | if (NeedDef) |
| 384 | PhysRegDef[Reg]->addOperand(MachineOperand::CreateReg(SubReg, |
| 385 | true/*IsDef*/, true/*IsImp*/)); |
Evan Cheng | a4025df | 2009-12-01 00:44:45 +0000 | [diff] [blame] | 386 | MachineInstr *LastSubRef = FindLastRefOrPartRef(SubReg); |
| 387 | if (LastSubRef) |
| 388 | LastSubRef->addRegisterKilled(SubReg, TRI, true); |
| 389 | else { |
| 390 | LastRefOrPartRef->addRegisterKilled(SubReg, TRI, true); |
| 391 | PhysRegUse[SubReg] = LastRefOrPartRef; |
| 392 | for (const unsigned *SSRegs = TRI->getSubRegisters(SubReg); |
| 393 | unsigned SSReg = *SSRegs; ++SSRegs) |
| 394 | PhysRegUse[SSReg] = LastRefOrPartRef; |
| 395 | } |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 396 | for (const unsigned *SS = TRI->getSubRegisters(SubReg); *SS; ++SS) |
| 397 | PartUses.erase(*SS); |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 398 | } |
Jakob Stoklund Olesen | 53e000b | 2010-03-05 21:49:17 +0000 | [diff] [blame] | 399 | } else if (LastRefOrPartRef == PhysRegDef[Reg] && LastRefOrPartRef != MI) { |
| 400 | if (LastPartDef) |
| 401 | // The last partial def kills the register. |
| 402 | LastPartDef->addOperand(MachineOperand::CreateReg(Reg, false/*IsDef*/, |
| 403 | true/*IsImp*/, true/*IsKill*/)); |
| 404 | else { |
| 405 | MachineOperand *MO = |
| 406 | LastRefOrPartRef->findRegisterDefOperand(Reg, false, TRI); |
| 407 | bool NeedEC = MO->isEarlyClobber() && MO->getReg() != Reg; |
| 408 | // If the last reference is the last def, then it's not used at all. |
| 409 | // That is, unless we are currently processing the last reference itself. |
| 410 | LastRefOrPartRef->addRegisterDead(Reg, TRI, true); |
| 411 | if (NeedEC) { |
| 412 | // If we are adding a subreg def and the superreg def is marked early |
| 413 | // clobber, add an early clobber marker to the subreg def. |
| 414 | MO = LastRefOrPartRef->findRegisterDefOperand(Reg); |
| 415 | if (MO) |
| 416 | MO->setIsEarlyClobber(); |
| 417 | } |
| 418 | } |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 419 | } else |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 420 | LastRefOrPartRef->addRegisterKilled(Reg, TRI, true); |
| 421 | return true; |
| 422 | } |
| 423 | |
Evan Cheng | 296925d | 2009-09-23 06:28:31 +0000 | [diff] [blame] | 424 | void LiveVariables::HandlePhysRegDef(unsigned Reg, MachineInstr *MI, |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 425 | SmallVector<unsigned, 4> &Defs) { |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 426 | // What parts of the register are previously defined? |
Owen Anderson | bffdf66 | 2008-06-27 07:05:59 +0000 | [diff] [blame] | 427 | SmallSet<unsigned, 32> Live; |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 428 | if (PhysRegDef[Reg] || PhysRegUse[Reg]) { |
| 429 | Live.insert(Reg); |
| 430 | for (const unsigned *SS = TRI->getSubRegisters(Reg); *SS; ++SS) |
| 431 | Live.insert(*SS); |
| 432 | } else { |
| 433 | for (const unsigned *SubRegs = TRI->getSubRegisters(Reg); |
| 434 | unsigned SubReg = *SubRegs; ++SubRegs) { |
| 435 | // If a register isn't itself defined, but all parts that make up of it |
| 436 | // are defined, then consider it also defined. |
| 437 | // e.g. |
| 438 | // AL = |
| 439 | // AH = |
| 440 | // = AX |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 441 | if (Live.count(SubReg)) |
| 442 | continue; |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 443 | if (PhysRegDef[SubReg] || PhysRegUse[SubReg]) { |
| 444 | Live.insert(SubReg); |
| 445 | for (const unsigned *SS = TRI->getSubRegisters(SubReg); *SS; ++SS) |
| 446 | Live.insert(*SS); |
| 447 | } |
Bill Wendling | 420cdeb | 2008-02-20 07:36:31 +0000 | [diff] [blame] | 448 | } |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 449 | } |
Alkis Evlogimenos | 19b6486 | 2004-01-13 06:24:30 +0000 | [diff] [blame] | 450 | |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 451 | // Start from the largest piece, find the last time any part of the register |
| 452 | // is referenced. |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 453 | HandlePhysRegKill(Reg, MI); |
| 454 | // Only some of the sub-registers are used. |
| 455 | for (const unsigned *SubRegs = TRI->getSubRegisters(Reg); |
| 456 | unsigned SubReg = *SubRegs; ++SubRegs) { |
| 457 | if (!Live.count(SubReg)) |
| 458 | // Skip if this sub-register isn't defined. |
| 459 | continue; |
| 460 | HandlePhysRegKill(SubReg, MI); |
Evan Cheng | 24a3cc4 | 2007-04-25 07:30:23 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 463 | if (MI) |
| 464 | Defs.push_back(Reg); // Remember this def. |
Evan Cheng | 296925d | 2009-09-23 06:28:31 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | void LiveVariables::UpdatePhysRegDefs(MachineInstr *MI, |
| 468 | SmallVector<unsigned, 4> &Defs) { |
| 469 | while (!Defs.empty()) { |
| 470 | unsigned Reg = Defs.back(); |
| 471 | Defs.pop_back(); |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 472 | PhysRegDef[Reg] = MI; |
| 473 | PhysRegUse[Reg] = NULL; |
Evan Cheng | 6130f66 | 2008-03-05 00:59:57 +0000 | [diff] [blame] | 474 | for (const unsigned *SubRegs = TRI->getSubRegisters(Reg); |
Evan Cheng | 4efe741 | 2007-06-26 21:03:35 +0000 | [diff] [blame] | 475 | unsigned SubReg = *SubRegs; ++SubRegs) { |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 476 | PhysRegDef[SubReg] = MI; |
| 477 | PhysRegUse[SubReg] = NULL; |
Evan Cheng | 4efe741 | 2007-06-26 21:03:35 +0000 | [diff] [blame] | 478 | } |
Alkis Evlogimenos | 19b6486 | 2004-01-13 06:24:30 +0000 | [diff] [blame] | 479 | } |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Evan Cheng | c6a2410 | 2007-03-17 09:29:54 +0000 | [diff] [blame] | 482 | bool LiveVariables::runOnMachineFunction(MachineFunction &mf) { |
| 483 | MF = &mf; |
Evan Cheng | ea1d9cd | 2008-04-02 18:04:08 +0000 | [diff] [blame] | 484 | MRI = &mf.getRegInfo(); |
Evan Cheng | 6130f66 | 2008-03-05 00:59:57 +0000 | [diff] [blame] | 485 | TRI = MF->getTarget().getRegisterInfo(); |
Chris Lattner | 96aef89 | 2004-02-09 01:35:21 +0000 | [diff] [blame] | 486 | |
Evan Cheng | 6130f66 | 2008-03-05 00:59:57 +0000 | [diff] [blame] | 487 | ReservedRegisters = TRI->getReservedRegs(mf); |
Chris Lattner | 5cdfbad | 2003-05-07 20:08:36 +0000 | [diff] [blame] | 488 | |
Evan Cheng | 6130f66 | 2008-03-05 00:59:57 +0000 | [diff] [blame] | 489 | unsigned NumRegs = TRI->getNumRegs(); |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 490 | PhysRegDef = new MachineInstr*[NumRegs]; |
| 491 | PhysRegUse = new MachineInstr*[NumRegs]; |
Evan Cheng | e96f501 | 2007-04-25 19:34:00 +0000 | [diff] [blame] | 492 | PHIVarInfo = new SmallVector<unsigned, 4>[MF->getNumBlockIDs()]; |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 493 | std::fill(PhysRegDef, PhysRegDef + NumRegs, (MachineInstr*)0); |
| 494 | std::fill(PhysRegUse, PhysRegUse + NumRegs, (MachineInstr*)0); |
Jakob Stoklund Olesen | dcfe5f3 | 2010-02-23 22:43:58 +0000 | [diff] [blame] | 495 | PHIJoins.clear(); |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 496 | |
Evan Cheng | c6a2410 | 2007-03-17 09:29:54 +0000 | [diff] [blame] | 497 | analyzePHINodes(mf); |
Bill Wendling | f7da4e9 | 2006-10-03 07:20:20 +0000 | [diff] [blame] | 498 | |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 499 | // Calculate live variable information in depth first order on the CFG of the |
| 500 | // function. This guarantees that we will see the definition of a virtual |
| 501 | // register before its uses due to dominance properties of SSA (except for PHI |
| 502 | // nodes, which are treated as a special case). |
Evan Cheng | c6a2410 | 2007-03-17 09:29:54 +0000 | [diff] [blame] | 503 | MachineBasicBlock *Entry = MF->begin(); |
Evan Cheng | 0410407 | 2007-06-27 05:23:00 +0000 | [diff] [blame] | 504 | SmallPtrSet<MachineBasicBlock*,16> Visited; |
Bill Wendling | 6d79474 | 2008-02-20 09:15:16 +0000 | [diff] [blame] | 505 | |
Evan Cheng | 0410407 | 2007-06-27 05:23:00 +0000 | [diff] [blame] | 506 | for (df_ext_iterator<MachineBasicBlock*, SmallPtrSet<MachineBasicBlock*,16> > |
| 507 | DFI = df_ext_begin(Entry, Visited), E = df_ext_end(Entry, Visited); |
| 508 | DFI != E; ++DFI) { |
Chris Lattner | f25fb4b | 2004-05-01 21:24:24 +0000 | [diff] [blame] | 509 | MachineBasicBlock *MBB = *DFI; |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 510 | |
Evan Cheng | b371f45 | 2007-02-19 21:49:54 +0000 | [diff] [blame] | 511 | // Mark live-in registers as live-in. |
Evan Cheng | 296925d | 2009-09-23 06:28:31 +0000 | [diff] [blame] | 512 | SmallVector<unsigned, 4> Defs; |
Dan Gohman | 81bf03e | 2010-04-13 16:57:55 +0000 | [diff] [blame] | 513 | for (MachineBasicBlock::livein_iterator II = MBB->livein_begin(), |
Evan Cheng | 0c9f92e | 2007-02-13 01:30:55 +0000 | [diff] [blame] | 514 | EE = MBB->livein_end(); II != EE; ++II) { |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 515 | assert(TargetRegisterInfo::isPhysicalRegister(*II) && |
Evan Cheng | 0c9f92e | 2007-02-13 01:30:55 +0000 | [diff] [blame] | 516 | "Cannot have a live-in virtual register!"); |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 517 | HandlePhysRegDef(*II, 0, Defs); |
Evan Cheng | 0c9f92e | 2007-02-13 01:30:55 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 520 | // Loop over all of the instructions, processing them. |
Evan Cheng | ea1d9cd | 2008-04-02 18:04:08 +0000 | [diff] [blame] | 521 | DistanceMap.clear(); |
| 522 | unsigned Dist = 0; |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 523 | for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); |
Misha Brukman | 09ba906 | 2004-06-24 21:31:16 +0000 | [diff] [blame] | 524 | I != E; ++I) { |
Alkis Evlogimenos | c0b9dc5 | 2004-02-12 02:27:10 +0000 | [diff] [blame] | 525 | MachineInstr *MI = I; |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 526 | if (MI->isDebugValue()) |
Dale Johannesen | d94998f | 2010-02-09 02:01:46 +0000 | [diff] [blame] | 527 | continue; |
Evan Cheng | ea1d9cd | 2008-04-02 18:04:08 +0000 | [diff] [blame] | 528 | DistanceMap.insert(std::make_pair(MI, Dist++)); |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 529 | |
| 530 | // Process all of the operands of the instruction... |
| 531 | unsigned NumOperandsToProcess = MI->getNumOperands(); |
| 532 | |
| 533 | // Unless it is a PHI node. In this case, ONLY process the DEF, not any |
| 534 | // of the uses. They will be handled in other basic blocks. |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 535 | if (MI->isPHI()) |
Misha Brukman | 09ba906 | 2004-06-24 21:31:16 +0000 | [diff] [blame] | 536 | NumOperandsToProcess = 1; |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 537 | |
Evan Cheng | d05e805 | 2010-03-26 02:12:24 +0000 | [diff] [blame] | 538 | // Clear kill and dead markers. LV will recompute them. |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 539 | SmallVector<unsigned, 4> UseRegs; |
| 540 | SmallVector<unsigned, 4> DefRegs; |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 541 | for (unsigned i = 0; i != NumOperandsToProcess; ++i) { |
Evan Cheng | d05e805 | 2010-03-26 02:12:24 +0000 | [diff] [blame] | 542 | MachineOperand &MO = MI->getOperand(i); |
Evan Cheng | a894ae1 | 2009-01-20 21:25:12 +0000 | [diff] [blame] | 543 | if (!MO.isReg() || MO.getReg() == 0) |
| 544 | continue; |
| 545 | unsigned MOReg = MO.getReg(); |
Evan Cheng | d05e805 | 2010-03-26 02:12:24 +0000 | [diff] [blame] | 546 | if (MO.isUse()) { |
| 547 | MO.setIsKill(false); |
Evan Cheng | a894ae1 | 2009-01-20 21:25:12 +0000 | [diff] [blame] | 548 | UseRegs.push_back(MOReg); |
Evan Cheng | d05e805 | 2010-03-26 02:12:24 +0000 | [diff] [blame] | 549 | } else /*MO.isDef()*/ { |
| 550 | MO.setIsDead(false); |
Evan Cheng | a894ae1 | 2009-01-20 21:25:12 +0000 | [diff] [blame] | 551 | DefRegs.push_back(MOReg); |
Evan Cheng | d05e805 | 2010-03-26 02:12:24 +0000 | [diff] [blame] | 552 | } |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 555 | // Process all uses. |
| 556 | for (unsigned i = 0, e = UseRegs.size(); i != e; ++i) { |
| 557 | unsigned MOReg = UseRegs[i]; |
| 558 | if (TargetRegisterInfo::isVirtualRegister(MOReg)) |
| 559 | HandleVirtRegUse(MOReg, MBB, MI); |
Dan Gohman | 3bdf5fe | 2008-09-21 21:11:41 +0000 | [diff] [blame] | 560 | else if (!ReservedRegisters[MOReg]) |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 561 | HandlePhysRegUse(MOReg, MI); |
| 562 | } |
| 563 | |
Bill Wendling | 6d79474 | 2008-02-20 09:15:16 +0000 | [diff] [blame] | 564 | // Process all defs. |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 565 | for (unsigned i = 0, e = DefRegs.size(); i != e; ++i) { |
| 566 | unsigned MOReg = DefRegs[i]; |
Dan Gohman | 3bdf5fe | 2008-09-21 21:11:41 +0000 | [diff] [blame] | 567 | if (TargetRegisterInfo::isVirtualRegister(MOReg)) |
| 568 | HandleVirtRegDef(MOReg, MI); |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 569 | else if (!ReservedRegisters[MOReg]) |
| 570 | HandlePhysRegDef(MOReg, MI, Defs); |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 571 | } |
Evan Cheng | 296925d | 2009-09-23 06:28:31 +0000 | [diff] [blame] | 572 | UpdatePhysRegDefs(MI, Defs); |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | // Handle any virtual assignments from PHI nodes which might be at the |
| 576 | // bottom of this basic block. We check all of our successor blocks to see |
| 577 | // if they have PHI nodes, and if so, we simulate an assignment at the end |
| 578 | // of the current block. |
Evan Cheng | e96f501 | 2007-04-25 19:34:00 +0000 | [diff] [blame] | 579 | if (!PHIVarInfo[MBB->getNumber()].empty()) { |
| 580 | SmallVector<unsigned, 4>& VarInfoVec = PHIVarInfo[MBB->getNumber()]; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 581 | |
Evan Cheng | e96f501 | 2007-04-25 19:34:00 +0000 | [diff] [blame] | 582 | for (SmallVector<unsigned, 4>::iterator I = VarInfoVec.begin(), |
Bill Wendling | 420cdeb | 2008-02-20 07:36:31 +0000 | [diff] [blame] | 583 | E = VarInfoVec.end(); I != E; ++I) |
| 584 | // Mark it alive only in the block we are representing. |
Evan Cheng | ea1d9cd | 2008-04-02 18:04:08 +0000 | [diff] [blame] | 585 | MarkVirtRegAliveInBlock(getVarInfo(*I),MRI->getVRegDef(*I)->getParent(), |
Owen Anderson | 40a627d | 2008-01-15 22:58:11 +0000 | [diff] [blame] | 586 | MBB); |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 587 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 588 | |
Bill Wendling | 6d79474 | 2008-02-20 09:15:16 +0000 | [diff] [blame] | 589 | // Finally, if the last instruction in the block is a return, make sure to |
| 590 | // mark it as using all of the live-out values in the function. |
Dale Johannesen | 88004c2 | 2010-06-05 00:30:45 +0000 | [diff] [blame] | 591 | // Things marked both call and return are tail calls; do not do this for |
| 592 | // them. The tail callee need not take the same registers as input |
| 593 | // that it produces as output, and there are dependencies for its input |
| 594 | // registers elsewhere. |
| 595 | if (!MBB->empty() && MBB->back().getDesc().isReturn() |
| 596 | && !MBB->back().getDesc().isCall()) { |
Chris Lattner | d493b34 | 2005-04-09 15:23:25 +0000 | [diff] [blame] | 597 | MachineInstr *Ret = &MBB->back(); |
Bill Wendling | 420cdeb | 2008-02-20 07:36:31 +0000 | [diff] [blame] | 598 | |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 599 | for (MachineRegisterInfo::liveout_iterator |
| 600 | I = MF->getRegInfo().liveout_begin(), |
| 601 | E = MF->getRegInfo().liveout_end(); I != E; ++I) { |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 602 | assert(TargetRegisterInfo::isPhysicalRegister(*I) && |
Dan Gohman | 48b0b88 | 2008-06-25 22:14:43 +0000 | [diff] [blame] | 603 | "Cannot have a live-out virtual register!"); |
Chris Lattner | d493b34 | 2005-04-09 15:23:25 +0000 | [diff] [blame] | 604 | HandlePhysRegUse(*I, Ret); |
Bill Wendling | 420cdeb | 2008-02-20 07:36:31 +0000 | [diff] [blame] | 605 | |
Evan Cheng | a6c4c1e | 2006-11-15 20:51:59 +0000 | [diff] [blame] | 606 | // Add live-out registers as implicit uses. |
Evan Cheng | 6130f66 | 2008-03-05 00:59:57 +0000 | [diff] [blame] | 607 | if (!Ret->readsRegister(*I)) |
Chris Lattner | 8019f41 | 2007-12-30 00:41:17 +0000 | [diff] [blame] | 608 | Ret->addOperand(MachineOperand::CreateReg(*I, false, true)); |
Chris Lattner | d493b34 | 2005-04-09 15:23:25 +0000 | [diff] [blame] | 609 | } |
| 610 | } |
| 611 | |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 612 | // Loop over PhysRegDef / PhysRegUse, killing any registers that are |
| 613 | // available at the end of the basic block. |
Evan Cheng | e96f501 | 2007-04-25 19:34:00 +0000 | [diff] [blame] | 614 | for (unsigned i = 0; i != NumRegs; ++i) |
Evan Cheng | ad934b8 | 2009-09-24 02:15:22 +0000 | [diff] [blame] | 615 | if (PhysRegDef[i] || PhysRegUse[i]) |
| 616 | HandlePhysRegDef(i, 0, Defs); |
Evan Cheng | 24a3cc4 | 2007-04-25 07:30:23 +0000 | [diff] [blame] | 617 | |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 618 | std::fill(PhysRegDef, PhysRegDef + NumRegs, (MachineInstr*)0); |
| 619 | std::fill(PhysRegUse, PhysRegUse + NumRegs, (MachineInstr*)0); |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 620 | } |
| 621 | |
Evan Cheng | a6c4c1e | 2006-11-15 20:51:59 +0000 | [diff] [blame] | 622 | // Convert and transfer the dead / killed information we have gathered into |
| 623 | // VirtRegInfo onto MI's. |
Jakob Stoklund Olesen | b421c56 | 2011-01-08 23:10:57 +0000 | [diff] [blame] | 624 | for (unsigned i = 0, e1 = VirtRegInfo.size(); i != e1; ++i) { |
| 625 | const unsigned Reg = TargetRegisterInfo::index2VirtReg(i); |
| 626 | for (unsigned j = 0, e2 = VirtRegInfo[Reg].Kills.size(); j != e2; ++j) |
| 627 | if (VirtRegInfo[Reg].Kills[j] == MRI->getVRegDef(Reg)) |
| 628 | VirtRegInfo[Reg].Kills[j]->addRegisterDead(Reg, TRI); |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 629 | else |
Jakob Stoklund Olesen | b421c56 | 2011-01-08 23:10:57 +0000 | [diff] [blame] | 630 | VirtRegInfo[Reg].Kills[j]->addRegisterKilled(Reg, TRI); |
| 631 | } |
Chris Lattner | a5287a6 | 2004-07-01 04:24:29 +0000 | [diff] [blame] | 632 | |
Chris Lattner | 9fb6cf1 | 2004-07-09 16:44:37 +0000 | [diff] [blame] | 633 | // Check to make sure there are no unreachable blocks in the MC CFG for the |
| 634 | // function. If so, it is due to a bug in the instruction selector or some |
| 635 | // other part of the code generator if this happens. |
| 636 | #ifndef NDEBUG |
Evan Cheng | c6a2410 | 2007-03-17 09:29:54 +0000 | [diff] [blame] | 637 | for(MachineFunction::iterator i = MF->begin(), e = MF->end(); i != e; ++i) |
Chris Lattner | 9fb6cf1 | 2004-07-09 16:44:37 +0000 | [diff] [blame] | 638 | assert(Visited.count(&*i) != 0 && "unreachable basic block found"); |
| 639 | #endif |
| 640 | |
Evan Cheng | 0d4bdde | 2008-04-16 09:46:40 +0000 | [diff] [blame] | 641 | delete[] PhysRegDef; |
| 642 | delete[] PhysRegUse; |
Evan Cheng | e96f501 | 2007-04-25 19:34:00 +0000 | [diff] [blame] | 643 | delete[] PHIVarInfo; |
| 644 | |
Chris Lattner | bc40e89 | 2003-01-13 20:01:16 +0000 | [diff] [blame] | 645 | return false; |
| 646 | } |
Chris Lattner | 5ed001b | 2004-02-19 18:28:02 +0000 | [diff] [blame] | 647 | |
Evan Cheng | be04dc1 | 2008-07-03 00:07:19 +0000 | [diff] [blame] | 648 | /// replaceKillInstruction - Update register kill info by replacing a kill |
| 649 | /// instruction with a new one. |
| 650 | void LiveVariables::replaceKillInstruction(unsigned Reg, MachineInstr *OldMI, |
| 651 | MachineInstr *NewMI) { |
| 652 | VarInfo &VI = getVarInfo(Reg); |
Evan Cheng | 5b9f60b | 2008-07-03 00:28:27 +0000 | [diff] [blame] | 653 | std::replace(VI.Kills.begin(), VI.Kills.end(), OldMI, NewMI); |
Evan Cheng | be04dc1 | 2008-07-03 00:07:19 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Chris Lattner | 7a3abdc | 2006-09-03 00:05:09 +0000 | [diff] [blame] | 656 | /// removeVirtualRegistersKilled - Remove all killed info for the specified |
| 657 | /// instruction. |
| 658 | void LiveVariables::removeVirtualRegistersKilled(MachineInstr *MI) { |
Evan Cheng | a6c4c1e | 2006-11-15 20:51:59 +0000 | [diff] [blame] | 659 | for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { |
| 660 | MachineOperand &MO = MI->getOperand(i); |
Dan Gohman | d735b80 | 2008-10-03 15:45:36 +0000 | [diff] [blame] | 661 | if (MO.isReg() && MO.isKill()) { |
Chris Lattner | f738230 | 2007-12-30 21:56:09 +0000 | [diff] [blame] | 662 | MO.setIsKill(false); |
Evan Cheng | a6c4c1e | 2006-11-15 20:51:59 +0000 | [diff] [blame] | 663 | unsigned Reg = MO.getReg(); |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 664 | if (TargetRegisterInfo::isVirtualRegister(Reg)) { |
Evan Cheng | a6c4c1e | 2006-11-15 20:51:59 +0000 | [diff] [blame] | 665 | bool removed = getVarInfo(Reg).removeKill(MI); |
| 666 | assert(removed && "kill not in register's VarInfo?"); |
Devang Patel | 59500c8 | 2008-11-21 20:00:59 +0000 | [diff] [blame] | 667 | removed = true; |
Evan Cheng | a6c4c1e | 2006-11-15 20:51:59 +0000 | [diff] [blame] | 668 | } |
Chris Lattner | 7a3abdc | 2006-09-03 00:05:09 +0000 | [diff] [blame] | 669 | } |
| 670 | } |
Chris Lattner | 7a3abdc | 2006-09-03 00:05:09 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Bill Wendling | f7da4e9 | 2006-10-03 07:20:20 +0000 | [diff] [blame] | 673 | /// analyzePHINodes - Gather information about the PHI nodes in here. In |
Bill Wendling | 6d79474 | 2008-02-20 09:15:16 +0000 | [diff] [blame] | 674 | /// particular, we want to map the variable information of a virtual register |
| 675 | /// which is used in a PHI node. We map that to the BB the vreg is coming from. |
Bill Wendling | f7da4e9 | 2006-10-03 07:20:20 +0000 | [diff] [blame] | 676 | /// |
| 677 | void LiveVariables::analyzePHINodes(const MachineFunction& Fn) { |
| 678 | for (MachineFunction::const_iterator I = Fn.begin(), E = Fn.end(); |
| 679 | I != E; ++I) |
| 680 | for (MachineBasicBlock::const_iterator BBI = I->begin(), BBE = I->end(); |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 681 | BBI != BBE && BBI->isPHI(); ++BBI) |
Bill Wendling | f7da4e9 | 2006-10-03 07:20:20 +0000 | [diff] [blame] | 682 | for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2) |
Bill Wendling | 90a3868 | 2008-02-20 06:10:21 +0000 | [diff] [blame] | 683 | PHIVarInfo[BBI->getOperand(i + 1).getMBB()->getNumber()] |
| 684 | .push_back(BBI->getOperand(i).getReg()); |
Bill Wendling | f7da4e9 | 2006-10-03 07:20:20 +0000 | [diff] [blame] | 685 | } |
Jakob Stoklund Olesen | f235f13 | 2009-11-10 22:01:05 +0000 | [diff] [blame] | 686 | |
Jakob Stoklund Olesen | 323d8c3 | 2009-11-21 02:05:21 +0000 | [diff] [blame] | 687 | bool LiveVariables::VarInfo::isLiveIn(const MachineBasicBlock &MBB, |
| 688 | unsigned Reg, |
| 689 | MachineRegisterInfo &MRI) { |
| 690 | unsigned Num = MBB.getNumber(); |
| 691 | |
| 692 | // Reg is live-through. |
| 693 | if (AliveBlocks.test(Num)) |
| 694 | return true; |
| 695 | |
| 696 | // Registers defined in MBB cannot be live in. |
| 697 | const MachineInstr *Def = MRI.getVRegDef(Reg); |
| 698 | if (Def && Def->getParent() == &MBB) |
| 699 | return false; |
| 700 | |
| 701 | // Reg was not defined in MBB, was it killed here? |
| 702 | return findKill(&MBB); |
| 703 | } |
| 704 | |
Jakob Stoklund Olesen | 8f72235 | 2009-12-01 17:13:31 +0000 | [diff] [blame] | 705 | bool LiveVariables::isLiveOut(unsigned Reg, const MachineBasicBlock &MBB) { |
| 706 | LiveVariables::VarInfo &VI = getVarInfo(Reg); |
| 707 | |
| 708 | // Loop over all of the successors of the basic block, checking to see if |
| 709 | // the value is either live in the block, or if it is killed in the block. |
| 710 | std::vector<MachineBasicBlock*> OpSuccBlocks; |
| 711 | for (MachineBasicBlock::const_succ_iterator SI = MBB.succ_begin(), |
| 712 | E = MBB.succ_end(); SI != E; ++SI) { |
| 713 | MachineBasicBlock *SuccMBB = *SI; |
| 714 | |
| 715 | // Is it alive in this successor? |
| 716 | unsigned SuccIdx = SuccMBB->getNumber(); |
| 717 | if (VI.AliveBlocks.test(SuccIdx)) |
| 718 | return true; |
| 719 | OpSuccBlocks.push_back(SuccMBB); |
| 720 | } |
| 721 | |
| 722 | // Check to see if this value is live because there is a use in a successor |
| 723 | // that kills it. |
| 724 | switch (OpSuccBlocks.size()) { |
| 725 | case 1: { |
| 726 | MachineBasicBlock *SuccMBB = OpSuccBlocks[0]; |
| 727 | for (unsigned i = 0, e = VI.Kills.size(); i != e; ++i) |
| 728 | if (VI.Kills[i]->getParent() == SuccMBB) |
| 729 | return true; |
| 730 | break; |
| 731 | } |
| 732 | case 2: { |
| 733 | MachineBasicBlock *SuccMBB1 = OpSuccBlocks[0], *SuccMBB2 = OpSuccBlocks[1]; |
| 734 | for (unsigned i = 0, e = VI.Kills.size(); i != e; ++i) |
| 735 | if (VI.Kills[i]->getParent() == SuccMBB1 || |
| 736 | VI.Kills[i]->getParent() == SuccMBB2) |
| 737 | return true; |
| 738 | break; |
| 739 | } |
| 740 | default: |
| 741 | std::sort(OpSuccBlocks.begin(), OpSuccBlocks.end()); |
| 742 | for (unsigned i = 0, e = VI.Kills.size(); i != e; ++i) |
| 743 | if (std::binary_search(OpSuccBlocks.begin(), OpSuccBlocks.end(), |
| 744 | VI.Kills[i]->getParent())) |
| 745 | return true; |
| 746 | } |
| 747 | return false; |
| 748 | } |
| 749 | |
Jakob Stoklund Olesen | 3e20475 | 2009-11-11 19:31:31 +0000 | [diff] [blame] | 750 | /// addNewBlock - Add a new basic block BB as an empty succcessor to DomBB. All |
| 751 | /// variables that are live out of DomBB will be marked as passing live through |
| 752 | /// BB. |
| 753 | void LiveVariables::addNewBlock(MachineBasicBlock *BB, |
Jakob Stoklund Olesen | 323d8c3 | 2009-11-21 02:05:21 +0000 | [diff] [blame] | 754 | MachineBasicBlock *DomBB, |
| 755 | MachineBasicBlock *SuccBB) { |
Jakob Stoklund Olesen | 3e20475 | 2009-11-11 19:31:31 +0000 | [diff] [blame] | 756 | const unsigned NumNew = BB->getNumber(); |
Jakob Stoklund Olesen | 323d8c3 | 2009-11-21 02:05:21 +0000 | [diff] [blame] | 757 | |
| 758 | // All registers used by PHI nodes in SuccBB must be live through BB. |
| 759 | for (MachineBasicBlock::const_iterator BBI = SuccBB->begin(), |
Chris Lattner | 518bb53 | 2010-02-09 19:54:29 +0000 | [diff] [blame] | 760 | BBE = SuccBB->end(); BBI != BBE && BBI->isPHI(); ++BBI) |
Jakob Stoklund Olesen | 323d8c3 | 2009-11-21 02:05:21 +0000 | [diff] [blame] | 761 | for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2) |
| 762 | if (BBI->getOperand(i+1).getMBB() == BB) |
| 763 | getVarInfo(BBI->getOperand(i).getReg()).AliveBlocks.set(NumNew); |
Jakob Stoklund Olesen | f235f13 | 2009-11-10 22:01:05 +0000 | [diff] [blame] | 764 | |
| 765 | // Update info for all live variables |
Jakob Stoklund Olesen | b421c56 | 2011-01-08 23:10:57 +0000 | [diff] [blame] | 766 | for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) { |
| 767 | unsigned Reg = TargetRegisterInfo::index2VirtReg(i); |
Jakob Stoklund Olesen | 3e20475 | 2009-11-11 19:31:31 +0000 | [diff] [blame] | 768 | VarInfo &VI = getVarInfo(Reg); |
Jakob Stoklund Olesen | 323d8c3 | 2009-11-21 02:05:21 +0000 | [diff] [blame] | 769 | if (!VI.AliveBlocks.test(NumNew) && VI.isLiveIn(*SuccBB, Reg, *MRI)) |
Jakob Stoklund Olesen | 3e20475 | 2009-11-11 19:31:31 +0000 | [diff] [blame] | 770 | VI.AliveBlocks.set(NumNew); |
Jakob Stoklund Olesen | f235f13 | 2009-11-10 22:01:05 +0000 | [diff] [blame] | 771 | } |
| 772 | } |