[llvm-commits] [llvm] r47862 - /llvm/trunk/lib/CodeGen/MachineInstr.cpp

Evan Cheng evan.cheng at apple.com
Mon Mar 3 15:14:56 PST 2008


On Mar 3, 2008, at 2:14 PM, Bill Wendling wrote:

> Author: void
> Date: Mon Mar  3 16:14:33 2008
> New Revision: 47862
>
> URL: http://llvm.org/viewvc/llvm-project?rev=47862&view=rev
> Log:
> Go through the machine instruction's operands to make sure that  
> we're not
> marking both a super- and sub-register as "killed". This removes  
> implicit uses
> that are marked as "killed".
>
>
> Modified:
>    llvm/trunk/lib/CodeGen/MachineInstr.cpp
>
> Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=47862&r1=47861&r2=47862&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
> +++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Mon Mar  3 16:14:33 2008
> @@ -678,34 +678,74 @@
> bool MachineInstr::addRegisterKilled(unsigned IncomingReg,
>                                      const TargetRegisterInfo  
> *RegInfo,
>                                      bool AddIfNotFound) {
> -  bool Found = false;
> -  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
> +  // Go through the machine instruction's operands to eliminate any  
> potentially
> +  // illegal conditions. I.e., a super- and sub-register both  
> marked "kill".
> + Restart:
> +  for (unsigned i = 0, e = getNumOperands(); i < e; ++i) {
>     MachineOperand &MO = getOperand(i);
> +
>     if (MO.isRegister() && MO.isUse()) {
>       unsigned Reg = MO.getReg();
> -      if (!Reg)
> +
> +      if (!Reg || IncomingReg == Reg ||
> +          !TargetRegisterInfo::isPhysicalRegister(Reg) ||
> +          !TargetRegisterInfo::isPhysicalRegister(IncomingReg))
>         continue;
> +
> +      if (RegInfo->isSubRegister(IncomingReg, Reg)) {
> +        if (MO.isKill()) {
> +          if (MO.isImplicit()) {
>
> +            // Remove this implicit use that marks the sub-register  
> "kill". Let
> +            // the super-register take care of this information.
> +            RemoveOperand(i);
> +            goto Restart;       // Instruction was modified, redo  
> checking.

Seems like this may increase compile time unnecessarily? Do you have  
to restart from first operand? Can you simply recompute 'e' and make  
sure i isn't incremented?

>
> +          } else {
> +            // The super-register is going to take care of this kill
> +            // information.
> +            MO.setIsKill(false);
> +          }
> +        }
> +      } else if (RegInfo->isSuperRegister(IncomingReg, Reg) &&  
> MO.isKill()) {
> +        // The kill information is already handled by a super- 
> register. Don't
> +        // add this sub-register as a kill.
> +        return true;
> +      }

Check this first so we can take advantage of the early exit to avoid  
nesting.

>
> +    }
> +  }
> +
> +  // If the register already exists, then make sure it or its super- 
> register is
> +  // marked "kill".
> +  for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
> +    MachineOperand &MO = getOperand(i);
> +
> +    if (MO.isRegister() && MO.isUse()) {
> +      unsigned Reg = MO.getReg();
> +      if (!Reg) continue;
> +
>       if (Reg == IncomingReg) {
>         MO.setIsKill();
> -        Found = true;
> -        break;
> +        return true;
>
>       } else if (TargetRegisterInfo::isPhysicalRegister(Reg) &&

No need for else here.

Evan

>
>                  TargetRegisterInfo::isPhysicalRegister(IncomingReg)  
> &&
>                  RegInfo->isSuperRegister(IncomingReg, Reg) &&
> -                 MO.isKill())
> +                 MO.isKill()) {
>         // A super-register kill already exists.
> -        Found = true;
> +        return true;
> +      }
>     }
>   }
>
> -  // If not found, this means an alias of one of the operand is  
> killed. Add a
> +  // If not found, this means an alias of one of the operands is  
> killed. Add a
>   // new implicit operand if required.
> -  if (!Found && AddIfNotFound) {
> -    addOperand(MachineOperand::CreateReg(IncomingReg, false/*IsDef*/,
> -                                         true/*IsImp*/,true/ 
> *IsKill*/));
> +  if (AddIfNotFound) {
> +    addOperand(MachineOperand::CreateReg(IncomingReg,
> +                                         false /*IsDef*/,
> +                                         true  /*IsImp*/,
> +                                         true  /*IsKill*/));
>     return true;
>   }
> -  return Found;
> +
> +  return false;
> }
>
> bool MachineInstr::addRegisterDead(unsigned IncomingReg,
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list