<div dir="ltr"><div>For your purposes, would it be possible to have a target specific IR pass before SelectionDAG that finds the information you care about and creates the inline assembly instruction that you need? Or maybe some other target specific intrinsic that captures the information in a form your backend could use?</div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Feb 1, 2021 at 11:58 AM Alex Susu <<a href="mailto:alex.e.susu@gmail.com">alex.e.susu@gmail.com</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">   Hi, Craig,<br>
     The added map to the SelectionDAG class was meant to help my own back end.<br>
     The crtNodeMapPtr map is not meant as it is to model the case with several SDValues <br>
that represent a Value* (the example with StructType you provide). If we would be <br>
interested to care about this case then maybe we should use C++'s std::unordered_multimap <br>
instead of a DenseMap - would you be interested in having that changed like this:<br>
     std::unordered_multimap<const Value*, SDValue> *crtNodeMapPtr ?<br>
<br>
     I have to add that I do not care about such complex cases as the one from your <br>
example: I have only 2 assembler instructions that check for crtNodeMapPtr (just for <br>
information, one Connex vector instruction is called VLOAD and the other REPEAT).<br>
<br>
<br>
     Please note that I also changed besides the source file <br>
lib/CodeGen/SelectionDAG/SelectionDAG.cpp, the following source files a bit (please see <br>
<a href="https://reviews.llvm.org/D60052#change-SowgZab8ZLD7" rel="noreferrer" target="_blank">https://reviews.llvm.org/D60052#change-SowgZab8ZLD7</a>):<br>
       lib/CodeGen/SelectionDAG/DAGCombiner.cpp<br>
       lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h<br>
       lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp<br>
<br>
   Thank you very much,<br>
     Alex<br>
<br>
<br>
On 1/31/2021 9:26 PM, Craig Topper wrote:<br>
> Hi Alex,<br>
> <br>
> I'm not sure I understand how this map works. A single Value * may have a StructType which <br>
> is initially represented by a MERGE_VALUES node. But that node will be removed in <br>
> DAGCombine by connecting each operand of the MERGE_VALUES to the users of each of the <br>
> results. At that point there is no single SDValue that represents the Value *. How does <br>
> the map model this?<br>
> <br>
> ~Craig<br>
> <br>
> <br>
> On Sun, Jan 31, 2021 at 10:38 AM Alex Susu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <br>
> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>> wrote:<br>
> <br>
>         Hello, llvm-dev.<br>
>           I am trying to commit in the following weeks the back end I wrote for our research<br>
>     lab's Connex SIMD processor, a promising vector processor which we hope to make it<br>
>     visible<br>
>     (please see if you have the time these links related to the Connex processor:<br>
>     <a href="https://dl.acm.org/doi/10.1145/3406536" rel="noreferrer" target="_blank">https://dl.acm.org/doi/10.1145/3406536</a> <<a href="https://dl.acm.org/doi/10.1145/3406536" rel="noreferrer" target="_blank">https://dl.acm.org/doi/10.1145/3406536</a>>,<br>
>     <a href="http://users.dcae.pub.ro/~gstefan/2ndLevel/functional_electronics.html" rel="noreferrer" target="_blank">http://users.dcae.pub.ro/~gstefan/2ndLevel/functional_electronics.html</a><br>
>     <<a href="http://users.dcae.pub.ro/~gstefan/2ndLevel/functional_electronics.html" rel="noreferrer" target="_blank">http://users.dcae.pub.ro/~gstefan/2ndLevel/functional_electronics.html</a>> ).<br>
> <br>
>           But, since our back end has the exotic feature of handling symbolic immediate<br>
>     assembler operands to achieve vector-length portability by using JIT assembling I had to<br>
>     make a small change to the SelectionDAG class which I now would like to commit on Github.<br>
> <br>
>           So I come to ask you what do you think about adding this useful small feature in<br>
>     the<br>
>     SelectionDAG class (a DenseMap<const Value*, SDValue> *crtNodeMapPtr datastructure and a<br>
>     bit of book-keeping for it).<br>
> <br>
>           From <a href="https://reviews.llvm.org/D60052#change-7t38wfUuDjbR" rel="noreferrer" target="_blank">https://reviews.llvm.org/D60052#change-7t38wfUuDjbR</a><br>
>     <<a href="https://reviews.llvm.org/D60052#change-7t38wfUuDjbR" rel="noreferrer" target="_blank">https://reviews.llvm.org/D60052#change-7t38wfUuDjbR</a>> (my previous attempt to<br>
>     commit the Connex backend):<br>
>           >      As written at<br>
>     <a href="http://lists.llvm.org/pipermail/llvm-dev/2019-May/132133.html" rel="noreferrer" target="_blank">http://lists.llvm.org/pipermail/llvm-dev/2019-May/132133.html</a><br>
>     <<a href="http://lists.llvm.org/pipermail/llvm-dev/2019-May/132133.html" rel="noreferrer" target="_blank">http://lists.llvm.org/pipermail/llvm-dev/2019-May/132133.html</a>>:<br>
>           >         There is one thing a bit more special with this back end, namely our back<br>
>           > end handles symbolic immediate operands (C/C++ expressions written as strings in<br>
>           INLINEASM MachineInstrs). This means the back end can output vector assembly<br>
>     code like:<br>
>           >         VLOAD Reg0, N * 10 + 5 // where N is a variable in the original C program,<br>
>             which means that to assign to register Reg0 the value N*10 + 5. This<br>
>     instruction is<br>
>     later JIT assembled (at runtime) in order to have a constant immediate operand equal to<br>
>     N*10 + 5<br>
>           >       Therefore, in order to support recovering from a SelectionDAG node to<br>
>     LLVM IR<br>
>     (and then all the way back to the original source C/C++ code), something possible with<br>
>     the<br>
>     current LLVM distribution, which is implemented in our Connex LLVM compiler project, we<br>
>     require adding a simple data structure in the LLVM source file:<br>
>           >           include/llvm/CodeGen/SelectionDAG.h (and helper methods in the related<br>
>           > SelectionDAG.cpp file)<br>
>           >         that maps an SDValue to the LLVM IR Value object it was used to translate<br>
>     from called:<br>
>           > DenseMap<const Value*, SDValue> *crtNodeMapPtr .<br>
> <br>
>           Roman Lebedev asked me about this new feature that I propose, at<br>
>     <a href="https://lists.llvm.org/pipermail/llvm-dev/2019-May/132136.html" rel="noreferrer" target="_blank">https://lists.llvm.org/pipermail/llvm-dev/2019-May/132136.html</a><br>
>     <<a href="https://lists.llvm.org/pipermail/llvm-dev/2019-May/132136.html" rel="noreferrer" target="_blank">https://lists.llvm.org/pipermail/llvm-dev/2019-May/132136.html</a>><br>
>           > I'm not sure how that is supposed to work. What if IR does not originate from C?<br>
>           > How do you verify that the "C string" is in the form that will be understood<br>
>           > by whatever will handle it later on? Is there a clang part of the patch?<br>
>          My answer to his question is: the IR originates from C and there is no clang patch,<br>
>     since there is no need to alter clang. To recover a C/C++ expression from SelectionDAG<br>
>     node to LLVM IR (and then all the way back to the original source C/C++ code) we only<br>
>     need<br>
>     to add this crtNodeMapPtr data structure. The recovery is performed by walking<br>
>     recursively<br>
>     on the LLVM IR code starting from the immediate operand of the assembler instruction<br>
>     until<br>
>     the end: the moment we visit an LLVM IR add instruction we simply put in the resulting<br>
>     C/C++ string we create a "+" operator.<br>
> <br>
>          This recovery from SelectionDAG node to LLVM IR and then to C/C++ is working very<br>
>     well<br>
>     in my LLVM build. It is well tested on a few tenths of small benchmarks.<br>
> <br>
>          Please let me know if you have any questions related to this proposed small<br>
>     change to<br>
>     the SelectionDAG class. You can find some more explanation on how we recover to C/C++ in<br>
>     my PhD thesis: see Section 4.1.8 ("Symbolic Scalar Immediate Operands") at<br>
>     <a href="https://sites.google.com/site/alexsusu/myfilecabinet/PhDThesis_AlexSusu.pdf" rel="noreferrer" target="_blank">https://sites.google.com/site/alexsusu/myfilecabinet/PhDThesis_AlexSusu.pdf</a><br>
>     <<a href="https://sites.google.com/site/alexsusu/myfilecabinet/PhDThesis_AlexSusu.pdf" rel="noreferrer" target="_blank">https://sites.google.com/site/alexsusu/myfilecabinet/PhDThesis_AlexSusu.pdf</a>> .<br>
> <br>
> <br>
>         Thank you,<br>
>           Alex<br>
>     _______________________________________________<br>
>     LLVM Developers mailing list<br>
>     <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<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>
>     <<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>
> <br>
</blockquote></div>