diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2011-09-29 20:21:17 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2011-09-29 20:21:17 +0000 |
commit | 95031ed8372b030351c48ad0a2f62b7614a12c90 (patch) | |
tree | 77e15bf6baecf091994bff0122bdb54632bef2bb /llvm/lib/Target/CBackend | |
parent | 1a526fd96cb393bb5a5bcef3e376bf0a2d61073a (diff) | |
download | bcm5719-llvm-95031ed8372b030351c48ad0a2f62b7614a12c90.tar.gz bcm5719-llvm-95031ed8372b030351c48ad0a2f62b7614a12c90.zip |
Clean up uses of switch instructions so they are not dependent on the operand ordering. Patch by Stepan Dyatkovskiy.
llvm-svn: 140803
Diffstat (limited to 'llvm/lib/Target/CBackend')
-rw-r--r-- | llvm/lib/Target/CBackend/CBackend.cpp | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/Target/CBackend/CBackend.cpp b/llvm/lib/Target/CBackend/CBackend.cpp index e3524e4c38d..020b80102eb 100644 --- a/llvm/lib/Target/CBackend/CBackend.cpp +++ b/llvm/lib/Target/CBackend/CBackend.cpp @@ -2383,22 +2383,29 @@ void CWriter::visitReturnInst(ReturnInst &I) { void CWriter::visitSwitchInst(SwitchInst &SI) { + Value* Cond = SI.getCondition(); + Out << " switch ("; - writeOperand(SI.getOperand(0)); + writeOperand(Cond); Out << ") {\n default:\n"; printPHICopiesForSuccessor (SI.getParent(), SI.getDefaultDest(), 2); printBranchToBlock(SI.getParent(), SI.getDefaultDest(), 2); Out << ";\n"; - for (unsigned i = 2, e = SI.getNumOperands(); i != e; i += 2) { + + unsigned NumCases = SI.getNumCases(); + // Skip the first item since that's the default case. + for (unsigned i = 1; i < NumCases; ++i) { + ConstantInt* CaseVal = SI.getCaseValue(i); + BasicBlock* Succ = SI.getSuccessor(i); Out << " case "; - writeOperand(SI.getOperand(i)); + writeOperand(CaseVal); Out << ":\n"; - BasicBlock *Succ = cast<BasicBlock>(SI.getOperand(i+1)); printPHICopiesForSuccessor (SI.getParent(), Succ, 2); printBranchToBlock(SI.getParent(), Succ, 2); if (Function::iterator(Succ) == llvm::next(Function::iterator(SI.getParent()))) Out << " break;\n"; } + Out << " }\n"; } |