[PATCH] LowerDbgDeclare - get rid of redundant dbg.values when an alloca survives optimization

Adrian Prantl aprantl at apple.com
Mon Mar 31 08:57:31 PDT 2014


On Mar 30, 2014, at 12:02 PM, David Blaikie <dblaikie at gmail.com> wrote:

> Can much of this be split out into separate commits (some look like
> (from your description - I haven't read the patch itself) they'd even
> be post-commit-reviewable)?
> 
It’s tricky to create valid tescases for the in-between commits, but I’ll try to just commit this as a series of smaller patches. In the worst case I’ll be incrementally adding CHECK lines to my existing test case. It’s possible that some of the intermediate stages make things a little worse, but I can try to reorder them in the most sensible way.

> The merge improvement, for example, sounds like it should be standalone - yes?

yes.

> But even some of the other stuff - the ctor renaming you mentioned in
> SDDbgValue. The first couple of points (emitting dbg.value for
> "allocas passed by reference"*, dropping all dbg.declares) sound like
> they might be standalone - but I don't necessarily understand how the
> rest of your fixes are possibly related.

yeah, that’s more of a refactoring.
> 
> * "allocas passed by reference" - by that you mean C++ non-trivial
> pass by value (where the structure has by-value language semantics,
> but it's lowered to IR that passes a pointer (and the caller copies
> the object then passes the pointer to the callee))?

My test case is a C function that takes a struct argument by reference. The case that you mention AFAIK already handled by r185966, if at all. (Do we even emit debug infer for a temporary copy created for a by-value argument?)  This patch really aims at the situation where a variable is on the stack only for a limited range.
> 
> When you say "dropping all dbg.declares" - do you mean we're removing
> that intrinsic from LLVM entirely (ie: it won't exist) or that we
> "drop" dbg.declares in IR by removing them at some point in the middle
> end?

I’m not sure if I understand this question entirely, but yes, LowerDbgDeclare will lower a dbg.declare into multiple dbg.values (one for each use) and then delete the dbg.declare.

cheers,
adrian
> 
> On Sun, Mar 30, 2014 at 11:50 AM, Adrian Prantl <aprantl at apple.com> wrote:
>> Hi Eric and David,
>> 
>> Here is the promised second part, which is actually independent from part 1. This improves the quality of debug info for optimized code a lot, particularly in the case where variables are passed by reference. Also, it solves the mystery of the lost DBG_VALUEs discovered earlier in this thread.
>> 
>>    Debug info for optimized code: Support variables that are on the stack and
>>    described by DBG_VALUEs during their lifetime.
>> 
>>    Previously, when a variable was at a FrameIndex for any part of its
>>    lifetime, this would shadow all other DBG_VALUEs and only a single
>>    fbreg location would be emitted, which in fact is only valid for a small
>>    range and not the entire lexical scope of the variable. The included
>>    dbg-value-const-byref testcase demonstrates this.
>> 
>>    This patch fixes this by
>>    Local.cpp
>>    - emitting dbg.value intrinsics for allocas that are passed by reference
>>    - dropping all dbg.declares (they are now fully lowered to dbg.values)
>>    SelectionDAG
>>    - renamed constructors for SDDbgValue for better readability.
>>    - fix UserValue::match() to handle indirect values correctly
>>    - not inserting an MMI table entries for dbg.values that describe allocas.
>>    - lowering dbg.values that describe allocas into *indirect* DBG_VALUEs.
>>    CodeGenPrepare
>>    - leaving dbg.values for an alloca were they are (see comment)
>>    DwarfDebug
>>    - drive-by fix for Merge() not handling constant values correctly, testcase
>>      included.
>>    Other
>>    - regenerated/updated instcombine-intrinsics testcase and included source
>> 
>> 
>> 
>> 
>> 
>> 
>> cheers,
>> adrian
>> 
>> On Mar 27, 2014, at 1:54 PM, Adrian Prantl <aprantl at apple.com> wrote:
>> 
>>> Hi Eric, David,
>>> 
>>> time to revive age-old threads! I looked at this again, and here is the first in a series of patches that aim at improving debugging for optimized code.
>>> 
>>> This one eliminates redundant variables being emitted when LowerDbgDeclare is hoisting a dbg.declare into a different lexical block as it happens in the included testcase.
>>> 
>>> Next up: dealing with variables that are located at a FrameIndex and described DBG_VALUEs in different parts of the same function.
>>> 
>>> -- adrian
>>> 
>>> <0001-Debug-info-Allow-collectVariableInfoFromMMITable-to-.patch>
>>> 
>>> 
>>> On Oct 29, 2013, at 1:23 PM, Eric Christopher <echristo at gmail.com> wrote:
>>> 
>>>> 
>>>> 
>>>> 
>>>> On Tue, Oct 29, 2013 at 1:10 PM, David Blaikie <dblaikie at gmail.com> wrote:
>>>> 
>>>> 
>>>> 
>>>> On Tue, Oct 29, 2013 at 1:06 PM, Adrian Prantl <aprantl at apple.com> wrote:
>>>> 
>>>> On Oct 29, 2013, at 11:51, David Blaikie <dblaikie at gmail.com> wrote:
>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> On Tue, Oct 29, 2013 at 11:41 AM, Adrian Prantl <aprantl at apple.com> wrote:
>>>>> Hi Eric and David,
>>>>> 
>>>>> On Oct 21, 2013, at 17:07, Eric Christopher <echristo at gmail.com> wrote:
>>>>> Cool deal. I've got some ideas on how to refactor/rewrite some of our
>>>>>> loc handling anyhow, but it's going to be a few days before it's
>>>>>> ready.
>>>>> 
>>>>> 
>>>>> I had some time to look into this some more and I learned a couple of interesting things:
>>>>> - The ##DEBUG_VALUE: comments in the asm output are really just comments do not necessarily show up in the DWARF. This is maybe not surprising, but what was surprising to me are the circumstances under which a DBG_VALUE makes it into the location list of a local variable:
>>>>> - dbg.declare and dbg.value intrinsics are mutually exclusive; the presence of a dbg.declare will shadow any dbg.values that refer to the same variable. As soon as there is an entry in the MMI map (FunctionLowering::set() in FunctionLowering.cpp:134), the dbg.values will be ignored by DwarfDebug::collectVariableInfo (DwarfDebug.cpp::1366).
>>>>> - Simply disabling that check will result in two separate DIEs for the same variable.
>>>>> 
>>>>> This means that while my patch was correct based on how DwarfDebug currently behaves, that behavior is broken and I should instead allow for dbg.values and dbg.declares to be coalesced into a single location list.
>>>>> 
>>>>> Before I dive into this I'd be curious to hear more about your ideas for location handling that you mentioned in your last mail, so we don't accidentally evolve the code into two different directions.
>>>>> 
>>>>> 
>>>>> I also found a second, related issue that I'd like to tackle.
>>>>> 
>>>>> This example:
>>>>> 
>>>>>> foo(int map)
>>>>>> {
>>>>>> lookup(&map);
>>>>>> if (!verify(map)) {  }
>>>>>> }
>>>>>> 
>>>>> 
>>>>> results in the following DWARF:
>>>>> 
>>>>>> 0x00000027:     TAG_subprogram [2] *
>>>>>>                AT_name( "foo" )
>>>>>>                AT_low_pc( 0x0000000000000000 )
>>>>>>                AT_high_pc( 0x0000000000000026 )
>>>>>>             ...
>>>>>> 0x00000046:         TAG_formal_parameter [3]
>>>>>>                    AT_name( "map" )
>>>>>>                    AT_type( {0x00000075} ( int ) )
>>>>>>                    AT_location( fbreg -4 )
>>>>>> 
>>>>>> 0x00000054:         TAG_lexical_block [4] *
>>>>>>                    AT_low_pc( 0x0000000000000016 )
>>>>>>                    AT_high_pc( 0x0000000000000020 )
>>>>>> 
>>>>>> 0x00000065:             TAG_formal_parameter [3]
>>>>>>                        AT_name( "map" )
>>>>>>                        AT_type( {0x00000075} ( int ) )
>>>>>>                        AT_location( fbreg -4 )
>>>>> 
>>>>> I would like teach DWARFDebug::constructScopeDIE() to recognize if a variable DIE describes a "subset" of a DIE in one of its parent lexical blocks.
>>>>> 
>>>>> To be clear, this just looks buggy - we shouldn't have two formal parameters here... there is only one formal parameter to 'foo'. If we create two DIEs that's a bug, we shouldn't do that.
>>>>> 
>>>> 
>>>> That would be a fairly trivial fix in DWARFDebug::createScopeChildrenDIE(). I'm wondering: Should there ever be more than one DIE describing a variable in different lexical scopes or should there be only ever a single DIE with multiple entries in the DW_AT_location list?
>>>> 
>>>> The latter, I'm fairly sure.
>>>> 
>>>> Yes.
>>>> 
>>>> -eric
>>> 
>> 
>> 





More information about the llvm-commits mailing list