- unsigned SubReg = *SubRegs; ++SubRegs) {
- PhysRegPartUse[SubReg] = NULL;
- PhysRegInfo[SubReg] = MI;
- PhysRegUsed[SubReg] = true;
- }
-
- for (const unsigned *SuperRegs = TRI->getSuperRegisters(Reg);
- unsigned SuperReg = *SuperRegs; ++SuperRegs) {
- // Remember the partial use of this super-register if it was previously
- // defined.
- bool HasPrevDef = PhysRegInfo[SuperReg] != NULL;
-
- if (!HasPrevDef)
- // No need to go up more levels. A def of a register also sets its sub-
- // registers. So if PhysRegInfo[SuperReg] is NULL, it means SuperReg's
- // super-registers are not previously defined.
- for (const unsigned *SSRegs = TRI->getSuperRegisters(SuperReg);
- unsigned SSReg = *SSRegs; ++SSRegs)
- if (PhysRegInfo[SSReg] != NULL) {
- HasPrevDef = true;
- break;
- }
-
- if (HasPrevDef) {
- PhysRegInfo[SuperReg] = MI;
- PhysRegPartUse[SuperReg] = MI;
- }
- }
-}
-
-/// addRegisterKills - For all of a register's sub-registers that are killed in
-/// at this machine instruction, mark them as "killed". (If the machine operand
-/// isn't found, add it first.)
-void LiveVariables::addRegisterKills(unsigned Reg, MachineInstr *MI,
- SmallSet<unsigned, 4> &SubKills) {
- if (SubKills.count(Reg) == 0) {
- MI->addRegisterKilled(Reg, TRI, true);
- return;
- }
-
- for (const unsigned *SubRegs = TRI->getImmediateSubRegisters(Reg);
- unsigned SubReg = *SubRegs; ++SubRegs)
- addRegisterKills(SubReg, MI, SubKills);
-}
-
-/// HandlePhysRegKill - The recursive version of HandlePhysRegKill. Returns true
-/// if:
-///
-/// - The register has no sub-registers and the machine instruction is the
-/// last def/use of the register, or
-/// - The register has sub-registers and none of them are killed elsewhere.
-///
-/// SubKills is filled with the set of sub-registers that are killed elsewhere.
-bool LiveVariables::HandlePhysRegKill(unsigned Reg, const MachineInstr *RefMI,
- SmallSet<unsigned, 4> &SubKills) {
- const unsigned *SubRegs = TRI->getImmediateSubRegisters(Reg);
-
- for (; unsigned SubReg = *SubRegs; ++SubRegs) {
- const MachineInstr *LastRef = PhysRegInfo[SubReg];
-
- if (LastRef != RefMI ||
- !HandlePhysRegKill(SubReg, RefMI, SubKills))
- SubKills.insert(SubReg);
- }
-
- if (*SubRegs == 0) {
- // No sub-registers, just check if reg is killed by RefMI.
- if (PhysRegInfo[Reg] == RefMI && PhysRegInfo[Reg]->readsRegister(Reg)) {
- return true;
- }
- } else if (SubKills.empty()) {
- // None of the sub-registers are killed elsewhere.
- return true;
- }
-
- return false;
-}
-
-/// HandlePhysRegKill - Returns true if the whole register is killed in the
-/// machine instruction. If only some of its sub-registers are killed in this
-/// machine instruction, then mark those as killed and return false.
-bool LiveVariables::HandlePhysRegKill(unsigned Reg, MachineInstr *RefMI) {
- SmallSet<unsigned, 4> SubKills;
-
- if (HandlePhysRegKill(Reg, RefMI, SubKills)) {
- // This machine instruction kills this register.
- RefMI->addRegisterKilled(Reg, TRI, true);
- return true;
- }
-
- // Some sub-registers are killed by another machine instruction.
- for (const unsigned *SubRegs = TRI->getImmediateSubRegisters(Reg);