[llvm-commits] [llvm] r156114 - in /llvm/trunk: include/llvm/Transforms/Utils/FunctionUtils.h lib/Transforms/Utils/CodeExtractor.cpp

Duncan Sands baldrick at free.fr
Fri May 4 00:35:30 PDT 2012


Hi Chandler,

> 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.

> --- llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp (original)
> +++ llvm/trunk/lib/Transforms/Utils/CodeExtractor.cpp Thu May  3 17:26:53 2012
> @@ -756,24 +756,31 @@
>   }
>
>   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;

it would be good to do something cleverer for landing pads.  In theory if both
the landing pad and all invokes feeding it are in the same code region then
extracting them should be OK.  Unfortunately this won't work right because the
various exception handling intrinsics (eg eh.typeid.for) that may be used down
stream from the landing pad need to be in the same function as the landing pad
and invoke.  That may be fixable.

Ciao, Duncan.

> +
> +  // 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.
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list