From a46e62424bd148012b37a0cca405877e708973c8 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Thu, 3 May 2012 22:26:53 +0000 Subject: 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. llvm-svn: 156114 --- llvm/lib/Transforms/Utils/CodeExtractor.cpp | 35 +++++++++++++++++------------ 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'llvm/lib/Transforms/Utils/CodeExtractor.cpp') diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp index e8c0b80c212..b8cea45178c 100644 --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -756,24 +756,31 @@ ExtractCodeRegion(ArrayRef code) { } bool CodeExtractor::isEligible(ArrayRef code) { - // Deny a single basic block that's a landing pad block. - if (code.size() == 1 && code[0]->isLandingPad()) - return false; + for (ArrayRef::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::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(*I)) - return false; - else if (const CallInst *CI = dyn_cast(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(I) || isa(I)) + return false; + if (const CallInst *CI = dyn_cast(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. -- cgit v1.2.3