[ObjC][ARC] Check the basic block size before calling
authorAkira Hatanaka <ahatanaka@apple.com>
Tue, 23 Apr 2019 19:49:03 +0000 (19:49 +0000)
committerAkira Hatanaka <ahatanaka@apple.com>
Tue, 23 Apr 2019 19:49:03 +0000 (19:49 +0000)
commit5c3117b0a98dd11717eaffd7fb583985d39544b2
treed4e35303acc7f1f3221cdd77c6e1bbb89575ac44
parent2f51176223f19dde7fd90e97c203649aefb35310
[ObjC][ARC] Check the basic block size before calling
DominatorTree::dominate.

ARC contract pass has an optimization that replaces the uses of the
argument of an ObjC runtime function call with the call result.

For example:

; Before optimization
%1 = tail call i8* @foo1()
%2 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %1)
store i8* %1, i8** @g0, align 8

; After optimization
%1 = tail call i8* @foo1()
%2 = tail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %1)
store i8* %2, i8** @g0, align 8 // %1 is replaced with %2

Before replacing the argument use, DominatorTree::dominate is called to
determine whether the user instruction is dominated by the ObjC runtime
function call instruction. The call to DominatorTree::dominate can be
expensive if the two instructions belong to the same basic block and the
size of the basic block is large. This patch checks the basic block size
and just bails out if the size exceeds the limit set by command line
option "arc-contract-max-bb-size".

rdar://problem/49477063

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

llvm-svn: 359027
llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp
llvm/test/Transforms/ObjCARC/contract-max-bb-size.ll [new file with mode: 0644]