[llvm-commits] [llvm] r48521 - in /llvm/trunk: include/llvm/CodeGen/LiveVariables.h lib/CodeGen/LiveVariables.cpp test/CodeGen/PowerPC/2008-03-18-RegScavengerAssert.ll test/CodeGen/X86/x86-64-ret0.ll

Chris Lattner clattner at apple.com
Tue Mar 18 21:59:33 PDT 2008


On Mar 18, 2008, at 5:52 PM, Evan Cheng wrote:

> +/// hasRegisterUseBelow - Return true if the specified register is  
> used after
> +/// the current instruction and before it's next definition.
> +bool LiveVariables::hasRegisterUseBelow(unsigned Reg,
> +                                        MachineBasicBlock::iterator  
> I,
> +                                        MachineBasicBlock *MBB) {
> +  if (I == MBB->end())
> +    return false;
> +  ++I;
> +  // FIXME: This is slow. We probably need a smarter solution.  
> Possibilities:
> +  // 1. Scan all instructions once and build def / use information  
> of physical
> +  //    registers. We also need a fast way to compare relative  
> ordering of
> +  //    instructions.
> +  // 2. Cache information so this function only has to scan  
> instructions that
> +  //    read / def physical instructions.
> +  for (MachineBasicBlock::iterator E = MBB->end(); I != E; ++I) {
> +    MachineInstr *MI = I;
> +    for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
> +      const MachineOperand &MO = MI->getOperand(i);
> +      if (!MO.isRegister() || MO.getReg() != Reg)
> +        continue;
> +      if (MO.isDef())
> +        return false;
> +      return true;
> +    }
> +  }
> +  return false;
> +}

Hi Evan,

How about using reg_iterators to do this?  I assume this only applies  
to vregs.  If you walk the use_iterator list for the register, you can  
very efficiently discard uses in other blocks (check User->getparent()  
== MBB).  Any uses within the same block are either a) in phi nodes,  
in which case they are above the instruction or b) users later in the  
block.

If the representation is not in SSA form, you have to do some more  
checks, but this should be a lot faster than scanning the whole  
machine block.  MBB's can be very large after all :)

-Chris




More information about the llvm-commits mailing list