[llvm-commits] [llvm] r47965 - /llvm/trunk/lib/Transforms/Utils/UnifyFunctionExitNodes.cpp

Chris Lattner clattner at apple.com
Fri Mar 7 17:27:13 PST 2008


On Mar 5, 2008, at 1:50 PM, Devang Patel wrote:
> Author: dpatel
> Log:
> Handle 'ret' with multiple values.
>
>
> -  PHINode *PN = 0;
> -  if (F.getReturnType() != Type::VoidTy) {
> +  SmallVector<Value *, 4> Phis;
> +  unsigned NumRetVals = ReturningBlocks[0]->getTerminator()- 
> >getNumOperands();
> +  if (NumRetVals == 0)
> +    new ReturnInst(NULL, NewRetBlock);

Ok.

> +  else if (const StructType *STy =  
> dyn_cast<StructType>(F.getReturnType())) {
> +    for (unsigned i = 0; i < NumRetVals; ++i) {
> +      PHINode *PN = new PHINode(STy->getElementType(i),  
> "UnifiedRetVal");
> +      NewRetBlock->getInstList().push_back(PN);
> +      Phis.push_back(PN);
> +    }
> +    new ReturnInst(&Phis[0], NumRetVals);

This loop is not specific to multiple return case.  It would work just  
as well for the single return case.  Please remove the check for  
StructType.

Also, you can specify the insertion point directly in the phi node, to  
avoid the getInstList().push_back.  As with the inliner, you should  
use more specific names "UnifiedRetVal.42" if possible, and insert in  
forward order instead of backwards.

-Chris



More information about the llvm-commits mailing list