/// Simulates liveness when stepping forward over an instruction(bundle): Remove
/// killed-uses, add defs. This is the not recommended way, because it depends
-/// on accurate kill flags. If possible use stepBackwards() instead of this
+/// on accurate kill flags. If possible use stepBackward() instead of this
/// function.
void LivePhysRegs::stepForward(const MachineInstr &MI,
SmallVectorImpl<std::pair<unsigned, const MachineOperand*>> &Clobbers) {
/// Add live-in registers of basic block \p MBB to \p LiveRegs.
static void addLiveIns(LivePhysRegs &LiveRegs, const MachineBasicBlock &MBB) {
- for (unsigned Reg : make_range(MBB.livein_begin(), MBB.livein_end()))
- LiveRegs.addReg(Reg);
+ for (const auto &LI : MBB.liveins())
+ LiveRegs.addReg(LI.PhysReg);
}
/// Add pristine registers to the given \p LiveRegs. This function removes
}
void LivePhysRegs::addLiveOuts(const MachineBasicBlock *MBB,
- bool AddPristines) {
- if (AddPristines) {
+ bool AddPristinesAndCSRs) {
+ if (AddPristinesAndCSRs) {
const MachineFunction &MF = *MBB->getParent();
addPristines(*this, MF, *TRI);
+ if (!MBB->isReturnBlock()) {
+ // The return block has no successors whose live-ins we could merge
+ // below. So instead we add the callee saved registers manually.
+ for (const MCPhysReg *I = TRI->getCalleeSavedRegs(&MF); *I; ++I)
+ addReg(*I);
+ }
}
+
+ // To get the live-outs we simply merge the live-ins of all successors.
for (const MachineBasicBlock *Succ : MBB->successors())
::addLiveIns(*this, *Succ);
}