[CodeGen][ObjC] Make copying and disposing of a non-escaping block
authorAkira Hatanaka <ahatanaka@apple.com>
Fri, 20 Jul 2018 17:10:32 +0000 (17:10 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Fri, 20 Jul 2018 17:10:32 +0000 (17:10 +0000)
commitdbfa453e4138bb977644929c69d1c71e5e8b4bee
treefd0755e09eefe0ed813945492b2886441d6e8334
parentc358e51e9b9d42be542ae577d10b851e9358cd39
[CodeGen][ObjC] Make copying and disposing of a non-escaping block
no-ops.

A non-escaping block on the stack will never be called after its
lifetime ends, so it doesn't have to be copied to the heap. To prevent
a non-escaping block from being copied to the heap, this patch sets
field 'isa' of the block object to NSConcreteGlobalBlock and sets the
BLOCK_IS_GLOBAL bit of field 'flags', which causes the runtime to treat
the block as if it were a global block (calling _Block_copy on the block
just returns the original block and calling _Block_release is a no-op).

Also, a new flag bit 'BLOCK_IS_NOESCAPE' is added, which allows the
runtime or tools to distinguish between true global blocks and
non-escaping blocks.

rdar://problem/39352313

Differential Revision: https://reviews.llvm.org/D49303

llvm-svn: 337580
clang/docs/Block-ABI-Apple.rst
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGBlocks.h
clang/test/CodeGenObjC/noescape.m