[llvm-commits] PATCH: stronger tail recursion elimination with nocapture

Nick Lewycky nlewycky at google.com
Mon Oct 8 16:35:13 PDT 2012


Here's a new way to handle it. shouldExplore() is handed each value we're
going to inspect for the potential that the pointer is leaked. Scan its
use-list and see if any users are calls or invokes and add those to the
list.

New patch attached. Please review!

Nick

On 4 October 2012 01:42, Nick Lewycky <nicholas at mxc.ca> wrote:

> Duncan Sands wrote:
>
>> Hi Nick,
>>
>> On 04/10/12 06:59, Nick Lewycky wrote:
>>
>>> Tail recursion elimination has to check whether allocas are escaping. It
>>> currently doesn't bother and just assumes that if mem2reg/sroa hasn't
>>> removed
>>> the alloca, then it's an escaping alloca. This patch teaches it to use
>>> CaptureTracking to find calls to functions where the alloca is passed
>>> in through
>>> an argument marked nocapture, and safely ignore those. Those calls can't
>>> themselves be marked tail, but they don't block other calls from being
>>> marked tail.
>>>
>>
>> I didn't read very far, but...
>>
>>  --- include/llvm/Analysis/**CaptureTracking.h (revision 165196)
>>> +++ include/llvm/Analysis/**CaptureTracking.h (working copy)
>>> @@ -46,12 +46,17 @@
>>> /// capture) return false. To search it, return true.
>>> ///
>>> /// U->getUser() is always an Instruction.
>>> - virtual bool shouldExplore(Use *U) = 0;
>>> + virtual bool shouldExplore(Use *U);
>>>
>>> /// captured - Information about the pointer was captured by the user of
>>> /// use U. Return true to stop the traversal or false to continue looking
>>> /// for more capturing instructions.
>>> virtual bool captured(Use *U) = 0;
>>> +
>>> + /// temporarilyCaptured - Information about the pointer was captured
>>> by the
>>> + /// user of use U, but only for a known duration, such as the length
>>> of a
>>> + /// single function call. Return true to stop the traversal.
>>> + virtual bool temporarilyCaptured(Use *U);
>>>
>>
>> this seems way too vaguely defined to me. Is it just for the duration of
>> a call
>> or not? And how can you determine that anyway: what if the callee stores
>> it to
>> a global?
>>
>
> I agree. How about:
>
>   /// used - This is a non-capturing use.
>   virtual bool used(Use *U);
>
> If unused, the additional function calls would melt away in any optimized
> build.
>
> Nick
>
>
>  Ciao, Duncan.
>>
>>  };
>>>
>>> /// PointerMayBeCaptured - Visit the value and the values derived from
>>> it and
>>>
>>
>>
>>
>> ______________________________**_________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/**mailman/listinfo/llvm-commits<http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits>
>>
>>
> ______________________________**_________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/**mailman/listinfo/llvm-commits<http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121008/06b5a6e1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tre-nocapture-2.patch
Type: application/octet-stream
Size: 7773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20121008/06b5a6e1/attachment.obj>


More information about the llvm-commits mailing list