Don't store COPY pointers in VNInfo.

If a value is defined by a COPY, that instuction can easily and cheaply
be found by getInstructionFromIndex(VNI->def).

This reduces the size of VNInfo from 24 to 16 bytes, and improves
llc compile time by 3%.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149763 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jakob Stoklund Olesen
2012-02-04 05:20:49 +00:00
parent edc8db87dc
commit 3b1088a2cc
9 changed files with 52 additions and 119 deletions

View File

@ -48,7 +48,6 @@ namespace llvm {
IS_UNUSED = 1 << 3 IS_UNUSED = 1 << 3
}; };
MachineInstr *copy;
unsigned char flags; unsigned char flags;
public: public:
@ -61,19 +60,18 @@ namespace llvm {
SlotIndex def; SlotIndex def;
/// VNInfo constructor. /// VNInfo constructor.
VNInfo(unsigned i, SlotIndex d, MachineInstr *c) VNInfo(unsigned i, SlotIndex d)
: copy(c), flags(0), id(i), def(d) : flags(0), id(i), def(d)
{ } { }
/// VNInfo construtor, copies values from orig, except for the value number. /// VNInfo construtor, copies values from orig, except for the value number.
VNInfo(unsigned i, const VNInfo &orig) VNInfo(unsigned i, const VNInfo &orig)
: copy(orig.copy), flags(orig.flags), id(i), def(orig.def) : flags(orig.flags), id(i), def(orig.def)
{ } { }
/// Copy from the parameter into this VNInfo. /// Copy from the parameter into this VNInfo.
void copyFrom(VNInfo &src) { void copyFrom(VNInfo &src) {
flags = src.flags; flags = src.flags;
copy = src.copy;
def = src.def; def = src.def;
} }
@ -86,19 +84,6 @@ namespace llvm {
flags = (flags | VNI->flags) & ~IS_UNUSED; flags = (flags | VNI->flags) & ~IS_UNUSED;
} }
/// For a register interval, if this VN was definied by a copy instr
/// getCopy() returns a pointer to it, otherwise returns 0.
/// For a stack interval the behaviour of this method is undefined.
MachineInstr* getCopy() const { return copy; }
/// For a register interval, set the copy member.
/// This method should not be called on stack intervals as it may lead to
/// undefined behavior.
void setCopy(MachineInstr *c) { copy = c; }
/// isDefByCopy - Return true when this value was defined by a copy-like
/// instruction as determined by MachineInstr::isCopyLike.
bool isDefByCopy() const { return copy != 0; }
/// Returns true if one or more kills are PHI nodes. /// Returns true if one or more kills are PHI nodes.
/// Obsolete, do not use! /// Obsolete, do not use!
bool hasPHIKill() const { return flags & HAS_PHI_KILL; } bool hasPHIKill() const { return flags & HAS_PHI_KILL; }
@ -294,10 +279,9 @@ namespace llvm {
/// getNextValue - Create a new value number and return it. MIIdx specifies /// getNextValue - Create a new value number and return it. MIIdx specifies
/// the instruction that defines the value number. /// the instruction that defines the value number.
VNInfo *getNextValue(SlotIndex def, MachineInstr *CopyMI, VNInfo *getNextValue(SlotIndex def, VNInfo::Allocator &VNInfoAllocator) {
VNInfo::Allocator &VNInfoAllocator) {
VNInfo *VNI = VNInfo *VNI =
new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), def, CopyMI); new (VNInfoAllocator) VNInfo((unsigned)valnos.size(), def);
valnos.push_back(VNI); valnos.push_back(VNI);
return VNI; return VNI;
} }

View File

@ -298,8 +298,7 @@ namespace llvm {
void handlePhysicalRegisterDef(MachineBasicBlock* mbb, void handlePhysicalRegisterDef(MachineBasicBlock* mbb,
MachineBasicBlock::iterator mi, MachineBasicBlock::iterator mi,
SlotIndex MIIdx, MachineOperand& MO, SlotIndex MIIdx, MachineOperand& MO,
LiveInterval &interval, LiveInterval &interval);
MachineInstr *CopyMI);
/// handleLiveInRegister - Create interval for a livein register. /// handleLiveInRegister - Create interval for a livein register.
void handleLiveInRegister(MachineBasicBlock* mbb, void handleLiveInRegister(MachineBasicBlock* mbb,

View File

@ -644,15 +644,17 @@ void InlineSpiller::analyzeSiblingValues() {
if (VNI->isUnused()) if (VNI->isUnused())
continue; continue;
MachineInstr *DefMI = 0; MachineInstr *DefMI = 0;
if (!VNI->isPHIDef()) {
DefMI = LIS.getInstructionFromIndex(VNI->def);
assert(DefMI && "No defining instruction");
}
// Check possible sibling copies. // Check possible sibling copies.
if (VNI->isPHIDef() || VNI->getCopy()) { if (VNI->isPHIDef() || DefMI->isCopy()) {
VNInfo *OrigVNI = OrigLI.getVNInfoAt(VNI->def); VNInfo *OrigVNI = OrigLI.getVNInfoAt(VNI->def);
assert(OrigVNI && "Def outside original live range"); assert(OrigVNI && "Def outside original live range");
if (OrigVNI->def != VNI->def) if (OrigVNI->def != VNI->def)
DefMI = traceSiblingValue(Reg, VNI, OrigVNI); DefMI = traceSiblingValue(Reg, VNI, OrigVNI);
} }
if (!DefMI && !VNI->isPHIDef())
DefMI = LIS.getInstructionFromIndex(VNI->def);
if (DefMI && Edit->checkRematerializable(VNI, DefMI, TII, AA)) { if (DefMI && Edit->checkRematerializable(VNI, DefMI, TII, AA)) {
DEBUG(dbgs() << "Value " << PrintReg(Reg) << ':' << VNI->id << '@' DEBUG(dbgs() << "Value " << PrintReg(Reg) << ':' << VNI->id << '@'
<< VNI->def << " may remat from " << *DefMI); << VNI->def << " may remat from " << *DefMI);
@ -905,7 +907,7 @@ bool InlineSpiller::reMaterializeFor(LiveInterval &VirtReg,
} }
DEBUG(dbgs() << "\t " << UseIdx << '\t' << *MI); DEBUG(dbgs() << "\t " << UseIdx << '\t' << *MI);
VNInfo *DefVNI = NewLI.getNextValue(DefIdx, 0, LIS.getVNInfoAllocator()); VNInfo *DefVNI = NewLI.getNextValue(DefIdx, LIS.getVNInfoAllocator());
NewLI.addRange(LiveRange(DefIdx, UseIdx.getRegSlot(), DefVNI)); NewLI.addRange(LiveRange(DefIdx, UseIdx.getRegSlot(), DefVNI));
DEBUG(dbgs() << "\tinterval: " << NewLI << '\n'); DEBUG(dbgs() << "\tinterval: " << NewLI << '\n');
++NumRemats; ++NumRemats;
@ -1079,8 +1081,7 @@ void InlineSpiller::insertReload(LiveInterval &NewLI,
--MI; // Point to load instruction. --MI; // Point to load instruction.
SlotIndex LoadIdx = LIS.InsertMachineInstrInMaps(MI).getRegSlot(); SlotIndex LoadIdx = LIS.InsertMachineInstrInMaps(MI).getRegSlot();
DEBUG(dbgs() << "\treload: " << LoadIdx << '\t' << *MI); DEBUG(dbgs() << "\treload: " << LoadIdx << '\t' << *MI);
VNInfo *LoadVNI = NewLI.getNextValue(LoadIdx, 0, VNInfo *LoadVNI = NewLI.getNextValue(LoadIdx, LIS.getVNInfoAllocator());
LIS.getVNInfoAllocator());
NewLI.addRange(LiveRange(LoadIdx, Idx, LoadVNI)); NewLI.addRange(LiveRange(LoadIdx, Idx, LoadVNI));
++NumReloads; ++NumReloads;
} }
@ -1094,7 +1095,7 @@ void InlineSpiller::insertSpill(LiveInterval &NewLI, const LiveInterval &OldLI,
--MI; // Point to store instruction. --MI; // Point to store instruction.
SlotIndex StoreIdx = LIS.InsertMachineInstrInMaps(MI).getRegSlot(); SlotIndex StoreIdx = LIS.InsertMachineInstrInMaps(MI).getRegSlot();
DEBUG(dbgs() << "\tspilled: " << StoreIdx << '\t' << *MI); DEBUG(dbgs() << "\tspilled: " << StoreIdx << '\t' << *MI);
VNInfo *StoreVNI = NewLI.getNextValue(Idx, 0, LIS.getVNInfoAllocator()); VNInfo *StoreVNI = NewLI.getNextValue(Idx, LIS.getVNInfoAllocator());
NewLI.addRange(LiveRange(Idx, StoreIdx, StoreVNI)); NewLI.addRange(LiveRange(Idx, StoreIdx, StoreVNI));
++NumSpills; ++NumSpills;
} }
@ -1205,7 +1206,7 @@ void InlineSpiller::spillAroundUses(unsigned Reg) {
else { else {
// This instruction defines a dead value. We don't need to spill it, // This instruction defines a dead value. We don't need to spill it,
// but do create a live range for the dead value. // but do create a live range for the dead value.
VNInfo *VNI = NewLI.getNextValue(Idx, 0, LIS.getVNInfoAllocator()); VNInfo *VNI = NewLI.getNextValue(Idx, LIS.getVNInfoAllocator());
NewLI.addRange(LiveRange(Idx, Idx.getDeadSlot(), VNI)); NewLI.addRange(LiveRange(Idx, Idx.getDeadSlot(), VNI));
} }
} }
@ -1220,7 +1221,7 @@ void InlineSpiller::spillAll() {
if (StackSlot == VirtRegMap::NO_STACK_SLOT) { if (StackSlot == VirtRegMap::NO_STACK_SLOT) {
StackSlot = VRM.assignVirt2StackSlot(Original); StackSlot = VRM.assignVirt2StackSlot(Original);
StackInt = &LSS.getOrCreateInterval(StackSlot, MRI.getRegClass(Original)); StackInt = &LSS.getOrCreateInterval(StackSlot, MRI.getRegClass(Original));
StackInt->getNextValue(SlotIndex(), 0, LSS.getVNInfoAllocator()); StackInt->getNextValue(SlotIndex(), LSS.getVNInfoAllocator());
} else } else
StackInt = &LSS.getInterval(StackSlot); StackInt = &LSS.getInterval(StackSlot);

View File

@ -202,12 +202,7 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb,
} }
} }
MachineInstr *CopyMI = NULL; VNInfo *ValNo = interval.getNextValue(defIndex, VNInfoAllocator);
if (mi->isCopyLike()) {
CopyMI = mi;
}
VNInfo *ValNo = interval.getNextValue(defIndex, CopyMI, VNInfoAllocator);
assert(ValNo->id == 0 && "First value in interval is not 0?"); assert(ValNo->id == 0 && "First value in interval is not 0?");
// Loop over all of the blocks that the vreg is defined in. There are // Loop over all of the blocks that the vreg is defined in. There are
@ -275,7 +270,7 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb,
if (PHIJoin) { if (PHIJoin) {
assert(getInstructionFromIndex(Start) == 0 && assert(getInstructionFromIndex(Start) == 0 &&
"PHI def index points at actual instruction."); "PHI def index points at actual instruction.");
ValNo = interval.getNextValue(Start, 0, VNInfoAllocator); ValNo = interval.getNextValue(Start, VNInfoAllocator);
ValNo->setIsPHIDef(true); ValNo->setIsPHIDef(true);
} }
LiveRange LR(Start, killIdx, ValNo); LiveRange LR(Start, killIdx, ValNo);
@ -323,11 +318,6 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb,
// Value#0 is now defined by the 2-addr instruction. // Value#0 is now defined by the 2-addr instruction.
OldValNo->def = RedefIndex; OldValNo->def = RedefIndex;
OldValNo->setCopy(0);
// A re-def may be a copy. e.g. %reg1030:6<def> = VMOVD %reg1026, ...
if (PartReDef && mi->isCopyLike())
OldValNo->setCopy(&*mi);
// Add the new live interval which replaces the range for the input copy. // Add the new live interval which replaces the range for the input copy.
LiveRange LR(DefIndex, RedefIndex, ValNo); LiveRange LR(DefIndex, RedefIndex, ValNo);
@ -353,11 +343,7 @@ void LiveIntervals::handleVirtualRegisterDef(MachineBasicBlock *mbb,
if (MO.isEarlyClobber()) if (MO.isEarlyClobber())
defIndex = MIIdx.getRegSlot(true); defIndex = MIIdx.getRegSlot(true);
VNInfo *ValNo; VNInfo *ValNo = interval.getNextValue(defIndex, VNInfoAllocator);
MachineInstr *CopyMI = NULL;
if (mi->isCopyLike())
CopyMI = mi;
ValNo = interval.getNextValue(defIndex, CopyMI, VNInfoAllocator);
SlotIndex killIndex = getMBBEndIdx(mbb); SlotIndex killIndex = getMBBEndIdx(mbb);
LiveRange LR(defIndex, killIndex, ValNo); LiveRange LR(defIndex, killIndex, ValNo);
@ -376,8 +362,7 @@ void LiveIntervals::handlePhysicalRegisterDef(MachineBasicBlock *MBB,
MachineBasicBlock::iterator mi, MachineBasicBlock::iterator mi,
SlotIndex MIIdx, SlotIndex MIIdx,
MachineOperand& MO, MachineOperand& MO,
LiveInterval &interval, LiveInterval &interval) {
MachineInstr *CopyMI) {
// A physical register cannot be live across basic block, so its // A physical register cannot be live across basic block, so its
// lifetime must end somewhere in its defining basic block. // lifetime must end somewhere in its defining basic block.
DEBUG(dbgs() << "\t\tregister: " << PrintReg(interval.reg, tri_)); DEBUG(dbgs() << "\t\tregister: " << PrintReg(interval.reg, tri_));
@ -446,7 +431,7 @@ exit:
VNInfo *ValNo = interval.getVNInfoAt(start); VNInfo *ValNo = interval.getVNInfoAt(start);
bool Extend = ValNo != 0; bool Extend = ValNo != 0;
if (!Extend) if (!Extend)
ValNo = interval.getNextValue(start, CopyMI, VNInfoAllocator); ValNo = interval.getNextValue(start, VNInfoAllocator);
if (Extend && MO.isEarlyClobber()) if (Extend && MO.isEarlyClobber())
ValNo->setHasRedefByEC(true); ValNo->setHasRedefByEC(true);
LiveRange LR(start, end, ValNo); LiveRange LR(start, end, ValNo);
@ -462,13 +447,9 @@ void LiveIntervals::handleRegisterDef(MachineBasicBlock *MBB,
if (TargetRegisterInfo::isVirtualRegister(MO.getReg())) if (TargetRegisterInfo::isVirtualRegister(MO.getReg()))
handleVirtualRegisterDef(MBB, MI, MIIdx, MO, MOIdx, handleVirtualRegisterDef(MBB, MI, MIIdx, MO, MOIdx,
getOrCreateInterval(MO.getReg())); getOrCreateInterval(MO.getReg()));
else { else
MachineInstr *CopyMI = NULL;
if (MI->isCopyLike())
CopyMI = MI;
handlePhysicalRegisterDef(MBB, MI, MIIdx, MO, handlePhysicalRegisterDef(MBB, MI, MIIdx, MO,
getOrCreateInterval(MO.getReg()), CopyMI); getOrCreateInterval(MO.getReg()));
}
} }
void LiveIntervals::handleLiveInRegister(MachineBasicBlock *MBB, void LiveIntervals::handleLiveInRegister(MachineBasicBlock *MBB,
@ -535,8 +516,7 @@ void LiveIntervals::handleLiveInRegister(MachineBasicBlock *MBB,
SlotIndex defIdx = getMBBStartIdx(MBB); SlotIndex defIdx = getMBBStartIdx(MBB);
assert(getInstructionFromIndex(defIdx) == 0 && assert(getInstructionFromIndex(defIdx) == 0 &&
"PHI def index points at actual instruction."); "PHI def index points at actual instruction.");
VNInfo *vni = VNInfo *vni = interval.getNextValue(defIdx, VNInfoAllocator);
interval.getNextValue(defIdx, 0, VNInfoAllocator);
vni->setIsPHIDef(true); vni->setIsPHIDef(true);
LiveRange LR(start, end, vni); LiveRange LR(start, end, vni);
@ -1124,7 +1104,7 @@ LiveRange LiveIntervals::addLiveRangeToEndOfBlock(unsigned reg,
LiveInterval& Interval = getOrCreateInterval(reg); LiveInterval& Interval = getOrCreateInterval(reg);
VNInfo* VN = Interval.getNextValue( VNInfo* VN = Interval.getNextValue(
SlotIndex(getInstructionIndex(startInst).getRegSlot()), SlotIndex(getInstructionIndex(startInst).getRegSlot()),
startInst, getVNInfoAllocator()); getVNInfoAllocator());
VN->setHasPHIKill(true); VN->setHasPHIKill(true);
LiveRange LR( LiveRange LR(
SlotIndex(getInstructionIndex(startInst).getRegSlot()), SlotIndex(getInstructionIndex(startInst).getRegSlot()),

View File

@ -237,7 +237,7 @@ void LiveRangeCalc::updateSSA(SlotIndexes *Indexes,
assert(Alloc && "Need VNInfo allocator to create PHI-defs"); assert(Alloc && "Need VNInfo allocator to create PHI-defs");
SlotIndex Start, End; SlotIndex Start, End;
tie(Start, End) = Indexes->getMBBRange(MBB); tie(Start, End) = Indexes->getMBBRange(MBB);
VNInfo *VNI = I->LI->getNextValue(Start, 0, *Alloc); VNInfo *VNI = I->LI->getNextValue(Start, *Alloc);
VNI->setIsPHIDef(true); VNI->setIsPHIDef(true);
I->Value = VNI; I->Value = VNI;
// This block is done, we know the final value. // This block is done, we know the final value.

View File

@ -169,10 +169,6 @@ namespace {
/// it as well. /// it as well.
bool RemoveDeadDef(LiveInterval &li, MachineInstr *DefMI); bool RemoveDeadDef(LiveInterval &li, MachineInstr *DefMI);
/// RemoveCopyFlag - If DstReg is no longer defined by CopyMI, clear the
/// VNInfo copy flag for DstReg and all aliases.
void RemoveCopyFlag(unsigned DstReg, const MachineInstr *CopyMI);
/// markAsJoined - Remember that CopyMI has already been joined. /// markAsJoined - Remember that CopyMI has already been joined.
void markAsJoined(MachineInstr *CopyMI); void markAsJoined(MachineInstr *CopyMI);
@ -434,8 +430,7 @@ bool RegisterCoalescer::AdjustCopiesBackFrom(const CoalescerPair &CP,
// Get the location that B is defined at. Two options: either this value has // Get the location that B is defined at. Two options: either this value has
// an unknown definition point or it is defined at CopyIdx. If unknown, we // an unknown definition point or it is defined at CopyIdx. If unknown, we
// can't process it. // can't process it.
if (!BValNo->isDefByCopy()) return false; if (BValNo->def != CopyIdx) return false;
assert(BValNo->def == CopyIdx && "Copy doesn't define the value?");
// AValNo is the value number in A that defines the copy, A3 in the example. // AValNo is the value number in A that defines the copy, A3 in the example.
SlotIndex CopyUseIdx = CopyIdx.getRegSlot(true); SlotIndex CopyUseIdx = CopyIdx.getRegSlot(true);
@ -467,7 +462,8 @@ bool RegisterCoalescer::AdjustCopiesBackFrom(const CoalescerPair &CP,
// If AValNo is defined as a copy from IntB, we can potentially process this. // If AValNo is defined as a copy from IntB, we can potentially process this.
// Get the instruction that defines this value number. // Get the instruction that defines this value number.
if (!CP.isCoalescable(AValNo->getCopy())) MachineInstr *ACopyMI = LIS->getInstructionFromIndex(AValNo->def);
if (!CP.isCoalescable(ACopyMI))
return false; return false;
// Get the LiveRange in IntB that this value number starts with. // Get the LiveRange in IntB that this value number starts with.
@ -512,7 +508,6 @@ bool RegisterCoalescer::AdjustCopiesBackFrom(const CoalescerPair &CP,
// that defines this value #'. Update the valnum with the new defining // that defines this value #'. Update the valnum with the new defining
// instruction #. // instruction #.
BValNo->def = FillerStart; BValNo->def = FillerStart;
BValNo->setCopy(0);
// Okay, we can merge them. We need to insert a new liverange: // Okay, we can merge them. We need to insert a new liverange:
// [ValLR.end, BLR.begin) of either value number, then we merge the // [ValLR.end, BLR.begin) of either value number, then we merge the
@ -527,7 +522,7 @@ bool RegisterCoalescer::AdjustCopiesBackFrom(const CoalescerPair &CP,
continue; continue;
LiveInterval &SRLI = LIS->getInterval(*SR); LiveInterval &SRLI = LIS->getInterval(*SR);
SRLI.addRange(LiveRange(FillerStart, FillerEnd, SRLI.addRange(LiveRange(FillerStart, FillerEnd,
SRLI.getNextValue(FillerStart, 0, SRLI.getNextValue(FillerStart,
LIS->getVNInfoAllocator()))); LIS->getVNInfoAllocator())));
} }
} }
@ -637,7 +632,7 @@ bool RegisterCoalescer::RemoveCopyByCommutingDef(const CoalescerPair &CP,
// BValNo is a value number in B that is defined by a copy from A. 'B3' in // BValNo is a value number in B that is defined by a copy from A. 'B3' in
// the example above. // the example above.
VNInfo *BValNo = IntB.getVNInfoAt(CopyIdx); VNInfo *BValNo = IntB.getVNInfoAt(CopyIdx);
if (!BValNo || !BValNo->isDefByCopy()) if (!BValNo || BValNo->def != CopyIdx)
return false; return false;
assert(BValNo->def == CopyIdx && "Copy doesn't define the value?"); assert(BValNo->def == CopyIdx && "Copy doesn't define the value?");
@ -781,7 +776,6 @@ bool RegisterCoalescer::RemoveCopyByCommutingDef(const CoalescerPair &CP,
// is updated. // is updated.
VNInfo *ValNo = BValNo; VNInfo *ValNo = BValNo;
ValNo->def = AValNo->def; ValNo->def = AValNo->def;
ValNo->setCopy(0);
for (LiveInterval::iterator AI = IntA.begin(), AE = IntA.end(); for (LiveInterval::iterator AI = IntA.begin(), AE = IntA.end();
AI != AE; ++AI) { AI != AE; ++AI) {
if (AI->valno != AValNo) continue; if (AI->valno != AValNo) continue;
@ -833,8 +827,6 @@ bool RegisterCoalescer::ReMaterializeTrivialDef(LiveInterval &SrcInt,
return false; return false;
} }
RemoveCopyFlag(DstReg, CopyMI);
MachineBasicBlock *MBB = CopyMI->getParent(); MachineBasicBlock *MBB = CopyMI->getParent();
MachineBasicBlock::iterator MII = MachineBasicBlock::iterator MII =
llvm::next(MachineBasicBlock::iterator(CopyMI)); llvm::next(MachineBasicBlock::iterator(CopyMI));
@ -861,8 +853,6 @@ bool RegisterCoalescer::ReMaterializeTrivialDef(LiveInterval &SrcInt,
MachineOperand &MO = CopyMI->getOperand(i); MachineOperand &MO = CopyMI->getOperand(i);
if (MO.isReg() && MO.isImplicit()) if (MO.isReg() && MO.isImplicit())
NewMI->addOperand(MO); NewMI->addOperand(MO);
if (MO.isDef())
RemoveCopyFlag(MO.getReg(), CopyMI);
} }
LIS->ReplaceMachineInstrInMaps(CopyMI, NewMI); LIS->ReplaceMachineInstrInMaps(CopyMI, NewMI);
@ -871,7 +861,7 @@ bool RegisterCoalescer::ReMaterializeTrivialDef(LiveInterval &SrcInt,
for (unsigned i = 0, e = NewMIImplDefs.size(); i != e; ++i) { for (unsigned i = 0, e = NewMIImplDefs.size(); i != e; ++i) {
unsigned reg = NewMIImplDefs[i]; unsigned reg = NewMIImplDefs[i];
LiveInterval &li = LIS->getInterval(reg); LiveInterval &li = LIS->getInterval(reg);
VNInfo *DeadDefVN = li.getNextValue(NewMIIdx.getRegSlot(), 0, VNInfo *DeadDefVN = li.getNextValue(NewMIIdx.getRegSlot(),
LIS->getVNInfoAllocator()); LIS->getVNInfoAllocator());
LiveRange lr(NewMIIdx.getRegSlot(), NewMIIdx.getDeadSlot(), DeadDefVN); LiveRange lr(NewMIIdx.getRegSlot(), NewMIIdx.getDeadSlot(), DeadDefVN);
li.addRange(lr); li.addRange(lr);
@ -1047,27 +1037,6 @@ bool RegisterCoalescer::RemoveDeadDef(LiveInterval &li,
return removeIntervalIfEmpty(li, LIS, TRI); return removeIntervalIfEmpty(li, LIS, TRI);
} }
void RegisterCoalescer::RemoveCopyFlag(unsigned DstReg,
const MachineInstr *CopyMI) {
SlotIndex DefIdx = LIS->getInstructionIndex(CopyMI).getRegSlot();
if (LIS->hasInterval(DstReg)) {
LiveInterval &LI = LIS->getInterval(DstReg);
if (const LiveRange *LR = LI.getLiveRangeContaining(DefIdx))
if (LR->valno->def == DefIdx)
LR->valno->setCopy(0);
}
if (!TargetRegisterInfo::isPhysicalRegister(DstReg))
return;
for (const unsigned* AS = TRI->getAliasSet(DstReg); *AS; ++AS) {
if (!LIS->hasInterval(*AS))
continue;
LiveInterval &LI = LIS->getInterval(*AS);
if (const LiveRange *LR = LI.getLiveRangeContaining(DefIdx))
if (LR->valno->def == DefIdx)
LR->valno->setCopy(0);
}
}
/// shouldJoinPhys - Return true if a copy involving a physreg should be joined. /// shouldJoinPhys - Return true if a copy involving a physreg should be joined.
/// We need to be careful about coalescing a source physical register with a /// We need to be careful about coalescing a source physical register with a
/// virtual register. Once the coalescing is done, it cannot be broken and these /// virtual register. Once the coalescing is done, it cannot be broken and these
@ -1394,9 +1363,9 @@ static bool RegistersDefinedFromSameValue(LiveIntervals &li,
// FIXME: This is very conservative. For example, we don't handle // FIXME: This is very conservative. For example, we don't handle
// physical registers. // physical registers.
MachineInstr *MI = VNI->getCopy(); MachineInstr *MI = li.getInstructionFromIndex(VNI->def);
if (!MI->isFullCopy() || CP.isPartial() || CP.isPhys()) if (!MI || !MI->isFullCopy() || CP.isPartial() || CP.isPhys())
return false; return false;
unsigned Dst = MI->getOperand(0).getReg(); unsigned Dst = MI->getOperand(0).getReg();
@ -1414,11 +1383,9 @@ static bool RegistersDefinedFromSameValue(LiveIntervals &li,
assert(Dst == A); assert(Dst == A);
VNInfo *Other = LR->valno; VNInfo *Other = LR->valno;
if (!Other->isDefByCopy()) const MachineInstr *OtherMI = li.getInstructionFromIndex(Other->def);
return false;
const MachineInstr *OtherMI = Other->getCopy();
if (!OtherMI->isFullCopy()) if (!OtherMI || !OtherMI->isFullCopy())
return false; return false;
unsigned OtherDst = OtherMI->getOperand(0).getReg(); unsigned OtherDst = OtherMI->getOperand(0).getReg();
@ -1536,7 +1503,11 @@ bool RegisterCoalescer::JoinIntervals(CoalescerPair &CP) {
for (LiveInterval::vni_iterator i = LHS.vni_begin(), e = LHS.vni_end(); for (LiveInterval::vni_iterator i = LHS.vni_begin(), e = LHS.vni_end();
i != e; ++i) { i != e; ++i) {
VNInfo *VNI = *i; VNInfo *VNI = *i;
if (VNI->isUnused() || !VNI->isDefByCopy()) // Src not defined by a copy? if (VNI->isUnused() || VNI->isPHIDef())
continue;
MachineInstr *MI = LIS->getInstructionFromIndex(VNI->def);
assert(MI && "Missing def");
if (!MI->isCopyLike()) // Src not defined by a copy?
continue; continue;
// Never join with a register that has EarlyClobber redefs. // Never join with a register that has EarlyClobber redefs.
@ -1550,7 +1521,6 @@ bool RegisterCoalescer::JoinIntervals(CoalescerPair &CP) {
// DstReg is known to be a register in the LHS interval. If the src is // DstReg is known to be a register in the LHS interval. If the src is
// from the RHS interval, we can use its value #. // from the RHS interval, we can use its value #.
MachineInstr *MI = VNI->getCopy();
if (!CP.isCoalescable(MI) && if (!CP.isCoalescable(MI) &&
!RegistersDefinedFromSameValue(*LIS, *TRI, CP, VNI, lr, DupCopies)) !RegistersDefinedFromSameValue(*LIS, *TRI, CP, VNI, lr, DupCopies))
continue; continue;
@ -1563,7 +1533,11 @@ bool RegisterCoalescer::JoinIntervals(CoalescerPair &CP) {
for (LiveInterval::vni_iterator i = RHS.vni_begin(), e = RHS.vni_end(); for (LiveInterval::vni_iterator i = RHS.vni_begin(), e = RHS.vni_end();
i != e; ++i) { i != e; ++i) {
VNInfo *VNI = *i; VNInfo *VNI = *i;
if (VNI->isUnused() || !VNI->isDefByCopy()) // Src not defined by a copy? if (VNI->isUnused() || VNI->isPHIDef())
continue;
MachineInstr *MI = LIS->getInstructionFromIndex(VNI->def);
assert(MI && "Missing def");
if (!MI->isCopyLike()) // Src not defined by a copy?
continue; continue;
// Never join with a register that has EarlyClobber redefs. // Never join with a register that has EarlyClobber redefs.
@ -1577,7 +1551,6 @@ bool RegisterCoalescer::JoinIntervals(CoalescerPair &CP) {
// DstReg is known to be a register in the RHS interval. If the src is // DstReg is known to be a register in the RHS interval. If the src is
// from the LHS interval, we can use its value #. // from the LHS interval, we can use its value #.
MachineInstr *MI = VNI->getCopy();
if (!CP.isCoalescable(MI) && if (!CP.isCoalescable(MI) &&
!RegistersDefinedFromSameValue(*LIS, *TRI, CP, VNI, lr, DupCopies)) !RegistersDefinedFromSameValue(*LIS, *TRI, CP, VNI, lr, DupCopies))
continue; continue;

View File

@ -142,7 +142,7 @@ protected:
lis->InsertMachineInstrInMaps(loadInstr).getRegSlot(); lis->InsertMachineInstrInMaps(loadInstr).getRegSlot();
SlotIndex endIndex = loadIndex.getNextIndex(); SlotIndex endIndex = loadIndex.getNextIndex();
VNInfo *loadVNI = VNInfo *loadVNI =
newLI->getNextValue(loadIndex, 0, lis->getVNInfoAllocator()); newLI->getNextValue(loadIndex, lis->getVNInfoAllocator());
newLI->addRange(LiveRange(loadIndex, endIndex, loadVNI)); newLI->addRange(LiveRange(loadIndex, endIndex, loadVNI));
} }
@ -155,7 +155,7 @@ protected:
lis->InsertMachineInstrInMaps(storeInstr).getRegSlot(); lis->InsertMachineInstrInMaps(storeInstr).getRegSlot();
SlotIndex beginIndex = storeIndex.getPrevIndex(); SlotIndex beginIndex = storeIndex.getPrevIndex();
VNInfo *storeVNI = VNInfo *storeVNI =
newLI->getNextValue(beginIndex, 0, lis->getVNInfoAllocator()); newLI->getNextValue(beginIndex, lis->getVNInfoAllocator());
newLI->addRange(LiveRange(beginIndex, storeIndex, storeVNI)); newLI->addRange(LiveRange(beginIndex, storeIndex, storeVNI));
} }

View File

@ -374,7 +374,7 @@ VNInfo *SplitEditor::defValue(unsigned RegIdx,
LiveInterval *LI = Edit->get(RegIdx); LiveInterval *LI = Edit->get(RegIdx);
// Create a new value. // Create a new value.
VNInfo *VNI = LI->getNextValue(Idx, 0, LIS.getVNInfoAllocator()); VNInfo *VNI = LI->getNextValue(Idx, LIS.getVNInfoAllocator());
// Use insert for lookup, so we can add missing values with a second lookup. // Use insert for lookup, so we can add missing values with a second lookup.
std::pair<ValueMap::iterator, bool> InsP = std::pair<ValueMap::iterator, bool> InsP =
@ -449,9 +449,7 @@ VNInfo *SplitEditor::defFromParent(unsigned RegIdx,
} }
// Define the value in Reg. // Define the value in Reg.
VNInfo *VNI = defValue(RegIdx, ParentVNI, Def); return defValue(RegIdx, ParentVNI, Def);
VNI->setCopy(CopyMI);
return VNI;
} }
/// Create a new virtual register and live interval. /// Create a new virtual register and live interval.
@ -1053,7 +1051,6 @@ void SplitEditor::finish(SmallVectorImpl<unsigned> *LRMap) {
unsigned RegIdx = RegAssign.lookup(ParentVNI->def); unsigned RegIdx = RegAssign.lookup(ParentVNI->def);
VNInfo *VNI = defValue(RegIdx, ParentVNI, ParentVNI->def); VNInfo *VNI = defValue(RegIdx, ParentVNI, ParentVNI->def);
VNI->setIsPHIDef(ParentVNI->isPHIDef()); VNI->setIsPHIDef(ParentVNI->isPHIDef());
VNI->setCopy(ParentVNI->getCopy());
// Force rematted values to be recomputed everywhere. // Force rematted values to be recomputed everywhere.
// The new live ranges may be truncated. // The new live ranges may be truncated.

View File

@ -779,7 +779,6 @@ void StrongPHIElimination::InsertCopiesForPHI(MachineInstr *PHI,
SlotIndex MBBStartIndex = LI->getMBBStartIdx(MBB); SlotIndex MBBStartIndex = LI->getMBBStartIdx(MBB);
SlotIndex DestCopyIndex = LI->getInstructionIndex(CopyInstr); SlotIndex DestCopyIndex = LI->getInstructionIndex(CopyInstr);
VNInfo *CopyVNI = CopyLI.getNextValue(MBBStartIndex, VNInfo *CopyVNI = CopyLI.getNextValue(MBBStartIndex,
CopyInstr,
LI->getVNInfoAllocator()); LI->getVNInfoAllocator());
CopyVNI->setIsPHIDef(true); CopyVNI->setIsPHIDef(true);
CopyLI.addRange(LiveRange(MBBStartIndex, CopyLI.addRange(LiveRange(MBBStartIndex,