Skip to content

Commit 8d65f36

Browse files
When checking if an Argument escapes, check if
the argument is marked nocapture - no need to analyze the argument if the answer is already known! llvm-svn: 61753
1 parent 8804293 commit 8d65f36

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ using namespace llvm;
3535
// Useful predicates
3636
//===----------------------------------------------------------------------===//
3737

38-
// Determine if an AllocationInst instruction escapes from the function it is
39-
// contained in. If it does not escape, there is no way for another function to
40-
// mod/ref it. We do this by looking at its uses and determining if the uses
41-
// can escape (recursively).
38+
// Determine if a value escapes from the function it is contained in (being
39+
// returned by the function does not count as escaping here). If a value local
40+
// to the function does not escape, there is no way another function can mod/ref
41+
// it. We do this by looking at its uses and determining if they can escape
42+
// (recursively).
4243
static bool AddressMightEscape(const Value *V) {
4344
for (Value::use_const_iterator UI = V->use_begin(), E = V->use_end();
4445
UI != E; ++UI) {
@@ -161,12 +162,17 @@ static bool isNonEscapingLocalObject(const Value *V) {
161162
// If this is a local allocation, check to see if it escapes.
162163
if (isa<AllocationInst>(V) || isNoAliasCall(V))
163164
return !AddressMightEscape(V);
164-
165+
165166
// If this is an argument that corresponds to a byval or noalias argument,
166-
// it can't escape either.
167+
// then it has not escaped before entering the function. Check if it escapes
168+
// inside the function.
167169
if (const Argument *A = dyn_cast<Argument>(V))
168-
if (A->hasByValAttr() || A->hasNoAliasAttr())
170+
if (A->hasByValAttr() || A->hasNoAliasAttr()) {
171+
// Don't bother analyzing arguments already known not to escape.
172+
if (A->hasNoCaptureAttr())
173+
return true;
169174
return !AddressMightEscape(V);
175+
}
170176
return false;
171177
}
172178

0 commit comments

Comments
 (0)