This is an archive of the discontinued LLVM Phabricator instance.

[coroutines] Handle spills before catchswitch
ClosedPublic

Authored by GorNishanov on Apr 8 2017, 9:54 AM.
Tokens
"Mountain of Wealth" token, awarded by GorNishanov.

Details

Reviewers
majnemer
rnk
Summary

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

Diff Detail

Event Timeline

GorNishanov created this revision.Apr 8 2017, 9:54 AM
majnemer added inline comments.Apr 10 2017, 5:18 PM
lib/Transforms/Coroutines/CoroFrame.cpp
360–368

What if the catchswitch had a phi on it? You are adding a predecessor which would mean it needs new entries.

GorNishanov added inline comments.Apr 10 2017, 5:26 PM
lib/Transforms/Coroutines/CoroFrame.cpp
360–368

Not sure I understand.

PHIs are staying in place. The purpose of this change is to break the catchswitch away from its PHIs, so that we have room to insert spills. The catchswitch goes into a new block and refers to the original PHIs as before.

GorNishanov edited the summary of this revision. (Show Details)Apr 10 2017, 5:30 PM
majnemer accepted this revision.Apr 10 2017, 5:30 PM

LGTM

lib/Transforms/Coroutines/CoroFrame.cpp
360–368

Ah, I understand now.

This revision is now accepted and ready to land.Apr 10 2017, 5:30 PM
GorNishanov added inline comments.Apr 10 2017, 5:32 PM
lib/Transforms/Coroutines/CoroFrame.cpp
360–368

Aah. I understand now. Description was incorrectly stating that we are splitting the PHIs away.
Fixed the description to clarify that we splitting away the catchswitch keeping the PHIs in place.

GorNishanov closed this revision.May 16 2017, 8:23 PM

Thank you very much for the review!

Committed r303232