<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap:break-word"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div> <br> <div id="bloop_sign_1498140493432806912" class="bloop_sign"></div> <br><p class="airmail_on">On June 22, 2017 at 5:51:39 AM, Pavel Labath (<a href="mailto:labath@google.com">labath@google.com</a>) wrote:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>I don't have any concrete feedback, but:
<br>
<br>- +1 for removing the "FastDemagler"
<br>
<br>- If you already construct an AST as a part of your demangling
<br>process, would it be possible to export that AST for external
<br>consumption somehow? Right now in lldb we sometimes need to parse the
<br>demangled name (to get the "basename" of a function for example), and
<br>the code for doing that is quite ugly. It would be much nicer if we
<br>could just query the parsed representation of the name somehow, and
<br>the AST would enable us to do that.
<br></div></div></span></blockquote><div><br></div><div>I was thinking about this use case a little, actually. I think it makes more sense to provide a function, say getItaniumDemangledBasename(), which could just parse and query the AST for the base name (the AST already has an way of doing this). This would allow the demangler to bail out if it knows that the rest of the input string isn’t relevant, i.e., we could bail out after parsing the ‘foo’ in _Z3fooiiiiiii. That, and not having to print out the AST should make parsing the base name significantly faster on top of this.</div><div><br></div><div>Do you have any other use case for the AST outside of base names? It still would be possible to export it from ItaniumDemangle.</div><br><blockquote type="cite" class="clean_bq"><span><div><div>

<br>On 22 June 2017 at 02:03, Erik Pilkington via llvm-dev
<br><<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:
<br>>
<br>>
<br>> On 6/21/17 5:42 PM, Rui Ueyama wrote:
<br>>
<br>> I'm very interested in your work because I've just started writing a
<br>> demangler for the Microsoft mangling scheme. What I found in the current
<br>> Itanium demangler is the same as you -- it looks like it allocates too much
<br>> memory during parsing and concatenates std::strings too often. I could see
<br>> there's a (probably big) room to improve. Demangler's performance is
<br>> sometimes important for LLD, which is my main project, as linkers often have
<br>> to print out a lot of symbols if a verbose output is requested. For example,
<br>> if you link Chrome with the -map option, the linker has to demangle 300 MiB
<br>> strings in total, which currently takes more than 20 seconds on my machine
<br>> if single-threaded.
<br>>
<br>> The way I'm trying to implement a MS demangler is the same as you, too. I'm
<br>> trying to create an AST to describe type and then convert it to string. I
<br>> guess that we can use the same AST type between Itanium and MS so that we
<br>> can use the same code for converting ASTs to strings.
<br>>
<br>> Using the same AST is an interesting idea. The AST that I wrote isn't that
<br>> complicated, and is pretty closely tied to the libcxxabi demangler, so I bet
<br>> it would be easier to have separate representations, especially if your
<br>> intending on mimicking the output of MS's demangler. I'm also not at all
<br>> familiar with how MS mangles their C++, which might imply a slightly
<br>> different representation.
<br>>
<br>> It's unfortunate that my work is overlapping with yours. Looks like you are
<br>> ahead of me, so I'll take a look at your code to see if there's something I
<br>> can do for you.
<br>>
<br>> On Wed, Jun 21, 2017 at 4:42 PM, Erik Pilkington via llvm-dev
<br>> <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:
<br>>>
<br>>> Hello all,
<br>>> The itanium demangler in libcxxabi (and also, llvm/lib/Demangle) is really
<br>>> slow. This is largely because the textual representation of the symbol that
<br>>> is being demangled is held in a std::string, and manipulations done during
<br>>> parsing are done on that string. The demangler is always concatenating
<br>>> strings and inserting into the middle of strings, which is terrible. The
<br>>> fact that the parsing logic and the string manipulation/formatting logic is
<br>>> interleaved also makes the demangler pretty ugly. Another problem was that
<br>>> the demangler used a lot stack space, and has a bunch of stack overflows
<br>>> filed against it.
<br>>>
<br>>> I've been working on fixing this by parsing first into an AST structure,
<br>>> and then traversing that AST to produce a demangled string. This provides a
<br>>> significant performance improvement and also make the demangler somewhat
<br>>> more clean. Attached you should find a patch to this effect. This patch is
<br>>> still very much a work in progress, but currently passes the libcxxabi test
<br>>> suite and demangles all the symbols in LLVM identically to the current
<br>>> demangler. It also provides a significant performance improvement: it
<br>>> demangles the symbols in LLVM about 3.7 times faster than the current
<br>>> demangler. Also, separating the formatting code from the parser reduces
<br>>> stack usage (the activation frame for parse_type reduced from 416 to 144
<br>>> bytes on my machine). The stack usage is still pretty bad, but this helps
<br>>> with some of it.
<br>>>
<br>>> Does anyone have any early feedback on the patch? Does this seem like a
<br>>> good direction for the demangler?
<br>>>
<br>>> As far as future plans for this file, I have a few more refactorings and
<br>>> performance improvements that I'd like to get through. After that, it might
<br>>> be interesting to try to replace the FastDemangle.cpp demangler in LLDB with
<br>>> this, to restore the one true demangler in the source tree. The
<br>>> FastDemangler.cpp is only partially completed, and calls out to
<br>>> ItaniumDemangle.cpp in llvm (which is a copy of cxa_demangle.cpp) if it
<br>>> fails to parse the symbol.
<br>>>
<br>>> Any thoughts here would be appreciated!
<br>>> Thanks,
<br>>> Erik
<br>>>
<br>>> _______________________________________________
<br>>> LLVM Developers mailing list
<br>>> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<br>>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
<br>>>
<br>>
<br>>
<br>>
<br>> _______________________________________________
<br>> LLVM Developers mailing list
<br>> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<br>> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
<br>>
<br></div></div></span></blockquote></body></html>