@@ -35,10 +35,11 @@ using namespace llvm;
35
35
// Useful predicates
36
36
// ===----------------------------------------------------------------------===//
37
37
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).
42
43
static bool AddressMightEscape (const Value *V) {
43
44
for (Value::use_const_iterator UI = V->use_begin (), E = V->use_end ();
44
45
UI != E; ++UI) {
@@ -161,12 +162,17 @@ static bool isNonEscapingLocalObject(const Value *V) {
161
162
// If this is a local allocation, check to see if it escapes.
162
163
if (isa<AllocationInst>(V) || isNoAliasCall (V))
163
164
return !AddressMightEscape (V);
164
-
165
+
165
166
// 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.
167
169
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 ;
169
174
return !AddressMightEscape (V);
175
+ }
170
176
return false ;
171
177
}
172
178
0 commit comments