Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/CodeGen/ReachingDefAnalysis.cpp
Show First 20 Lines • Show All 221 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
int ReachingDefAnalysis::getClearance(MachineInstr *MI, MCPhysReg PhysReg) { | int ReachingDefAnalysis::getClearance(MachineInstr *MI, MCPhysReg PhysReg) { | ||||
assert(InstIds.count(MI) && "Unexpected machine instuction."); | assert(InstIds.count(MI) && "Unexpected machine instuction."); | ||||
return InstIds[MI] - getReachingDef(MI, PhysReg); | return InstIds[MI] - getReachingDef(MI, PhysReg); | ||||
} | } | ||||
void ReachingDefAnalysis::getReachingLocalUses(MachineInstr *Def, int PhysReg, | void ReachingDefAnalysis::getReachingLocalUses(MachineInstr *Def, int PhysReg, | ||||
SmallVectorImpl<MachineInstr*> &Uses) { | SmallVectorImpl<MachineInstr*> &Uses) { | ||||
MachineBasicBlock *MBB = Def->getParent(); | MachineBasicBlock *MBB = Def->getParent(); | ||||
MachineBasicBlock::iterator MI = MachineBasicBlock::iterator(Def); | MachineBasicBlock::iterator MI = MachineBasicBlock::iterator(Def); | ||||
while (++MI != MBB->end()) { | while (++MI != MBB->end()) { | ||||
for (auto &MO : MI->operands()) { | for (auto &MO : MI->operands()) { | ||||
if (!MO.isReg() || !MO.isUse() || MO.getReg() != PhysReg) | if (!MO.isReg() || !MO.isUse() || MO.getReg() != PhysReg) | ||||
continue; | continue; | ||||
// If/when we find a new reaching def, we know that there's no more uses | // If/when we find a new reaching def, we know that there's no more uses | ||||
Show All 28 Lines | bool ReachingDefAnalysis::isRegUsedAfter(MachineInstr *MI, int PhysReg) { | ||||
for (auto Last = MBB->rbegin(), End = MBB->rend(); Last != End; ++Last) { | for (auto Last = MBB->rbegin(), End = MBB->rend(); Last != End; ++Last) { | ||||
LiveRegs.stepBackward(*Last); | LiveRegs.stepBackward(*Last); | ||||
if (LiveRegs.contains(PhysReg)) | if (LiveRegs.contains(PhysReg)) | ||||
return InstIds[&*Last] > InstIds[MI]; | return InstIds[&*Last] > InstIds[MI]; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
MachineInstr *ReachingDefAnalysis::getInstWithUseBefore(MachineInstr *MI, | |||||
samparker: I would favour just returning a bool here, or renaming the method. | |||||
int PhysReg) { | |||||
auto I = MachineBasicBlock::reverse_iterator(MI); | |||||
auto E = MI->getParent()->rend(); | |||||
I++; | |||||
for ( ; I != E; I++) | |||||
for (auto &MO : I->operands()) | |||||
Not Done ReplyInline ActionsHow about using reverse iterators? Probably would have saved you from the the off-by-one? samparker: How about using reverse iterators? Probably would have saved you from the the off-by-one? | |||||
if (MO.isReg() && MO.isUse() && MO.getReg() == PhysReg) | |||||
return &*I; | |||||
return nullptr; | |||||
} | |||||
void ReachingDefAnalysis::getAllInstWithUseBefore(MachineInstr *MI, | |||||
int PhysReg, SmallVectorImpl<MachineInstr*> &Uses) { | |||||
MachineInstr *Use = nullptr; | |||||
MachineInstr *Pos = MI; | |||||
while ((Use = getInstWithUseBefore(Pos, PhysReg))) { | |||||
Uses.push_back(Use); | |||||
Pos = Use; | |||||
} | |||||
} |
I would favour just returning a bool here, or renaming the method.