<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 2, 2015 at 9:32 AM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On 2015-Apr-02, at 09:14, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Thu, Apr 2, 2015 at 9:10 AM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>> wrote:<br>
><br>
> > On 2015-Apr-02, at 08:01, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
> ><br>
> ><br>
> > On Apr 1, 2015 11:36 PM, "Duncan P. N. Exon Smith" <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>> wrote:<br>
> > ><br>
> > > When I was gathering LTO heap profiles a few weeks ago, the single<br>
> > > largest `Metadata` contributer to memory usage was `MDLocalVariable`,<br>
> > > with a huge chunk coming from `MDLocalVariable::withInline()`.<br>
> > ><br>
> > > This patch stops storing where an `MDLocalVariable` has been inlined.<br>
> > > This inlined-at info was used two ways:<br>
> > ><br>
> > > - To tell the backend where a variable was inlined.<br>
> > > - To create a unique id for each inlined variable.<br>
> > ><br>
> > > However, every instruction has a `!dbg` attachment with the same<br>
> > > information in its inlined-at field. AFAICT, David Blaikie's work to<br>
> > > make that accurate has paid off, since this naive patch (which just<br>
> > > removes the field entirely) passes all the tests.<br>
> > ><br>
> > > The unique id for inlined variables is now a typedef called<br>
> > > `InlinedVariable` of `std::pair<MDLocalVariable*, MDLocation*>`.<br>
> > ><br>
> > > Besides the patch, I've attached the upgrade script I used to update<br>
> > > testcases.<br>
> > ><br>
> > > Any reason not to commit? (Am I missing something here?)<br>
> ><br>
> > Last time I tried this (not sure whether I got as far as commuting/referring it) either I hit those issues I have since fixed (maybe that's part of what me going on that kick) or some other issues...<br>
> ><br>
> > In any case, would it be possible to run some tests that assert that these two locations are the same (possibly this assertion could take the place of the construction of these excessive/redundant/bloated inlined DIVariables - so we could gain the memory savings while still leaving the checking in just in case there are new/weird/interesting cases) for now?<br>
><br>
> I can't remove the field and assert about its value at the same time ;).<br>
><br>
> Sorry, what I meant (& perhaps it's still not possible) is to assert, at the point where the field would be initialized/the extra DIVariable created, instead just assert that the inlinedAt location we were about to use is the same as the dbgloc we would've used.<br>
><br>
<br>
</span>As it happens, that's already true by construction. The only calls to<br>
`createInlinedVariable()` (which is the only caller of<br>
`MDLocalVariable::withInline()`) are here in `InlineFunction.cpp`:<br>
<br>
lib/Transforms/Utils/InlineFunction.cpp-905- } else {<br>
lib/Transforms/Utils/InlineFunction.cpp-906- BI->setDebugLoc(updateInlinedAtInfo(DL, InlinedAtNode, BI->getContext(), IANodes));<br>
lib/Transforms/Utils/InlineFunction.cpp-907- if (DbgValueInst *DVI = dyn_cast<DbgValueInst>(BI)) {<br>
lib/Transforms/Utils/InlineFunction.cpp-908- LLVMContext &Ctx = BI->getContext();<br>
lib/Transforms/Utils/InlineFunction.cpp-909- MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt();<br>
lib/Transforms/Utils/InlineFunction.cpp-910- DVI->setOperand(2, MetadataAsValue::get(<br>
lib/Transforms/Utils/InlineFunction.cpp:911: Ctx, createInlinedVariable(DVI->getVariable(),<br>
lib/Transforms/Utils/InlineFunction.cpp-912- InlinedAt, Ctx)));<br>
lib/Transforms/Utils/InlineFunction.cpp-913- } else if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI)) {<br>
lib/Transforms/Utils/InlineFunction.cpp-914- LLVMContext &Ctx = BI->getContext();<br>
lib/Transforms/Utils/InlineFunction.cpp-915- MDNode *InlinedAt = BI->getDebugLoc().getInlinedAt();<br>
lib/Transforms/Utils/InlineFunction.cpp-916- DDI->setOperand(1, MetadataAsValue::get(<br>
lib/Transforms/Utils/InlineFunction.cpp:917: Ctx, createInlinedVariable(DDI->getVariable(),<br>
lib/Transforms/Utils/InlineFunction.cpp-918- InlinedAt, Ctx)));<br>
lib/Transforms/Utils/InlineFunction.cpp-919- }<br>
lib/Transforms/Utils/InlineFunction.cpp-920- }<br>
<br>
However, the `assert()`s in my patch are firing so I think we're<br>
losing the inlined-at somewhere in the backend before we construct the<br>
variables. (The Verifier checks fail on a few testcases too, but it<br>
looks like that's just bitrot.)<br></blockquote><div><br>Alrighty - be curious to see where. Totally happy to help out with fixing/debugging/reducing/whatever these issues.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span class=""><br>
> I'll start by adding the assertion, and after a while (a day? a week?)<br>
> if no bot complains I'll rip out the field. (If bots do complain we can<br>
> fix bugs until they're happy.)<br>
><br>
> *nod* Sounds good - I'm not too fussed about waiting ages, but at least a good clang/opt bootstrap, etc. A week's probably not unreasonable.<br>
><br>
> Currently running `ninja check-all` on the attached patch; I'll commit<br>
> it after fixing up any failing testcases and we can go from there.<br>
><br>
> Looks reasonable (though how'd you pick those 3-4 places to add assertions? Are they all the places that use DIVariable::getInlinedAt?)<br>
<br>
</span>These are the spots that my first patch constructed an `InlinedVariable`<br>
union the callers of `MDLocalVariable::getInlinedAt()` that have a<br>
`!dbg` attachment around.<br></blockquote><div><br>I can't quite parse that sentence... ^<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
There are a couple of callers to `MDLocalVariable::getInlinedAt()` that<br>
don't have access to the `!dbg` attachment until my first patch passes<br>
them through via `InlinedVariable`.</blockquote></div><br></div></div>