[PATCH] D50152: [CodeGen] Merge equivalent block copy/helper functions

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 1 12:10:40 PDT 2018


ahatanak created this revision.
ahatanak added reviewers: rjmccall, arphaman.
Herald added subscribers: dexonsmith, mgrang.

Currently, clang generates different copy or dispose helper functions for each block literal on the stack if the block has the possibility of being copied to the heap. This patch makes changes to merge equivalent copy and dispose helper functions and reduce code size.

To enable merging equivalent copy/dispose functions, the types and offsets of the captured objects are encoded into the helper function name. This allows IRGen to check whether an equivalent helper function has already been emitted and reuse the function instead of generating a new helper function whenever a block is defined. In addition, the helper functions are marked as `linkonce_odr` to enable merging helper functions that have the same name across translation units and marked as `unnamed_addr` to enable the linker's deduplication pass to merge functions that have different names but the same content.

rdar://problem/22950898


Repository:
  rC Clang

https://reviews.llvm.org/D50152

Files:
  lib/CodeGen/CGBlocks.cpp
  lib/CodeGen/CGNonTrivialStruct.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGen/blocks-1.c
  test/CodeGen/blocks.c
  test/CodeGen/sanitize-thread-no-checking-at-run-time.m
  test/CodeGenCXX/block-byref-cxx-objc.cpp
  test/CodeGenCXX/blocks.cpp
  test/CodeGenCXX/cxx-block-objects.cpp
  test/CodeGenObjC/arc-blocks.m
  test/CodeGenObjC/debug-info-block-helper.m
  test/CodeGenObjC/debug-info-blocks.m
  test/CodeGenObjC/mrc-weak.m
  test/CodeGenObjC/strong-in-c-struct.m
  test/CodeGenObjCXX/arc-blocks.mm
  test/CodeGenObjCXX/lambda-to-block.mm
  test/CodeGenObjCXX/mrc-weak.mm

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50152.158588.patch
Type: text/x-patch
Size: 52511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180801/0ef3c6e3/attachment-0001.bin>


More information about the cfe-commits mailing list