1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

If we are extracting a block that has multiple successors that are the same

block (common in a switch), make sure to remove extra edges in successor
blocks.  This fixes CodeExtractor/2004-08-12-BlockExtractPHI.ll and should
be pulled into LLVM 1.3 (though the regression test need not be, as that
would require pulling in the LoopExtract.cpp changes).

llvm-svn: 15717
This commit is contained in:
Chris Lattner 2004-08-13 03:27:07 +00:00
parent 2c3ad7902d
commit 84445ee674

View File

@ -657,10 +657,19 @@ ExtractCodeRegion(const std::vector<BasicBlock*> &code) {
succ_end(codeReplacer));
for (unsigned i = 0, e = Succs.size(); i != e; ++i)
for (BasicBlock::iterator I = Succs[i]->begin();
PHINode *PN = dyn_cast<PHINode>(I); ++I)
PHINode *PN = dyn_cast<PHINode>(I); ++I) {
std::set<BasicBlock*> ProcessedPreds;
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
if (BlocksToExtract.count(PN->getIncomingBlock(i)))
PN->setIncomingBlock(i, codeReplacer);
if (ProcessedPreds.insert(PN->getIncomingBlock(i)).second)
PN->setIncomingBlock(i, codeReplacer);
else {
// There were multiple entries in the PHI for this block, now there
// is only one, so remove the duplicated entries.
PN->removeIncomingValue(i, false);
--i; --e;
}
}
//std::cerr << "NEW FUNCTION: " << *newFunction;
// verifyFunction(*newFunction);