This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen][Blocks] Refactor capture handling in code that generates block copy/destroy routines
ClosedPublic

Authored by arphaman on Feb 24 2017, 10:53 AM.

Details

Summary

This patch refactors the code figures out which block captures need to be copied/destroyed using special copy/destroy code.
This is a preparation patch for work on merging block copy/destroy routines.

Thanks for taking a look!

Diff Detail

Repository
rL LLVM

Event Timeline

arphaman created this revision.Feb 24 2017, 10:53 AM
vsk edited edge metadata.Feb 24 2017, 2:15 PM

Looks NFC to me.

lib/CodeGen/CGBlocks.cpp
1414 ↗(On Diff #89695)

I don't see the need for two GenericInfo types (although it's plausible it'll make sense with your upcoming changes!). I had in mind a single 'enum BlockCaptureOperationType' with 8 entries, and a 'struct BlockCaptureOperation'.

1478 ↗(On Diff #89695)

Ditto (re: removing continue statements where possible).

1666 ↗(On Diff #89695)

It looks like there are 4 paths which prep some part of a DestroyInfo and then fall through to the emplace_back. I think this logic would be easier to follow if the emplace_backs occurred right after the DestroyInfo is prepped (i.e, have 4 emplace_backs, and none at the end of the for loop). That should let you get rid of 3 continue statements (imo those were hard to follow).

rjmccall edited edge metadata.Feb 27 2017, 9:33 PM

You're doing this refactor to... support doing another refactor of the same code? Why are these patches separate?

You're doing this refactor to... support doing another refactor of the same code? Why are these patches separate?

Not quite, by "merging block copy/destroy routines" I meant that my next patch will try to generate the IR only for unique copy/destroy functions, so individual functions will be merged.

arphaman updated this revision to Diff 90033.Feb 28 2017, 7:48 AM
arphaman marked 3 inline comments as done.

The updated patch uses just one enum and simplifies the capture search loops.

lib/CodeGen/CGBlocks.cpp
1414 ↗(On Diff #89695)

Agreed, fixed.

You're doing this refactor to... support doing another refactor of the same code? Why are these patches separate?

Not quite, by "merging block copy/destroy routines" I meant that my next patch will try to generate the IR only for unique copy/destroy functions, so individual functions will be merged.

Ah, okay, sure.

lib/CodeGen/CGBlocks.cpp
1380 ↗(On Diff #90033)

BlockCaptureEntityKind, please.

1389 ↗(On Diff #90033)

Grammar, and the complementary generic operation to "copy" is "destroy", not "release".

1391 ↗(On Diff #90033)

Similarly, please name this Kind.

1608 ↗(On Diff #90033)

Please don't name local variables "Type". "QT" or "T" would be fine.

arphaman updated this revision to Diff 90197.Mar 1 2017, 9:34 AM
arphaman marked 4 inline comments as done.

Addressed John's comments.

Thanks, LGTM.

This revision was automatically updated to reflect the committed changes.