mirror of
https://github.com/Gericom/teak-llvm.git
synced 2025-06-24 22:08:57 -04:00

Clang generates copy and dispose helper functions for each block literal on the stack. Often these functions are equivalent for different blocks. This commit makes changes to merge equivalent copy and dispose helper functions and reduce code size. To enable merging equivalent copy/dispose functions, the captured object infomation is 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/42640608 Differential Revision: https://reviews.llvm.org/D50152 llvm-svn: 339438
34 lines
763 B
C++
34 lines
763 B
C++
// RUN: %clang_cc1 %s -fblocks -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
|
|
// rdar://8594790
|
|
|
|
extern "C" {
|
|
extern "C" void *_Block_copy(const void *aBlock);
|
|
extern "C" void _Block_release(const void *aBlock);
|
|
}
|
|
|
|
class A {
|
|
public:
|
|
int x;
|
|
A(const A &o);
|
|
A();
|
|
virtual ~A();
|
|
void hello() const;
|
|
};
|
|
|
|
int
|
|
main()
|
|
{
|
|
A a;
|
|
void (^c)(void) = ((__typeof(^{ a.hello(); }))_Block_copy((const void *)(^{ a.hello(); })));
|
|
c();
|
|
_Block_release((const void *)(c));
|
|
return 0;
|
|
}
|
|
|
|
// CHECK-LABEL: define linkonce_odr hidden void @__copy_helper_block_
|
|
// CHECK: call void @_ZN1AC1ERKS_
|
|
|
|
|
|
// CHECK-LABEL:define linkonce_odr hidden void @__destroy_helper_block_
|
|
// CHECK: call void @_ZN1AD1Ev
|