1 //===-- llvm/CodeGen/MachineBasicBlock.cpp ----------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // Collect the sequence of machine instructions for a basic block. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/CodeGen/MachineBasicBlock.h" 15 #include "llvm/ADT/SmallPtrSet.h" 16 #include "llvm/ADT/SmallString.h" 17 #include "llvm/CodeGen/LiveIntervalAnalysis.h" 18 #include "llvm/CodeGen/LiveVariables.h" 19 #include "llvm/CodeGen/MachineDominators.h" 20 #include "llvm/CodeGen/MachineFunction.h" 21 #include "llvm/CodeGen/MachineInstrBuilder.h" 22 #include "llvm/CodeGen/MachineLoopInfo.h" 23 #include "llvm/CodeGen/MachineRegisterInfo.h" 24 #include "llvm/CodeGen/SlotIndexes.h" 25 #include "llvm/IR/BasicBlock.h" 26 #include "llvm/IR/DataLayout.h" 27 #include "llvm/IR/ModuleSlotTracker.h" 28 #include "llvm/MC/MCAsmInfo.h" 29 #include "llvm/MC/MCContext.h" 30 #include "llvm/Support/Debug.h" 31 #include "llvm/Support/raw_ostream.h" 32 #include "llvm/Target/TargetInstrInfo.h" 33 #include "llvm/Target/TargetMachine.h" 34 #include "llvm/Target/TargetRegisterInfo.h" 35 #include "llvm/Target/TargetSubtargetInfo.h" 36 #include <algorithm> 37 using namespace llvm; 38 39 #define DEBUG_TYPE "codegen" 40 41 MachineBasicBlock::MachineBasicBlock(MachineFunction &mf, const BasicBlock *bb) 42 : BB(bb), Number(-1), xParent(&mf), Alignment(0), IsLandingPad(false), 43 AddressTaken(false), CachedMCSymbol(nullptr) { 44 Insts.Parent = this; 45 } 46 47 MachineBasicBlock::~MachineBasicBlock() { 48 } 49 50 /// getSymbol - Return the MCSymbol for this basic block. 51 /// 52 MCSymbol *MachineBasicBlock::getSymbol() const { 53 if (!CachedMCSymbol) { 54 const MachineFunction *MF = getParent(); 55 MCContext &Ctx = MF->getContext(); 56 const char *Prefix = Ctx.getAsmInfo()->getPrivateLabelPrefix(); 57 CachedMCSymbol = Ctx.getOrCreateSymbol(Twine(Prefix) + "BB" + 58 Twine(MF->getFunctionNumber()) + 59 "_" + Twine(getNumber())); 60 } 61 62 return CachedMCSymbol; 63 } 64 65 66 raw_ostream &llvm::operator<<(raw_ostream &OS, const MachineBasicBlock &MBB) { 67 MBB.print(OS); 68 return OS; 69 } 70 71 /// addNodeToList (MBB) - When an MBB is added to an MF, we need to update the 72 /// parent pointer of the MBB, the MBB numbering, and any instructions in the 73 /// MBB to be on the right operand list for registers. 74 /// 75 /// MBBs start out as #-1. When a MBB is added to a MachineFunction, it 76 /// gets the next available unique MBB number. If it is removed from a 77 /// MachineFunction, it goes back to being #-1. 78 void ilist_traits<MachineBasicBlock>::addNodeToList(MachineBasicBlock *N) { 79 MachineFunction &MF = *N->getParent(); 80 N->Number = MF.addToMBBNumbering(N); 81 82 // Make sure the instructions have their operands in the reginfo lists. 83 MachineRegisterInfo &RegInfo = MF.getRegInfo(); 84 for (MachineBasicBlock::instr_iterator 85 I = N->instr_begin(), E = N->instr_end(); I != E; ++I) 86 I->AddRegOperandsToUseLists(RegInfo); 87 } 88 89 void ilist_traits<MachineBasicBlock>::removeNodeFromList(MachineBasicBlock *N) { 90 N->getParent()->removeFromMBBNumbering(N->Number); 91 N->Number = -1; 92 } 93 94 95 /// addNodeToList (MI) - When we add an instruction to a basic block 96 /// list, we update its parent pointer and add its operands from reg use/def 97 /// lists if appropriate. 98 void ilist_traits<MachineInstr>::addNodeToList(MachineInstr *N) { 99 assert(!N->getParent() && "machine instruction already in a basic block"); 100 N->setParent(Parent); 101 102 // Add the instruction's register operands to their corresponding 103 // use/def lists. 104 MachineFunction *MF = Parent->getParent(); 105 N->AddRegOperandsToUseLists(MF->getRegInfo()); 106 } 107 108 /// removeNodeFromList (MI) - When we remove an instruction from a basic block 109 /// list, we update its parent pointer and remove its operands from reg use/def 110 /// lists if appropriate. 111 void ilist_traits<MachineInstr>::removeNodeFromList(MachineInstr *N) { 112 assert(N->getParent() && "machine instruction not in a basic block"); 113 114 // Remove from the use/def lists. 115 if (MachineFunction *MF = N->getParent()->getParent()) 116 N->RemoveRegOperandsFromUseLists(MF->getRegInfo()); 117 118 N->setParent(nullptr); 119 } 120 121 /// transferNodesFromList (MI) - When moving a range of instructions from one 122 /// MBB list to another, we need to update the parent pointers and the use/def 123 /// lists. 124 void ilist_traits<MachineInstr>:: 125 transferNodesFromList(ilist_traits<MachineInstr> &fromList, 126 ilist_iterator<MachineInstr> first, 127 ilist_iterator<MachineInstr> last) { 128 assert(Parent->getParent() == fromList.Parent->getParent() && 129 "MachineInstr parent mismatch!"); 130 131 // Splice within the same MBB -> no change. 132 if (Parent == fromList.Parent) return; 133 134 // If splicing between two blocks within the same function, just update the 135 // parent pointers. 136 for (; first != last; ++first) 137 first->setParent(Parent); 138 } 139 140 void ilist_traits<MachineInstr>::deleteNode(MachineInstr* MI) { 141 assert(!MI->getParent() && "MI is still in a block!"); 142 Parent->getParent()->DeleteMachineInstr(MI); 143 } 144 145 MachineBasicBlock::iterator MachineBasicBlock::getFirstNonPHI() { 146 instr_iterator I = instr_begin(), E = instr_end(); 147 while (I != E && I->isPHI()) 148 ++I; 149 assert((I == E || !I->isInsideBundle()) && 150 "First non-phi MI cannot be inside a bundle!"); 151 return I; 152 } 153 154 MachineBasicBlock::iterator 155 MachineBasicBlock::SkipPHIsAndLabels(MachineBasicBlock::iterator I) { 156 iterator E = end(); 157 while (I != E && (I->isPHI() || I->isPosition() || I->isDebugValue())) 158 ++I; 159 // FIXME: This needs to change if we wish to bundle labels / dbg_values 160 // inside the bundle. 161 assert((I == E || !I->isInsideBundle()) && 162 "First non-phi / non-label instruction is inside a bundle!"); 163 return I; 164 } 165 166 MachineBasicBlock::iterator MachineBasicBlock::getFirstTerminator() { 167 iterator B = begin(), E = end(), I = E; 168 while (I != B && ((--I)->isTerminator() || I->isDebugValue())) 169 ; /*noop */ 170 while (I != E && !I->isTerminator()) 171 ++I; 172 return I; 173 } 174 175 MachineBasicBlock::instr_iterator MachineBasicBlock::getFirstInstrTerminator() { 176 instr_iterator B = instr_begin(), E = instr_end(), I = E; 177 while (I != B && ((--I)->isTerminator() || I->isDebugValue())) 178 ; /*noop */ 179 while (I != E && !I->isTerminator()) 180 ++I; 181 return I; 182 } 183 184 MachineBasicBlock::iterator MachineBasicBlock::getFirstNonDebugInstr() { 185 // Skip over begin-of-block dbg_value instructions. 186 iterator I = begin(), E = end(); 187 while (I != E && I->isDebugValue()) 188 ++I; 189 return I; 190 } 191 192 MachineBasicBlock::iterator MachineBasicBlock::getLastNonDebugInstr() { 193 // Skip over end-of-block dbg_value instructions. 194 instr_iterator B = instr_begin(), I = instr_end(); 195 while (I != B) { 196 --I; 197 // Return instruction that starts a bundle. 198 if (I->isDebugValue() || I->isInsideBundle()) 199 continue; 200 return I; 201 } 202 // The block is all debug values. 203 return end(); 204 } 205 206 const MachineBasicBlock *MachineBasicBlock::getLandingPadSuccessor() const { 207 // A block with a landing pad successor only has one other successor. 208 if (succ_size() > 2) 209 return nullptr; 210 for (const_succ_iterator I = succ_begin(), E = succ_end(); I != E; ++I) 211 if ((*I)->isLandingPad()) 212 return *I; 213 return nullptr; 214 } 215 216 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 217 void MachineBasicBlock::dump() const { 218 print(dbgs()); 219 } 220 #endif 221 222 StringRef MachineBasicBlock::getName() const { 223 if (const BasicBlock *LBB = getBasicBlock()) 224 return LBB->getName(); 225 else 226 return "(null)"; 227 } 228 229 /// Return a hopefully unique identifier for this block. 230 std::string MachineBasicBlock::getFullName() const { 231 std::string Name; 232 if (getParent()) 233 Name = (getParent()->getName() + ":").str(); 234 if (getBasicBlock()) 235 Name += getBasicBlock()->getName(); 236 else 237 Name += ("BB" + Twine(getNumber())).str(); 238 return Name; 239 } 240 241 void MachineBasicBlock::print(raw_ostream &OS, SlotIndexes *Indexes) const { 242 const MachineFunction *MF = getParent(); 243 if (!MF) { 244 OS << "Can't print out MachineBasicBlock because parent MachineFunction" 245 << " is null\n"; 246 return; 247 } 248 const Function *F = MF->getFunction(); 249 const Module *M = F ? F->getParent() : nullptr; 250 ModuleSlotTracker MST(M); 251 print(OS, MST, Indexes); 252 } 253 254 void MachineBasicBlock::print(raw_ostream &OS, ModuleSlotTracker &MST, 255 SlotIndexes *Indexes) const { 256 const MachineFunction *MF = getParent(); 257 if (!MF) { 258 OS << "Can't print out MachineBasicBlock because parent MachineFunction" 259 << " is null\n"; 260 return; 261 } 262 263 if (Indexes) 264 OS << Indexes->getMBBStartIdx(this) << '\t'; 265 266 OS << "BB#" << getNumber() << ": "; 267 268 const char *Comma = ""; 269 if (const BasicBlock *LBB = getBasicBlock()) { 270 OS << Comma << "derived from LLVM BB "; 271 LBB->printAsOperand(OS, /*PrintType=*/false, MST); 272 Comma = ", "; 273 } 274 if (isLandingPad()) { OS << Comma << "EH LANDING PAD"; Comma = ", "; } 275 if (hasAddressTaken()) { OS << Comma << "ADDRESS TAKEN"; Comma = ", "; } 276 if (Alignment) 277 OS << Comma << "Align " << Alignment << " (" << (1u << Alignment) 278 << " bytes)"; 279 280 OS << '\n'; 281 282 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo(); 283 if (!livein_empty()) { 284 if (Indexes) OS << '\t'; 285 OS << " Live Ins:"; 286 for (livein_iterator I = livein_begin(),E = livein_end(); I != E; ++I) 287 OS << ' ' << PrintReg(*I, TRI); 288 OS << '\n'; 289 } 290 // Print the preds of this block according to the CFG. 291 if (!pred_empty()) { 292 if (Indexes) OS << '\t'; 293 OS << " Predecessors according to CFG:"; 294 for (const_pred_iterator PI = pred_begin(), E = pred_end(); PI != E; ++PI) 295 OS << " BB#" << (*PI)->getNumber(); 296 OS << '\n'; 297 } 298 299 for (const_instr_iterator I = instr_begin(); I != instr_end(); ++I) { 300 if (Indexes) { 301 if (Indexes->hasIndex(I)) 302 OS << Indexes->getInstructionIndex(I); 303 OS << '\t'; 304 } 305 OS << '\t'; 306 if (I->isInsideBundle()) 307 OS << " * "; 308 I->print(OS, MST); 309 } 310 311 // Print the successors of this block according to the CFG. 312 if (!succ_empty()) { 313 if (Indexes) OS << '\t'; 314 OS << " Successors according to CFG:"; 315 for (const_succ_iterator SI = succ_begin(), E = succ_end(); SI != E; ++SI) { 316 OS << " BB#" << (*SI)->getNumber(); 317 if (!Weights.empty()) 318 OS << '(' << *getWeightIterator(SI) << ')'; 319 } 320 OS << '\n'; 321 } 322 } 323 324 void MachineBasicBlock::printAsOperand(raw_ostream &OS, bool /*PrintType*/) const { 325 OS << "BB#" << getNumber(); 326 } 327 328 void MachineBasicBlock::removeLiveIn(unsigned Reg) { 329 std::vector<unsigned>::iterator I = 330 std::find(LiveIns.begin(), LiveIns.end(), Reg); 331 if (I != LiveIns.end()) 332 LiveIns.erase(I); 333 } 334 335 unsigned 336 MachineBasicBlock::addLiveIn(unsigned PhysReg, const TargetRegisterClass *RC) { 337 assert(getParent() && "MBB must be inserted in function"); 338 assert(TargetRegisterInfo::isPhysicalRegister(PhysReg) && "Expected physreg"); 339 assert(RC && "Register class is required"); 340 assert((isLandingPad() || this == &getParent()->front()) && 341 "Only the entry block and landing pads can have physreg live ins"); 342 343 bool LiveIn = isLiveIn(PhysReg); 344 iterator I = SkipPHIsAndLabels(begin()), E = end(); 345 MachineRegisterInfo &MRI = getParent()->getRegInfo(); 346 const TargetInstrInfo &TII = *getParent()->getSubtarget().getInstrInfo(); 347 348 // Look for an existing copy. 349 if (LiveIn) 350 for (;I != E && I->isCopy(); ++I) 351 if (I->getOperand(1).getReg() == PhysReg) { 352 unsigned VirtReg = I->getOperand(0).getReg(); 353 if (!MRI.constrainRegClass(VirtReg, RC)) 354 llvm_unreachable("Incompatible live-in register class."); 355 return VirtReg; 356 } 357 358 // No luck, create a virtual register. 359 unsigned VirtReg = MRI.createVirtualRegister(RC); 360 BuildMI(*this, I, DebugLoc(), TII.get(TargetOpcode::COPY), VirtReg) 361 .addReg(PhysReg, RegState::Kill); 362 if (!LiveIn) 363 addLiveIn(PhysReg); 364 return VirtReg; 365 } 366 367 void MachineBasicBlock::moveBefore(MachineBasicBlock *NewAfter) { 368 getParent()->splice(NewAfter, this); 369 } 370 371 void MachineBasicBlock::moveAfter(MachineBasicBlock *NewBefore) { 372 MachineFunction::iterator BBI = NewBefore; 373 getParent()->splice(++BBI, this); 374 } 375 376 void MachineBasicBlock::updateTerminator() { 377 const TargetInstrInfo *TII = getParent()->getSubtarget().getInstrInfo(); 378 // A block with no successors has no concerns with fall-through edges. 379 if (this->succ_empty()) return; 380 381 MachineBasicBlock *TBB = nullptr, *FBB = nullptr; 382 SmallVector<MachineOperand, 4> Cond; 383 DebugLoc dl; // FIXME: this is nowhere 384 bool B = TII->AnalyzeBranch(*this, TBB, FBB, Cond); 385 (void) B; 386 assert(!B && "UpdateTerminators requires analyzable predecessors!"); 387 if (Cond.empty()) { 388 if (TBB) { 389 // The block has an unconditional branch. If its successor is now 390 // its layout successor, delete the branch. 391 if (isLayoutSuccessor(TBB)) 392 TII->RemoveBranch(*this); 393 } else { 394 // The block has an unconditional fallthrough. If its successor is not 395 // its layout successor, insert a branch. First we have to locate the 396 // only non-landing-pad successor, as that is the fallthrough block. 397 for (succ_iterator SI = succ_begin(), SE = succ_end(); SI != SE; ++SI) { 398 if ((*SI)->isLandingPad()) 399 continue; 400 assert(!TBB && "Found more than one non-landing-pad successor!"); 401 TBB = *SI; 402 } 403 404 // If there is no non-landing-pad successor, the block has no 405 // fall-through edges to be concerned with. 406 if (!TBB) 407 return; 408 409 // Finally update the unconditional successor to be reached via a branch 410 // if it would not be reached by fallthrough. 411 if (!isLayoutSuccessor(TBB)) 412 TII->InsertBranch(*this, TBB, nullptr, Cond, dl); 413 } 414 } else { 415 if (FBB) { 416 // The block has a non-fallthrough conditional branch. If one of its 417 // successors is its layout successor, rewrite it to a fallthrough 418 // conditional branch. 419 if (isLayoutSuccessor(TBB)) { 420 if (TII->ReverseBranchCondition(Cond)) 421 return; 422 TII->RemoveBranch(*this); 423 TII->InsertBranch(*this, FBB, nullptr, Cond, dl); 424 } else if (isLayoutSuccessor(FBB)) { 425 TII->RemoveBranch(*this); 426 TII->InsertBranch(*this, TBB, nullptr, Cond, dl); 427 } 428 } else { 429 // Walk through the successors and find the successor which is not 430 // a landing pad and is not the conditional branch destination (in TBB) 431 // as the fallthrough successor. 432 MachineBasicBlock *FallthroughBB = nullptr; 433 for (succ_iterator SI = succ_begin(), SE = succ_end(); SI != SE; ++SI) { 434 if ((*SI)->isLandingPad() || *SI == TBB) 435 continue; 436 assert(!FallthroughBB && "Found more than one fallthrough successor."); 437 FallthroughBB = *SI; 438 } 439 if (!FallthroughBB && canFallThrough()) { 440 // We fallthrough to the same basic block as the conditional jump 441 // targets. Remove the conditional jump, leaving unconditional 442 // fallthrough. 443 // FIXME: This does not seem like a reasonable pattern to support, but it 444 // has been seen in the wild coming out of degenerate ARM test cases. 445 TII->RemoveBranch(*this); 446 447 // Finally update the unconditional successor to be reached via a branch 448 // if it would not be reached by fallthrough. 449 if (!isLayoutSuccessor(TBB)) 450 TII->InsertBranch(*this, TBB, nullptr, Cond, dl); 451 return; 452 } 453 454 // The block has a fallthrough conditional branch. 455 if (isLayoutSuccessor(TBB)) { 456 if (TII->ReverseBranchCondition(Cond)) { 457 // We can't reverse the condition, add an unconditional branch. 458 Cond.clear(); 459 TII->InsertBranch(*this, FallthroughBB, nullptr, Cond, dl); 460 return; 461 } 462 TII->RemoveBranch(*this); 463 TII->InsertBranch(*this, FallthroughBB, nullptr, Cond, dl); 464 } else if (!isLayoutSuccessor(FallthroughBB)) { 465 TII->RemoveBranch(*this); 466 TII->InsertBranch(*this, TBB, FallthroughBB, Cond, dl); 467 } 468 } 469 } 470 } 471 472 void MachineBasicBlock::addSuccessor(MachineBasicBlock *succ, uint32_t weight) { 473 474 // If we see non-zero value for the first time it means we actually use Weight 475 // list, so we fill all Weights with 0's. 476 if (weight != 0 && Weights.empty()) 477 Weights.resize(Successors.size()); 478 479 if (weight != 0 || !Weights.empty()) 480 Weights.push_back(weight); 481 482 Successors.push_back(succ); 483 succ->addPredecessor(this); 484 } 485 486 void MachineBasicBlock::removeSuccessor(MachineBasicBlock *succ) { 487 succ->removePredecessor(this); 488 succ_iterator I = std::find(Successors.begin(), Successors.end(), succ); 489 assert(I != Successors.end() && "Not a current successor!"); 490 491 // If Weight list is empty it means we don't use it (disabled optimization). 492 if (!Weights.empty()) { 493 weight_iterator WI = getWeightIterator(I); 494 Weights.erase(WI); 495 } 496 497 Successors.erase(I); 498 } 499 500 MachineBasicBlock::succ_iterator 501 MachineBasicBlock::removeSuccessor(succ_iterator I) { 502 assert(I != Successors.end() && "Not a current successor!"); 503 504 // If Weight list is empty it means we don't use it (disabled optimization). 505 if (!Weights.empty()) { 506 weight_iterator WI = getWeightIterator(I); 507 Weights.erase(WI); 508 } 509 510 (*I)->removePredecessor(this); 511 return Successors.erase(I); 512 } 513 514 void MachineBasicBlock::replaceSuccessor(MachineBasicBlock *Old, 515 MachineBasicBlock *New) { 516 if (Old == New) 517 return; 518 519 succ_iterator E = succ_end(); 520 succ_iterator NewI = E; 521 succ_iterator OldI = E; 522 for (succ_iterator I = succ_begin(); I != E; ++I) { 523 if (*I == Old) { 524 OldI = I; 525 if (NewI != E) 526 break; 527 } 528 if (*I == New) { 529 NewI = I; 530 if (OldI != E) 531 break; 532 } 533 } 534 assert(OldI != E && "Old is not a successor of this block"); 535 Old->removePredecessor(this); 536 537 // If New isn't already a successor, let it take Old's place. 538 if (NewI == E) { 539 New->addPredecessor(this); 540 *OldI = New; 541 return; 542 } 543 544 // New is already a successor. 545 // Update its weight instead of adding a duplicate edge. 546 if (!Weights.empty()) { 547 weight_iterator OldWI = getWeightIterator(OldI); 548 *getWeightIterator(NewI) += *OldWI; 549 Weights.erase(OldWI); 550 } 551 Successors.erase(OldI); 552 } 553 554 void MachineBasicBlock::addPredecessor(MachineBasicBlock *pred) { 555 Predecessors.push_back(pred); 556 } 557 558 void MachineBasicBlock::removePredecessor(MachineBasicBlock *pred) { 559 pred_iterator I = std::find(Predecessors.begin(), Predecessors.end(), pred); 560 assert(I != Predecessors.end() && "Pred is not a predecessor of this block!"); 561 Predecessors.erase(I); 562 } 563 564 void MachineBasicBlock::transferSuccessors(MachineBasicBlock *fromMBB) { 565 if (this == fromMBB) 566 return; 567 568 while (!fromMBB->succ_empty()) { 569 MachineBasicBlock *Succ = *fromMBB->succ_begin(); 570 uint32_t Weight = 0; 571 572 // If Weight list is empty it means we don't use it (disabled optimization). 573 if (!fromMBB->Weights.empty()) 574 Weight = *fromMBB->Weights.begin(); 575 576 addSuccessor(Succ, Weight); 577 fromMBB->removeSuccessor(Succ); 578 } 579 } 580 581 void 582 MachineBasicBlock::transferSuccessorsAndUpdatePHIs(MachineBasicBlock *fromMBB) { 583 if (this == fromMBB) 584 return; 585 586 while (!fromMBB->succ_empty()) { 587 MachineBasicBlock *Succ = *fromMBB->succ_begin(); 588 uint32_t Weight = 0; 589 if (!fromMBB->Weights.empty()) 590 Weight = *fromMBB->Weights.begin(); 591 addSuccessor(Succ, Weight); 592 fromMBB->removeSuccessor(Succ); 593 594 // Fix up any PHI nodes in the successor. 595 for (MachineBasicBlock::instr_iterator MI = Succ->instr_begin(), 596 ME = Succ->instr_end(); MI != ME && MI->isPHI(); ++MI) 597 for (unsigned i = 2, e = MI->getNumOperands()+1; i != e; i += 2) { 598 MachineOperand &MO = MI->getOperand(i); 599 if (MO.getMBB() == fromMBB) 600 MO.setMBB(this); 601 } 602 } 603 } 604 605 bool MachineBasicBlock::isPredecessor(const MachineBasicBlock *MBB) const { 606 return std::find(pred_begin(), pred_end(), MBB) != pred_end(); 607 } 608 609 bool MachineBasicBlock::isSuccessor(const MachineBasicBlock *MBB) const { 610 return std::find(succ_begin(), succ_end(), MBB) != succ_end(); 611 } 612 613 bool MachineBasicBlock::isLayoutSuccessor(const MachineBasicBlock *MBB) const { 614 MachineFunction::const_iterator I(this); 615 return std::next(I) == MachineFunction::const_iterator(MBB); 616 } 617 618 bool MachineBasicBlock::canFallThrough() { 619 MachineFunction::iterator Fallthrough = this; 620 ++Fallthrough; 621 // If FallthroughBlock is off the end of the function, it can't fall through. 622 if (Fallthrough == getParent()->end()) 623 return false; 624 625 // If FallthroughBlock isn't a successor, no fallthrough is possible. 626 if (!isSuccessor(Fallthrough)) 627 return false; 628 629 // Analyze the branches, if any, at the end of the block. 630 MachineBasicBlock *TBB = nullptr, *FBB = nullptr; 631 SmallVector<MachineOperand, 4> Cond; 632 const TargetInstrInfo *TII = getParent()->getSubtarget().getInstrInfo(); 633 if (TII->AnalyzeBranch(*this, TBB, FBB, Cond)) { 634 // If we couldn't analyze the branch, examine the last instruction. 635 // If the block doesn't end in a known control barrier, assume fallthrough 636 // is possible. The isPredicated check is needed because this code can be 637 // called during IfConversion, where an instruction which is normally a 638 // Barrier is predicated and thus no longer an actual control barrier. 639 return empty() || !back().isBarrier() || TII->isPredicated(&back()); 640 } 641 642 // If there is no branch, control always falls through. 643 if (!TBB) return true; 644 645 // If there is some explicit branch to the fallthrough block, it can obviously 646 // reach, even though the branch should get folded to fall through implicitly. 647 if (MachineFunction::iterator(TBB) == Fallthrough || 648 MachineFunction::iterator(FBB) == Fallthrough) 649 return true; 650 651 // If it's an unconditional branch to some block not the fall through, it 652 // doesn't fall through. 653 if (Cond.empty()) return false; 654 655 // Otherwise, if it is conditional and has no explicit false block, it falls 656 // through. 657 return FBB == nullptr; 658 } 659 660 MachineBasicBlock * 661 MachineBasicBlock::SplitCriticalEdge(MachineBasicBlock *Succ, Pass *P) { 662 // Splitting the critical edge to a landing pad block is non-trivial. Don't do 663 // it in this generic function. 664 if (Succ->isLandingPad()) 665 return nullptr; 666 667 MachineFunction *MF = getParent(); 668 DebugLoc dl; // FIXME: this is nowhere 669 670 // Performance might be harmed on HW that implements branching using exec mask 671 // where both sides of the branches are always executed. 672 if (MF->getTarget().requiresStructuredCFG()) 673 return nullptr; 674 675 // We may need to update this's terminator, but we can't do that if 676 // AnalyzeBranch fails. If this uses a jump table, we won't touch it. 677 const TargetInstrInfo *TII = MF->getSubtarget().getInstrInfo(); 678 MachineBasicBlock *TBB = nullptr, *FBB = nullptr; 679 SmallVector<MachineOperand, 4> Cond; 680 if (TII->AnalyzeBranch(*this, TBB, FBB, Cond)) 681 return nullptr; 682 683 // Avoid bugpoint weirdness: A block may end with a conditional branch but 684 // jumps to the same MBB is either case. We have duplicate CFG edges in that 685 // case that we can't handle. Since this never happens in properly optimized 686 // code, just skip those edges. 687 if (TBB && TBB == FBB) { 688 DEBUG(dbgs() << "Won't split critical edge after degenerate BB#" 689 << getNumber() << '\n'); 690 return nullptr; 691 } 692 693 MachineBasicBlock *NMBB = MF->CreateMachineBasicBlock(); 694 MF->insert(std::next(MachineFunction::iterator(this)), NMBB); 695 DEBUG(dbgs() << "Splitting critical edge:" 696 " BB#" << getNumber() 697 << " -- BB#" << NMBB->getNumber() 698 << " -- BB#" << Succ->getNumber() << '\n'); 699 700 LiveIntervals *LIS = P->getAnalysisIfAvailable<LiveIntervals>(); 701 SlotIndexes *Indexes = P->getAnalysisIfAvailable<SlotIndexes>(); 702 if (LIS) 703 LIS->insertMBBInMaps(NMBB); 704 else if (Indexes) 705 Indexes->insertMBBInMaps(NMBB); 706 707 // On some targets like Mips, branches may kill virtual registers. Make sure 708 // that LiveVariables is properly updated after updateTerminator replaces the 709 // terminators. 710 LiveVariables *LV = P->getAnalysisIfAvailable<LiveVariables>(); 711 712 // Collect a list of virtual registers killed by the terminators. 713 SmallVector<unsigned, 4> KilledRegs; 714 if (LV) 715 for (instr_iterator I = getFirstInstrTerminator(), E = instr_end(); 716 I != E; ++I) { 717 MachineInstr *MI = I; 718 for (MachineInstr::mop_iterator OI = MI->operands_begin(), 719 OE = MI->operands_end(); OI != OE; ++OI) { 720 if (!OI->isReg() || OI->getReg() == 0 || 721 !OI->isUse() || !OI->isKill() || OI->isUndef()) 722 continue; 723 unsigned Reg = OI->getReg(); 724 if (TargetRegisterInfo::isPhysicalRegister(Reg) || 725 LV->getVarInfo(Reg).removeKill(MI)) { 726 KilledRegs.push_back(Reg); 727 DEBUG(dbgs() << "Removing terminator kill: " << *MI); 728 OI->setIsKill(false); 729 } 730 } 731 } 732 733 SmallVector<unsigned, 4> UsedRegs; 734 if (LIS) { 735 for (instr_iterator I = getFirstInstrTerminator(), E = instr_end(); 736 I != E; ++I) { 737 MachineInstr *MI = I; 738 739 for (MachineInstr::mop_iterator OI = MI->operands_begin(), 740 OE = MI->operands_end(); OI != OE; ++OI) { 741 if (!OI->isReg() || OI->getReg() == 0) 742 continue; 743 744 unsigned Reg = OI->getReg(); 745 if (std::find(UsedRegs.begin(), UsedRegs.end(), Reg) == UsedRegs.end()) 746 UsedRegs.push_back(Reg); 747 } 748 } 749 } 750 751 ReplaceUsesOfBlockWith(Succ, NMBB); 752 753 // If updateTerminator() removes instructions, we need to remove them from 754 // SlotIndexes. 755 SmallVector<MachineInstr*, 4> Terminators; 756 if (Indexes) { 757 for (instr_iterator I = getFirstInstrTerminator(), E = instr_end(); 758 I != E; ++I) 759 Terminators.push_back(I); 760 } 761 762 updateTerminator(); 763 764 if (Indexes) { 765 SmallVector<MachineInstr*, 4> NewTerminators; 766 for (instr_iterator I = getFirstInstrTerminator(), E = instr_end(); 767 I != E; ++I) 768 NewTerminators.push_back(I); 769 770 for (SmallVectorImpl<MachineInstr*>::iterator I = Terminators.begin(), 771 E = Terminators.end(); I != E; ++I) { 772 if (std::find(NewTerminators.begin(), NewTerminators.end(), *I) == 773 NewTerminators.end()) 774 Indexes->removeMachineInstrFromMaps(*I); 775 } 776 } 777 778 // Insert unconditional "jump Succ" instruction in NMBB if necessary. 779 NMBB->addSuccessor(Succ); 780 if (!NMBB->isLayoutSuccessor(Succ)) { 781 Cond.clear(); 782 MF->getSubtarget().getInstrInfo()->InsertBranch(*NMBB, Succ, nullptr, Cond, 783 dl); 784 785 if (Indexes) { 786 for (instr_iterator I = NMBB->instr_begin(), E = NMBB->instr_end(); 787 I != E; ++I) { 788 // Some instructions may have been moved to NMBB by updateTerminator(), 789 // so we first remove any instruction that already has an index. 790 if (Indexes->hasIndex(I)) 791 Indexes->removeMachineInstrFromMaps(I); 792 Indexes->insertMachineInstrInMaps(I); 793 } 794 } 795 } 796 797 // Fix PHI nodes in Succ so they refer to NMBB instead of this 798 for (MachineBasicBlock::instr_iterator 799 i = Succ->instr_begin(),e = Succ->instr_end(); 800 i != e && i->isPHI(); ++i) 801 for (unsigned ni = 1, ne = i->getNumOperands(); ni != ne; ni += 2) 802 if (i->getOperand(ni+1).getMBB() == this) 803 i->getOperand(ni+1).setMBB(NMBB); 804 805 // Inherit live-ins from the successor 806 for (MachineBasicBlock::livein_iterator I = Succ->livein_begin(), 807 E = Succ->livein_end(); I != E; ++I) 808 NMBB->addLiveIn(*I); 809 810 // Update LiveVariables. 811 const TargetRegisterInfo *TRI = MF->getSubtarget().getRegisterInfo(); 812 if (LV) { 813 // Restore kills of virtual registers that were killed by the terminators. 814 while (!KilledRegs.empty()) { 815 unsigned Reg = KilledRegs.pop_back_val(); 816 for (instr_iterator I = instr_end(), E = instr_begin(); I != E;) { 817 if (!(--I)->addRegisterKilled(Reg, TRI, /* addIfNotFound= */ false)) 818 continue; 819 if (TargetRegisterInfo::isVirtualRegister(Reg)) 820 LV->getVarInfo(Reg).Kills.push_back(I); 821 DEBUG(dbgs() << "Restored terminator kill: " << *I); 822 break; 823 } 824 } 825 // Update relevant live-through information. 826 LV->addNewBlock(NMBB, this, Succ); 827 } 828 829 if (LIS) { 830 // After splitting the edge and updating SlotIndexes, live intervals may be 831 // in one of two situations, depending on whether this block was the last in 832 // the function. If the original block was the last in the function, all live 833 // intervals will end prior to the beginning of the new split block. If the 834 // original block was not at the end of the function, all live intervals will 835 // extend to the end of the new split block. 836 837 bool isLastMBB = 838 std::next(MachineFunction::iterator(NMBB)) == getParent()->end(); 839 840 SlotIndex StartIndex = Indexes->getMBBEndIdx(this); 841 SlotIndex PrevIndex = StartIndex.getPrevSlot(); 842 SlotIndex EndIndex = Indexes->getMBBEndIdx(NMBB); 843 844 // Find the registers used from NMBB in PHIs in Succ. 845 SmallSet<unsigned, 8> PHISrcRegs; 846 for (MachineBasicBlock::instr_iterator 847 I = Succ->instr_begin(), E = Succ->instr_end(); 848 I != E && I->isPHI(); ++I) { 849 for (unsigned ni = 1, ne = I->getNumOperands(); ni != ne; ni += 2) { 850 if (I->getOperand(ni+1).getMBB() == NMBB) { 851 MachineOperand &MO = I->getOperand(ni); 852 unsigned Reg = MO.getReg(); 853 PHISrcRegs.insert(Reg); 854 if (MO.isUndef()) 855 continue; 856 857 LiveInterval &LI = LIS->getInterval(Reg); 858 VNInfo *VNI = LI.getVNInfoAt(PrevIndex); 859 assert(VNI && "PHI sources should be live out of their predecessors."); 860 LI.addSegment(LiveInterval::Segment(StartIndex, EndIndex, VNI)); 861 } 862 } 863 } 864 865 MachineRegisterInfo *MRI = &getParent()->getRegInfo(); 866 for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) { 867 unsigned Reg = TargetRegisterInfo::index2VirtReg(i); 868 if (PHISrcRegs.count(Reg) || !LIS->hasInterval(Reg)) 869 continue; 870 871 LiveInterval &LI = LIS->getInterval(Reg); 872 if (!LI.liveAt(PrevIndex)) 873 continue; 874 875 bool isLiveOut = LI.liveAt(LIS->getMBBStartIdx(Succ)); 876 if (isLiveOut && isLastMBB) { 877 VNInfo *VNI = LI.getVNInfoAt(PrevIndex); 878 assert(VNI && "LiveInterval should have VNInfo where it is live."); 879 LI.addSegment(LiveInterval::Segment(StartIndex, EndIndex, VNI)); 880 } else if (!isLiveOut && !isLastMBB) { 881 LI.removeSegment(StartIndex, EndIndex); 882 } 883 } 884 885 // Update all intervals for registers whose uses may have been modified by 886 // updateTerminator(). 887 LIS->repairIntervalsInRange(this, getFirstTerminator(), end(), UsedRegs); 888 } 889 890 if (MachineDominatorTree *MDT = 891 P->getAnalysisIfAvailable<MachineDominatorTree>()) 892 MDT->recordSplitCriticalEdge(this, Succ, NMBB); 893 894 if (MachineLoopInfo *MLI = P->getAnalysisIfAvailable<MachineLoopInfo>()) 895 if (MachineLoop *TIL = MLI->getLoopFor(this)) { 896 // If one or the other blocks were not in a loop, the new block is not 897 // either, and thus LI doesn't need to be updated. 898 if (MachineLoop *DestLoop = MLI->getLoopFor(Succ)) { 899 if (TIL == DestLoop) { 900 // Both in the same loop, the NMBB joins loop. 901 DestLoop->addBasicBlockToLoop(NMBB, MLI->getBase()); 902 } else if (TIL->contains(DestLoop)) { 903 // Edge from an outer loop to an inner loop. Add to the outer loop. 904 TIL->addBasicBlockToLoop(NMBB, MLI->getBase()); 905 } else if (DestLoop->contains(TIL)) { 906 // Edge from an inner loop to an outer loop. Add to the outer loop. 907 DestLoop->addBasicBlockToLoop(NMBB, MLI->getBase()); 908 } else { 909 // Edge from two loops with no containment relation. Because these 910 // are natural loops, we know that the destination block must be the 911 // header of its loop (adding a branch into a loop elsewhere would 912 // create an irreducible loop). 913 assert(DestLoop->getHeader() == Succ && 914 "Should not create irreducible loops!"); 915 if (MachineLoop *P = DestLoop->getParentLoop()) 916 P->addBasicBlockToLoop(NMBB, MLI->getBase()); 917 } 918 } 919 } 920 921 return NMBB; 922 } 923 924 /// Prepare MI to be removed from its bundle. This fixes bundle flags on MI's 925 /// neighboring instructions so the bundle won't be broken by removing MI. 926 static void unbundleSingleMI(MachineInstr *MI) { 927 // Removing the first instruction in a bundle. 928 if (MI->isBundledWithSucc() && !MI->isBundledWithPred()) 929 MI->unbundleFromSucc(); 930 // Removing the last instruction in a bundle. 931 if (MI->isBundledWithPred() && !MI->isBundledWithSucc()) 932 MI->unbundleFromPred(); 933 // If MI is not bundled, or if it is internal to a bundle, the neighbor flags 934 // are already fine. 935 } 936 937 MachineBasicBlock::instr_iterator 938 MachineBasicBlock::erase(MachineBasicBlock::instr_iterator I) { 939 unbundleSingleMI(I); 940 return Insts.erase(I); 941 } 942 943 MachineInstr *MachineBasicBlock::remove_instr(MachineInstr *MI) { 944 unbundleSingleMI(MI); 945 MI->clearFlag(MachineInstr::BundledPred); 946 MI->clearFlag(MachineInstr::BundledSucc); 947 return Insts.remove(MI); 948 } 949 950 MachineBasicBlock::instr_iterator 951 MachineBasicBlock::insert(instr_iterator I, MachineInstr *MI) { 952 assert(!MI->isBundledWithPred() && !MI->isBundledWithSucc() && 953 "Cannot insert instruction with bundle flags"); 954 // Set the bundle flags when inserting inside a bundle. 955 if (I != instr_end() && I->isBundledWithPred()) { 956 MI->setFlag(MachineInstr::BundledPred); 957 MI->setFlag(MachineInstr::BundledSucc); 958 } 959 return Insts.insert(I, MI); 960 } 961 962 /// removeFromParent - This method unlinks 'this' from the containing function, 963 /// and returns it, but does not delete it. 964 MachineBasicBlock *MachineBasicBlock::removeFromParent() { 965 assert(getParent() && "Not embedded in a function!"); 966 getParent()->remove(this); 967 return this; 968 } 969 970 971 /// eraseFromParent - This method unlinks 'this' from the containing function, 972 /// and deletes it. 973 void MachineBasicBlock::eraseFromParent() { 974 assert(getParent() && "Not embedded in a function!"); 975 getParent()->erase(this); 976 } 977 978 979 /// ReplaceUsesOfBlockWith - Given a machine basic block that branched to 980 /// 'Old', change the code and CFG so that it branches to 'New' instead. 981 void MachineBasicBlock::ReplaceUsesOfBlockWith(MachineBasicBlock *Old, 982 MachineBasicBlock *New) { 983 assert(Old != New && "Cannot replace self with self!"); 984 985 MachineBasicBlock::instr_iterator I = instr_end(); 986 while (I != instr_begin()) { 987 --I; 988 if (!I->isTerminator()) break; 989 990 // Scan the operands of this machine instruction, replacing any uses of Old 991 // with New. 992 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) 993 if (I->getOperand(i).isMBB() && 994 I->getOperand(i).getMBB() == Old) 995 I->getOperand(i).setMBB(New); 996 } 997 998 // Update the successor information. 999 replaceSuccessor(Old, New); 1000 } 1001 1002 /// CorrectExtraCFGEdges - Various pieces of code can cause excess edges in the 1003 /// CFG to be inserted. If we have proven that MBB can only branch to DestA and 1004 /// DestB, remove any other MBB successors from the CFG. DestA and DestB can be 1005 /// null. 1006 /// 1007 /// Besides DestA and DestB, retain other edges leading to LandingPads 1008 /// (currently there can be only one; we don't check or require that here). 1009 /// Note it is possible that DestA and/or DestB are LandingPads. 1010 bool MachineBasicBlock::CorrectExtraCFGEdges(MachineBasicBlock *DestA, 1011 MachineBasicBlock *DestB, 1012 bool isCond) { 1013 // The values of DestA and DestB frequently come from a call to the 1014 // 'TargetInstrInfo::AnalyzeBranch' method. We take our meaning of the initial 1015 // values from there. 1016 // 1017 // 1. If both DestA and DestB are null, then the block ends with no branches 1018 // (it falls through to its successor). 1019 // 2. If DestA is set, DestB is null, and isCond is false, then the block ends 1020 // with only an unconditional branch. 1021 // 3. If DestA is set, DestB is null, and isCond is true, then the block ends 1022 // with a conditional branch that falls through to a successor (DestB). 1023 // 4. If DestA and DestB is set and isCond is true, then the block ends with a 1024 // conditional branch followed by an unconditional branch. DestA is the 1025 // 'true' destination and DestB is the 'false' destination. 1026 1027 bool Changed = false; 1028 1029 MachineFunction::iterator FallThru = 1030 std::next(MachineFunction::iterator(this)); 1031 1032 if (!DestA && !DestB) { 1033 // Block falls through to successor. 1034 DestA = FallThru; 1035 DestB = FallThru; 1036 } else if (DestA && !DestB) { 1037 if (isCond) 1038 // Block ends in conditional jump that falls through to successor. 1039 DestB = FallThru; 1040 } else { 1041 assert(DestA && DestB && isCond && 1042 "CFG in a bad state. Cannot correct CFG edges"); 1043 } 1044 1045 // Remove superfluous edges. I.e., those which aren't destinations of this 1046 // basic block, duplicate edges, or landing pads. 1047 SmallPtrSet<const MachineBasicBlock*, 8> SeenMBBs; 1048 MachineBasicBlock::succ_iterator SI = succ_begin(); 1049 while (SI != succ_end()) { 1050 const MachineBasicBlock *MBB = *SI; 1051 if (!SeenMBBs.insert(MBB).second || 1052 (MBB != DestA && MBB != DestB && !MBB->isLandingPad())) { 1053 // This is a superfluous edge, remove it. 1054 SI = removeSuccessor(SI); 1055 Changed = true; 1056 } else { 1057 ++SI; 1058 } 1059 } 1060 1061 return Changed; 1062 } 1063 1064 /// findDebugLoc - find the next valid DebugLoc starting at MBBI, skipping 1065 /// any DBG_VALUE instructions. Return UnknownLoc if there is none. 1066 DebugLoc 1067 MachineBasicBlock::findDebugLoc(instr_iterator MBBI) { 1068 DebugLoc DL; 1069 instr_iterator E = instr_end(); 1070 if (MBBI == E) 1071 return DL; 1072 1073 // Skip debug declarations, we don't want a DebugLoc from them. 1074 while (MBBI != E && MBBI->isDebugValue()) 1075 MBBI++; 1076 if (MBBI != E) 1077 DL = MBBI->getDebugLoc(); 1078 return DL; 1079 } 1080 1081 /// getSuccWeight - Return weight of the edge from this block to MBB. 1082 /// 1083 uint32_t MachineBasicBlock::getSuccWeight(const_succ_iterator Succ) const { 1084 if (Weights.empty()) 1085 return 0; 1086 1087 return *getWeightIterator(Succ); 1088 } 1089 1090 /// Set successor weight of a given iterator. 1091 void MachineBasicBlock::setSuccWeight(succ_iterator I, uint32_t weight) { 1092 if (Weights.empty()) 1093 return; 1094 *getWeightIterator(I) = weight; 1095 } 1096 1097 /// getWeightIterator - Return wight iterator corresonding to the I successor 1098 /// iterator 1099 MachineBasicBlock::weight_iterator MachineBasicBlock:: 1100 getWeightIterator(MachineBasicBlock::succ_iterator I) { 1101 assert(Weights.size() == Successors.size() && "Async weight list!"); 1102 size_t index = std::distance(Successors.begin(), I); 1103 assert(index < Weights.size() && "Not a current successor!"); 1104 return Weights.begin() + index; 1105 } 1106 1107 /// getWeightIterator - Return wight iterator corresonding to the I successor 1108 /// iterator 1109 MachineBasicBlock::const_weight_iterator MachineBasicBlock:: 1110 getWeightIterator(MachineBasicBlock::const_succ_iterator I) const { 1111 assert(Weights.size() == Successors.size() && "Async weight list!"); 1112 const size_t index = std::distance(Successors.begin(), I); 1113 assert(index < Weights.size() && "Not a current successor!"); 1114 return Weights.begin() + index; 1115 } 1116 1117 /// Return whether (physical) register "Reg" has been <def>ined and not <kill>ed 1118 /// as of just before "MI". 1119 /// 1120 /// Search is localised to a neighborhood of 1121 /// Neighborhood instructions before (searching for defs or kills) and N 1122 /// instructions after (searching just for defs) MI. 1123 MachineBasicBlock::LivenessQueryResult 1124 MachineBasicBlock::computeRegisterLiveness(const TargetRegisterInfo *TRI, 1125 unsigned Reg, const_iterator Before, 1126 unsigned Neighborhood) const { 1127 unsigned N = Neighborhood; 1128 1129 // Start by searching backwards from Before, looking for kills, reads or defs. 1130 const_iterator I(Before); 1131 // If this is the first insn in the block, don't search backwards. 1132 if (I != begin()) { 1133 do { 1134 --I; 1135 1136 MachineOperandIteratorBase::PhysRegInfo Analysis = 1137 ConstMIOperands(I).analyzePhysReg(Reg, TRI); 1138 1139 if (Analysis.Defines) 1140 // Outputs happen after inputs so they take precedence if both are 1141 // present. 1142 return Analysis.DefinesDead ? LQR_Dead : LQR_Live; 1143 1144 if (Analysis.Kills || Analysis.Clobbers) 1145 // Register killed, so isn't live. 1146 return LQR_Dead; 1147 1148 else if (Analysis.ReadsOverlap) 1149 // Defined or read without a previous kill - live. 1150 return Analysis.Reads ? LQR_Live : LQR_OverlappingLive; 1151 1152 } while (I != begin() && --N > 0); 1153 } 1154 1155 // Did we get to the start of the block? 1156 if (I == begin()) { 1157 // If so, the register's state is definitely defined by the live-in state. 1158 for (MCRegAliasIterator RAI(Reg, TRI, /*IncludeSelf=*/true); 1159 RAI.isValid(); ++RAI) { 1160 if (isLiveIn(*RAI)) 1161 return (*RAI == Reg) ? LQR_Live : LQR_OverlappingLive; 1162 } 1163 1164 return LQR_Dead; 1165 } 1166 1167 N = Neighborhood; 1168 1169 // Try searching forwards from Before, looking for reads or defs. 1170 I = const_iterator(Before); 1171 // If this is the last insn in the block, don't search forwards. 1172 if (I != end()) { 1173 for (++I; I != end() && N > 0; ++I, --N) { 1174 MachineOperandIteratorBase::PhysRegInfo Analysis = 1175 ConstMIOperands(I).analyzePhysReg(Reg, TRI); 1176 1177 if (Analysis.ReadsOverlap) 1178 // Used, therefore must have been live. 1179 return (Analysis.Reads) ? 1180 LQR_Live : LQR_OverlappingLive; 1181 1182 else if (Analysis.Clobbers || Analysis.Defines) 1183 // Defined (but not read) therefore cannot have been live. 1184 return LQR_Dead; 1185 } 1186 } 1187 1188 // At this point we have no idea of the liveness of the register. 1189 return LQR_Unknown; 1190 } 1191