+
+ for (const unsigned *SubRegs = RegInfo->getSubRegisters(Reg);
+ unsigned SubReg = *SubRegs; ++SubRegs) {
+ PhysRegInfo[SubReg] = MI;
+ PhysRegUsed[SubReg] = true;
+ }
+
+ for (const unsigned *SuperRegs = RegInfo->getSuperRegisters(Reg);
+ unsigned SuperReg = *SuperRegs; ++SuperRegs) {
+ // Remember the partial use of this superreg if it was previously defined.
+ bool HasPrevDef = PhysRegInfo[SuperReg] != NULL;
+ if (!HasPrevDef) {
+ for (const unsigned *SSRegs = RegInfo->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
+/// other instructions (?), indicate that they are killed in this machine
+/// instruction by marking the operand 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, RegInfo, true);
+ return;
+ }
+
+ for (const unsigned *SubRegs = RegInfo->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.
+///
+bool LiveVariables::HandlePhysRegKill(unsigned Reg, const MachineInstr *RefMI,
+ SmallSet<unsigned, 4> &SubKills) {
+ const unsigned *SubRegs = RegInfo->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)
+ return true;
+ } else if (SubKills.empty()) {
+ // None of the sub-registers are killed elsewhere.
+ return true;
+ }
+
+ return false;
+}
+
+/// HandlePhysRegKill - Calls the recursive version of HandlePhysRegKill. (See
+/// above for details.)
+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, RegInfo, true);
+ return true;
+ }
+
+ // Some sub-registers are killed by another machine instruction.
+ for (const unsigned *SubRegs = RegInfo->getImmediateSubRegisters(Reg);
+ unsigned SubReg = *SubRegs; ++SubRegs)
+ addRegisterKills(SubReg, RefMI, SubKills);
+
+ return false;