[llvm-dev] [PATCH] D14227: Add a new attribute: norecurse
Duncan P. N. Exon Smith via llvm-dev
llvm-dev at lists.llvm.org
Thu Nov 5 09:45:09 PST 2015
> On 2015-Nov-05, at 07:54, Hal Finkel <hfinkel at anl.gov> wrote:
>
>
> From: "James Molloy via llvm-dev" <llvm-dev at lists.llvm.org>
> To: "Philip Reames" <listmail at philipreames.com>, reviews+D14227+public+6a20206dc9791b02 at reviews.llvm.org, "James Molloy" <james.molloy at arm.com>, "manman ren" <manman.ren at gmail.com>, dexonsmith at apple.com, "mehdi amini" <mehdi.amini at apple.com>, "LLVM Dev" <llvm-dev at lists.llvm.org>
> Cc: "LLVM Commits" <llvm-commits at lists.llvm.org>
> Sent: Thursday, November 5, 2015 9:44:45 AM
> Subject: Re: [llvm-dev] [PATCH] D14227: Add a new attribute: norecurse
>
> [Adding llvm-dev and re-stating the situation for llvm-dev's benefit]
>
> RFC: A new attribute, "norecurse".
>
> In some cases, it is possible to demote global variables to local variables. This is possible when the global is only used in one function, and that function is known not to recurse (because if the function recurses, a local variable cannot be equivalent to a global as the global would hold state over the recursive call).
>
> GlobalOpt has this ability already, however it is currently (a) weak and (b) broken.
>
> GlobalOpt has a special case for the function "main". It assumes that any function called "main" with external linkage is by definition non-recursive. It does this because in C++, main is defined by the standard not to recurse. However, this is not the case in C, so GlobalOpt will happily break C code.
>
> GlobalOpt also currently won't even attempt to discover functions that don't recurse - it only checks "main".
>
> What I'd like to do is improve GlobalOpt to be more aggressive with demoting globals to locals, and to do that I need to teach it which functions are known to be non-recursive. At the same time I'd really like to fix the "main" kludge.
>
> There are three options I see:
> 1. Just use an analysis pass to infer non-recursiveness as a property. This can be a simple SCC pass which is queried by GlobalOpt.
> 2. Add an attribute, "norecurse". This would be inferred just like above by FunctionAttrs in the general case, but it also allows frontends to add the attribute if they have specific knowledge - for example "main" in C++ mode.
> 3. (1), but use metadata to add the non-recursiveness information in the frontend, to solve the "main" problem.
>
> What I'm suggesting here is (2).
>
> +1
>
> This is a very generic property, and I'm happy with the conciseness provided by an attribute.
+1
I think (2), an IR-level attribute, makes the most sense.
More information about the llvm-dev
mailing list