float weight; // weight of this interval
MachineInstr* remat; // definition if the definition rematerializable
Ranges ranges; // the ranges in which this register is live
+
+ /// ValueNumberInfo - If the value number definition is undefined (e.g. phi
+ /// merge point), it contains ~0,x,x. If the value number is not in use, it
+ /// contains ~1,x,x to indicate that the value # is not used. The first
+ /// entry is the instruction # of the definition, the second is the kill #.
+ /// If the third value is non-zero, then the val# is defined by a copy and
+ /// it represents the register number it is copied from.
+ struct VNInfo {
+ unsigned def;
+ unsigned kill;
+ unsigned reg;
+ VNInfo() : def(~1U), kill(~0U), reg(0) {};
+ VNInfo(unsigned d, unsigned k, unsigned r) : def(d), kill(k), reg(r) {};
+ };
private:
- /// ValueNumberInfo - If this value number is not defined by a copy, this
- /// holds ~0,x. If the value number is not in use, it contains ~1,x to
- /// indicate that the value # is not used. If the val# is defined by a
- /// copy, the first entry is the instruction # of the copy, and the second
- /// is the register number copied from.
- SmallVector<std::pair<unsigned,unsigned>, 4> ValueNumberInfo;
+ SmallVector<VNInfo, 4> ValueNumberInfo;
public:
LiveInterval(unsigned Reg, float Weight)
/// getNextValue - Create a new value number and return it. MIIdx specifies
/// the instruction that defines the value number.
unsigned getNextValue(unsigned MIIdx, unsigned SrcReg) {
- ValueNumberInfo.push_back(std::make_pair(MIIdx, SrcReg));
+ ValueNumberInfo.push_back(VNInfo(MIIdx, ~0U, SrcReg));
return ValueNumberInfo.size()-1;
}
/// specified value number.
unsigned getInstForValNum(unsigned ValNo) const {
//assert(ValNo < ValueNumberInfo.size());
- return ValueNumberInfo[ValNo].first;
+ return ValueNumberInfo[ValNo].def;
+ }
+
+ /// getKillForValNum - Return the machine instruction index that kills the
+ /// specified value number.
+ unsigned getKillForValNum(unsigned ValNo) const {
+ //assert(ValNo < ValueNumberInfo.size());
+ return ValueNumberInfo[ValNo].kill;
}
unsigned getSrcRegForValNum(unsigned ValNo) const {
//assert(ValNo < ValueNumberInfo.size());
- if (ValueNumberInfo[ValNo].first < ~2U)
- return ValueNumberInfo[ValNo].second;
- return 0;
+ return ValueNumberInfo[ValNo].reg;
}
- std::pair<unsigned, unsigned> getValNumInfo(unsigned ValNo) const {
+ VNInfo getValNumInfo(unsigned ValNo) const {
//assert(ValNo < ValueNumberInfo.size());
return ValueNumberInfo[ValNo];
}
/// setValueNumberInfo - Change the value number info for the specified
/// value number.
- void setValueNumberInfo(unsigned ValNo,
- const std::pair<unsigned, unsigned> &I){
+ void setValueNumberInfo(unsigned ValNo, const VNInfo &I) {
ValueNumberInfo[ValNo] = I;
}
/// the intervals are not joinable, this aborts.
void join(LiveInterval &Other, int *ValNoAssignments,
int *RHSValNoAssignments,
- SmallVector<std::pair<unsigned,unsigned>,16> &NewValueNumberInfo);
+ SmallVector<VNInfo,16> &NewValueNumberInfo);
/// removeRange - Remove the specified range from this interval. Note that
/// the range must already be in this interval in its entirety.
/// the intervals are not joinable, this aborts.
void LiveInterval::join(LiveInterval &Other, int *LHSValNoAssignments,
int *RHSValNoAssignments,
- SmallVector<std::pair<unsigned,
- unsigned>, 16> &NewValueNumberInfo) {
+ SmallVector<VNInfo, 16> &NewValueNumberInfo) {
// Try to do the least amount of work possible. In particular, if there are
// more liverange chunks in the other set than there are in the 'this' set,
// we want to avoid the interval scan if not.
bool MustMapCurValNos = false;
for (unsigned i = 0, e = getNumValNums(); i != e; ++i) {
- if (ValueNumberInfo[i].first == ~2U) continue; // tombstone value #
+ assert(ValueNumberInfo[i].def != ~2U);
+ if (ValueNumberInfo[i].def == ~1U) continue; // tombstone value #
if (i != (unsigned)LHSValNoAssignments[i]) {
MustMapCurValNos = true;
break;
if (V1 == getNumValNums()-1) {
do {
ValueNumberInfo.pop_back();
- } while (ValueNumberInfo.back().first == ~1U);
+ } while (ValueNumberInfo.back().def == ~1U);
} else {
- ValueNumberInfo[V1].first = ~1U;
+ ValueNumberInfo[V1].def = ~1U;
}
}
for (unsigned i = 0; i != getNumValNums(); ++i) {
if (i) OS << " ";
OS << i << "@";
- if (ValueNumberInfo[i].first == ~0U) {
+ if (ValueNumberInfo[i].def == ~0U) {
OS << "?";
} else {
- OS << ValueNumberInfo[i].first;
+ OS << ValueNumberInfo[i].def;
+ }
+ if (ValueNumberInfo[i].kill == ~0U) {
+ OS << ",?";
+ } else {
+ OS << "," << ValueNumberInfo[i].kill;
}
}
}
unsigned ValNum;
unsigned SrcReg, DstReg;
if (!tii_->isMoveInstr(*mi, SrcReg, DstReg))
- ValNum = interval.getNextValue(~0U, 0);
+ ValNum = interval.getNextValue(defIndex, 0);
else
ValNum = interval.getNextValue(defIndex, SrcReg);
interval.setValueNumberInfo(1, interval.getValNumInfo(0));
// Value#0 is now defined by the 2-addr instruction.
- interval.setValueNumberInfo(0, std::make_pair(~0U, 0U));
+ interval.setValueNumberInfo(0, LiveInterval::VNInfo(DefIndex, ~0U, 0U));
// Add the new live interval which replaces the range for the input copy.
LiveRange LR(DefIndex, RedefIndex, ValNo);
// Replace the interval with one of a NEW value number. Note that this
// value number isn't actually defined by an instruction, weird huh? :)
- LiveRange LR(Start, End, interval.getNextValue(~0U, 0));
+ LiveRange LR(Start, End, interval.getNextValue(~0, 0));
DOUT << " replace range with " << LR;
interval.addRange(LR);
DOUT << " RESULT: "; interval.print(DOUT, mri_);
unsigned ValNum;
unsigned SrcReg, DstReg;
if (!tii_->isMoveInstr(*mi, SrcReg, DstReg))
- ValNum = interval.getNextValue(~0U, 0);
+ ValNum = interval.getNextValue(defIndex, 0);
else
ValNum = interval.getNextValue(defIndex, SrcReg);
// Already exists? Extend old live interval.
LiveInterval::iterator OldLR = interval.FindLiveRangeContaining(start);
unsigned Id = (OldLR != interval.end())
- ? OldLR->ValId
- : interval.getNextValue(SrcReg != 0 ? start : ~0U, SrcReg);
+ ? OldLR->ValId : interval.getNextValue(start, SrcReg);
LiveRange LR(start, end, Id);
interval.addRange(LR);
DOUT << " +" << LR << '\n';
}
}
- LiveRange LR(start, end, interval.getNextValue(~0U, 0));
+ LiveRange LR(start, end, interval.getNextValue(start, 0));
DOUT << " +" << LR << '\n';
interval.addRange(LR);
}
// an unknown definition point or it is defined at CopyIdx. If unknown, we
// can't process it.
unsigned BValNoDefIdx = IntB.getInstForValNum(BValNo);
- if (BValNoDefIdx == ~0U) return false;
+ if (!IntB.getSrcRegForValNum(BValNo)) return false;
assert(BValNoDefIdx == CopyIdx &&
"Copy doesn't define the value?");
DOUT << "\nExtending: "; IntB.print(DOUT, mri_);
+ unsigned FillerStart = ValLR->end, FillerEnd = BLR->start;
// We are about to delete CopyMI, so need to remove it as the 'instruction
- // that defines this value #'.
- IntB.setValueNumberInfo(BValNo, std::make_pair(~0U, 0));
+ // that defines this value #'. Update the the valnum with the new defining
+ // instruction #.
+ IntB.setValueNumberInfo(BValNo, LiveInterval::VNInfo(FillerStart, ~0U, 0));
// Okay, we can merge them. We need to insert a new liverange:
// [ValLR.end, BLR.begin) of either value number, then we merge the
// two value numbers.
- unsigned FillerStart = ValLR->end, FillerEnd = BLR->start;
IntB.addRange(LiveRange(FillerStart, FillerEnd, BValNo));
// If the IntB live range is assigned to a physical register, and if that
for (const unsigned *AS = mri_->getSubRegisters(IntB.reg); *AS; ++AS) {
LiveInterval &AliasLI = li_->getInterval(*AS);
AliasLI.addRange(LiveRange(FillerStart, FillerEnd,
- AliasLI.getNextValue(~0U, 0)));
+ AliasLI.getNextValue(FillerStart, 0)));
}
}
/// contains the value number the copy is from.
///
static unsigned ComputeUltimateVN(unsigned VN,
- SmallVector<std::pair<unsigned,
- unsigned>, 16> &ValueNumberInfo,
+ SmallVector<LiveInterval::VNInfo, 16> &ValueNumberInfo,
SmallVector<int, 16> &ThisFromOther,
SmallVector<int, 16> &OtherFromThis,
SmallVector<int, 16> &ThisValNoAssignments,
// coalesced.
SmallVector<int, 16> LHSValNoAssignments;
SmallVector<int, 16> RHSValNoAssignments;
- SmallVector<std::pair<unsigned,unsigned>, 16> ValueNumberInfo;
+ SmallVector<LiveInterval::VNInfo, 16> ValueNumberInfo;
// If a live interval is a physical register, conservatively check if any
// of its sub-registers is overlapping the live interval of the virtual
// Find out if the RHS is defined as a copy from some value in the LHS.
int RHSValID = -1;
- std::pair<unsigned,unsigned> RHSValNoInfo;
+ LiveInterval::VNInfo RHSValNoInfo;
unsigned RHSSrcReg = RHS.getSrcRegForValNum(0);
if ((RHSSrcReg == 0 || rep(RHSSrcReg) != LHS.reg)) {
// If RHS is not defined as a copy from the LHS, we can use simpler and
// Otherwise, use the specified value #.
LHSValNoAssignments[VN] = RHSValID;
if (VN != (unsigned)RHSValID)
- ValueNumberInfo[VN].first = ~1U;
+ ValueNumberInfo[VN].def = ~1U;
else
ValueNumberInfo[VN] = RHSValNoInfo;
}
ValueNumberInfo.reserve(LHS.getNumValNums() + RHS.getNumValNums());
for (unsigned VN = 0, e = LHS.getNumValNums(); VN != e; ++VN) {
- if (LHSValNoAssignments[VN] >= 0 || LHS.getInstForValNum(VN) == ~2U)
+ if (LHSValNoAssignments[VN] >= 0 || LHS.getInstForValNum(VN) == ~1U)
continue;
ComputeUltimateVN(VN, ValueNumberInfo,
LHSValsDefinedFromRHS, RHSValsDefinedFromLHS,
LHSValNoAssignments, RHSValNoAssignments, LHS, RHS);
}
for (unsigned VN = 0, e = RHS.getNumValNums(); VN != e; ++VN) {
- if (RHSValNoAssignments[VN] >= 0 || RHS.getInstForValNum(VN) == ~2U)
+ if (RHSValNoAssignments[VN] >= 0 || RHS.getInstForValNum(VN) == ~1U)
continue;
// If this value number isn't a copy from the LHS, it's a new number.
if (RHSValsDefinedFromLHS[VN] == -1) {