diff options
author | Chris Lattner <sabre@nondot.org> | 2009-10-29 01:21:20 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-10-29 01:21:20 +0000 |
commit | 4c0236fd8b94f9721bac8a66c3220e797310c593 (patch) | |
tree | d7367f0b61584a270684fb043f7026de15ffe85b /lib/Transforms/Scalar/SCCP.cpp | |
parent | 78c5cdaf2a24c9d2b5c89fdb5d66fd6ca3b5654b (diff) | |
download | llvm-4c0236fd8b94f9721bac8a66c3220e797310c593.tar.gz llvm-4c0236fd8b94f9721bac8a66c3220e797310c593.tar.bz2 llvm-4c0236fd8b94f9721bac8a66c3220e797310c593.tar.xz |
teach various passes about blockaddress. We no longer
crash on any clang tests.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85465 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/SCCP.cpp')
-rw-r--r-- | lib/Transforms/Scalar/SCCP.cpp | 72 |
1 files changed, 48 insertions, 24 deletions
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp index 4701d2f740..4e5fae8a04 100644 --- a/lib/Transforms/Scalar/SCCP.cpp +++ b/lib/Transforms/Scalar/SCCP.cpp @@ -448,10 +448,16 @@ void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI, Succs[BCValue.getConstant() == ConstantInt::getFalse(*Context)] = true; } } - } else if (isa<InvokeInst>(&TI)) { + return; + } + + if (isa<InvokeInst>(&TI)) { // Invoke instructions successors are always executable. Succs[0] = Succs[1] = true; - } else if (SwitchInst *SI = dyn_cast<SwitchInst>(&TI)) { + return; + } + + if (SwitchInst *SI = dyn_cast<SwitchInst>(&TI)) { LatticeVal &SCValue = getValueState(SI->getCondition()); if (SCValue.isOverdefined() || // Overdefined condition? (SCValue.isConstant() && !isa<ConstantInt>(SCValue.getConstant()))) { @@ -459,9 +465,20 @@ void SCCPSolver::getFeasibleSuccessors(TerminatorInst &TI, Succs.assign(TI.getNumSuccessors(), true); } else if (SCValue.isConstant()) Succs[SI->findCaseValue(cast<ConstantInt>(SCValue.getConstant()))] = true; - } else { - llvm_unreachable("SCCP: Don't know how to handle this terminator!"); + return; } + + // TODO: This could be improved if the operand is a [cast of a] BlockAddress. + if (isa<IndirectBrInst>(&TI)) { + // Just mark all destinations executable! + Succs.assign(TI.getNumSuccessors(), true); + return; + } + +#ifndef NDEBUG + errs() << "Unknown terminator instruction: " << TI << '\n'; +#endif + llvm_unreachable("SCCP: Don't know how to handle this terminator!"); } @@ -479,25 +496,27 @@ bool SCCPSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To) { if (BranchInst *BI = dyn_cast<BranchInst>(TI)) { if (BI->isUnconditional()) return true; - else { - LatticeVal &BCValue = getValueState(BI->getCondition()); - if (BCValue.isOverdefined()) { - // Overdefined condition variables mean the branch could go either way. - return true; - } else if (BCValue.isConstant()) { - // Not branching on an evaluatable constant? - if (!isa<ConstantInt>(BCValue.getConstant())) return true; + + LatticeVal &BCValue = getValueState(BI->getCondition()); + if (BCValue.isOverdefined()) { + // Overdefined condition variables mean the branch could go either way. + return true; + } else if (BCValue.isConstant()) { + // Not branching on an evaluatable constant? + if (!isa<ConstantInt>(BCValue.getConstant())) return true; - // Constant condition variables mean the branch can only go a single way - return BI->getSuccessor(BCValue.getConstant() == - ConstantInt::getFalse(*Context)) == To; - } - return false; + // Constant condition variables mean the branch can only go a single way + return BI->getSuccessor(BCValue.getConstant() == + ConstantInt::getFalse(*Context)) == To; } - } else if (isa<InvokeInst>(TI)) { - // Invoke instructions successors are always executable. + return false; + } + + // Invoke instructions successors are always executable. + if (isa<InvokeInst>(TI)) return true; - } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) { + + if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) { LatticeVal &SCValue = getValueState(SI->getCondition()); if (SCValue.isOverdefined()) { // Overdefined condition? // All destinations are executable! @@ -517,12 +536,17 @@ bool SCCPSolver::isEdgeFeasible(BasicBlock *From, BasicBlock *To) { return SI->getDefaultDest() == To; } return false; - } else { + } + + // Just mark all destinations executable! + // TODO: This could be improved if the operand is a [cast of a] BlockAddress. + if (isa<IndirectBrInst>(&TI)) + return true; + #ifndef NDEBUG - errs() << "Unknown terminator instruction: " << *TI << '\n'; + errs() << "Unknown terminator instruction: " << *TI << '\n'; #endif - llvm_unreachable(0); - } + llvm_unreachable(0); } // visit Implementations - Something changed in this instruction... Either an |