diff options
author | Chris Lattner <sabre@nondot.org> | 2004-05-12 03:22:33 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-05-12 03:22:33 +0000 |
commit | 5b01e298ed42d5ce6aaf7634618b5e1769766b21 (patch) | |
tree | 1f0d839a891e39769a142c1870729360d706866c /lib | |
parent | b83c0f3f6391e5f8039305ec267f7cd43ffb4de9 (diff) | |
download | external_llvm-5b01e298ed42d5ce6aaf7634618b5e1769766b21.zip external_llvm-5b01e298ed42d5ce6aaf7634618b5e1769766b21.tar.gz external_llvm-5b01e298ed42d5ce6aaf7634618b5e1769766b21.tar.bz2 |
Two minor improvements:
1. Get rid of the silly abort block. When doing bb extraction, we get one
abort block for every block extracted, which is kinda annoying.
2. If the switch ends up having a single destination, turn it into an
unconditional branch.
I would like to add support for conditional branches, but to do this we will
want to have the function return a bool instead of a ushort.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13478 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Utils/CodeExtractor.cpp | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index b16a71b..84b149c 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -390,24 +390,20 @@ CodeExtractor::emitCallAndSwitchStatement(Function *newFunction, } } - // Now that we've done the deed, make the default destination of the switch - // instruction be a block with a call to abort() -- since this path should not - // be taken, this will abort sooner rather than later. - if (TheSwitch->getNumSuccessors() > 1) { - Function *container = codeReplacer->getParent(); - BasicBlock *abortBB = new BasicBlock("abortBlock", container); - std::vector<const Type*> paramTypes; - FunctionType *abortTy = FunctionType::get(Type::VoidTy, paramTypes, false); - Function *abortFunc = - container->getParent()->getOrInsertFunction("abort", abortTy); - abortBB->getInstList().push_back(new CallInst(abortFunc)); - Function *ParentFunc = TheSwitch->getParent()->getParent(); - if (ParentFunc->getReturnType() == Type::VoidTy) - new ReturnInst(0, abortBB); - else - new ReturnInst(Constant::getNullValue(ParentFunc->getReturnType()), - abortBB); - TheSwitch->setSuccessor(0, abortBB); + // Now that we've done the deed, simplify the switch instruction. + unsigned NumSuccs = TheSwitch->getNumSuccessors(); + if (NumSuccs > 1) { + if (NumSuccs-1 == 1) { + // Only a single destination, change the switch into an unconditional + // branch. + new BranchInst(TheSwitch->getSuccessor(1), TheSwitch); + TheSwitch->getParent()->getInstList().erase(TheSwitch); + } else { + // Otherwise, make the default destination of the switch instruction be + // one of the other successors. + TheSwitch->setSuccessor(0, TheSwitch->getSuccessor(NumSuccs-1)); + TheSwitch->removeCase(NumSuccs-1); // Remove redundant case + } } else { // There is only 1 successor (the block containing the switch itself), which // means that previously this was the last part of the function, and hence |