[llvm-commits] [llvm] r150319 - /llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp

Nick Lewycky nicholas at mxc.ca
Sat Feb 11 16:47:24 PST 2012


Author: nicholas
Date: Sat Feb 11 18:47:24 2012
New Revision: 150319

URL: http://llvm.org/viewvc/llvm-project?rev=150319&view=rev
Log:
Don't traverse the PHI nodes twice. No functionality change!

Modified:
    llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp

Modified: llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp?rev=150319&r1=150318&r2=150319&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalOpt.cpp Sat Feb 11 18:47:24 2012
@@ -2294,7 +2294,7 @@
 /// EvaluateBlock - Evaluate all instructions in block BB, returning true if
 /// successful, false if we can't evaluate it.  NewBB returns the next BB that
 /// control flows into, or null upon return.
-static bool EvaluateBlock(BasicBlock *BB, BasicBlock *&NextBB,
+static bool EvaluateBlock(BasicBlock::iterator CurInst, BasicBlock *&NextBB,
                           std::vector<Function*> &CallStack,
                           DenseMap<Value*, Constant*> &Values,
                           DenseMap<Constant*, Constant*> &MutatedMemory,
@@ -2302,9 +2302,6 @@
                           SmallPtrSet<Constant*, 8> &SimpleConstants,
                           const TargetData *TD,
                           const TargetLibraryInfo *TLI) {
-  // CurInst - The current instruction we're evaluating.
-  BasicBlock::iterator CurInst = BB->getFirstNonPHI();
-
   // This is the main evaluation loop.
   while (1) {
     Constant *InstResult = 0;
@@ -2538,9 +2535,11 @@
   // CurBB - The current basic block we're evaluating.
   BasicBlock *CurBB = F->begin();
 
+  BasicBlock::iterator CurInst = CurBB->begin();
+
   while (1) {
     BasicBlock *NextBB;
-    if (!EvaluateBlock(CurBB, NextBB, CallStack, Values, MutatedMemory,
+    if (!EvaluateBlock(CurInst, NextBB, CallStack, Values, MutatedMemory,
                        AllocaTmps, SimpleConstants, TD, TLI))
       return false;
 
@@ -2564,8 +2563,8 @@
     // are any PHI nodes.  If so, evaluate them with information about where
     // we came from.
     PHINode *PN = 0;
-    for (BasicBlock::iterator Inst = NextBB->begin();
-         (PN = dyn_cast<PHINode>(Inst)); ++Inst)
+    for (CurInst = NextBB->begin();
+         (PN = dyn_cast<PHINode>(CurInst)); ++CurInst)
       Values[PN] = getVal(Values, PN->getIncomingValueForBlock(CurBB));
 
     // Advance to the next block.





More information about the llvm-commits mailing list