[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

Evan Cheng evan.cheng at apple.com
Mon Mar 24 18:41:10 PDT 2008


On Mar 18, 2008, at 9:59 PM, Chris Lattner wrote:

>
> 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.

No, this applies to physical registers only.

We need def / use information for physical registers and MI to  
distance from top of MBB mapping to quickly determine this property.  
This is not *yet* showing up to be a compile time issue, so I am  
ignoring it for now.

Isn't Owen going to do something about LiveVariables? Can I volunteer  
Own to own this problem? :-)

Evan


>
>
> 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
>
> _______________________________________________
> 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