[llvm-commits] [llvm] r47860 - /llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp

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


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

> Author: void
> Date: Mon Mar  3 16:11:16 2008
> New Revision: 47860
>
> URL: http://llvm.org/viewvc/llvm-project?rev=47860&view=rev
> Log:
> Multiple instructions can be inserted when eliminating frame  
> indexes. We need
> the register scavenger to process all of those new instructions  
> instead of just
> the last one inserted.
>
>
> Modified:
>    llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
>
> Modified: llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp?rev=47860&r1=47859&r2=47860&view=diff
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
> --- llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp (original)
> +++ llvm/trunk/lib/CodeGen/PrologEpilogInserter.cpp Mon Mar  3  
> 16:11:16 2008
> @@ -530,27 +530,44 @@
>         // Visit the instructions created by  
> eliminateCallFramePseudoInstr().
>         I = next(PrevI);
>         MI = NULL;
> -      } else if (I->getOpcode() == TargetInstrInfo::DECLARE)
> +      } else if (I->getOpcode() == TargetInstrInfo::DECLARE) {
>         // Ignore it.
> -        I++;
> -      else {
> -        I++;
> +        ++I;

This can be cleaned up. How about?

       if (I->getOpcode() == TargetInstrInfo::DECLARE) {
         // Ignore it.
         ++I;
         continue;
       }

       if (I->getOpcode() == FrameSetupOpcode ||
           I->getOpcode() == FrameDestroyOpcode) {
         // Remember how much SP has been adjusted to create the call  
frame.
         int Size = I->getOperand(0).getImm();
         if ((!StackGrowsDown && I->getOpcode() == FrameSetupOpcode) ||
             (StackGrowsDown && I->getOpcode() == FrameDestroyOpcode))
           Size = -Size;
         SPAdj += Size;
         MachineBasicBlock::iterator PrevI = prior(I);
         TRI.eliminateCallFramePseudoInstr(Fn, *BB, I);
         // Visit the instructions created by  
eliminateCallFramePseudoInstr().
         I = next(PrevI);
         continue;
       }

Then the next chunk doesn't have to be in else {}.

Evan

>
> +      } else {
> +        bool DoIncr = true;
> +
>         for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i)
>           if (MI->getOperand(i).isFrameIndex()) {
> +            // Some instructions (e.g. inline asm instructions) can  
> have
> +            // multiple frame indices and/or cause  
> eliminateFrameIndex to insert
> +            // more than one instruction. We need the register  
> scavenger to go
> +            // through all of these instructions so that it can  
> update its
> +            // register information. We keep the iterator at the  
> point before
> +            // insertion so that we can revisit them in full.
> +            bool AtBeginning = (I == BB->begin());
> +            if (!AtBeginning) --I;
> +
>             // If this instruction has a FrameIndex operand, we need  
> to use that
>             // target machine register info object to eliminate it.
>             TRI.eliminateFrameIndex(MI, SPAdj, RS);
>
> -            // Revisit the instruction in full.  Some instructions  
> (e.g. inline
> -            // asm instructions) can have multiple frame indices.
> -            --I;
> +            // Reset the iterator if we were at the beginning of  
> the BB.
> +            if (AtBeginning) {
> +              I = BB->begin();
> +              DoIncr = false;
> +            }
> +
>             MI = 0;
>             break;
>           }
> +
> +        if (DoIncr) ++I;
>       }
> +
>       // Update register states.
>       if (RS && MI) RS->forward(MI);
>     }
> +
>     assert(SPAdj == 0 && "Unbalanced call frame setup / destroy  
> pairs?");
>   }
> }
>
>
> _______________________________________________
> 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