[LLVMdev] unwinds to in the CFG

Nick Lewycky nicholas at mxc.ca
Sun Mar 30 13:03:28 PDT 2008


Hi Gordon, I've been thinking about this problem a bit.

Nick Lewycky wrote:
> Gordon Henriksen wrote:
>> Also, consider a phi node:
>>
>> phi i32 [%x, %bb1] ; %x defined in %bb1.
>>
>> Depending on what type of predecessor %bb1 is, some of the models  
>> you've mentioned declare this phi node illegal.
> 
> Oh. Now that's a very good point.
> 
> bb1: unwinds to %cleanup
>    %x = add i32 @foo, @bar
>    ret i32 %x
> cleanup:
>    %y = phi i32 [%x, bb1]
> 
> If %cleanup has %bb1 as a predecessor then the above is legal. (PHI 
> nodes being the only Instruction that works on pred/succ and not 
> dominators.)

We already have this issue with invoke. Consider:

bb1:
   %x = invoke i32 @f() to label %normal unwind label %unwind
normal:
   phi i32 [%x, %bb1]
   ret i32 %x
unwind:
   phi i32 [%x, %bb1]  ; illegal
   ret i32 %x

The PHI in %unwind must mention %bb1, but may not refer to %x.

In the code sample I pasted before (bb1: unwinds to %cleanup) it would 
mean that the PHI node in %cleanup must reference %bb1 but may not 
contain any instructions inside of %bb1. Yes this rule will require 
fixing up some optimizations, but I'm prepared to do that.

This only applies to PHI nodes so it'll be fast to check for. The usual 
dominance test will take care of the case where %unwind branches out to 
other blocks that try to use %x.

Any other issues I should keep in mind?

Nick



More information about the llvm-dev mailing list