diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2012-05-03 22:26:53 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2012-05-03 22:26:53 +0000 |
commit | 9f7af7b74892e5479e26ab535c9a76131e1947c3 (patch) | |
tree | 30201c77e9623debc534e82068795aa57307ac85 /lib/Transforms/Utils | |
parent | cb348b9b45025393ec5b28eac8bb6773a9b603f6 (diff) |
Factor the logic for testing whether a basic block is viable for code
extraction into a public interface. Also clean it up and apply it more
consistently such that we check for landing pads *anywhere* in the
extracted code, not just in single-block extraction.
This will be used to guide decisions in passes that are planning to
eventually perform a round of code extraction.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156114 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Utils')
-rw-r--r-- | lib/Transforms/Utils/CodeExtractor.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/lib/Transforms/Utils/CodeExtractor.cpp b/lib/Transforms/Utils/CodeExtractor.cpp index e8c0b80c21..b8cea45178 100644 --- a/lib/Transforms/Utils/CodeExtractor.cpp +++ b/lib/Transforms/Utils/CodeExtractor.cpp @@ -756,24 +756,31 @@ ExtractCodeRegion(ArrayRef<BasicBlock*> code) { } bool CodeExtractor::isEligible(ArrayRef<BasicBlock*> code) { - // Deny a single basic block that's a landing pad block. - if (code.size() == 1 && code[0]->isLandingPad()) - return false; + for (ArrayRef<BasicBlock*>::iterator I = code.begin(), E = code.end(); + I != E; ++I) + if (!isBlockViableForExtraction(**I)) + return false; - // Deny code region if it contains allocas or vastarts. - for (ArrayRef<BasicBlock*>::iterator BB = code.begin(), e=code.end(); - BB != e; ++BB) - for (BasicBlock::const_iterator I = (*BB)->begin(), Ie = (*BB)->end(); - I != Ie; ++I) - if (isa<AllocaInst>(*I)) - return false; - else if (const CallInst *CI = dyn_cast<CallInst>(I)) - if (const Function *F = CI->getCalledFunction()) - if (F->getIntrinsicID() == Intrinsic::vastart) - return false; return true; } +bool llvm::isBlockViableForExtraction(const BasicBlock &BB) { + // Landing pads must be in the function where they were inserted for cleanup. + if (BB.isLandingPad()) + return false; + + // Don't hoist code containing allocas, invokes, or vastarts. + for (BasicBlock::const_iterator I = BB.begin(), E = BB.end(); I != E; ++I) { + if (isa<AllocaInst>(I) || isa<InvokeInst>(I)) + return false; + if (const CallInst *CI = dyn_cast<CallInst>(I)) + if (const Function *F = CI->getCalledFunction()) + if (F->getIntrinsicID() == Intrinsic::vastart) + return false; + } + + return true; +} /// ExtractCodeRegion - Slurp a sequence of basic blocks into a brand new /// function. |