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 | 3b193679f045962d255e7a1e0cdf09c76bee5e83 (patch) | |
| tree | 1f9228904d7699e0a65d6197281471321290057f /llvm/lib/Transforms | |
| parent | e4e91e3835ba41f6cc242929eac516342f0c9afa (diff) | |
| download | bcm5719-llvm-3b193679f045962d255e7a1e0cdf09c76bee5e83.tar.gz bcm5719-llvm-3b193679f045962d255e7a1e0cdf09c76bee5e83.zip | |
Bug fix: cannot modify Phi operands while iterating over them!
llvm-svn: 1203
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/HoistPHIConstants.cpp | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/HoistPHIConstants.cpp b/llvm/lib/Transforms/HoistPHIConstants.cpp index b8e1d7b46f9..6e903498f57 100644 --- a/llvm/lib/Transforms/HoistPHIConstants.cpp +++ b/llvm/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; } |

