[llvm-commits] CVS: llvm/lib/Transforms/Utils/CloneFunction.cpp
Chris Lattner
lattner at cs.uiuc.edu
Wed Sep 13 14:27:14 PDT 2006
Changes in directory llvm/lib/Transforms/Utils:
CloneFunction.cpp updated: 1.30 -> 1.31
---
Log message:
Second half of the fix for Transforms/Inline/inline_cleanup.ll
This folds unconditional branches that are often produced by code
specialization.
---
Diffs of the changes: (+28 -2)
CloneFunction.cpp | 30 ++++++++++++++++++++++++++++--
1 files changed, 28 insertions(+), 2 deletions(-)
Index: llvm/lib/Transforms/Utils/CloneFunction.cpp
diff -u llvm/lib/Transforms/Utils/CloneFunction.cpp:1.30 llvm/lib/Transforms/Utils/CloneFunction.cpp:1.31
--- llvm/lib/Transforms/Utils/CloneFunction.cpp:1.30 Thu Jun 1 15:02:28 2006
+++ llvm/lib/Transforms/Utils/CloneFunction.cpp Wed Sep 13 16:27:00 2006
@@ -449,6 +449,32 @@
}
}
}
-}
-
+
+ // Now that the inlined function body has been fully constructed, go through
+ // and zap unconditional fall-through branches. This happen all the time when
+ // specializing code: code specialization turns conditional branches into
+ // uncond branches, and this code folds them.
+ Function::iterator I = cast<BasicBlock>(ValueMap[&OldFunc->getEntryBlock()]);
+ while (I != NewFunc->end()) {
+ BranchInst *BI = dyn_cast<BranchInst>(I->getTerminator());
+ if (!BI || BI->isConditional()) { ++I; continue; }
+
+ BasicBlock *Dest = BI->getSuccessor(0);
+ if (!Dest->getSinglePredecessor()) { ++I; continue; }
+
+ // We know all single-entry PHI nodes in the inlined function have been
+ // removed, so we just need to splice the blocks.
+ BI->eraseFromParent();
+
+ // Move all the instructions in the succ to the pred.
+ I->getInstList().splice(I->end(), Dest->getInstList());
+
+ // Make all PHI nodes that referred to Dest now refer to I as their source.
+ Dest->replaceAllUsesWith(I);
+ // Remove the dest block.
+ Dest->eraseFromParent();
+
+ // Do not increment I, iteratively merge all things this block branches to.
+ }
+}
More information about the llvm-commits
mailing list