<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>At some point I tried doing something like this for debug
information verification (via XML, the effort did not go very
far). I would be very interested in using and contributing to this
code.<br>
</p>
<p>-Petr<br>
</p>
<br>
<div class="moz-cite-prefix">On 10/31/2017 22:16, Chris Lattner via
llvm-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:64F4CD63-E4C1-4BAE-A882-8B95BC0166F1@nondot.org">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252">
It would be really interesting to see this as an extension of
FileCheck. Having the ability to write these sorts of predicates
in CHECK: lines would be pretty cool, and could make existing
regex checks a lot more principled.
<div class=""><br class="">
</div>
<div class="">-Chris</div>
<div class=""><br class="">
<div>
<blockquote type="cite" class="">
<div class="">On Oct 31, 2017, at 3:21 PM, Dean Michael
Berris via llvm-dev <<a
href="mailto:llvm-dev@lists.llvm.org" class=""
moz-do-not-send="true">llvm-dev@lists.llvm.org</a>>
wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252" class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode:
space; -webkit-line-break: after-white-space;" class="">As
much as I'm not a fan of most XML things, this
application of XPath is *inspired*.
<div class=""><br class="">
</div>
<div class="">This would be a great testing/query tool
for tests.</div>
<div class=""><br class="">
</div>
<div class="">It would also be a great way to prototype
passes.</div>
<div class=""><br class="">
</div>
<div class="">Looking forward to seeing something like
this in llvm/tools/ !</div>
<div class=""><br class="">
</div>
<div class="">Cheers</div>
<div class=""><br class="">
<div class="">
<blockquote type="cite" class="">
<div class="">On 1 Nov 2017, at 04:00, Sean Silva
via llvm-dev <<a
href="mailto:llvm-dev@lists.llvm.org" class=""
moz-do-not-send="true">llvm-dev@lists.llvm.org</a>>
wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div dir="auto" class="">This is so cool! I once
had a similar idea but the way I was thinking
about it ended up more complex than I had time
to implement (I sketched it here: <a
href="http://lists.llvm.org/pipermail/llvm-dev/2013-November/067720.html"
target="_blank" class=""
moz-do-not-send="true">http://lists.llvm.org/<wbr
class="">pipermail/llvm-dev/2013-<wbr
class="">November/067720.html</a>).
<div dir="auto" class=""><br class="">
</div>
<div dir="auto" class="">Good idea using xpath
to simplify the implementation and reuse
existing languages/libraries as a starting
point!</div>
</div>
<div class="gmail_extra"><br class="">
<div class="gmail_quote">On Oct 29, 2017 6:47
AM, "Alessandro Di Federico via llvm-dev"
<<a href="mailto:llvm-dev@lists.llvm.org"
target="_blank" class=""
moz-do-not-send="true">llvm-dev@lists.llvm.org</a>>
wrote:<br type="attribution" class="">
<blockquote class="gmail_quote"
style="margin:0 0 0 .8ex;border-left:1px
#ccc solid;padding-left:1ex">Hi, sometimes
when dealing with LLVM IR getting to a
desired point of<br class="">
the code is a bit cumbersome, in
particular if you're instrumenting<br
class="">
existing code. A lot of nested loops and
if checks.<br class="">
<br class="">
Maybe all of this could be avoided by
employing a query language. Since<br
class="">
an LLVM module can be seen as a sort of
tree with attributes, I think<br class="">
that reusing an existing query language
for XML would be appropriate.<br class="">
<br class="">
In particular I choose XPath [1] since
it's more expressive than, say,<br
class="">
CSS selectors (e.g., you can move from the
current element to the<br class="">
parent).<br class="">
<br class="">
Therefore, in a spare night, I took
pugixml [2], a lightweight XML parser<br
class="">
with XPath support, stripped away
everything was XML-specific and<br
class="">
adapted it so that it could query an
arbitrary tree, as long as a class<br
class="">
providing certain traits is provided.<br
class="">
<br class="">
Attached you can find the class to query a
LLVM module and example LLVM<br class="">
module (using LLVM 3.8, but newer versions
should do to).<br class="">
<br class="">
The current implementation pretends that a
module looks like the<br class="">
following XML tree (more or less):<br
class="">
<br class="">
<main.ll><br class="">
<main><br class="">
<basicblock1><br class="">
<alloca /><br class="">
<alloca /><br class="">
...<br class="">
</basicblock1><br class="">
...<br class="">
</main><br class="">
</main.ll><br class="">
<br class="">
Additional information could be encoded in
attributes.<br class="">
Please note that the queries are done on
the LLVM IR directly, no XML<br class="">
tree is materialized.<br class="">
<br class="">
In the following you can find some
examples:<br class="">
<br class="">
$ # Find all the basic blocks
containing at least an alloca<br class="">
$ llvm-xpath '/main/*[count(alloca)
> 0]' main.ll<br class="">
<br class="">
%1 = alloca i32, align 4<br class="">
%2 = alloca i32, align 4<br class="">
%i = alloca i32, align 4<br class="">
store i32 0, i32* %1, align 4<br
class="">
store i32 %argc, i32* %2, align 4<br
class="">
%3 = load i32, i32* %2, align 4<br
class="">
store i32 %3, i32* %i, align 4<br
class="">
br label %4<br class="">
<br class="">
$ # Find all store instructions<br
class="">
$ llvm-xpath '/*/*/store'<br class="">
store i32 0, i32* %1, align 4<br
class="">
store i32 %argc, i32* %2, align 4<br
class="">
store i32 %3, i32* %i, align 4<br
class="">
store i32 %6, i32* %i, align 4<br
class="">
<br class="">
Obviously this doesn't have to be
exclusively a command line tool, but<br
class="">
we could have something like:<br class="">
<br class="">
for (auto *Store :
TheModule.xpath<StoreInst>("/*<wbr
class="">/*/store"))<br class="">
/* ... */<br class="">
<br class="">
I'm not releasing the full code yet since
it's very much work in<br class="">
progress, but if anyone is interested in
such a thing, just ping me.<br class="">
The applications could range from using it
in existing code to just<br class="">
provide it for fast prototyping, e.g., in
llvmcpy [3].<br class="">
<br class="">
Obviously there are some open questions,
such as how to deal with<br class="">
operands, which could lead to an infinite
tree, or how to organize<br class="">
attributes. But it should be doable.<br
class="">
<br class="">
---<br class="">
Alessandro Di Federico<br class="">
PhD student at Politecnico di Milano<br
class="">
<br class="">
[1] <a
href="https://en.wikipedia.org/wiki/XPath"
rel="noreferrer" target="_blank"
class="" moz-do-not-send="true">https://en.wikipedia.org/wiki/<wbr
class="">XPath</a><br class="">
[2] <a href="https://pugixml.org/"
rel="noreferrer" target="_blank"
class="" moz-do-not-send="true">https://pugixml.org/</a><br
class="">
[3] <a
href="https://github.com/revng/llvmcpy"
rel="noreferrer" target="_blank"
class="" moz-do-not-send="true">https://github.com/revng/<wbr
class="">llvmcpy</a><br class="">
<br class="">
______________________________<wbr
class="">_________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org"
class="" moz-do-not-send="true">llvm-dev@lists.llvm.org</a><br
class="">
<a
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"
rel="noreferrer" target="_blank"
class="" moz-do-not-send="true">http://lists.llvm.org/cgi-bin/<wbr
class="">mailman/listinfo/llvm-dev</a><br
class="">
<br class="">
</blockquote>
</div>
</div>
_______________________________________________<br
class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org"
class="" moz-do-not-send="true">llvm-dev@lists.llvm.org</a><br
class="">
<a
href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"
class="" moz-do-not-send="true">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br
class="">
</div>
</blockquote>
</div>
<br class="">
<div class="">
<div style="letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; word-wrap:
break-word; -webkit-nbsp-mode: space;
-webkit-line-break: after-white-space;" class="">
<div style="letter-spacing: normal; text-align:
start; text-indent: 0px; text-transform: none;
white-space: normal; word-spacing: 0px;
-webkit-text-stroke-width: 0px; word-wrap:
break-word; -webkit-nbsp-mode: space;
-webkit-line-break: after-white-space;" class="">--
Dean</div>
</div>
</div>
<br class="">
</div>
</div>
_______________________________________________<br
class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" class=""
moz-do-not-send="true">llvm-dev@lists.llvm.org</a><br
class="">
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br
class="">
</div>
</blockquote>
</div>
<br class="">
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<br>
</body>
</html>