static LaneBitmask getLanesWithProperty(const LiveIntervals &LIS,
const MachineRegisterInfo &MRI, bool TrackLaneMasks, unsigned RegUnit,
- SlotIndex Pos,
+ SlotIndex Pos, LaneBitmask SafeDefault,
bool(*Property)(const LiveRange &LR, SlotIndex Pos)) {
if (TargetRegisterInfo::isVirtualRegister(RegUnit)) {
const LiveInterval &LI = LIS.getInterval(RegUnit);
// Be prepared for missing liveranges: We usually do not compute liveranges
// for physical registers on targets with many registers (GPUs).
if (LR == nullptr)
- return 0;
+ return SafeDefault;
return Property(*LR, Pos) ? ~0u : 0;
}
}
const MachineRegisterInfo &MRI,
bool TrackLaneMasks, unsigned RegUnit,
SlotIndex Pos) {
- return getLanesWithProperty(LIS, MRI, TrackLaneMasks, RegUnit, Pos,
+ return getLanesWithProperty(LIS, MRI, TrackLaneMasks, RegUnit, Pos, ~0u,
[](const LiveRange &LR, SlotIndex Pos) {
return LR.liveAt(Pos);
});
AddFlagsMI != nullptr && (LiveAfter & ~I->LaneMask) == 0)
AddFlagsMI->setRegisterDefReadUndef(RegUnit);
- LaneBitmask LaneMask = I->LaneMask & LiveAfter;
- if (LaneMask == 0) {
+ LaneBitmask ActualDef = I->LaneMask & LiveAfter;
+ if (ActualDef == 0) {
I = Defs.erase(I);
} else {
- I->LaneMask = LaneMask;
+ I->LaneMask = ActualDef;
++I;
}
}
}
// Discover live outs if this may be the first occurance of this register.
- LaneBitmask LiveOut = getLiveThroughAt(Reg, SlotIdx);
- if (LiveOut != 0)
- discoverLiveOut(RegisterMaskPair(Reg, LiveOut));
+ if (RequireIntervals) {
+ LaneBitmask LiveOut = getLiveThroughAt(Reg, SlotIdx);
+ if (LiveOut != 0)
+ discoverLiveOut(RegisterMaskPair(Reg, LiveOut));
+ }
}
increaseRegPressure(Reg, PreviousMask, NewMask);
LiveRegs.insert(RegisterMaskPair(Reg, LiveIn));
}
// Kill liveness at last uses.
- LaneBitmask LastUseMask = getLastUsedLanes(Reg, SlotIdx);
- if (LastUseMask != 0) {
- LiveRegs.erase(RegisterMaskPair(Reg, LastUseMask));
- decreaseRegPressure(Reg, LiveMask, LiveMask & ~LastUseMask);
+ if (RequireIntervals) {
+ LaneBitmask LastUseMask = getLastUsedLanes(Reg, SlotIdx);
+ if (LastUseMask != 0) {
+ LiveRegs.erase(RegisterMaskPair(Reg, LastUseMask));
+ decreaseRegPressure(Reg, LiveMask, LiveMask & ~LastUseMask);
+ }
}
}
LaneBitmask RegPressureTracker::getLiveLanesAt(unsigned RegUnit,
SlotIndex Pos) const {
- if (!RequireIntervals)
- return 0;
-
- return getLanesWithProperty(*LIS, *MRI, TrackLaneMasks, RegUnit, Pos,
+ assert(RequireIntervals);
+ return getLanesWithProperty(*LIS, *MRI, TrackLaneMasks, RegUnit, Pos, ~0u,
[](const LiveRange &LR, SlotIndex Pos) {
return LR.liveAt(Pos);
});
LaneBitmask RegPressureTracker::getLastUsedLanes(unsigned RegUnit,
SlotIndex Pos) const {
- if (!RequireIntervals)
- return 0;
-
+ assert(RequireIntervals);
return getLanesWithProperty(*LIS, *MRI, TrackLaneMasks, RegUnit,
- Pos.getBaseIndex(),
+ Pos.getBaseIndex(), 0,
[](const LiveRange &LR, SlotIndex Pos) {
const LiveRange::Segment *S = LR.getSegmentContaining(Pos);
return S != nullptr && S->end == Pos.getRegSlot();
LaneBitmask RegPressureTracker::getLiveThroughAt(unsigned RegUnit,
SlotIndex Pos) const {
- if (!RequireIntervals)
- return 0;
-
- return getLanesWithProperty(*LIS, *MRI, TrackLaneMasks, RegUnit, Pos,
+ assert(RequireIntervals);
+ return getLanesWithProperty(*LIS, *MRI, TrackLaneMasks, RegUnit, Pos, 0u,
[](const LiveRange &LR, SlotIndex Pos) {
const LiveRange::Segment *S = LR.getSegmentContaining(Pos);
return S != nullptr && S->start < Pos.getRegSlot(true) &&
if (TrackLaneMasks)
RegOpers.adjustLaneLiveness(*LIS, *MRI, SlotIdx);
- for (const RegisterMaskPair &Use : RegOpers.Uses) {
- unsigned Reg = Use.RegUnit;
- LaneBitmask LastUseMask = getLastUsedLanes(Reg, SlotIdx);
- if (LastUseMask == 0)
- continue;
- if (RequireIntervals) {
+ if (RequireIntervals) {
+ for (const RegisterMaskPair &Use : RegOpers.Uses) {
+ unsigned Reg = Use.RegUnit;
+ LaneBitmask LastUseMask = getLastUsedLanes(Reg, SlotIdx);
+ if (LastUseMask == 0)
+ continue;
// The LastUseMask is queried from the liveness information of instruction
// which may be further down the schedule. Some lanes may actually not be
// last uses for the current position.
= findUseBetween(Reg, LastUseMask, CurrIdx, SlotIdx, *MRI, LIS);
if (LastUseMask == 0)
continue;
- }
- LaneBitmask LiveMask = LiveRegs.contains(Reg);
- LaneBitmask NewMask = LiveMask & ~LastUseMask;
- decreaseRegPressure(Reg, LiveMask, NewMask);
+ LaneBitmask LiveMask = LiveRegs.contains(Reg);
+ LaneBitmask NewMask = LiveMask & ~LastUseMask;
+ decreaseRegPressure(Reg, LiveMask, NewMask);
+ }
}
// Generate liveness for defs.