From 32e813e486c656ed17c5df6650581100bf2b876a Mon Sep 17 00:00:00 2001 From: John Criswell Date: Fri, 13 Aug 2004 18:52:00 +0000 Subject: Merged from mainline. llvm-svn: 15723 --- llvm/lib/Transforms/Utils/CodeExtractor.cpp | 15 ++++++++++++--- llvm/lib/Transforms/Utils/ValueMapper.cpp | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index b3de38a..aabc587 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -622,7 +622,7 @@ ExtractCodeRegion(const std::vector &code) { Function *oldFunction = header->getParent(); // This takes place of the original loop - BasicBlock *codeReplacer = new BasicBlock("codeRepl", oldFunction); + BasicBlock *codeReplacer = new BasicBlock("codeRepl", oldFunction, header); // The new function needs a root node because other nodes can branch to the // head of the region, but the entry node of a function cannot have preds. @@ -657,10 +657,19 @@ ExtractCodeRegion(const std::vector &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(I); ++I) + PHINode *PN = dyn_cast(I); ++I) { + std::set 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); diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp index 72ce4ae..d7507f9 100644 --- a/llvm/lib/Transforms/Utils/ValueMapper.cpp +++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp @@ -81,6 +81,11 @@ Value *llvm::MapValue(const Value *V, std::map &VM) { for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) Idx.push_back(cast(MapValue(CE->getOperand(i), VM))); return VMSlot = ConstantExpr::getGetElementPtr(MV, Idx); + } else if (CE->getOpcode() == Instruction::Select) { + Constant *MV1 = cast(MapValue(CE->getOperand(0), VM)); + Constant *MV2 = cast(MapValue(CE->getOperand(1), VM)); + Constant *MV3 = cast(MapValue(CE->getOperand(2), VM)); + return VMSlot = ConstantExpr::getSelect(MV1, MV2, MV3); } else { assert(CE->getNumOperands() == 2 && "Must be binary operator?"); Constant *MV1 = cast(MapValue(CE->getOperand(0), VM)); -- cgit v1.1