Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
//===- CallSiteSplitting.cpp ----------------------------------------------===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements a transformation that 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 :
|
|
|
|
//
|
2017-12-24 04:02:26 +08:00
|
|
|
// 1) Try to a split call-site with constrained arguments, if any constraints
|
|
|
|
// on any argument can be found by following the single predecessors of the
|
|
|
|
// all site's predecessors. Currently this pass only handles call-sites with 2
|
|
|
|
// predecessors. 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.
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
//
|
|
|
|
// Split from :
|
|
|
|
// if (!ptr || c)
|
|
|
|
// callee(ptr);
|
|
|
|
// to :
|
|
|
|
// if (!ptr)
|
|
|
|
// callee(null) // 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 :
|
|
|
|
// Header:
|
|
|
|
// %c = icmp eq i32 %i1, %i2
|
|
|
|
// br i1 %c, label %Tail, label %TBB
|
|
|
|
// TBB:
|
|
|
|
// br label Tail%
|
|
|
|
// Tail:
|
|
|
|
// %p = phi i32 [ 0, %Header], [ 1, %TBB]
|
|
|
|
// call void @bar(i32 %p)
|
|
|
|
// to
|
|
|
|
// Header:
|
|
|
|
// %c = icmp eq i32 %i1, %i2
|
|
|
|
// br i1 %c, label %Tail-split0, label %TBB
|
|
|
|
// TBB:
|
|
|
|
// br label %Tail-split1
|
|
|
|
// Tail-split0:
|
|
|
|
// call void @bar(i32 0)
|
|
|
|
// br label %Tail
|
|
|
|
// Tail-split1:
|
|
|
|
// call void @bar(i32 1)
|
|
|
|
// br label %Tail
|
|
|
|
// Tail:
|
|
|
|
// %p = phi i32 [ 0, %Tail-split0 ], [ 1, %Tail-split1 ]
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/Transforms/Scalar/CallSiteSplitting.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/Analysis/TargetLibraryInfo.h"
|
2018-02-14 21:59:12 +08:00
|
|
|
#include "llvm/Analysis/TargetTransformInfo.h"
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
|
|
|
#include "llvm/IR/PatternMatch.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-14 05:15:01 +08:00
|
|
|
#include "llvm/InitializePasses.h"
|
2019-11-15 07:15:48 +08:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
|
|
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
2018-02-14 21:59:12 +08:00
|
|
|
#include "llvm/Transforms/Utils/Cloning.h"
|
Sink all InitializePasses.h includes
This file lists every pass in LLVM, and is included by Pass.h, which is
very popular. Every time we add, remove, or rename a pass in LLVM, it
caused lots of recompilation.
I found this fact by looking at this table, which is sorted by the
number of times a file was changed over the last 100,000 git commits
multiplied by the number of object files that depend on it in the
current checkout:
recompiles touches affected_files header
342380 95 3604 llvm/include/llvm/ADT/STLExtras.h
314730 234 1345 llvm/include/llvm/InitializePasses.h
307036 118 2602 llvm/include/llvm/ADT/APInt.h
213049 59 3611 llvm/include/llvm/Support/MathExtras.h
170422 47 3626 llvm/include/llvm/Support/Compiler.h
162225 45 3605 llvm/include/llvm/ADT/Optional.h
158319 63 2513 llvm/include/llvm/ADT/Triple.h
140322 39 3598 llvm/include/llvm/ADT/StringRef.h
137647 59 2333 llvm/include/llvm/Support/Error.h
131619 73 1803 llvm/include/llvm/Support/FileSystem.h
Before this change, touching InitializePasses.h would cause 1345 files
to recompile. After this change, touching it only causes 550 compiles in
an incremental rebuild.
Reviewers: bkramer, asbirlea, bollu, jdoerfert
Differential Revision: https://reviews.llvm.org/D70211
2019-11-14 05:15:01 +08:00
|
|
|
#include "llvm/Transforms/Utils/Local.h"
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace PatternMatch;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "callsite-splitting"
|
|
|
|
|
|
|
|
STATISTIC(NumCallSiteSplit, "Number of call-site split");
|
|
|
|
|
2018-02-14 21:59:12 +08:00
|
|
|
/// Only allow instructions before a call, if their CodeSize cost is below
|
|
|
|
/// DuplicationThreshold. Those instructions need to be duplicated in all
|
|
|
|
/// split blocks.
|
|
|
|
static cl::opt<unsigned>
|
|
|
|
DuplicationThreshold("callsite-splitting-duplication-threshold", cl::Hidden,
|
|
|
|
cl::desc("Only allow instructions before a call, if "
|
|
|
|
"their cost is below DuplicationThreshold"),
|
|
|
|
cl::init(5));
|
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
static void addNonNullAttribute(CallBase &CB, Value *Op) {
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
unsigned ArgNo = 0;
|
2020-04-16 06:11:44 +08:00
|
|
|
for (auto &I : CB.args()) {
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
if (&*I == Op)
|
2020-04-16 06:11:44 +08:00
|
|
|
CB.addParamAttr(ArgNo, Attribute::NonNull);
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
++ArgNo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
static void setConstantInArgument(CallBase &CB, Value *Op,
|
2018-01-17 06:13:15 +08:00
|
|
|
Constant *ConstValue) {
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
unsigned ArgNo = 0;
|
2020-04-16 06:11:44 +08:00
|
|
|
for (auto &I : CB.args()) {
|
2018-04-24 04:09:08 +08:00
|
|
|
if (&*I == Op) {
|
|
|
|
// It is possible we have already added the non-null attribute to the
|
|
|
|
// parameter by using an earlier constraining condition.
|
2020-04-16 06:11:44 +08:00
|
|
|
CB.removeParamAttr(ArgNo, Attribute::NonNull);
|
|
|
|
CB.setArgOperand(ArgNo, ConstValue);
|
2018-04-24 04:09:08 +08:00
|
|
|
}
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
++ArgNo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
static bool isCondRelevantToAnyCallArgument(ICmpInst *Cmp, CallBase &CB) {
|
2017-11-19 02:14:13 +08:00
|
|
|
assert(isa<Constant>(Cmp->getOperand(1)) && "Expected a constant operand.");
|
|
|
|
Value *Op0 = Cmp->getOperand(0);
|
|
|
|
unsigned ArgNo = 0;
|
2020-04-16 06:11:44 +08:00
|
|
|
for (auto I = CB.arg_begin(), E = CB.arg_end(); I != E; ++I, ++ArgNo) {
|
2017-11-19 02:14:13 +08:00
|
|
|
// Don't consider constant or arguments that are already known non-null.
|
2020-04-16 06:11:44 +08:00
|
|
|
if (isa<Constant>(*I) || CB.paramHasAttr(ArgNo, Attribute::NonNull))
|
2017-11-19 02:14:13 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (*I == Op0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-17 06:13:15 +08:00
|
|
|
typedef std::pair<ICmpInst *, unsigned> ConditionTy;
|
|
|
|
typedef SmallVector<ConditionTy, 2> ConditionsTy;
|
|
|
|
|
2017-12-13 11:05:20 +08:00
|
|
|
/// If From has a conditional jump to To, add the condition to Conditions,
|
2020-04-16 06:11:44 +08:00
|
|
|
/// if it is relevant to any argument at CB.
|
|
|
|
static void recordCondition(CallBase &CB, BasicBlock *From, BasicBlock *To,
|
2018-01-17 06:13:15 +08:00
|
|
|
ConditionsTy &Conditions) {
|
2017-12-13 11:05:20 +08:00
|
|
|
auto *BI = dyn_cast<BranchInst>(From->getTerminator());
|
|
|
|
if (!BI || !BI->isConditional())
|
|
|
|
return;
|
|
|
|
|
|
|
|
CmpInst::Predicate Pred;
|
|
|
|
Value *Cond = BI->getCondition();
|
|
|
|
if (!match(Cond, m_ICmp(Pred, m_Value(), m_Constant())))
|
|
|
|
return;
|
|
|
|
|
|
|
|
ICmpInst *Cmp = cast<ICmpInst>(Cond);
|
|
|
|
if (Pred == ICmpInst::ICMP_EQ || Pred == ICmpInst::ICMP_NE)
|
2020-04-16 06:11:44 +08:00
|
|
|
if (isCondRelevantToAnyCallArgument(Cmp, CB))
|
2017-12-13 11:05:20 +08:00
|
|
|
Conditions.push_back({Cmp, From->getTerminator()->getSuccessor(0) == To
|
|
|
|
? Pred
|
|
|
|
: Cmp->getInversePredicate()});
|
|
|
|
}
|
2017-11-19 02:14:13 +08:00
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
/// Record ICmp conditions relevant to any argument in CB following Pred's
|
2018-04-13 12:35:38 +08:00
|
|
|
/// single predecessors. If there are conflicting conditions along a path, like
|
2018-11-14 18:04:30 +08:00
|
|
|
/// x == 1 and x == 0, the first condition will be used. We stop once we reach
|
|
|
|
/// an edge to StopAt.
|
2020-04-16 06:11:44 +08:00
|
|
|
static void recordConditions(CallBase &CB, BasicBlock *Pred,
|
2018-11-14 18:04:30 +08:00
|
|
|
ConditionsTy &Conditions, BasicBlock *StopAt) {
|
2017-12-13 11:05:20 +08:00
|
|
|
BasicBlock *From = Pred;
|
|
|
|
BasicBlock *To = Pred;
|
2018-01-26 18:36:50 +08:00
|
|
|
SmallPtrSet<BasicBlock *, 4> Visited;
|
2018-11-14 18:04:30 +08:00
|
|
|
while (To != StopAt && !Visited.count(From->getSinglePredecessor()) &&
|
2017-12-13 11:05:20 +08:00
|
|
|
(From = From->getSinglePredecessor())) {
|
2020-04-16 06:11:44 +08:00
|
|
|
recordCondition(CB, From, To, Conditions);
|
2018-01-26 18:36:50 +08:00
|
|
|
Visited.insert(From);
|
2017-12-13 11:05:20 +08:00
|
|
|
To = From;
|
2017-11-19 02:14:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
static void addConditions(CallBase &CB, const ConditionsTy &Conditions) {
|
2017-12-13 11:05:20 +08:00
|
|
|
for (auto &Cond : Conditions) {
|
|
|
|
Value *Arg = Cond.first->getOperand(0);
|
|
|
|
Constant *ConstVal = cast<Constant>(Cond.first->getOperand(1));
|
|
|
|
if (Cond.second == ICmpInst::ICMP_EQ)
|
2020-04-16 06:11:44 +08:00
|
|
|
setConstantInArgument(CB, Arg, ConstVal);
|
2017-12-13 11:05:20 +08:00
|
|
|
else if (ConstVal->getType()->isPointerTy() && ConstVal->isNullValue()) {
|
|
|
|
assert(Cond.second == ICmpInst::ICMP_NE);
|
2020-04-16 06:11:44 +08:00
|
|
|
addNonNullAttribute(CB, Arg);
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-13 11:05:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static SmallVector<BasicBlock *, 2> getTwoPredecessors(BasicBlock *BB) {
|
|
|
|
SmallVector<BasicBlock *, 2> Preds(predecessors((BB)));
|
|
|
|
assert(Preds.size() == 2 && "Expected exactly 2 predecessors!");
|
|
|
|
return Preds;
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
static bool canSplitCallSite(CallBase &CB, TargetTransformInfo &TTI) {
|
|
|
|
if (CB.isConvergent() || CB.cannotDuplicate())
|
2019-05-30 00:59:48 +08:00
|
|
|
return false;
|
|
|
|
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
// FIXME: As of now we handle only CallInst. InvokeInst could be handled
|
|
|
|
// without too much effort.
|
2020-04-16 06:11:44 +08:00
|
|
|
if (!isa<CallInst>(CB))
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
return false;
|
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
BasicBlock *CallSiteBB = CB.getParent();
|
2018-07-21 22:13:44 +08:00
|
|
|
// Need 2 predecessors and cannot split an edge from an IndirectBrInst.
|
|
|
|
SmallVector<BasicBlock *, 2> Preds(predecessors(CallSiteBB));
|
|
|
|
if (Preds.size() != 2 || isa<IndirectBrInst>(Preds[0]->getTerminator()) ||
|
|
|
|
isa<IndirectBrInst>(Preds[1]->getTerminator()))
|
|
|
|
return false;
|
|
|
|
|
2018-11-07 22:35:36 +08:00
|
|
|
// BasicBlock::canSplitPredecessors is more aggressive, so checking for
|
2018-07-21 22:13:44 +08:00
|
|
|
// BasicBlock::isEHPad as well.
|
|
|
|
if (!CallSiteBB->canSplitPredecessors() || CallSiteBB->isEHPad())
|
|
|
|
return false;
|
|
|
|
|
2018-02-14 21:59:12 +08:00
|
|
|
// Allow splitting a call-site only when the CodeSize cost of the
|
|
|
|
// instructions before the call is less then DuplicationThreshold. The
|
|
|
|
// instructions before the call will be duplicated in the split blocks and
|
|
|
|
// corresponding uses will be updated.
|
2020-11-10 19:09:20 +08:00
|
|
|
InstructionCost Cost = 0;
|
2018-02-14 21:59:12 +08:00
|
|
|
for (auto &InstBeforeCall :
|
2020-04-16 06:11:44 +08:00
|
|
|
llvm::make_range(CallSiteBB->begin(), CB.getIterator())) {
|
2018-02-14 21:59:12 +08:00
|
|
|
Cost += TTI.getInstructionCost(&InstBeforeCall,
|
|
|
|
TargetTransformInfo::TCK_CodeSize);
|
|
|
|
if (Cost >= DuplicationThreshold)
|
|
|
|
return false;
|
|
|
|
}
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
|
2018-07-21 22:13:44 +08:00
|
|
|
return true;
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
}
|
|
|
|
|
2018-03-04 05:40:14 +08:00
|
|
|
static Instruction *cloneInstForMustTail(Instruction *I, Instruction *Before,
|
|
|
|
Value *V) {
|
|
|
|
Instruction *Copy = I->clone();
|
|
|
|
Copy->setName(I->getName());
|
|
|
|
Copy->insertBefore(Before);
|
|
|
|
if (V)
|
|
|
|
Copy->setOperand(0, V);
|
|
|
|
return Copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Copy mandatory `musttail` return sequence that follows original `CI`, and
|
|
|
|
/// link it up to `NewCI` value instead:
|
|
|
|
///
|
|
|
|
/// * (optional) `bitcast NewCI to ...`
|
|
|
|
/// * `ret bitcast or NewCI`
|
2018-01-17 06:13:15 +08:00
|
|
|
///
|
2018-03-04 05:40:14 +08:00
|
|
|
/// Insert this sequence right before `SplitBB`'s terminator, which will be
|
|
|
|
/// cleaned up later in `splitCallSite` below.
|
|
|
|
static void copyMustTailReturn(BasicBlock *SplitBB, Instruction *CI,
|
|
|
|
Instruction *NewCI) {
|
|
|
|
bool IsVoid = SplitBB->getParent()->getReturnType()->isVoidTy();
|
|
|
|
auto II = std::next(CI->getIterator());
|
|
|
|
|
|
|
|
BitCastInst* BCI = dyn_cast<BitCastInst>(&*II);
|
|
|
|
if (BCI)
|
|
|
|
++II;
|
|
|
|
|
|
|
|
ReturnInst* RI = dyn_cast<ReturnInst>(&*II);
|
|
|
|
assert(RI && "`musttail` call must be followed by `ret` instruction");
|
|
|
|
|
2018-10-15 18:04:59 +08:00
|
|
|
Instruction *TI = SplitBB->getTerminator();
|
2018-03-04 05:40:14 +08:00
|
|
|
Value *V = NewCI;
|
|
|
|
if (BCI)
|
|
|
|
V = cloneInstForMustTail(BCI, TI, V);
|
|
|
|
cloneInstForMustTail(RI, TI, IsVoid ? nullptr : V);
|
|
|
|
|
|
|
|
// FIXME: remove TI here, `DuplicateInstructionsInSplitBetween` has a bug
|
|
|
|
// that prevents doing this now.
|
|
|
|
}
|
|
|
|
|
2018-01-17 06:13:15 +08:00
|
|
|
/// For each (predecessor, conditions from predecessors) pair, it will split the
|
|
|
|
/// basic block containing the call site, hook it up to the predecessor and
|
|
|
|
/// replace the call instruction with new call instructions, which contain
|
|
|
|
/// constraints based on the conditions from their predecessors.
|
2017-12-24 04:02:26 +08:00
|
|
|
/// For example, in the IR below with an OR condition, the call-site can
|
2018-01-17 06:13:15 +08:00
|
|
|
/// be split. In this case, Preds for Tail is [(Header, a == null),
|
|
|
|
/// (TBB, a != null, b == null)]. Tail is replaced by 2 split blocks, containing
|
|
|
|
/// CallInst1, which has constraints based on the conditions from Head and
|
|
|
|
/// CallInst2, which has constraints based on the conditions coming from TBB.
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
///
|
2017-12-24 04:02:26 +08:00
|
|
|
/// From :
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
///
|
|
|
|
/// Header:
|
|
|
|
/// %c = icmp eq i32* %a, null
|
|
|
|
/// br i1 %c %Tail, %TBB
|
|
|
|
/// TBB:
|
|
|
|
/// %c2 = icmp eq i32* %b, null
|
|
|
|
/// br i1 %c %Tail, %End
|
|
|
|
/// Tail:
|
|
|
|
/// %ca = call i1 @callee (i32* %a, i32* %b)
|
|
|
|
///
|
|
|
|
/// to :
|
|
|
|
///
|
|
|
|
/// Header: // PredBB1 is Header
|
|
|
|
/// %c = icmp eq i32* %a, null
|
|
|
|
/// br i1 %c %Tail-split1, %TBB
|
|
|
|
/// TBB: // PredBB2 is TBB
|
|
|
|
/// %c2 = icmp eq i32* %b, null
|
|
|
|
/// br i1 %c %Tail-split2, %End
|
|
|
|
/// Tail-split1:
|
|
|
|
/// %ca1 = call @callee (i32* null, i32* %b) // CallInst1
|
|
|
|
/// br %Tail
|
|
|
|
/// Tail-split2:
|
|
|
|
/// %ca2 = call @callee (i32* nonnull %a, i32* null) // CallInst2
|
|
|
|
/// br %Tail
|
|
|
|
/// Tail:
|
|
|
|
/// %p = phi i1 [%ca1, %Tail-split1],[%ca2, %Tail-split2]
|
|
|
|
///
|
2017-12-24 04:02:26 +08:00
|
|
|
/// Note that in case any arguments at the call-site are constrained by its
|
|
|
|
/// predecessors, new call-sites with more constrained arguments will be
|
|
|
|
/// created in createCallSitesOnPredicatedArgument().
|
2018-01-17 06:13:15 +08:00
|
|
|
static void splitCallSite(
|
2020-04-16 06:11:44 +08:00
|
|
|
CallBase &CB,
|
2018-03-22 23:23:33 +08:00
|
|
|
const SmallVectorImpl<std::pair<BasicBlock *, ConditionsTy>> &Preds,
|
2018-11-14 01:54:43 +08:00
|
|
|
DomTreeUpdater &DTU) {
|
2020-04-16 06:11:44 +08:00
|
|
|
BasicBlock *TailBB = CB.getParent();
|
|
|
|
bool IsMustTailCall = CB.isMustTailCall();
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
|
2018-01-17 06:13:15 +08:00
|
|
|
PHINode *CallPN = nullptr;
|
2018-03-04 05:40:14 +08:00
|
|
|
|
|
|
|
// `musttail` calls must be followed by optional `bitcast`, and `ret`. The
|
|
|
|
// split blocks will be terminated right after that so there're no users for
|
|
|
|
// this phi in a `TailBB`.
|
2020-04-16 06:11:44 +08:00
|
|
|
if (!IsMustTailCall && !CB.use_empty()) {
|
|
|
|
CallPN = PHINode::Create(CB.getType(), Preds.size(), "phi.call");
|
|
|
|
CallPN->setDebugLoc(CB.getDebugLoc());
|
2018-09-12 01:55:58 +08:00
|
|
|
}
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "split call-site : " << CB << " into \n");
|
2018-02-14 21:59:12 +08:00
|
|
|
|
|
|
|
assert(Preds.size() == 2 && "The ValueToValueMaps array has size 2.");
|
|
|
|
// ValueToValueMapTy is neither copy nor moveable, so we use a simple array
|
|
|
|
// here.
|
|
|
|
ValueToValueMapTy ValueToValueMaps[2];
|
|
|
|
for (unsigned i = 0; i < Preds.size(); i++) {
|
|
|
|
BasicBlock *PredBB = Preds[i].first;
|
|
|
|
BasicBlock *SplitBlock = DuplicateInstructionsInSplitBetween(
|
2020-04-16 06:11:44 +08:00
|
|
|
TailBB, PredBB, &*std::next(CB.getIterator()), ValueToValueMaps[i],
|
2018-11-14 01:54:43 +08:00
|
|
|
DTU);
|
2018-01-17 06:13:15 +08:00
|
|
|
assert(SplitBlock && "Unexpected new basic block split.");
|
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
auto *NewCI =
|
|
|
|
cast<CallBase>(&*std::prev(SplitBlock->getTerminator()->getIterator()));
|
|
|
|
addConditions(*NewCI, Preds[i].second);
|
2018-01-17 06:13:15 +08:00
|
|
|
|
|
|
|
// Handle PHIs used as arguments in the call-site.
|
|
|
|
for (PHINode &PN : TailBB->phis()) {
|
|
|
|
unsigned ArgNo = 0;
|
2020-04-16 06:11:44 +08:00
|
|
|
for (auto &CI : CB.args()) {
|
2018-01-17 06:13:15 +08:00
|
|
|
if (&*CI == &PN) {
|
2020-04-16 06:11:44 +08:00
|
|
|
NewCI->setArgOperand(ArgNo, PN.getIncomingValueForBlock(SplitBlock));
|
2018-01-17 06:13:15 +08:00
|
|
|
}
|
|
|
|
++ArgNo;
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
}
|
|
|
|
}
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << " " << *NewCI << " in " << SplitBlock->getName()
|
|
|
|
<< "\n");
|
2018-01-17 06:13:15 +08:00
|
|
|
if (CallPN)
|
|
|
|
CallPN->addIncoming(NewCI, SplitBlock);
|
2018-03-04 05:40:14 +08:00
|
|
|
|
|
|
|
// Clone and place bitcast and return instructions before `TI`
|
|
|
|
if (IsMustTailCall)
|
2020-04-16 06:11:44 +08:00
|
|
|
copyMustTailReturn(SplitBlock, &CB, NewCI);
|
2018-03-04 05:40:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NumCallSiteSplit++;
|
|
|
|
|
|
|
|
// FIXME: remove TI in `copyMustTailReturn`
|
|
|
|
if (IsMustTailCall) {
|
|
|
|
// Remove superfluous `br` terminators from the end of the Split blocks
|
2018-03-04 06:34:38 +08:00
|
|
|
// NOTE: Removing terminator removes the SplitBlock from the TailBB's
|
|
|
|
// predecessors. Therefore we must get complete list of Splits before
|
|
|
|
// attempting removal.
|
|
|
|
SmallVector<BasicBlock *, 2> Splits(predecessors((TailBB)));
|
|
|
|
assert(Splits.size() == 2 && "Expected exactly 2 splits!");
|
2018-11-29 23:27:04 +08:00
|
|
|
for (unsigned i = 0; i < Splits.size(); i++) {
|
2018-03-04 06:34:38 +08:00
|
|
|
Splits[i]->getTerminator()->eraseFromParent();
|
[DTU] Refine the interface and logic of applyUpdates
Summary:
This patch separates two semantics of `applyUpdates`:
1. User provides an accurate CFG diff and the dominator tree is updated according to the difference of `the number of edge insertions` and `the number of edge deletions` to infer the status of an edge before and after the update.
2. User provides a sequence of hints. Updates mentioned in this sequence might never happened and even duplicated.
Logic changes:
Previously, removing invalid updates is considered a side-effect of deduplication and is not guaranteed to be reliable. To handle the second semantic, `applyUpdates` does validity checking before deduplication, which can cause updates that have already been applied to be submitted again. Then, different calls to `applyUpdates` might cause unintended consequences, for example,
```
DTU(Lazy) and Edge A->B exists.
1. DTU.applyUpdates({{Delete, A, B}, {Insert, A, B}}) // User expects these 2 updates result in a no-op, but {Insert, A, B} is queued
2. Remove A->B
3. DTU.applyUpdates({{Delete, A, B}}) // DTU cancels this update with {Insert, A, B} mentioned above together (Unintended)
```
But by restricting the precondition that updates of an edge need to be strictly ordered as how CFG changes were made, we can infer the initial status of this edge to resolve this issue.
Interface changes:
The second semantic of `applyUpdates` is separated to `applyUpdatesPermissive`.
These changes enable DTU(Lazy) to use the first semantic if needed, which is quite useful in `transforms/utils`.
Reviewers: kuhar, brzycki, dmgreen, grosser
Reviewed By: brzycki
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D58170
llvm-svn: 354669
2019-02-22 21:48:38 +08:00
|
|
|
DTU.applyUpdatesPermissive({{DominatorTree::Delete, Splits[i], TailBB}});
|
2018-11-29 23:27:04 +08:00
|
|
|
}
|
2018-03-04 05:40:14 +08:00
|
|
|
|
|
|
|
// Erase the tail block once done with musttail patching
|
2018-11-14 01:54:43 +08:00
|
|
|
DTU.deleteBB(TailBB);
|
2018-03-04 05:40:14 +08:00
|
|
|
return;
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
}
|
|
|
|
|
2018-02-14 21:59:12 +08:00
|
|
|
auto *OriginalBegin = &*TailBB->begin();
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
// Replace users of the original call with a PHI mering call-sites split.
|
2018-01-17 06:13:15 +08:00
|
|
|
if (CallPN) {
|
2018-02-14 21:59:12 +08:00
|
|
|
CallPN->insertBefore(OriginalBegin);
|
2020-04-16 06:11:44 +08:00
|
|
|
CB.replaceAllUsesWith(CallPN);
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
}
|
2018-01-17 06:13:15 +08:00
|
|
|
|
2018-02-14 21:59:12 +08:00
|
|
|
// Remove instructions moved to split blocks from TailBB, from the duplicated
|
|
|
|
// call instruction to the beginning of the basic block. If an instruction
|
|
|
|
// has any uses, add a new PHI node to combine the values coming from the
|
|
|
|
// split blocks. The new PHI nodes are placed before the first original
|
|
|
|
// instruction, so we do not end up deleting them. By using reverse-order, we
|
|
|
|
// do not introduce unnecessary PHI nodes for def-use chains from the call
|
|
|
|
// instruction to the beginning of the block.
|
2020-04-16 06:11:44 +08:00
|
|
|
auto I = CB.getReverseIterator();
|
2018-02-14 21:59:12 +08:00
|
|
|
while (I != TailBB->rend()) {
|
|
|
|
Instruction *CurrentI = &*I++;
|
|
|
|
if (!CurrentI->use_empty()) {
|
|
|
|
// If an existing PHI has users after the call, there is no need to create
|
|
|
|
// a new one.
|
|
|
|
if (isa<PHINode>(CurrentI))
|
|
|
|
continue;
|
|
|
|
PHINode *NewPN = PHINode::Create(CurrentI->getType(), Preds.size());
|
2018-09-12 01:55:58 +08:00
|
|
|
NewPN->setDebugLoc(CurrentI->getDebugLoc());
|
2018-02-14 21:59:12 +08:00
|
|
|
for (auto &Mapping : ValueToValueMaps)
|
|
|
|
NewPN->addIncoming(Mapping[CurrentI],
|
|
|
|
cast<Instruction>(Mapping[CurrentI])->getParent());
|
|
|
|
NewPN->insertBefore(&*TailBB->begin());
|
|
|
|
CurrentI->replaceAllUsesWith(NewPN);
|
|
|
|
}
|
|
|
|
CurrentI->eraseFromParent();
|
|
|
|
// We are done once we handled the first original instruction in TailBB.
|
|
|
|
if (CurrentI == OriginalBegin)
|
|
|
|
break;
|
|
|
|
}
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if the call-site has an argument which is a PHI with only
|
|
|
|
// constant incoming values.
|
2020-04-16 06:11:44 +08:00
|
|
|
static bool isPredicatedOnPHI(CallBase &CB) {
|
|
|
|
BasicBlock *Parent = CB.getParent();
|
|
|
|
if (&CB != Parent->getFirstNonPHIOrDbg())
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
return false;
|
|
|
|
|
2020-04-02 17:06:44 +08:00
|
|
|
for (auto &PN : Parent->phis()) {
|
2020-04-16 06:11:44 +08:00
|
|
|
for (auto &Arg : CB.args()) {
|
2020-04-02 17:06:44 +08:00
|
|
|
if (&*Arg != &PN)
|
|
|
|
continue;
|
|
|
|
assert(PN.getNumIncomingValues() == 2 &&
|
|
|
|
"Unexpected number of incoming values");
|
|
|
|
if (PN.getIncomingBlock(0) == PN.getIncomingBlock(1))
|
|
|
|
return false;
|
|
|
|
if (PN.getIncomingValue(0) == PN.getIncomingValue(1))
|
|
|
|
continue;
|
|
|
|
if (isa<Constant>(PN.getIncomingValue(0)) &&
|
|
|
|
isa<Constant>(PN.getIncomingValue(1)))
|
|
|
|
return true;
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-14 01:54:43 +08:00
|
|
|
using PredsWithCondsTy = SmallVector<std::pair<BasicBlock *, ConditionsTy>, 2>;
|
|
|
|
|
|
|
|
// Check if any of the arguments in CS are predicated on a PHI node and return
|
|
|
|
// the set of predecessors we should use for splitting.
|
2020-04-16 06:11:44 +08:00
|
|
|
static PredsWithCondsTy shouldSplitOnPHIPredicatedArgument(CallBase &CB) {
|
|
|
|
if (!isPredicatedOnPHI(CB))
|
2018-11-14 01:54:43 +08:00
|
|
|
return {};
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
auto Preds = getTwoPredecessors(CB.getParent());
|
2018-11-14 01:54:43 +08:00
|
|
|
return {{Preds[0], {}}, {Preds[1], {}}};
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
}
|
|
|
|
|
2018-11-14 01:54:43 +08:00
|
|
|
// Checks if any of the arguments in CS are predicated in a predecessor and
|
|
|
|
// returns a list of predecessors with the conditions that hold on their edges
|
|
|
|
// to CS.
|
2020-04-16 06:11:44 +08:00
|
|
|
static PredsWithCondsTy shouldSplitOnPredicatedArgument(CallBase &CB,
|
2018-11-14 18:04:30 +08:00
|
|
|
DomTreeUpdater &DTU) {
|
2020-04-16 06:11:44 +08:00
|
|
|
auto Preds = getTwoPredecessors(CB.getParent());
|
2017-12-24 04:02:26 +08:00
|
|
|
if (Preds[0] == Preds[1])
|
2018-11-14 01:54:43 +08:00
|
|
|
return {};
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
|
2018-11-14 18:04:30 +08:00
|
|
|
// We can stop recording conditions once we reached the immediate dominator
|
|
|
|
// for the block containing the call site. Conditions in predecessors of the
|
|
|
|
// that node will be the same for all paths to the call site and splitting
|
|
|
|
// is not beneficial.
|
|
|
|
assert(DTU.hasDomTree() && "We need a DTU with a valid DT!");
|
2020-04-16 06:11:44 +08:00
|
|
|
auto *CSDTNode = DTU.getDomTree().getNode(CB.getParent());
|
2018-11-14 18:04:30 +08:00
|
|
|
BasicBlock *StopAt = CSDTNode ? CSDTNode->getIDom()->getBlock() : nullptr;
|
|
|
|
|
2018-01-17 06:13:15 +08:00
|
|
|
SmallVector<std::pair<BasicBlock *, ConditionsTy>, 2> PredsCS;
|
|
|
|
for (auto *Pred : make_range(Preds.rbegin(), Preds.rend())) {
|
|
|
|
ConditionsTy Conditions;
|
2018-11-14 18:04:30 +08:00
|
|
|
// Record condition on edge BB(CS) <- Pred
|
2020-04-16 06:11:44 +08:00
|
|
|
recordCondition(CB, Pred, CB.getParent(), Conditions);
|
2018-11-14 18:04:30 +08:00
|
|
|
// Record conditions following Pred's single predecessors.
|
2020-04-16 06:11:44 +08:00
|
|
|
recordConditions(CB, Pred, Conditions, StopAt);
|
2018-01-17 06:13:15 +08:00
|
|
|
PredsCS.push_back({Pred, Conditions});
|
|
|
|
}
|
2017-12-13 11:05:20 +08:00
|
|
|
|
2018-10-19 14:12:02 +08:00
|
|
|
if (all_of(PredsCS, [](const std::pair<BasicBlock *, ConditionsTy> &P) {
|
|
|
|
return P.second.empty();
|
|
|
|
}))
|
2018-11-14 01:54:43 +08:00
|
|
|
return {};
|
2017-11-19 02:14:13 +08:00
|
|
|
|
2018-11-14 01:54:43 +08:00
|
|
|
return PredsCS;
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
}
|
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
static bool tryToSplitCallSite(CallBase &CB, TargetTransformInfo &TTI,
|
2018-11-14 01:54:43 +08:00
|
|
|
DomTreeUpdater &DTU) {
|
|
|
|
// Check if we can split the call site.
|
2020-04-16 06:11:44 +08:00
|
|
|
if (!CB.arg_size() || !canSplitCallSite(CB, TTI))
|
2017-11-19 02:14:13 +08:00
|
|
|
return false;
|
2018-11-14 01:54:43 +08:00
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
auto PredsWithConds = shouldSplitOnPredicatedArgument(CB, DTU);
|
2018-11-14 01:54:43 +08:00
|
|
|
if (PredsWithConds.empty())
|
2020-04-16 06:11:44 +08:00
|
|
|
PredsWithConds = shouldSplitOnPHIPredicatedArgument(CB);
|
2018-11-14 01:54:43 +08:00
|
|
|
if (PredsWithConds.empty())
|
|
|
|
return false;
|
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
splitCallSite(CB, PredsWithConds, DTU);
|
2018-11-14 01:54:43 +08:00
|
|
|
return true;
|
2017-11-19 02:14:13 +08:00
|
|
|
}
|
|
|
|
|
2018-02-14 21:59:12 +08:00
|
|
|
static bool doCallSiteSplitting(Function &F, TargetLibraryInfo &TLI,
|
2018-11-14 18:04:30 +08:00
|
|
|
TargetTransformInfo &TTI, DominatorTree &DT) {
|
2018-11-14 01:54:43 +08:00
|
|
|
|
2018-11-14 18:04:30 +08:00
|
|
|
DomTreeUpdater DTU(&DT, DomTreeUpdater::UpdateStrategy::Lazy);
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
bool Changed = false;
|
|
|
|
for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE;) {
|
|
|
|
BasicBlock &BB = *BI++;
|
2018-03-06 22:00:58 +08:00
|
|
|
auto II = BB.getFirstNonPHIOrDbg()->getIterator();
|
|
|
|
auto IE = BB.getTerminator()->getIterator();
|
|
|
|
// Iterate until we reach the terminator instruction. tryToSplitCallSite
|
|
|
|
// can replace BB's terminator in case BB is a successor of itself. In that
|
|
|
|
// case, IE will be invalidated and we also have to check the current
|
|
|
|
// terminator.
|
|
|
|
while (II != IE && &*II != BB.getTerminator()) {
|
2020-04-16 06:11:44 +08:00
|
|
|
CallBase *CB = dyn_cast<CallBase>(&*II++);
|
|
|
|
if (!CB || isa<IntrinsicInst>(CB) || isInstructionTriviallyDead(CB, &TLI))
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
continue;
|
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
Function *Callee = CB->getCalledFunction();
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
if (!Callee || Callee->isDeclaration())
|
|
|
|
continue;
|
2018-03-04 05:40:14 +08:00
|
|
|
|
|
|
|
// Successful musttail call-site splits result in erased CI and erased BB.
|
|
|
|
// Check if such path is possible before attempting the splitting.
|
2020-04-16 06:11:44 +08:00
|
|
|
bool IsMustTail = CB->isMustTailCall();
|
2018-03-04 05:40:14 +08:00
|
|
|
|
2020-04-16 06:11:44 +08:00
|
|
|
Changed |= tryToSplitCallSite(*CB, TTI, DTU);
|
2018-03-04 05:40:14 +08:00
|
|
|
|
|
|
|
// There're no interesting instructions after this. The call site
|
|
|
|
// itself might have been erased on splitting.
|
|
|
|
if (IsMustTail)
|
|
|
|
break;
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
struct CallSiteSplittingLegacyPass : public FunctionPass {
|
|
|
|
static char ID;
|
|
|
|
CallSiteSplittingLegacyPass() : FunctionPass(ID) {
|
|
|
|
initializeCallSiteSplittingLegacyPassPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
|
|
|
AU.addRequired<TargetLibraryInfoWrapperPass>();
|
2018-02-14 21:59:12 +08:00
|
|
|
AU.addRequired<TargetTransformInfoWrapperPass>();
|
2018-11-14 18:04:30 +08:00
|
|
|
AU.addRequired<DominatorTreeWrapperPass>();
|
2018-03-22 23:23:33 +08:00
|
|
|
AU.addPreserved<DominatorTreeWrapperPass>();
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
FunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool runOnFunction(Function &F) override {
|
|
|
|
if (skipFunction(F))
|
|
|
|
return false;
|
|
|
|
|
Change TargetLibraryInfo analysis passes to always require Function
Summary:
This is the first change to enable the TLI to be built per-function so
that -fno-builtin* handling can be migrated to use function attributes.
See discussion on D61634 for background. This is an enabler for fixing
handling of these options for LTO, for example.
This change should not affect behavior, as the provided function is not
yet used to build a specifically per-function TLI, but rather enables
that migration.
Most of the changes were very mechanical, e.g. passing a Function to the
legacy analysis pass's getTLI interface, or in Module level cases,
adding a callback. This is similar to the way the per-function TTI
analysis works.
There was one place where we were looking for builtins but not in the
context of a specific function. See FindCXAAtExit in
lib/Transforms/IPO/GlobalOpt.cpp. I'm somewhat concerned my workaround
could provide the wrong behavior in some corner cases. Suggestions
welcome.
Reviewers: chandlerc, hfinkel
Subscribers: arsenm, dschuff, jvesely, nhaehnle, mehdi_amini, javed.absar, sbc100, jgravelle-google, eraman, aheejin, steven_wu, george.burgess.iv, dexonsmith, jfb, asbirlea, gchatelet, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D66428
llvm-svn: 371284
2019-09-07 11:09:36 +08:00
|
|
|
auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
|
2018-02-14 21:59:12 +08:00
|
|
|
auto &TTI = getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
|
2018-11-14 18:04:30 +08:00
|
|
|
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
|
|
|
return doCallSiteSplitting(F, TLI, TTI, DT);
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
char CallSiteSplittingLegacyPass::ID = 0;
|
|
|
|
INITIALIZE_PASS_BEGIN(CallSiteSplittingLegacyPass, "callsite-splitting",
|
|
|
|
"Call-site splitting", false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
|
2018-02-14 21:59:12 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
|
2018-11-14 18:04:30 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
INITIALIZE_PASS_END(CallSiteSplittingLegacyPass, "callsite-splitting",
|
|
|
|
"Call-site splitting", false, false)
|
|
|
|
FunctionPass *llvm::createCallSiteSplittingPass() {
|
|
|
|
return new CallSiteSplittingLegacyPass();
|
|
|
|
}
|
|
|
|
|
|
|
|
PreservedAnalyses CallSiteSplittingPass::run(Function &F,
|
|
|
|
FunctionAnalysisManager &AM) {
|
|
|
|
auto &TLI = AM.getResult<TargetLibraryAnalysis>(F);
|
2018-02-14 21:59:12 +08:00
|
|
|
auto &TTI = AM.getResult<TargetIRAnalysis>(F);
|
2018-11-14 18:04:30 +08:00
|
|
|
auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
|
2018-03-22 23:23:33 +08:00
|
|
|
if (!doCallSiteSplitting(F, TLI, TTI, DT))
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
return PreservedAnalyses::all();
|
|
|
|
PreservedAnalyses PA;
|
2018-03-22 23:23:33 +08:00
|
|
|
PA.preserve<DominatorTreeAnalysis>();
|
Recommit r317351 : Add CallSiteSplitting pass
This recommit r317351 after fixing a buildbot failure.
Original commit message:
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 ]
llvm-svn: 317362
2017-11-04 04:41:16 +08:00
|
|
|
return PA;
|
|
|
|
}
|