[PATCH] ADCE: Remove debug info intrinsics in dead scopes

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 30 10:26:52 PDT 2016


> On 2016-Mar-30, at 10:15, Mehdi Amini <mehdi.amini at apple.com> wrote:
> 
>> 
>> On Mar 30, 2016, at 9:18 AM, David Blaikie <dblaikie at gmail.com> wrote:
>> 
>> 
>> 
>> On Tue, Mar 29, 2016 at 10:59 PM, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:
>> +Mehdi
>> 
>> > On 2016-Mar-29, at 22:29, David Blaikie <dblaikie at gmail.com> wrote:
>> >
>> > Does it make sense to do this in ADCE and ADCE only? Lots of code can remove instructions & could be the place where a scope ceases to exist, so it seems strange to make this change only here, doesn't it?
>> 
>> I thought about the algorithm, and then looked for a pass that was
>> already doing something similar.  ADCE seemed to be good fit since it
>> also needed three passes through the function.
>> 
>> I had a look with Mehdi at the pass pipeline, and ADCE is run almost
>> at the end.  It is run just before exit for -flto=thin, too.
>> 
>> > I'm assuming you want to do this to reduce IR size early on? (pre-(Thin)LTO merge?) 
>> 
>> ^ ?
> 
> This is the motivation for this change (trying to emit less metadata in the end), but it is valuable in general: smaller basic blocks for all the optimization that will follow, less memory, etc.
> This seems a good motivation to run ADCE in general as well.
> 

[forgot to hit send earlier so by now mehdi has covered it, but here's
what i wrote up]

I want to run this at the end of the optimization pipeline:

  - in -cc1, before writing out bitcode (-flto=full or -flto=thin);
  - in -cc1, before codegen;
  - in libLTO, before codegen.

No problem if it runs more often.

My goals are to reduce bitcode size (1) by killing dangling references
to otherwise dead subprograms and (2) by reducing the number of
instructions.  A side benefit is to prune the final debug info.

This came up because of (1).  Adrian is working on reversing the link
between subprograms and compile units, partly in order to drop
subprograms that aren't associated with any code.  I realized that
they wouldn't be dropped if we still had references to their
variables.

> -- 
> Mehdi
> 
> 
>>  
>> Maybe as a separate pass?
>> 
>> > If it's just to reduce debug info output - maybe better to just delay until IR generation? (perhaps we already do this, I forget?)
>> 
>> Open to having a separate pass, but since ADCE was such a good fit
>> (it similarly needed three passes through the IR, which I could just
>> piggy-back on) and happened to run at the right times I decided not to
>> think any further.
>> 
>> Hmm, rightio - I don't know too much about pass design (when we try to make them independent, when we don't). So I'll leave it to you folks & others to chime in if there are relevant guiding principles that should be applied differently here.
>> 
>> - Dave
>>  
>> 
>> > On Tue, Mar 29, 2016 at 12:34 PM, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:
>> > During ADCE, track which debug info scopes still have live references
>> > from the code, and delete debug info intrinsics for the dead ones.
>> >
>> > These intrinsics describe the locations of variables (in registers or
>> > stack slots).  If there's no code left corresponding to a variable's
>> > scope, then there's no way to reference the variable in the debugger and
>> > it doesn't matter what its value is.
>> >
>> > I add a DEBUG printout when the described location in an SSA register,
>> > in case it helps some trying to track down why locations get lost.
>> > However, we still delete these; the root problem is that the scope
>> > itself isn't attached to any real code.
>> >
>> >



More information about the llvm-commits mailing list