llvm.org GIT mirror llvm / c114b2c
Completely change the way that joining with physregs is implemented. This paves the way for future changes, increases coallescing opportunities (in theory, not witnessed in practice), and eliminates the really expensive LiveIntervals::overlapsAliases method. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@29890 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
3 changed file(s) with 76 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
147147 /// cause merging of V1/V2 values numbers and compaction of the value space.
148148 void MergeValueNumberInto(unsigned V1, unsigned V2);
149149
150 /// MergeInClobberRanges - For any live ranges that are not defined in the
151 /// current interval, but are defined in the Clobbers interval, mark them
152 /// used with an unknown definition value.
153 void MergeInClobberRanges(const LiveInterval &Clobbers);
150154
151155 bool empty() const { return ranges.empty(); }
152156
260260 return MergeTo;
261261 }
262262
263 LiveInterval::Ranges::iterator
264 LiveInterval::addRangeFrom(LiveRange LR, Ranges::iterator From) {
263 LiveInterval::iterator
264 LiveInterval::addRangeFrom(LiveRange LR, iterator From) {
265265 unsigned Start = LR.start, End = LR.end;
266 Ranges::iterator it = std::upper_bound(From, ranges.end(), Start);
266 iterator it = std::upper_bound(From, ranges.end(), Start);
267267
268268 // If the inserted interval starts in the middle or right at the end of
269269 // another interval, just extend that interval to contain the range of LR.
270270 if (it != ranges.begin()) {
271 Ranges::iterator B = prior(it);
271 iterator B = prior(it);
272272 if (LR.ValId == B->ValId) {
273273 if (B->start <= Start && B->end >= Start) {
274274 extendIntervalEndTo(B, End);
390390 }
391391
392392 // Join the ranges of other into the ranges of this interval.
393 Ranges::iterator InsertPos = ranges.begin();
394393 std::map Dst2SrcIdxMap;
395 for (Ranges::iterator I = Other.ranges.begin(),
396 E = Other.ranges.end(); I != E; ++I) {
394 iterator InsertPos = begin();
395 for (iterator I = Other.begin(), E = Other.end(); I != E; ++I) {
397396 // Map the ValId in the other live range to the current live range.
398397 if (I->ValId == MergedSrcValIdx)
399398 I->ValId = MergedDstValIdx;
415414 }
416415
417416 weight += Other.weight;
417 }
418
419 /// MergeInClobberRanges - For any live ranges that are not defined in the
420 /// current interval, but are defined in the Clobbers interval, mark them
421 /// used with an unknown definition value.
422 void LiveInterval::MergeInClobberRanges(const LiveInterval &Clobbers) {
423 if (Clobbers.begin() == Clobbers.end()) return;
424
425 // Find a value # to use for the clobber ranges. If there is already a value#
426 // for unknown values, use it.
427 // FIXME: Use a single sentinal number for these!
428 unsigned ClobberValNo = getNextValue(~0U);
429
430 iterator IP = begin();
431 for (const_iterator I = Clobbers.begin(), E = Clobbers.end(); I != E; ++I) {
432 unsigned Start = I->start, End = I->end;
433 IP = std::upper_bound(IP, end(), Start);
434
435 // If the start of this range overlaps with an existing liverange, trim it.
436 if (IP != begin() && IP[-1].end > Start) {
437 Start = IP[-1].end;
438 // Trimmed away the whole range?
439 if (Start >= End) continue;
440 }
441 // If the end of this range overlaps with an existing liverange, trim it.
442 if (IP != end() && End > IP->start) {
443 End = IP->start;
444 // If this trimmed away the whole range, ignore it.
445 if (Start == End) continue;
446 }
447
448 // Insert the clobber interval.
449 IP = addRangeFrom(LiveRange(Start, End, ClobberValNo), IP);
450 }
418451 }
419452
420453 /// MergeValueNumberInto - This method is called when two value nubmers
672672 // Make sure that the end of the live range is inside the same block as
673673 // CopyMI.
674674 MachineInstr *ValLREndInst = getInstructionFromIndex(ValLR->end-1);
675 if (ValLREndInst->getParent() != CopyMI->getParent()) return false;
675 if (!ValLREndInst ||
676 ValLREndInst->getParent() != CopyMI->getParent()) return false;
676677
677678 // Okay, we now know that ValLR ends in the same block that the CopyMI
678679 // live-range starts. If there are no intervening live ranges between them in
684685 // Okay, we can merge them. We need to insert a new liverange:
685686 // [ValLR.end, BLR.begin) of either value number, then we merge the
686687 // two value numbers.
687 IntB.addRange(LiveRange(ValLR->end, BLR->start, BValNo));
688 unsigned FillerStart = ValLR->end, FillerEnd = BLR->start;
689 IntB.addRange(LiveRange(FillerStart, FillerEnd, BValNo));
690
691 // If the IntB live range is assigned to a physical register, and if that
692 // physreg has aliases,
693 if (MRegisterInfo::isPhysicalRegister(IntB.reg)) {
694 for (const unsigned *AS = mri_->getAliasSet(IntB.reg); *AS; ++AS) {
695 LiveInterval &AliasLI = getInterval(*AS);
696 AliasLI.addRange(LiveRange(FillerStart, FillerEnd,
697 AliasLI.getNextValue(~0U)));
698 }
699 }
688700
689701 // Okay, merge "B1" into the same value number as "B0".
690702 if (BValNo != ValLR->ValId)
772784 if (!Joinable && AdjustCopiesBackFrom(SrcInt, DestInt, CopyMI, MIDefIdx))
773785 return true;
774786
775 // If this looks joinable, do the final, expensive last check, checking to see
776 // if aliases overlap. If they do, we can never join these.
777 if (Joinable && overlapsAliases(&SrcInt, &DestInt)) {
778 DEBUG(std::cerr << "Alias Overlap Interference!\n");
779 return true; // Can never join these.
780 }
781
782787 if (!Joinable) {
783788 DEBUG(std::cerr << "Interference!\n");
784789 return false;
785790 }
786791
792 // If we're about to merge live ranges into a physical register live range,
793 // we have to update any aliased register's live ranges to indicate that they
794 // have clobbered values for this range.
795 if (MRegisterInfo::isPhysicalRegister(SrcReg) ||
796 MRegisterInfo::isPhysicalRegister(DstReg)) {
797 // Figure out which register is the physical reg and which one is the
798 // virtreg.
799 LiveInterval *PhysRegLI = &SrcInt, *VirtRegLI = &DestInt;
800 if (MRegisterInfo::isPhysicalRegister(DstReg))
801 std::swap(PhysRegLI, VirtRegLI);
802
803 for (const unsigned *AS = mri_->getAliasSet(PhysRegLI->reg); *AS; ++AS)
804 getInterval(*AS).MergeInClobberRanges(*VirtRegLI);
805 }
806
787807 DestInt.join(SrcInt, MIDefIdx);
808 // FIXME: If SrcInt/DestInt are physregs, we must insert the new liveranges
809 // into all aliasing registers as clobbers.
810
788811 DEBUG(std::cerr << "\n\t\tJoined. Result = "; DestInt.print(std::cerr, mri_);
789812 std::cerr << "\n");
790813
910933 return !RegClass->contains(RegB);
911934 }
912935
913 bool LiveIntervals::overlapsAliases(const LiveInterval *LHS,
914 const LiveInterval *RHS) const {
915 if (!MRegisterInfo::isPhysicalRegister(LHS->reg)) {
916 if (!MRegisterInfo::isPhysicalRegister(RHS->reg))
917 return false; // vreg-vreg merge has no aliases!
918 std::swap(LHS, RHS);
919 }
920
921 assert(MRegisterInfo::isPhysicalRegister(LHS->reg) &&
922 MRegisterInfo::isVirtualRegister(RHS->reg) &&
923 "first interval must describe a physical register");
924
925 for (const unsigned *AS = mri_->getAliasSet(LHS->reg); *AS; ++AS)
926 if (RHS->overlaps(getInterval(*AS)))
927 return true;
928
929 return false;
930 }
931
932936 LiveInterval LiveIntervals::createInterval(unsigned reg) {
933937 float Weight = MRegisterInfo::isPhysicalRegister(reg) ?
934938 (float)HUGE_VAL :0.0F;