diff options
author | Vikram S. Adve <vadve@cs.uiuc.edu> | 2001-11-08 05:25:33 +0000 |
---|---|---|
committer | Vikram S. Adve <vadve@cs.uiuc.edu> | 2001-11-08 05:25:33 +0000 |
commit | ddf5ff6f8c584c8672b284346f94a42e6bf96014 (patch) | |
tree | d4ba7643f2ddc5530919cf4fa497d6ec55e912fd /lib/Transforms | |
parent | 9b19894da9d9bdd101ba90c51c9fd99d91a04314 (diff) | |
download | external_llvm-ddf5ff6f8c584c8672b284346f94a42e6bf96014.zip external_llvm-ddf5ff6f8c584c8672b284346f94a42e6bf96014.tar.gz external_llvm-ddf5ff6f8c584c8672b284346f94a42e6bf96014.tar.bz2 |
Bug fix: cannot modify Phi operands while iterating over them!
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1203 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r-- | lib/Transforms/HoistPHIConstants.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/lib/Transforms/HoistPHIConstants.cpp b/lib/Transforms/HoistPHIConstants.cpp index b8e1d7b..6e90349 100644 --- a/lib/Transforms/HoistPHIConstants.cpp +++ b/lib/Transforms/HoistPHIConstants.cpp @@ -14,6 +14,7 @@ #include "llvm/BasicBlock.h" #include "llvm/Method.h" #include <map> +#include <vector> typedef pair<BasicBlock *, Value*> BBConstTy; typedef map<BBConstTy, CastInst *> CachedCopyMap; @@ -53,23 +54,29 @@ bool HoistPHIConstants::doHoistPHIConstants(Method *M) { bool Changed = false; for (Method::iterator BI = M->begin(), BE = M->end(); BI != BE; ++BI) - for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II) { - Instruction *Inst = *II; - if (!isa<PHINode>(Inst)) break; // All PHIs occur at top of BB! + { + vector<PHINode*> phis; // normalizing invalidates BB iterator - PHINode *PN = cast<PHINode>(Inst); - for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i) { - Value *Op = PN->getIncomingValue(i); - - //if (isa<ConstPoolVal>(Op)) { --- Do for all phi args -- Ruchira - - PN->setIncomingValue(i, - NormalizePhiOperand(PN, Op, PN->getIncomingBlock(i), Cache)); - Changed = true; - - //} - } + for (BasicBlock::iterator II = (*BI)->begin(); II != (*BI)->end(); ++II) + { + if (PHINode *PN = dyn_cast<PHINode>(*II)) + phis.push_back(PN); + else + break; // All PHIs occur at top of BB! + } + + for (vector<PHINode*>::iterator PI=phis.begin(); PI != phis.end(); ++PI) + for (unsigned i = 0; i < (*PI)->getNumIncomingValues(); ++i) + { + //if (isa<ConstPoolVal>(Op)) {--- Do for all phi args -- Ruchira + (*PI)->setIncomingValue(i, + NormalizePhiOperand((*PI), + (*PI)->getIncomingValue(i), + (*PI)->getIncomingBlock(i), Cache)); + Changed = true; + //} + } } - + return Changed; } |