This is an archive of the discontinued LLVM Phabricator instance.

[coroutine] update promise object's final layout index
ClosedPublic

Authored by ychen on Jan 5 2021, 4:07 PM.

Details

Summary

promise is a header field but it is not guaranteed that it would be the third
field of the frame due to performOptimizedStructLayout..

Diff Detail

Event Timeline

ychen created this revision.Jan 5 2021, 4:07 PM
ychen requested review of this revision.Jan 5 2021, 4:07 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2021, 4:07 PM
lxfind added inline comments.Jan 12 2021, 10:26 AM
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
746

PromiseAlloca is added here as a header field, which means it should have a fixed index?
Could it be there are bugs in performOptimizedStructLayout that moved it around somehow?

ychen added inline comments.Jan 12 2021, 10:35 AM
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
746

I'm inclined to say it should be fixed offset which is not changed after performOptimizedStructLayout.

  1. The use of IsHeader in addFieldForAllocas suggests that.
  2. The comment below in OptimizedStructLayout.h
/// - Fields may be assigned a fixed offset in the layout.  If there are
///   gaps among the fixed-offset fields, the algorithm may attempt
///   to allocate flexible-offset fields into those gaps.  If that's
///   undesirable, the caller should "block out" those gaps by e.g.
///   just creating a single fixed-offset field that represents the
///   entire "header".
lxfind added inline comments.Jan 12 2021, 12:17 PM
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
746

You are right.
In that case, I wonder if it is still necessary to add PromiseAlloca as a header field?

ychen added inline comments.Jan 12 2021, 12:32 PM
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
746

Yeah, that's an option too. TBH, I'm not quite sure about the importance or implication of PromiseAlloca using flexible offset. Or maybe it would make llvm.coro.promise implementation hard or impossible?

Thanks. I agree your fix is correct.
Some small suggestions commented

llvm/lib/Transforms/Coroutines/CoroFrame.cpp
2299–2300

You can move this code to right after "B.addFieldForAllocas(F, FrameData, Shape);" (comments will need to be updated)
Then you won't need to modify "updateLayoutIndex".
That way I think it's actually cleaner.

ychen added inline comments.Jan 12 2021, 3:49 PM
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
2299–2300

My first attempt was here. It seems FrameTypeBuilder object is not available here to do the update.

lxfind added inline comments.Jan 12 2021, 3:53 PM
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
2299–2300

Not update here. But move these code to right after "B.addFieldForAllocas(F, FrameData, Shape);"

ychen added inline comments.Jan 12 2021, 4:05 PM
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
2299–2300

I may misunderstand this. Right after "B.addFieldForAllocas(F, FrameData, Shape);", performOptimizedStructLayout is not yet done, how do I update the index?

2299–2300

Or you mean after B.finish(FrameTy);?

lxfind added inline comments.Jan 12 2021, 4:08 PM
llvm/lib/Transforms/Coroutines/CoroFrame.cpp
2299–2300

You won't need to update the index manually, if you append the promise alloca to the alloca list after addFieldForAllocas. updateLayoutIndex will take care of it naturally.

ychen updated this revision to Diff 316273.Jan 12 2021, 4:49 PM

Address comments

ychen updated this revision to Diff 316275.Jan 12 2021, 4:52 PM

rebase

llvm/lib/Transforms/Coroutines/CoroFrame.cpp
2299–2300

Thanks for the explanation!

lxfind accepted this revision.Jan 12 2021, 5:32 PM

Thank you!

This revision is now accepted and ready to land.Jan 12 2021, 5:32 PM
This revision was landed with ongoing or failed builds.Jan 12 2021, 5:44 PM
This revision was automatically updated to reflect the committed changes.