-
- // Now, fill only the reachable blocks with the cloned contents
- // of the originals.
- assert(CloneWorklist.empty() && "Dirty worklist before re-use\n");
- CloneWorklist.push_back(&OldFunc->getEntryBlock());
- while (!CloneWorklist.empty()) {
- const BasicBlock *BB = CloneWorklist.back();
- CloneWorklist.pop_back();
- PFC.CloneBlock(BB, cast<BasicBlock>(VMap[BB]), CloneWorklist,
- OrigBBs);
- }
-
- // Removed BB's that were created that turned out to be prunable.
- // Actual cloning may have found pruning opportunities since
- // branch or switch statement target may have been known at compile-time.
- // Alternatively we could write a routine CloneFunction and add a) a
- // parameter to actually do the cloning and b) a return parameter that
- // gives a list of blocks that need to be cloned also. Then we could
- // call CloneFunction when we collect the blocks to call, but suppress
- // cloning. And actually *do* the cloning in the while loop above. Also
- // the cleanup here would become redundant, and so would be the OrigBBs.
- for (std::set<const BasicBlock *>::iterator Oi = OrigBBs.begin(),
- Oe = OrigBBs.end(); Oi != Oe; ++Oi) {
- const BasicBlock *Orig = *Oi;
- BasicBlock *NewBB = cast<BasicBlock>(VMap[Orig]);
- delete NewBB;
- VMap[Orig] = 0;
- }
-