mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-13 08:35:46 +00:00
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
This commit is contained in:
parent
9b19894da9
commit
ddf5ff6f8c
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user