This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Don't emit the same global block multiple times.
AbandonedPublic

Authored by george.burgess.iv on Nov 8 2016, 12:10 PM.

Details

Reviewers
rjmccall
Summary

D14274 makes our constexpr evaluator more aggressive with some variables marked const. This changes how we behave on code like the following:

void foo() {
  void (^const block_A)(void) = ^{ return; };
  get_kernel_work_group_size(block_A);
  get_kernel_work_group_size(block_A);
}

The constexpr evaluator will now give us ^{ return; } three times (one for each use of block_A) instead of once (in block_A's assignment). CodeGen emits a block every time it gets handed a BlockExpr, so we end up emitting the code for ^{ return; } three times in total. We can fix this by tracking which global BlockExprs we've already generated code for.

This seems to not happen for local BlockExprs, since the constexpr fails for BlockExprs with captures (see PointerExprEvaluator::VisitBlockExpr in lib/AST/ExprConstant.cpp). That said, I'm happy to add this uniquing code for BlockExprs with captures if anyone wants me to.

Diff Detail

Event Timeline

george.burgess.iv retitled this revision from to [CodeGen] Don't emit the same global block multiple times..
george.burgess.iv updated this object.
george.burgess.iv added a reviewer: rjmccall.
george.burgess.iv added a subscriber: cfe-commits.
rjmccall edited edge metadata.Nov 10 2016, 10:36 PM

This looks great. One minor tweak and then it's ready.

lib/CodeGen/CGBlocks.cpp
1057

We conventionally name these things "set" rather than "put".

george.burgess.iv edited edge metadata.
george.burgess.iv marked an inline comment as done.

Thanks for the review!

I'll submit this with D14274. :)

george.burgess.iv abandoned this revision.Dec 19 2016, 5:18 PM

Committed in rL290149. Thanks again!