[coroutines] Handle spills before catchswitch
authorGor Nishanov <GorNishanov@gmail.com>
Wed, 17 May 2017 03:09:22 +0000 (03:09 +0000)
committerGor Nishanov <GorNishanov@gmail.com>
Wed, 17 May 2017 03:09:22 +0000 (03:09 +0000)
commitdb38485588fdba5b02225c7973c4cc1c74edf544
treeb60de95f96d7209cae2840d4daf352c60985a9b1
parent58bb7bd18acc63b90e6a98d4c1a337e76412e0a6
[coroutines] Handle spills before catchswitch

If we need to spill the result of the PHI instruction, we insert the spill after
all of the PHIs and EHPads, however, in a catchswitch block there is no
room to insert the spill. Make room by splitting away catchswitch into a separate
block.

Before the fix:

    catch.dispatch:
       %val = phi i32 [ 1, %if.then ], [ 2, %if.else ]
       %switch = catchswitch within none [label %catch] unwind label %cleanuppad

After:

    catch.dispatch:
       %val = phi i32 [ 1, %if.then ], [ 2, %if.else ]
       %tok = cleanuppad within none []
       ; spill goes here
       cleanupret from %tok unwind label %catch.dispatch.switch
    catch.dispatch.switch:
       %switch = catchswitch within none [label %catch] unwind label %cleanuppad

https://reviews.llvm.org/D31846

llvm-svn: 303232
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
llvm/test/Transforms/Coroutines/coro-catchswitch.ll [new file with mode: 0644]