<div dir="ltr"><div>Hi Paul,</div><div>If all you care about is debugging then for now we can just emit a few more debug messages which would help to "trace" the flow. To distinguish traces you can prefix it with some known string. I don't think you really need a 'trace' tag in the language spec for this.<br></div><div><br></div><div>Debugging Tablegen has always been a nightmare and I don't think we can ever reach a stage where we can start a debugger and debug statements in .td files step-by-step. This is far from reality unless we fundamentally change the language.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 5, 2020 at 1:32 PM Nicolai Hähnle via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Wed, Aug 5, 2020 at 1:08 AM Paul C. Anagnostopoulos<br>
<<a href="mailto:paul@windfall.com" target="_blank">paul@windfall.com</a>> wrote:<br>
> Are all the records collected as they are parsed, with template parameter substitution and lets, and *then*, after all records are collected, a "pass" is made to calculate the inter-field expressions?<br>
<br>
No, the inter-field expressions are resolved immediately as the final<br>
"def" is processed. See TGParser::addDefOne.<br>
<br>
<br>
> Once I understand this, I will add a section to the new guide to explain it. I presume it is the case that this behavior should be publicized.<br>
><br>
> It also appears to be the case that a record is created and bound to its name before fields are inherited from its superclasses, which is why you can write:<br>
><br>
> class A <dag d> {<br>
> dag the_dag = d;<br>
> }<br>
><br>
> def rec1 : A<(ops rec1)><br>
><br>
> Do I understand that correctly?<br>
<br>
Almost :)<br>
<br>
In reality, this is allowed as a special-case by<br>
TGParser::ParseIDValue, whose purpose is looking up identifiers. See<br>
the comment about self-references towards the bottom of the method.<br>
<br>
Cheers,<br>
Nicolai<br>
<br>
<br>
><br>
> At 8/4/2020 05:38 PM, Nicolai Hähnle wrote:<br>
> >On Tue, Aug 4, 2020 at 11:13 PM Paul C. Anagnostopoulos<br>
> ><<a href="mailto:paul@windfall.com" target="_blank">paul@windfall.com</a>> wrote:<br>
> >> Yes, I understand the problem. To be more useful, TableGen would have to carry the traces along with the classes and records and (re)display the values while the substitutions are being made.<br>
> >><br>
> >> I'm writing a new Programmer's Guide for TableGen and have been digging into the parse-time versus substitution-time issue. I haven't found a document that makes it clear. Can you give a quick summary of the phases?<br>
> ><br>
> >There aren't really any phases per se, in the sense that the TableGen<br>
> >frontend doesn't have passes. Maybe that's a mistake, but that's how<br>
> >it evolved.<br>
> ><br>
> >So instead, every time a record is "instantiated" -- whether that's by<br>
> >defining a new class that derives from one or more pre-existing<br>
> >classes, or by a def in a multi-class, or by a free-standing def, or a<br>
> >defm (inside or outside a multiclass) -- any free variables that are<br>
> >"resolved" as template parameters get their substitution applied. The<br>
> >relevant let-statements take effect just after that.<br>
> ><br>
> >However, and this is key, reference _between_ fields are only resolved<br>
> >and substituted once the final defined record at the global scope is<br>
> >produced. This is what makes:<br>
> ><br>
> >class A<int x> {<br>
> > int a = x;<br>
> > int b = a + 1;<br>
> >}<br>
> ><br>
> >def B : A<5> { let a = 10; }<br>
> ><br>
> >... result in b == 11 instead of b == 6.<br>
> ><br>
> >There's probably subtlety here that I'm forgetting, but that's the<br>
> >very short version of it ;)<br>
> ><br>
> >Cheers,<br>
> >Nicolai<br>
> ><br>
> ><br>
> >><br>
> >> At 8/4/2020 05:01 PM, Nicolai Hähnle wrote:<br>
> >> >On Mon, Aug 3, 2020 at 6:04 PM Paul C. Anagnostopoulos via llvm-dev<br>
> >> ><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> >> >> A question for those of you who have developed complex TableGen files: Do you think a trace facility would be useful during debugging? The idea is to add a new statement to TableGen along these lines:<br>
> >> >><br>
> >> >> trace tag : value1, value2, ... ;<br>
> >> >><br>
> >> >> When encountered, the TableGen parser would display the tag along with the values of the specified value1, value2, etc. The tag is an identifier that makes it easier to distinguish multiple traces.<br>
> >> ><br>
> >> >I'm not so sure that that's particularly useful or how it would even<br>
> >> >work. The issue is that at the point in time where the frontend parses<br>
> >> >those trace tags, most substitutions haven't taken place yet, so<br>
> >> >you'll usually get fairly trivial answers that by themselves aren't<br>
> >> >particularly helpful.<br>
> >> ><br>
> >> >Some form of inspection of how values are substituted would indeed be<br>
> >> >helpful, I just don't think the "trace" is quite it. In a perfect<br>
> >> >world, we'd have some sort of "record database explorer" that doesn't<br>
> >> >just let you look at all the final records (TableGen already allows<br>
> >> >you to do that), but also allows you to interactively explore their<br>
> >> >"history", i.e. how did the records come to be.<br>
> >> ><br>
> >> >Cheers,<br>
> >> >Nicolai<br>
> >> ><br>
> >> >--<br>
> >> >Lerne, wie die Welt wirklich ist,<br>
> >> >aber vergiss niemals, wie sie sein sollte.<br>
><br>
<br>
<br>
-- <br>
Lerne, wie die Welt wirklich ist,<br>
aber vergiss niemals, wie sie sein sollte.<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><i style="font-size:12.8px">Disclaimer: Views, concerns, thoughts, questions, ideas expressed in this mail are of my own and my employer has no take in it. </i><br></div><div>Thank You.<br>Madhur D. Amilkanthwar<br><br></div></div></div>