OSDN Git Service

Add CallSiteSplitting pass
authorJun Bum Lim <junbuml@codeaurora.org>
Fri, 3 Nov 2017 19:01:57 +0000 (19:01 +0000)
committerJun Bum Lim <junbuml@codeaurora.org>
Fri, 3 Nov 2017 19:01:57 +0000 (19:01 +0000)
commit1b91c5e8aad019b3b3649db6c496b74739b4e5d2
tree476503c20397bc4ea666c39ae9e4dd1c0dae9b22
parenta8631b87aef95da6cd44dd94508c4f37c26b4867
Add CallSiteSplitting pass

Summary:
This change add a pass which tries to split a call-site to pass
more constrained arguments if its argument is predicated in the control flow
so that we can expose better context to the later passes (e.g, inliner, jump
threading, or IPA-CP based function cloning, etc.).
As of now we support two cases :

1) If a call site is dominated by an OR condition and if any of its arguments
are predicated on this OR condition, try to split the condition with more
constrained arguments. For example, in the code below, we try to split the
call site since we can predicate the argument (ptr) based on the OR condition.

Split from :
      if (!ptr || c)
        callee(ptr);
to :
      if (!ptr)
        callee(null ptr)  // set the known constant value
      else if (c)
        callee(nonnull ptr)  // set non-null attribute in the argument

2) We can also split a call-site based on constant incoming values of a PHI
For example,
from :
      BB0:
       %c = icmp eq i32 %i1, %i2
       br i1 %c, label %BB2, label %BB1
      BB1:
       br label %BB2
      BB2:
       %p = phi i32 [ 0, %BB0 ], [ 1, %BB1 ]
       call void @bar(i32 %p)
to
      BB0:
       %c = icmp eq i32 %i1, %i2
       br i1 %c, label %BB2-split0, label %BB1
      BB1:
       br label %BB2-split1
      BB2-split0:
       call void @bar(i32 0)
       br label %BB2
      BB2-split1:
       call void @bar(i32 1)
       br label %BB2
      BB2:
       %p = phi i32 [ 0, %BB2-split0 ], [ 1, %BB2-split1 ]

Reviewers: davidxl, huntergr, chandlerc, mcrosier, eraman, davide

Reviewed By: davidxl

Subscribers: sdesmalen, ashutosh.nema, fhahn, mssimpso, aemerson, mgorny, mehdi_amini, kristof.beyls, llvm-commits

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@317351 91177308-0d34-0410-b5e6-96231b3b80d8
14 files changed:
include/llvm/InitializePasses.h
include/llvm/Transforms/Scalar.h
include/llvm/Transforms/Scalar/CallSiteSplitting.h [new file with mode: 0644]
lib/Passes/PassBuilder.cpp
lib/Passes/PassRegistry.def
lib/Transforms/IPO/PassManagerBuilder.cpp
lib/Transforms/Scalar/CMakeLists.txt
lib/Transforms/Scalar/CallSiteSplitting.cpp [new file with mode: 0644]
lib/Transforms/Scalar/Scalar.cpp
test/Other/new-pm-defaults.ll
test/Other/new-pm-lto-defaults.ll
test/Other/new-pm-thinlto-defaults.ll
test/Transforms/CallSiteSplitting/callsite-split-or-phi.ll [new file with mode: 0644]
test/Transforms/CallSiteSplitting/callsite-split.ll [new file with mode: 0644]