1 //===-- LiveVariables.cpp - Live Variable Analysis for Machine Code -------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file was developed by the LLVM research group and is distributed under 6 // the University of Illinois Open Source License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 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 // 27 //===----------------------------------------------------------------------===// 28 29 #include "llvm/CodeGen/LiveVariables.h" 30 #include "llvm/CodeGen/MachineInstr.h" 31 #include "llvm/Target/MRegisterInfo.h" 32 #include "llvm/Target/TargetInstrInfo.h" 33 #include "llvm/Target/TargetMachine.h" 34 #include "llvm/ADT/DepthFirstIterator.h" 35 #include "llvm/ADT/STLExtras.h" 36 #include "llvm/Config/alloca.h" 37 #include <algorithm> 38 using namespace llvm; 39 40 const int LiveVariables::ID = 0; 41 static RegisterPass<LiveVariables> X("livevars", "Live Variable Analysis"); 42 43 void LiveVariables::VarInfo::dump() const { 44 cerr << "Register Defined by: "; 45 if (DefInst) 46 cerr << *DefInst; 47 else 48 cerr << "<null>\n"; 49 cerr << " Alive in blocks: "; 50 for (unsigned i = 0, e = AliveBlocks.size(); i != e; ++i) 51 if (AliveBlocks[i]) cerr << i << ", "; 52 cerr << "\n Killed by:"; 53 if (Kills.empty()) 54 cerr << " No instructions.\n"; 55 else { 56 for (unsigned i = 0, e = Kills.size(); i != e; ++i) 57 cerr << "\n #" << i << ": " << *Kills[i]; 58 cerr << "\n"; 59 } 60 } 61 62 LiveVariables::VarInfo &LiveVariables::getVarInfo(unsigned RegIdx) { 63 assert(MRegisterInfo::isVirtualRegister(RegIdx) && 64 "getVarInfo: not a virtual register!"); 65 RegIdx -= MRegisterInfo::FirstVirtualRegister; 66 if (RegIdx >= VirtRegInfo.size()) { 67 if (RegIdx >= 2*VirtRegInfo.size()) 68 VirtRegInfo.resize(RegIdx*2); 69 else 70 VirtRegInfo.resize(2*VirtRegInfo.size()); 71 } 72 VarInfo &VI = VirtRegInfo[RegIdx]; 73 VI.AliveBlocks.resize(MF->getNumBlockIDs()); 74 return VI; 75 } 76 77 bool LiveVariables::KillsRegister(MachineInstr *MI, unsigned Reg) const { 78 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 79 MachineOperand &MO = MI->getOperand(i); 80 if (MO.isReg() && MO.isKill()) { 81 if ((MO.getReg() == Reg) || 82 (MRegisterInfo::isPhysicalRegister(MO.getReg()) && 83 MRegisterInfo::isPhysicalRegister(Reg) && 84 RegInfo->isSubRegister(MO.getReg(), Reg))) 85 return true; 86 } 87 } 88 return false; 89 } 90 91 bool LiveVariables::RegisterDefIsDead(MachineInstr *MI, unsigned Reg) const { 92 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 93 MachineOperand &MO = MI->getOperand(i); 94 if (MO.isReg() && MO.isDead()) { 95 if ((MO.getReg() == Reg) || 96 (MRegisterInfo::isPhysicalRegister(MO.getReg()) && 97 MRegisterInfo::isPhysicalRegister(Reg) && 98 RegInfo->isSubRegister(MO.getReg(), Reg))) 99 return true; 100 } 101 } 102 return false; 103 } 104 105 bool LiveVariables::ModifiesRegister(MachineInstr *MI, unsigned Reg) const { 106 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 107 MachineOperand &MO = MI->getOperand(i); 108 if (MO.isReg() && MO.isDef() && MO.getReg() == Reg) 109 return true; 110 } 111 return false; 112 } 113 114 void LiveVariables::MarkVirtRegAliveInBlock(VarInfo &VRInfo, 115 MachineBasicBlock *MBB) { 116 unsigned BBNum = MBB->getNumber(); 117 118 // Check to see if this basic block is one of the killing blocks. If so, 119 // remove it... 120 for (unsigned i = 0, e = VRInfo.Kills.size(); i != e; ++i) 121 if (VRInfo.Kills[i]->getParent() == MBB) { 122 VRInfo.Kills.erase(VRInfo.Kills.begin()+i); // Erase entry 123 break; 124 } 125 126 if (MBB == VRInfo.DefInst->getParent()) return; // Terminate recursion 127 128 if (VRInfo.AliveBlocks[BBNum]) 129 return; // We already know the block is live 130 131 // Mark the variable known alive in this bb 132 VRInfo.AliveBlocks[BBNum] = true; 133 134 for (MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(), 135 E = MBB->pred_end(); PI != E; ++PI) 136 MarkVirtRegAliveInBlock(VRInfo, *PI); 137 } 138 139 void LiveVariables::HandleVirtRegUse(VarInfo &VRInfo, MachineBasicBlock *MBB, 140 MachineInstr *MI) { 141 assert(VRInfo.DefInst && "Register use before def!"); 142 143 VRInfo.NumUses++; 144 145 // Check to see if this basic block is already a kill block... 146 if (!VRInfo.Kills.empty() && VRInfo.Kills.back()->getParent() == MBB) { 147 // Yes, this register is killed in this basic block already. Increase the 148 // live range by updating the kill instruction. 149 VRInfo.Kills.back() = MI; 150 return; 151 } 152 153 #ifndef NDEBUG 154 for (unsigned i = 0, e = VRInfo.Kills.size(); i != e; ++i) 155 assert(VRInfo.Kills[i]->getParent() != MBB && "entry should be at end!"); 156 #endif 157 158 assert(MBB != VRInfo.DefInst->getParent() && 159 "Should have kill for defblock!"); 160 161 // Add a new kill entry for this basic block. 162 // If this virtual register is already marked as alive in this basic block, 163 // that means it is alive in at least one of the successor block, it's not 164 // a kill. 165 if (!VRInfo.AliveBlocks[MBB->getNumber()]) 166 VRInfo.Kills.push_back(MI); 167 168 // Update all dominating blocks to mark them known live. 169 for (MachineBasicBlock::const_pred_iterator PI = MBB->pred_begin(), 170 E = MBB->pred_end(); PI != E; ++PI) 171 MarkVirtRegAliveInBlock(VRInfo, *PI); 172 } 173 174 bool LiveVariables::addRegisterKilled(unsigned IncomingReg, MachineInstr *MI, 175 bool AddIfNotFound) { 176 bool Found = false; 177 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 178 MachineOperand &MO = MI->getOperand(i); 179 if (MO.isReg() && MO.isUse()) { 180 unsigned Reg = MO.getReg(); 181 if (!Reg) 182 continue; 183 if (Reg == IncomingReg) { 184 MO.setIsKill(); 185 Found = true; 186 break; 187 } else if (MRegisterInfo::isPhysicalRegister(Reg) && 188 MRegisterInfo::isPhysicalRegister(IncomingReg) && 189 RegInfo->isSuperRegister(IncomingReg, Reg) && 190 MO.isKill()) 191 // A super-register kill already exists. 192 return true; 193 } 194 } 195 196 // If not found, this means an alias of one of the operand is killed. Add a 197 // new implicit operand if required. 198 if (!Found && AddIfNotFound) { 199 MI->addRegOperand(IncomingReg, false/*IsDef*/,true/*IsImp*/,true/*IsKill*/); 200 return true; 201 } 202 return Found; 203 } 204 205 bool LiveVariables::addRegisterDead(unsigned IncomingReg, MachineInstr *MI, 206 bool AddIfNotFound) { 207 bool Found = false; 208 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 209 MachineOperand &MO = MI->getOperand(i); 210 if (MO.isReg() && MO.isDef()) { 211 unsigned Reg = MO.getReg(); 212 if (!Reg) 213 continue; 214 if (Reg == IncomingReg) { 215 MO.setIsDead(); 216 Found = true; 217 break; 218 } else if (MRegisterInfo::isPhysicalRegister(Reg) && 219 MRegisterInfo::isPhysicalRegister(IncomingReg) && 220 RegInfo->isSuperRegister(IncomingReg, Reg) && 221 MO.isDead()) 222 // There exists a super-register that's marked dead. 223 return true; 224 } 225 } 226 227 // If not found, this means an alias of one of the operand is dead. Add a 228 // new implicit operand. 229 if (!Found && AddIfNotFound) { 230 MI->addRegOperand(IncomingReg, true/*IsDef*/,true/*IsImp*/,false/*IsKill*/, 231 true/*IsDead*/); 232 return true; 233 } 234 return Found; 235 } 236 237 void LiveVariables::HandlePhysRegUse(unsigned Reg, MachineInstr *MI) { 238 // There is a now a proper use, forget about the last partial use. 239 PhysRegPartUse[Reg] = NULL; 240 241 // Turn previous partial def's into read/mod/write. 242 for (unsigned i = 0, e = PhysRegPartDef[Reg].size(); i != e; ++i) { 243 MachineInstr *Def = PhysRegPartDef[Reg][i]; 244 // First one is just a def. This means the use is reading some undef bits. 245 if (i != 0) 246 Def->addRegOperand(Reg, false/*IsDef*/,true/*IsImp*/,true/*IsKill*/); 247 Def->addRegOperand(Reg, true/*IsDef*/,true/*IsImp*/); 248 } 249 PhysRegPartDef[Reg].clear(); 250 251 // There was an earlier def of a super-register. Add implicit def to that MI. 252 // A: EAX = ... 253 // B: = AX 254 // Add implicit def to A. 255 if (PhysRegInfo[Reg] && !PhysRegUsed[Reg]) { 256 MachineInstr *Def = PhysRegInfo[Reg]; 257 if (!Def->findRegisterDefOperand(Reg)) 258 Def->addRegOperand(Reg, true/*IsDef*/,true/*IsImp*/); 259 } 260 261 PhysRegInfo[Reg] = MI; 262 PhysRegUsed[Reg] = true; 263 264 for (const unsigned *SubRegs = RegInfo->getSubRegisters(Reg); 265 unsigned SubReg = *SubRegs; ++SubRegs) { 266 PhysRegInfo[SubReg] = MI; 267 PhysRegUsed[SubReg] = true; 268 } 269 270 // Remember the partial uses. 271 for (const unsigned *SuperRegs = RegInfo->getSuperRegisters(Reg); 272 unsigned SuperReg = *SuperRegs; ++SuperRegs) 273 PhysRegPartUse[SuperReg] = MI; 274 } 275 276 void LiveVariables::HandlePhysRegDef(unsigned Reg, MachineInstr *MI) { 277 // Does this kill a previous version of this register? 278 if (MachineInstr *LastRef = PhysRegInfo[Reg]) { 279 if (PhysRegUsed[Reg]) 280 addRegisterKilled(Reg, LastRef); 281 else if (PhysRegPartUse[Reg]) 282 // Add implicit use / kill to last use of a sub-register. 283 addRegisterKilled(Reg, PhysRegPartUse[Reg], true); 284 else 285 addRegisterDead(Reg, LastRef); 286 } 287 PhysRegInfo[Reg] = MI; 288 PhysRegUsed[Reg] = false; 289 PhysRegPartUse[Reg] = NULL; 290 291 for (const unsigned *SubRegs = RegInfo->getSubRegisters(Reg); 292 unsigned SubReg = *SubRegs; ++SubRegs) { 293 if (MachineInstr *LastRef = PhysRegInfo[SubReg]) { 294 if (PhysRegUsed[SubReg]) 295 addRegisterKilled(SubReg, LastRef); 296 else if (PhysRegPartUse[SubReg]) 297 // Add implicit use / kill to last use of a sub-register. 298 addRegisterKilled(SubReg, PhysRegPartUse[SubReg], true); 299 else 300 addRegisterDead(SubReg, LastRef); 301 } 302 PhysRegInfo[SubReg] = MI; 303 PhysRegUsed[SubReg] = false; 304 } 305 306 if (MI) 307 for (const unsigned *SuperRegs = RegInfo->getSuperRegisters(Reg); 308 unsigned SuperReg = *SuperRegs; ++SuperRegs) { 309 if (PhysRegInfo[SuperReg]) { 310 // The larger register is previously defined. Now a smaller part is 311 // being re-defined. Treat it as read/mod/write. 312 // EAX = 313 // AX = EAX<imp-use,kill>, EAX<imp-def> 314 MI->addRegOperand(SuperReg, false/*IsDef*/,true/*IsImp*/,true/*IsKill*/); 315 MI->addRegOperand(SuperReg, true/*IsDef*/,true/*IsImp*/); 316 PhysRegInfo[SuperReg] = MI; 317 PhysRegUsed[SuperReg] = false; 318 } else { 319 // Remember this partial def. 320 PhysRegPartDef[SuperReg].push_back(MI); 321 } 322 } 323 } 324 325 bool LiveVariables::runOnMachineFunction(MachineFunction &mf) { 326 MF = &mf; 327 const TargetInstrInfo &TII = *MF->getTarget().getInstrInfo(); 328 RegInfo = MF->getTarget().getRegisterInfo(); 329 assert(RegInfo && "Target doesn't have register information?"); 330 331 ReservedRegisters = RegInfo->getReservedRegs(mf); 332 333 unsigned NumRegs = RegInfo->getNumRegs(); 334 PhysRegInfo = new MachineInstr*[NumRegs]; 335 PhysRegUsed = new bool[NumRegs]; 336 PhysRegPartUse = new MachineInstr*[NumRegs]; 337 PhysRegPartDef = new SmallVector<MachineInstr*,4>[NumRegs]; 338 PHIVarInfo = new SmallVector<unsigned, 4>[MF->getNumBlockIDs()]; 339 std::fill(PhysRegInfo, PhysRegInfo + NumRegs, (MachineInstr*)0); 340 std::fill(PhysRegUsed, PhysRegUsed + NumRegs, false); 341 std::fill(PhysRegPartUse, PhysRegPartUse + NumRegs, (MachineInstr*)0); 342 343 /// Get some space for a respectable number of registers... 344 VirtRegInfo.resize(64); 345 346 analyzePHINodes(mf); 347 348 // Calculate live variable information in depth first order on the CFG of the 349 // function. This guarantees that we will see the definition of a virtual 350 // register before its uses due to dominance properties of SSA (except for PHI 351 // nodes, which are treated as a special case). 352 // 353 MachineBasicBlock *Entry = MF->begin(); 354 std::set<MachineBasicBlock*> Visited; 355 for (df_ext_iterator<MachineBasicBlock*> DFI = df_ext_begin(Entry, Visited), 356 E = df_ext_end(Entry, Visited); DFI != E; ++DFI) { 357 MachineBasicBlock *MBB = *DFI; 358 359 // Mark live-in registers as live-in. 360 for (MachineBasicBlock::const_livein_iterator II = MBB->livein_begin(), 361 EE = MBB->livein_end(); II != EE; ++II) { 362 assert(MRegisterInfo::isPhysicalRegister(*II) && 363 "Cannot have a live-in virtual register!"); 364 HandlePhysRegDef(*II, 0); 365 } 366 367 // Loop over all of the instructions, processing them. 368 for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end(); 369 I != E; ++I) { 370 MachineInstr *MI = I; 371 372 // Process all of the operands of the instruction... 373 unsigned NumOperandsToProcess = MI->getNumOperands(); 374 375 // Unless it is a PHI node. In this case, ONLY process the DEF, not any 376 // of the uses. They will be handled in other basic blocks. 377 if (MI->getOpcode() == TargetInstrInfo::PHI) 378 NumOperandsToProcess = 1; 379 380 // Process all uses... 381 for (unsigned i = 0; i != NumOperandsToProcess; ++i) { 382 MachineOperand &MO = MI->getOperand(i); 383 if (MO.isRegister() && MO.isUse() && MO.getReg()) { 384 if (MRegisterInfo::isVirtualRegister(MO.getReg())){ 385 HandleVirtRegUse(getVarInfo(MO.getReg()), MBB, MI); 386 } else if (MRegisterInfo::isPhysicalRegister(MO.getReg()) && 387 !ReservedRegisters[MO.getReg()]) { 388 HandlePhysRegUse(MO.getReg(), MI); 389 } 390 } 391 } 392 393 // Process all defs... 394 for (unsigned i = 0; i != NumOperandsToProcess; ++i) { 395 MachineOperand &MO = MI->getOperand(i); 396 if (MO.isRegister() && MO.isDef() && MO.getReg()) { 397 if (MRegisterInfo::isVirtualRegister(MO.getReg())) { 398 VarInfo &VRInfo = getVarInfo(MO.getReg()); 399 400 assert(VRInfo.DefInst == 0 && "Variable multiply defined!"); 401 VRInfo.DefInst = MI; 402 // Defaults to dead 403 VRInfo.Kills.push_back(MI); 404 } else if (MRegisterInfo::isPhysicalRegister(MO.getReg()) && 405 !ReservedRegisters[MO.getReg()]) { 406 HandlePhysRegDef(MO.getReg(), MI); 407 } 408 } 409 } 410 } 411 412 // Handle any virtual assignments from PHI nodes which might be at the 413 // bottom of this basic block. We check all of our successor blocks to see 414 // if they have PHI nodes, and if so, we simulate an assignment at the end 415 // of the current block. 416 if (!PHIVarInfo[MBB->getNumber()].empty()) { 417 SmallVector<unsigned, 4>& VarInfoVec = PHIVarInfo[MBB->getNumber()]; 418 419 for (SmallVector<unsigned, 4>::iterator I = VarInfoVec.begin(), 420 E = VarInfoVec.end(); I != E; ++I) { 421 VarInfo& VRInfo = getVarInfo(*I); 422 assert(VRInfo.DefInst && "Register use before def (or no def)!"); 423 424 // Only mark it alive only in the block we are representing. 425 MarkVirtRegAliveInBlock(VRInfo, MBB); 426 } 427 } 428 429 // Finally, if the last instruction in the block is a return, make sure to mark 430 // it as using all of the live-out values in the function. 431 if (!MBB->empty() && TII.isReturn(MBB->back().getOpcode())) { 432 MachineInstr *Ret = &MBB->back(); 433 for (MachineFunction::liveout_iterator I = MF->liveout_begin(), 434 E = MF->liveout_end(); I != E; ++I) { 435 assert(MRegisterInfo::isPhysicalRegister(*I) && 436 "Cannot have a live-in virtual register!"); 437 HandlePhysRegUse(*I, Ret); 438 // Add live-out registers as implicit uses. 439 if (Ret->findRegisterUseOperandIdx(*I) == -1) 440 Ret->addRegOperand(*I, false, true); 441 } 442 } 443 444 // Loop over PhysRegInfo, killing any registers that are available at the 445 // end of the basic block. This also resets the PhysRegInfo map. 446 for (unsigned i = 0; i != NumRegs; ++i) 447 if (PhysRegInfo[i]) 448 HandlePhysRegDef(i, 0); 449 450 // Clear some states between BB's. These are purely local information. 451 for (unsigned i = 0; i != NumRegs; ++i) 452 PhysRegPartDef[i].clear(); 453 std::fill(PhysRegPartUse, PhysRegPartUse + NumRegs, (MachineInstr*)0); 454 } 455 456 // Convert and transfer the dead / killed information we have gathered into 457 // VirtRegInfo onto MI's. 458 // 459 for (unsigned i = 0, e1 = VirtRegInfo.size(); i != e1; ++i) 460 for (unsigned j = 0, e2 = VirtRegInfo[i].Kills.size(); j != e2; ++j) { 461 if (VirtRegInfo[i].Kills[j] == VirtRegInfo[i].DefInst) 462 addRegisterDead(i + MRegisterInfo::FirstVirtualRegister, 463 VirtRegInfo[i].Kills[j]); 464 else 465 addRegisterKilled(i + MRegisterInfo::FirstVirtualRegister, 466 VirtRegInfo[i].Kills[j]); 467 } 468 469 // Check to make sure there are no unreachable blocks in the MC CFG for the 470 // function. If so, it is due to a bug in the instruction selector or some 471 // other part of the code generator if this happens. 472 #ifndef NDEBUG 473 for(MachineFunction::iterator i = MF->begin(), e = MF->end(); i != e; ++i) 474 assert(Visited.count(&*i) != 0 && "unreachable basic block found"); 475 #endif 476 477 delete[] PhysRegInfo; 478 delete[] PhysRegUsed; 479 delete[] PhysRegPartUse; 480 delete[] PhysRegPartDef; 481 delete[] PHIVarInfo; 482 483 return false; 484 } 485 486 /// instructionChanged - When the address of an instruction changes, this 487 /// method should be called so that live variables can update its internal 488 /// data structures. This removes the records for OldMI, transfering them to 489 /// the records for NewMI. 490 void LiveVariables::instructionChanged(MachineInstr *OldMI, 491 MachineInstr *NewMI) { 492 // If the instruction defines any virtual registers, update the VarInfo, 493 // kill and dead information for the instruction. 494 for (unsigned i = 0, e = OldMI->getNumOperands(); i != e; ++i) { 495 MachineOperand &MO = OldMI->getOperand(i); 496 if (MO.isRegister() && MO.getReg() && 497 MRegisterInfo::isVirtualRegister(MO.getReg())) { 498 unsigned Reg = MO.getReg(); 499 VarInfo &VI = getVarInfo(Reg); 500 if (MO.isDef()) { 501 if (MO.isDead()) { 502 MO.unsetIsDead(); 503 addVirtualRegisterDead(Reg, NewMI); 504 } 505 // Update the defining instruction. 506 if (VI.DefInst == OldMI) 507 VI.DefInst = NewMI; 508 } 509 if (MO.isUse()) { 510 if (MO.isKill()) { 511 MO.unsetIsKill(); 512 addVirtualRegisterKilled(Reg, NewMI); 513 } 514 // If this is a kill of the value, update the VI kills list. 515 if (VI.removeKill(OldMI)) 516 VI.Kills.push_back(NewMI); // Yes, there was a kill of it 517 } 518 } 519 } 520 } 521 522 /// removeVirtualRegistersKilled - Remove all killed info for the specified 523 /// instruction. 524 void LiveVariables::removeVirtualRegistersKilled(MachineInstr *MI) { 525 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 526 MachineOperand &MO = MI->getOperand(i); 527 if (MO.isReg() && MO.isKill()) { 528 MO.unsetIsKill(); 529 unsigned Reg = MO.getReg(); 530 if (MRegisterInfo::isVirtualRegister(Reg)) { 531 bool removed = getVarInfo(Reg).removeKill(MI); 532 assert(removed && "kill not in register's VarInfo?"); 533 } 534 } 535 } 536 } 537 538 /// removeVirtualRegistersDead - Remove all of the dead registers for the 539 /// specified instruction from the live variable information. 540 void LiveVariables::removeVirtualRegistersDead(MachineInstr *MI) { 541 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 542 MachineOperand &MO = MI->getOperand(i); 543 if (MO.isReg() && MO.isDead()) { 544 MO.unsetIsDead(); 545 unsigned Reg = MO.getReg(); 546 if (MRegisterInfo::isVirtualRegister(Reg)) { 547 bool removed = getVarInfo(Reg).removeKill(MI); 548 assert(removed && "kill not in register's VarInfo?"); 549 } 550 } 551 } 552 } 553 554 /// analyzePHINodes - Gather information about the PHI nodes in here. In 555 /// particular, we want to map the variable information of a virtual 556 /// register which is used in a PHI node. We map that to the BB the vreg is 557 /// coming from. 558 /// 559 void LiveVariables::analyzePHINodes(const MachineFunction& Fn) { 560 for (MachineFunction::const_iterator I = Fn.begin(), E = Fn.end(); 561 I != E; ++I) 562 for (MachineBasicBlock::const_iterator BBI = I->begin(), BBE = I->end(); 563 BBI != BBE && BBI->getOpcode() == TargetInstrInfo::PHI; ++BBI) 564 for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2) 565 PHIVarInfo[BBI->getOperand(i + 1).getMachineBasicBlock()->getNumber()]. 566 push_back(BBI->getOperand(i).getReg()); 567 } 568