aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-03-19 19:37:24 +0000
committerChris Lattner <sabre@nondot.org>2006-03-19 19:37:24 +0000
commit273f202890ab87d5a9a8f0575b5ebbffa0487eab (patch)
treea53a0d406b8eb92a8efe3ecaecde74f175f67a1d /lib/Transforms
parent2c58d3ac82ea7c6762e935c1f975be3ada2aeaf0 (diff)
downloadexternal_llvm-273f202890ab87d5a9a8f0575b5ebbffa0487eab.zip
external_llvm-273f202890ab87d5a9a8f0575b5ebbffa0487eab.tar.gz
external_llvm-273f202890ab87d5a9a8f0575b5ebbffa0487eab.tar.bz2
Teach cee to propagate through switch statements. This implements
Transforms/CorrelatedExprs/switch.ll Patch contributed by Eric Kidd! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@26872 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/CorrelatedExprs.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/CorrelatedExprs.cpp b/lib/Transforms/Scalar/CorrelatedExprs.cpp
index 3da7e6e..feae636 100644
--- a/lib/Transforms/Scalar/CorrelatedExprs.cpp
+++ b/lib/Transforms/Scalar/CorrelatedExprs.cpp
@@ -267,6 +267,7 @@ namespace {
const std::vector<BasicBlock*> &RegionExitBlocks);
void PropagateBranchInfo(BranchInst *BI);
+ void PropagateSwitchInfo(SwitchInst *SI);
void PropagateEquality(Value *Op0, Value *Op1, RegionInfo &RI);
void PropagateRelation(Instruction::BinaryOps Opcode, Value *Op0,
Value *Op1, RegionInfo &RI);
@@ -360,9 +361,12 @@ bool CEE::TransformRegion(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks){
// Now that all of our successors have information if they deserve it,
// propagate any information our terminator instruction finds to our
// successors.
- if (BranchInst *BI = dyn_cast<BranchInst>(TI))
+ if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
if (BI->isConditional())
PropagateBranchInfo(BI);
+ } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
+ PropagateSwitchInfo(SI);
+ }
// If this is a branch to a block outside our region that simply performs
// another conditional branch, one whose outcome is known inside of this
@@ -794,6 +798,22 @@ void CEE::PropagateBranchInfo(BranchInst *BI) {
}
+// PropagateSwitchInfo - We need to propagate the value tested by the
+// switch statement through each case block.
+//
+void CEE::PropagateSwitchInfo(SwitchInst *SI) {
+ // Propagate information down each of our non-default case labels. We
+ // don't yet propagate information down the default label, because a
+ // potentially large number of inequality constraints provide less
+ // benefit per unit work than a single equality constraint.
+ //
+ Value *cond = SI->getCondition();
+ for (unsigned i = 1; i < SI->getNumSuccessors(); ++i)
+ PropagateEquality(cond, SI->getSuccessorValue(i),
+ getRegionInfo(SI->getSuccessor(i)));
+}
+
+
// PropagateEquality - If we discover that two values are equal to each other in
// a specified region, propagate this knowledge recursively.
//