Mercurial > hg > CbC > CbC_llvm
comparison lib/CodeGen/LiveIntervalAnalysis.cpp @ 95:afa8332a0e37 LLVM3.8
LLVM 3.8
author | Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 13 Oct 2015 17:48:58 +0900 |
parents | 60c9769439b8 |
children | 7d135dc70f03 |
comparison
equal
deleted
inserted
replaced
84:f3e34b893a5f | 95:afa8332a0e37 |
---|---|
30 #include "llvm/IR/Value.h" | 30 #include "llvm/IR/Value.h" |
31 #include "llvm/Support/BlockFrequency.h" | 31 #include "llvm/Support/BlockFrequency.h" |
32 #include "llvm/Support/CommandLine.h" | 32 #include "llvm/Support/CommandLine.h" |
33 #include "llvm/Support/Debug.h" | 33 #include "llvm/Support/Debug.h" |
34 #include "llvm/Support/ErrorHandling.h" | 34 #include "llvm/Support/ErrorHandling.h" |
35 #include "llvm/Support/Format.h" | |
36 #include "llvm/Support/raw_ostream.h" | 35 #include "llvm/Support/raw_ostream.h" |
37 #include "llvm/Target/TargetInstrInfo.h" | 36 #include "llvm/Target/TargetInstrInfo.h" |
38 #include "llvm/Target/TargetRegisterInfo.h" | 37 #include "llvm/Target/TargetRegisterInfo.h" |
39 #include "llvm/Target/TargetSubtargetInfo.h" | 38 #include "llvm/Target/TargetSubtargetInfo.h" |
40 #include <algorithm> | 39 #include <algorithm> |
46 | 45 |
47 char LiveIntervals::ID = 0; | 46 char LiveIntervals::ID = 0; |
48 char &llvm::LiveIntervalsID = LiveIntervals::ID; | 47 char &llvm::LiveIntervalsID = LiveIntervals::ID; |
49 INITIALIZE_PASS_BEGIN(LiveIntervals, "liveintervals", | 48 INITIALIZE_PASS_BEGIN(LiveIntervals, "liveintervals", |
50 "Live Interval Analysis", false, false) | 49 "Live Interval Analysis", false, false) |
51 INITIALIZE_AG_DEPENDENCY(AliasAnalysis) | 50 INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass) |
52 INITIALIZE_PASS_DEPENDENCY(LiveVariables) | 51 INITIALIZE_PASS_DEPENDENCY(LiveVariables) |
53 INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree) | 52 INITIALIZE_PASS_DEPENDENCY(MachineDominatorTree) |
54 INITIALIZE_PASS_DEPENDENCY(SlotIndexes) | 53 INITIALIZE_PASS_DEPENDENCY(SlotIndexes) |
55 INITIALIZE_PASS_END(LiveIntervals, "liveintervals", | 54 INITIALIZE_PASS_END(LiveIntervals, "liveintervals", |
56 "Live Interval Analysis", false, false) | 55 "Live Interval Analysis", false, false) |
74 "Use segment set for the computation of the live ranges of physregs.")); | 73 "Use segment set for the computation of the live ranges of physregs.")); |
75 } | 74 } |
76 | 75 |
77 void LiveIntervals::getAnalysisUsage(AnalysisUsage &AU) const { | 76 void LiveIntervals::getAnalysisUsage(AnalysisUsage &AU) const { |
78 AU.setPreservesCFG(); | 77 AU.setPreservesCFG(); |
79 AU.addRequired<AliasAnalysis>(); | 78 AU.addRequired<AAResultsWrapperPass>(); |
80 AU.addPreserved<AliasAnalysis>(); | 79 AU.addPreserved<AAResultsWrapperPass>(); |
81 // LiveVariables isn't really required by this analysis, it is only required | 80 // LiveVariables isn't really required by this analysis, it is only required |
82 // here to make sure it is live during TwoAddressInstructionPass and | 81 // here to make sure it is live during TwoAddressInstructionPass and |
83 // PHIElimination. This is temporary. | 82 // PHIElimination. This is temporary. |
84 AU.addRequired<LiveVariables>(); | 83 AU.addRequired<LiveVariables>(); |
85 AU.addPreserved<LiveVariables>(); | 84 AU.addPreserved<LiveVariables>(); |
122 bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) { | 121 bool LiveIntervals::runOnMachineFunction(MachineFunction &fn) { |
123 MF = &fn; | 122 MF = &fn; |
124 MRI = &MF->getRegInfo(); | 123 MRI = &MF->getRegInfo(); |
125 TRI = MF->getSubtarget().getRegisterInfo(); | 124 TRI = MF->getSubtarget().getRegisterInfo(); |
126 TII = MF->getSubtarget().getInstrInfo(); | 125 TII = MF->getSubtarget().getInstrInfo(); |
127 AA = &getAnalysis<AliasAnalysis>(); | 126 AA = &getAnalysis<AAResultsWrapperPass>().getAAResults(); |
128 Indexes = &getAnalysis<SlotIndexes>(); | 127 Indexes = &getAnalysis<SlotIndexes>(); |
129 DomTree = &getAnalysis<MachineDominatorTree>(); | 128 DomTree = &getAnalysis<MachineDominatorTree>(); |
130 | 129 |
131 if (EnableSubRegLiveness && MF->getSubtarget().enableSubRegLiveness()) | 130 if (EnableSubRegLiveness && MF->getSubtarget().enableSubRegLiveness()) |
132 MRI->enableSubRegLiveness(true); | 131 MRI->enableSubRegLiveness(true); |
196 /// computeVirtRegInterval - Compute the live interval of a virtual register, | 195 /// computeVirtRegInterval - Compute the live interval of a virtual register, |
197 /// based on defs and uses. | 196 /// based on defs and uses. |
198 void LiveIntervals::computeVirtRegInterval(LiveInterval &LI) { | 197 void LiveIntervals::computeVirtRegInterval(LiveInterval &LI) { |
199 assert(LRCalc && "LRCalc not initialized."); | 198 assert(LRCalc && "LRCalc not initialized."); |
200 assert(LI.empty() && "Should only compute empty intervals."); | 199 assert(LI.empty() && "Should only compute empty intervals."); |
200 bool ShouldTrackSubRegLiveness = MRI->shouldTrackSubRegLiveness(LI.reg); | |
201 LRCalc->reset(MF, getSlotIndexes(), DomTree, &getVNInfoAllocator()); | 201 LRCalc->reset(MF, getSlotIndexes(), DomTree, &getVNInfoAllocator()); |
202 LRCalc->calculate(LI); | 202 LRCalc->calculate(LI, ShouldTrackSubRegLiveness); |
203 computeDeadValues(LI, nullptr); | 203 bool SeparatedComponents = computeDeadValues(LI, nullptr); |
204 if (SeparatedComponents) { | |
205 assert(ShouldTrackSubRegLiveness | |
206 && "Separated components should only occur for unused subreg defs"); | |
207 SmallVector<LiveInterval*, 8> SplitLIs; | |
208 splitSeparateComponents(LI, SplitLIs); | |
209 } | |
204 } | 210 } |
205 | 211 |
206 void LiveIntervals::computeVirtRegs() { | 212 void LiveIntervals::computeVirtRegs() { |
207 for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) { | 213 for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) { |
208 unsigned Reg = TargetRegisterInfo::index2VirtReg(i); | 214 unsigned Reg = TargetRegisterInfo::index2VirtReg(i); |
216 RegMaskBlocks.resize(MF->getNumBlockIDs()); | 222 RegMaskBlocks.resize(MF->getNumBlockIDs()); |
217 | 223 |
218 // Find all instructions with regmask operands. | 224 // Find all instructions with regmask operands. |
219 for (MachineFunction::iterator MBBI = MF->begin(), E = MF->end(); | 225 for (MachineFunction::iterator MBBI = MF->begin(), E = MF->end(); |
220 MBBI != E; ++MBBI) { | 226 MBBI != E; ++MBBI) { |
221 MachineBasicBlock *MBB = MBBI; | 227 MachineBasicBlock *MBB = &*MBBI; |
222 std::pair<unsigned, unsigned> &RMB = RegMaskBlocks[MBB->getNumber()]; | 228 std::pair<unsigned, unsigned> &RMB = RegMaskBlocks[MBB->getNumber()]; |
223 RMB.first = RegMaskSlots.size(); | 229 RMB.first = RegMaskSlots.size(); |
224 for (MachineBasicBlock::iterator MI = MBB->begin(), ME = MBB->end(); | 230 for (MachineBasicBlock::iterator MI = MBB->begin(), ME = MBB->end(); |
225 MI != ME; ++MI) | 231 MI != ME; ++MI) |
226 for (MIOperands MO(MI); MO.isValid(); ++MO) { | 232 for (const MachineOperand &MO : MI->operands()) { |
227 if (!MO->isRegMask()) | 233 if (!MO.isRegMask()) |
228 continue; | 234 continue; |
229 RegMaskSlots.push_back(Indexes->getInstructionIndex(MI).getRegSlot()); | 235 RegMaskSlots.push_back(Indexes->getInstructionIndex(MI).getRegSlot()); |
230 RegMaskBits.push_back(MO->getRegMask()); | 236 RegMaskBits.push_back(MO.getRegMask()); |
231 } | 237 } |
232 // Compute the number of register mask instructions in this block. | 238 // Compute the number of register mask instructions in this block. |
233 RMB.second = RegMaskSlots.size() - RMB.first; | 239 RMB.second = RegMaskSlots.size() - RMB.first; |
234 } | 240 } |
235 } | 241 } |
294 SmallVector<unsigned, 8> NewRanges; | 300 SmallVector<unsigned, 8> NewRanges; |
295 | 301 |
296 // Check all basic blocks for live-ins. | 302 // Check all basic blocks for live-ins. |
297 for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end(); | 303 for (MachineFunction::const_iterator MFI = MF->begin(), MFE = MF->end(); |
298 MFI != MFE; ++MFI) { | 304 MFI != MFE; ++MFI) { |
299 const MachineBasicBlock *MBB = MFI; | 305 const MachineBasicBlock *MBB = &*MFI; |
300 | 306 |
301 // We only care about ABI blocks: Entry + landing pads. | 307 // We only care about ABI blocks: Entry + landing pads. |
302 if ((MFI != MF->begin() && !MBB->isLandingPad()) || MBB->livein_empty()) | 308 if ((MFI != MF->begin() && !MBB->isEHPad()) || MBB->livein_empty()) |
303 continue; | 309 continue; |
304 | 310 |
305 // Create phi-defs at Begin for all live-in registers. | 311 // Create phi-defs at Begin for all live-in registers. |
306 SlotIndex Begin = Indexes->getMBBStartIdx(MBB); | 312 SlotIndex Begin = Indexes->getMBBStartIdx(MBB); |
307 DEBUG(dbgs() << Begin << "\tBB#" << MBB->getNumber()); | 313 DEBUG(dbgs() << Begin << "\tBB#" << MBB->getNumber()); |
308 for (MachineBasicBlock::livein_iterator LII = MBB->livein_begin(), | 314 for (const auto &LI : MBB->liveins()) { |
309 LIE = MBB->livein_end(); LII != LIE; ++LII) { | 315 for (MCRegUnitIterator Units(LI.PhysReg, TRI); Units.isValid(); ++Units) { |
310 for (MCRegUnitIterator Units(*LII, TRI); Units.isValid(); ++Units) { | |
311 unsigned Unit = *Units; | 316 unsigned Unit = *Units; |
312 LiveRange *LR = RegUnitRanges[Unit]; | 317 LiveRange *LR = RegUnitRanges[Unit]; |
313 if (!LR) { | 318 if (!LR) { |
314 // Use segment set to speed-up initial computation of the live range. | 319 // Use segment set to speed-up initial computation of the live range. |
315 LR = RegUnitRanges[Unit] = new LiveRange(UseSegmentSetForPhysRegs); | 320 LR = RegUnitRanges[Unit] = new LiveRange(UseSegmentSetForPhysRegs); |
394 WorkList.push_back(std::make_pair(Stop, VNI)); | 399 WorkList.push_back(std::make_pair(Stop, VNI)); |
395 } | 400 } |
396 } | 401 } |
397 } | 402 } |
398 | 403 |
399 /// shrinkToUses - After removing some uses of a register, shrink its live | |
400 /// range to just the remaining uses. This method does not compute reaching | |
401 /// defs for new uses, and it doesn't remove dead defs. | |
402 bool LiveIntervals::shrinkToUses(LiveInterval *li, | 404 bool LiveIntervals::shrinkToUses(LiveInterval *li, |
403 SmallVectorImpl<MachineInstr*> *dead) { | 405 SmallVectorImpl<MachineInstr*> *dead) { |
404 DEBUG(dbgs() << "Shrink: " << *li << '\n'); | 406 DEBUG(dbgs() << "Shrink: " << *li << '\n'); |
405 assert(TargetRegisterInfo::isVirtualRegister(li->reg) | 407 assert(TargetRegisterInfo::isVirtualRegister(li->reg) |
406 && "Can only shrink virtual registers"); | 408 && "Can only shrink virtual registers"); |
407 | 409 |
408 // Shrink subregister live ranges. | 410 // Shrink subregister live ranges. |
411 bool NeedsCleanup = false; | |
409 for (LiveInterval::SubRange &S : li->subranges()) { | 412 for (LiveInterval::SubRange &S : li->subranges()) { |
410 shrinkToUses(S, li->reg); | 413 shrinkToUses(S, li->reg); |
411 } | 414 if (S.empty()) |
415 NeedsCleanup = true; | |
416 } | |
417 if (NeedsCleanup) | |
418 li->removeEmptySubRanges(); | |
412 | 419 |
413 // Find all the values used, including PHI kills. | 420 // Find all the values used, including PHI kills. |
414 ShrinkToUsesWorkList WorkList; | 421 ShrinkToUsesWorkList WorkList; |
415 | 422 |
416 // Visit all instructions reading li->reg. | 423 // Visit all instructions reading li->reg. |
454 return CanSeparate; | 461 return CanSeparate; |
455 } | 462 } |
456 | 463 |
457 bool LiveIntervals::computeDeadValues(LiveInterval &LI, | 464 bool LiveIntervals::computeDeadValues(LiveInterval &LI, |
458 SmallVectorImpl<MachineInstr*> *dead) { | 465 SmallVectorImpl<MachineInstr*> *dead) { |
459 bool PHIRemoved = false; | 466 bool MayHaveSplitComponents = false; |
460 for (auto VNI : LI.valnos) { | 467 for (auto VNI : LI.valnos) { |
461 if (VNI->isUnused()) | 468 if (VNI->isUnused()) |
462 continue; | 469 continue; |
463 SlotIndex Def = VNI->def; | 470 SlotIndex Def = VNI->def; |
464 LiveRange::iterator I = LI.FindSegmentContaining(Def); | 471 LiveRange::iterator I = LI.FindSegmentContaining(Def); |
465 assert(I != LI.end() && "Missing segment for VNI"); | 472 assert(I != LI.end() && "Missing segment for VNI"); |
466 | 473 |
467 // Is the register live before? Otherwise we may have to add a read-undef | 474 // Is the register live before? Otherwise we may have to add a read-undef |
468 // flag for subregister defs. | 475 // flag for subregister defs. |
469 if (MRI->tracksSubRegLiveness()) { | 476 bool DeadBeforeDef = false; |
477 unsigned VReg = LI.reg; | |
478 if (MRI->shouldTrackSubRegLiveness(VReg)) { | |
470 if ((I == LI.begin() || std::prev(I)->end < Def) && !VNI->isPHIDef()) { | 479 if ((I == LI.begin() || std::prev(I)->end < Def) && !VNI->isPHIDef()) { |
471 MachineInstr *MI = getInstructionFromIndex(Def); | 480 MachineInstr *MI = getInstructionFromIndex(Def); |
472 MI->addRegisterDefReadUndef(LI.reg); | 481 MI->addRegisterDefReadUndef(VReg); |
482 DeadBeforeDef = true; | |
473 } | 483 } |
474 } | 484 } |
475 | 485 |
476 if (I->end != Def.getDeadSlot()) | 486 if (I->end != Def.getDeadSlot()) |
477 continue; | 487 continue; |
478 if (VNI->isPHIDef()) { | 488 if (VNI->isPHIDef()) { |
479 // This is a dead PHI. Remove it. | 489 // This is a dead PHI. Remove it. |
480 VNI->markUnused(); | 490 VNI->markUnused(); |
481 LI.removeSegment(I); | 491 LI.removeSegment(I); |
482 DEBUG(dbgs() << "Dead PHI at " << Def << " may separate interval\n"); | 492 DEBUG(dbgs() << "Dead PHI at " << Def << " may separate interval\n"); |
483 PHIRemoved = true; | 493 MayHaveSplitComponents = true; |
484 } else { | 494 } else { |
485 // This is a dead def. Make sure the instruction knows. | 495 // This is a dead def. Make sure the instruction knows. |
486 MachineInstr *MI = getInstructionFromIndex(Def); | 496 MachineInstr *MI = getInstructionFromIndex(Def); |
487 assert(MI && "No instruction defining live value"); | 497 assert(MI && "No instruction defining live value"); |
488 MI->addRegisterDead(LI.reg, TRI); | 498 MI->addRegisterDead(VReg, TRI); |
499 | |
500 // If we have a dead def that is completely separate from the rest of | |
501 // the liverange then we rewrite it to use a different VReg to not violate | |
502 // the rule that the liveness of a virtual register forms a connected | |
503 // component. This should only happen if subregister liveness is tracked. | |
504 if (DeadBeforeDef) | |
505 MayHaveSplitComponents = true; | |
506 | |
489 if (dead && MI->allDefsAreDead()) { | 507 if (dead && MI->allDefsAreDead()) { |
490 DEBUG(dbgs() << "All defs dead: " << Def << '\t' << *MI); | 508 DEBUG(dbgs() << "All defs dead: " << Def << '\t' << *MI); |
491 dead->push_back(MI); | 509 dead->push_back(MI); |
492 } | 510 } |
493 } | 511 } |
494 } | 512 } |
495 return PHIRemoved; | 513 return MayHaveSplitComponents; |
496 } | 514 } |
497 | 515 |
498 void LiveIntervals::shrinkToUses(LiveInterval::SubRange &SR, unsigned Reg) | 516 void LiveIntervals::shrinkToUses(LiveInterval::SubRange &SR, unsigned Reg) |
499 { | 517 { |
500 DEBUG(dbgs() << "Shrink: " << SR << '\n'); | 518 DEBUG(dbgs() << "Shrink: " << SR << '\n'); |
510 if (UseMI->isDebugValue()) | 528 if (UseMI->isDebugValue()) |
511 continue; | 529 continue; |
512 // Maybe the operand is for a subregister we don't care about. | 530 // Maybe the operand is for a subregister we don't care about. |
513 unsigned SubReg = MO.getSubReg(); | 531 unsigned SubReg = MO.getSubReg(); |
514 if (SubReg != 0) { | 532 if (SubReg != 0) { |
515 unsigned SubRegMask = TRI->getSubRegIndexLaneMask(SubReg); | 533 LaneBitmask LaneMask = TRI->getSubRegIndexLaneMask(SubReg); |
516 if ((SubRegMask & SR.LaneMask) == 0) | 534 if ((LaneMask & SR.LaneMask) == 0) |
517 continue; | 535 continue; |
518 } | 536 } |
519 // We only need to visit each instruction once. | 537 // We only need to visit each instruction once. |
520 SlotIndex Idx = getInstructionIndex(UseMI).getRegSlot(); | 538 SlotIndex Idx = getInstructionIndex(UseMI).getRegSlot(); |
521 if (Idx == LastIdx) | 539 if (Idx == LastIdx) |
660 if (RURange.empty()) | 678 if (RURange.empty()) |
661 continue; | 679 continue; |
662 RU.push_back(std::make_pair(&RURange, RURange.find(LI.begin()->end))); | 680 RU.push_back(std::make_pair(&RURange, RURange.find(LI.begin()->end))); |
663 } | 681 } |
664 | 682 |
665 if (MRI->tracksSubRegLiveness()) { | 683 if (MRI->subRegLivenessEnabled()) { |
666 SRs.clear(); | 684 SRs.clear(); |
667 for (const LiveInterval::SubRange &SR : LI.subranges()) { | 685 for (const LiveInterval::SubRange &SR : LI.subranges()) { |
668 SRs.push_back(std::make_pair(&SR, SR.find(LI.begin()->end))); | 686 SRs.push_back(std::make_pair(&SR, SR.find(LI.begin()->end))); |
669 } | 687 } |
670 } | 688 } |
698 continue; | 716 continue; |
699 // I is overlapping RI. | 717 // I is overlapping RI. |
700 goto CancelKill; | 718 goto CancelKill; |
701 } | 719 } |
702 | 720 |
703 if (MRI->tracksSubRegLiveness()) { | 721 if (MRI->subRegLivenessEnabled()) { |
704 // When reading a partial undefined value we must not add a kill flag. | 722 // When reading a partial undefined value we must not add a kill flag. |
705 // The regalloc might have used the undef lane for something else. | 723 // The regalloc might have used the undef lane for something else. |
706 // Example: | 724 // Example: |
707 // %vreg1 = ... ; R32: %vreg1 | 725 // %vreg1 = ... ; R32: %vreg1 |
708 // %vreg2:high16 = ... ; R64: %vreg2 | 726 // %vreg2:high16 = ... ; R64: %vreg2 |
710 // = read %vreg1 ; R32: %vreg1 | 728 // = read %vreg1 ; R32: %vreg1 |
711 // The <kill> flag is correct for %vreg2, but the register allocator may | 729 // The <kill> flag is correct for %vreg2, but the register allocator may |
712 // assign R0L to %vreg1, and R0 to %vreg2 because the low 32bits of R0 | 730 // assign R0L to %vreg1, and R0 to %vreg2 because the low 32bits of R0 |
713 // are actually never written by %vreg2. After assignment the <kill> | 731 // are actually never written by %vreg2. After assignment the <kill> |
714 // flag at the read instruction is invalid. | 732 // flag at the read instruction is invalid. |
715 unsigned DefinedLanesMask; | 733 LaneBitmask DefinedLanesMask; |
716 if (!SRs.empty()) { | 734 if (!SRs.empty()) { |
717 // Compute a mask of lanes that are defined. | 735 // Compute a mask of lanes that are defined. |
718 DefinedLanesMask = 0; | 736 DefinedLanesMask = 0; |
719 for (auto &SRP : SRs) { | 737 for (auto &SRP : SRs) { |
720 const LiveInterval::SubRange &SR = *SRP.first; | 738 const LiveInterval::SubRange &SR = *SRP.first; |
734 for (const MachineOperand &MO : MI->operands()) { | 752 for (const MachineOperand &MO : MI->operands()) { |
735 if (!MO.isReg() || MO.getReg() != Reg) | 753 if (!MO.isReg() || MO.getReg() != Reg) |
736 continue; | 754 continue; |
737 if (MO.isUse()) { | 755 if (MO.isUse()) { |
738 // Reading any undefined lanes? | 756 // Reading any undefined lanes? |
739 unsigned UseMask = TRI->getSubRegIndexLaneMask(MO.getSubReg()); | 757 LaneBitmask UseMask = TRI->getSubRegIndexLaneMask(MO.getSubReg()); |
740 if ((UseMask & ~DefinedLanesMask) != 0) | 758 if ((UseMask & ~DefinedLanesMask) != 0) |
741 goto CancelKill; | 759 goto CancelKill; |
742 } else if (MO.getSubReg() == 0) { | 760 } else if (MO.getSubReg() == 0) { |
743 // Writing to the full register? | 761 // Writing to the full register? |
744 assert(MO.isDef()); | 762 assert(MO.isDef()); |
925 /// Update all live ranges touched by MI, assuming a move from OldIdx to | 943 /// Update all live ranges touched by MI, assuming a move from OldIdx to |
926 /// NewIdx. | 944 /// NewIdx. |
927 void updateAllRanges(MachineInstr *MI) { | 945 void updateAllRanges(MachineInstr *MI) { |
928 DEBUG(dbgs() << "handleMove " << OldIdx << " -> " << NewIdx << ": " << *MI); | 946 DEBUG(dbgs() << "handleMove " << OldIdx << " -> " << NewIdx << ": " << *MI); |
929 bool hasRegMask = false; | 947 bool hasRegMask = false; |
930 for (MIOperands MO(MI); MO.isValid(); ++MO) { | 948 for (MachineOperand &MO : MI->operands()) { |
931 if (MO->isRegMask()) | 949 if (MO.isRegMask()) |
932 hasRegMask = true; | 950 hasRegMask = true; |
933 if (!MO->isReg()) | 951 if (!MO.isReg()) |
934 continue; | 952 continue; |
935 // Aggressively clear all kill flags. | 953 // Aggressively clear all kill flags. |
936 // They are reinserted by VirtRegRewriter. | 954 // They are reinserted by VirtRegRewriter. |
937 if (MO->isUse()) | 955 if (MO.isUse()) |
938 MO->setIsKill(false); | 956 MO.setIsKill(false); |
939 | 957 |
940 unsigned Reg = MO->getReg(); | 958 unsigned Reg = MO.getReg(); |
941 if (!Reg) | 959 if (!Reg) |
942 continue; | 960 continue; |
943 if (TargetRegisterInfo::isVirtualRegister(Reg)) { | 961 if (TargetRegisterInfo::isVirtualRegister(Reg)) { |
944 LiveInterval &LI = LIS.getInterval(Reg); | 962 LiveInterval &LI = LIS.getInterval(Reg); |
945 if (LI.hasSubRanges()) { | 963 if (LI.hasSubRanges()) { |
946 unsigned SubReg = MO->getSubReg(); | 964 unsigned SubReg = MO.getSubReg(); |
947 unsigned LaneMask = TRI.getSubRegIndexLaneMask(SubReg); | 965 LaneBitmask LaneMask = TRI.getSubRegIndexLaneMask(SubReg); |
948 for (LiveInterval::SubRange &S : LI.subranges()) { | 966 for (LiveInterval::SubRange &S : LI.subranges()) { |
949 if ((S.LaneMask & LaneMask) == 0) | 967 if ((S.LaneMask & LaneMask) == 0) |
950 continue; | 968 continue; |
951 updateRange(S, Reg, S.LaneMask); | 969 updateRange(S, Reg, S.LaneMask); |
952 } | 970 } |
966 } | 984 } |
967 | 985 |
968 private: | 986 private: |
969 /// Update a single live range, assuming an instruction has been moved from | 987 /// Update a single live range, assuming an instruction has been moved from |
970 /// OldIdx to NewIdx. | 988 /// OldIdx to NewIdx. |
971 void updateRange(LiveRange &LR, unsigned Reg, unsigned LaneMask) { | 989 void updateRange(LiveRange &LR, unsigned Reg, LaneBitmask LaneMask) { |
972 if (!Updated.insert(&LR).second) | 990 if (!Updated.insert(&LR).second) |
973 return; | 991 return; |
974 DEBUG({ | 992 DEBUG({ |
975 dbgs() << " "; | 993 dbgs() << " "; |
976 if (TargetRegisterInfo::isVirtualRegister(Reg)) { | 994 if (TargetRegisterInfo::isVirtualRegister(Reg)) { |
977 dbgs() << PrintReg(Reg); | 995 dbgs() << PrintReg(Reg); |
978 if (LaneMask != 0) | 996 if (LaneMask != 0) |
979 dbgs() << format(" L%04X", LaneMask); | 997 dbgs() << " L" << PrintLaneMask(LaneMask); |
980 } else { | 998 } else { |
981 dbgs() << PrintRegUnit(Reg, &TRI); | 999 dbgs() << PrintRegUnit(Reg, &TRI); |
982 } | 1000 } |
983 dbgs() << ":\t" << LR << '\n'; | 1001 dbgs() << ":\t" << LR << '\n'; |
984 }); | 1002 }); |
1096 /// | 1114 /// |
1097 /// 5. Value killed at OldIdx: | 1115 /// 5. Value killed at OldIdx: |
1098 /// Hoist kill to NewIdx, then scan for last kill between NewIdx and | 1116 /// Hoist kill to NewIdx, then scan for last kill between NewIdx and |
1099 /// OldIdx. | 1117 /// OldIdx. |
1100 /// | 1118 /// |
1101 void handleMoveUp(LiveRange &LR, unsigned Reg, unsigned LaneMask) { | 1119 void handleMoveUp(LiveRange &LR, unsigned Reg, LaneBitmask LaneMask) { |
1102 // First look for a kill at OldIdx. | 1120 // First look for a kill at OldIdx. |
1103 LiveRange::iterator I = LR.find(OldIdx.getBaseIndex()); | 1121 LiveRange::iterator I = LR.find(OldIdx.getBaseIndex()); |
1104 LiveRange::iterator E = LR.end(); | 1122 LiveRange::iterator E = LR.end(); |
1105 // Is LR even live at OldIdx? | 1123 // Is LR even live at OldIdx? |
1106 if (I == E || SlotIndex::isEarlierInstr(OldIdx, I->start)) | 1124 if (I == E || SlotIndex::isEarlierInstr(OldIdx, I->start)) |
1173 SlotIndex::isEarlierInstr(*RI, *std::next(RI))) && | 1191 SlotIndex::isEarlierInstr(*RI, *std::next(RI))) && |
1174 "Cannot move regmask instruction below another call"); | 1192 "Cannot move regmask instruction below another call"); |
1175 } | 1193 } |
1176 | 1194 |
1177 // Return the last use of reg between NewIdx and OldIdx. | 1195 // Return the last use of reg between NewIdx and OldIdx. |
1178 SlotIndex findLastUseBefore(unsigned Reg, unsigned LaneMask) { | 1196 SlotIndex findLastUseBefore(unsigned Reg, LaneBitmask LaneMask) { |
1179 | 1197 |
1180 if (TargetRegisterInfo::isVirtualRegister(Reg)) { | 1198 if (TargetRegisterInfo::isVirtualRegister(Reg)) { |
1181 SlotIndex LastUse = NewIdx; | 1199 SlotIndex LastUse = NewIdx; |
1182 for (MachineOperand &MO : MRI.use_nodbg_operands(Reg)) { | 1200 for (MachineOperand &MO : MRI.use_nodbg_operands(Reg)) { |
1183 unsigned SubReg = MO.getSubReg(); | 1201 unsigned SubReg = MO.getSubReg(); |
1253 | 1271 |
1254 void LiveIntervals::repairOldRegInRange(const MachineBasicBlock::iterator Begin, | 1272 void LiveIntervals::repairOldRegInRange(const MachineBasicBlock::iterator Begin, |
1255 const MachineBasicBlock::iterator End, | 1273 const MachineBasicBlock::iterator End, |
1256 const SlotIndex endIdx, | 1274 const SlotIndex endIdx, |
1257 LiveRange &LR, const unsigned Reg, | 1275 LiveRange &LR, const unsigned Reg, |
1258 const unsigned LaneMask) { | 1276 LaneBitmask LaneMask) { |
1259 LiveInterval::iterator LII = LR.find(endIdx); | 1277 LiveInterval::iterator LII = LR.find(endIdx); |
1260 SlotIndex lastUseIdx; | 1278 SlotIndex lastUseIdx; |
1261 if (LII != LR.end() && LII->start < endIdx) | 1279 if (LII != LR.end() && LII->start < endIdx) |
1262 lastUseIdx = LII->end; | 1280 lastUseIdx = LII->end; |
1263 else | 1281 else |
1280 const MachineOperand &MO = *OI; | 1298 const MachineOperand &MO = *OI; |
1281 if (!MO.isReg() || MO.getReg() != Reg) | 1299 if (!MO.isReg() || MO.getReg() != Reg) |
1282 continue; | 1300 continue; |
1283 | 1301 |
1284 unsigned SubReg = MO.getSubReg(); | 1302 unsigned SubReg = MO.getSubReg(); |
1285 unsigned Mask = TRI->getSubRegIndexLaneMask(SubReg); | 1303 LaneBitmask Mask = TRI->getSubRegIndexLaneMask(SubReg); |
1286 if ((Mask & LaneMask) == 0) | 1304 if ((Mask & LaneMask) == 0) |
1287 continue; | 1305 continue; |
1288 | 1306 |
1289 if (MO.isDef()) { | 1307 if (MO.isDef()) { |
1290 if (!isStartValid) { | 1308 if (!isStartValid) { |
1410 if (VNInfo *SVNI = S.getVNInfoAt(Pos)) | 1428 if (VNInfo *SVNI = S.getVNInfoAt(Pos)) |
1411 S.removeValNo(SVNI); | 1429 S.removeValNo(SVNI); |
1412 } | 1430 } |
1413 LI.removeEmptySubRanges(); | 1431 LI.removeEmptySubRanges(); |
1414 } | 1432 } |
1433 | |
1434 void LiveIntervals::splitSeparateComponents(LiveInterval &LI, | |
1435 SmallVectorImpl<LiveInterval*> &SplitLIs) { | |
1436 ConnectedVNInfoEqClasses ConEQ(*this); | |
1437 unsigned NumComp = ConEQ.Classify(&LI); | |
1438 if (NumComp <= 1) | |
1439 return; | |
1440 DEBUG(dbgs() << " Split " << NumComp << " components: " << LI << '\n'); | |
1441 unsigned Reg = LI.reg; | |
1442 const TargetRegisterClass *RegClass = MRI->getRegClass(Reg); | |
1443 for (unsigned I = 1; I < NumComp; ++I) { | |
1444 unsigned NewVReg = MRI->createVirtualRegister(RegClass); | |
1445 LiveInterval &NewLI = createEmptyInterval(NewVReg); | |
1446 SplitLIs.push_back(&NewLI); | |
1447 } | |
1448 ConEQ.Distribute(LI, SplitLIs.data(), *MRI); | |
1449 } |