<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">You’ve been watching us fumble around with manually creating vregs all this time and you didn’t mention that?!<div class=""><br class=""></div><div class=""><div><blockquote type="cite" class=""><div class="">On 30 Jan 2019, at 19:21, Aditya Nandakumar <<a href="mailto:proaditya@gmail.com" class="">proaditya@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">This is already possible.<div class="">To do the equivalent of what you mentioned, this should do it.</div><div class="">auto Add = Builder.buildAdd(LLT::scalar(32), Src1, Src);</div><div class="">auto Mul = Builder.buildMul(LLT::scalar(32), Add, Src3);</div><div class=""><br class=""></div><div class=""><br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 30, 2019 at 6:57 PM Amara Emerson via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class="">I agree that it’s annoying to have to create VRegs manually. I haven’t thought this through deeply but perhaps having a utility wrapper class to capture the destination regs of a newly built instruction could help, e.g. something like:<div class=""><font face="Menlo" class="">InstReg AddReg(MIRBuilder.buildAdd(LLT::scalar(32), Src1, Src));</font></div><div class=""><font face="Menlo" class="">InstReg MulReg(MIRBuilder.buildMul(LLT::scalar(32), AddReg.get(), Src3));</font></div><div class=""><font face="Menlo" class="">// etc etc</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class="">Where InstReg could be something like:</div><div class=""><font face="Menlo" class="">class InstReg {</font></div><div class=""><font face="Menlo" class=""> unsigned Reg = 0;</font></div><div class=""><font face="Menlo" class="">public:</font></div><div class=""><font face="Menlo" class=""> InstReg(MachineInstrBuilder &MIB) : Reg(MIB.getInstr().getOperand(0).getReg()) {}</font></div><div class=""><font face="Menlo" class=""> unsigned getReg() { return Reg; }</font></div><div class=""><font face="Menlo" class="">};</font></div><div class=""><div class=""><br class=""></div><div class="">This example only works for single dest reg instructions but could be extended for any number of regs.</div><div class=""><br class=""></div><div class="">Amara</div><div class=""><br class=""><blockquote type="cite" class=""><div class="">On 30 Jan 2019, at 18:43, Arsenault, Matthew via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="gmail-m_-4093945600506763570Apple-interchange-newline"><div class=""><div class="gmail-m_-4093945600506763570WordSection1" style="color:rgb(255,255,255);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none"><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">I’m less interested in literally passing the output of one as an argument to the next such that argument evaluation order matters. Intermediate register variables are fine. It would still be less code to have tmp = buildFoo(), buildFoo(tmp) than the current code required to manage the register<u class=""></u><u class=""></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><u class=""></u> <u class=""></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">-Matt<u class=""></u><u class=""></u></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><u class=""></u> <u class=""></u></div><div style="border-style:solid none none;border-top-width:1pt;border-top-color:rgb(181,196,223);padding:3pt 0in 0in" class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><b class=""><span style="font-size:12pt" class="">From:<span class="gmail-m_-4093945600506763570Apple-converted-space"> </span></span></b><span style="font-size:12pt" class=""><<a href="mailto:daniel_l_sanders@apple.com" target="_blank" class="">daniel_l_sanders@apple.com</a>> on behalf of Daniel Sanders <<a href="mailto:daniel_l_sanders@apple.com" target="_blank" class="">daniel_l_sanders@apple.com</a>><br class=""><b class="">Date:<span class="gmail-m_-4093945600506763570Apple-converted-space"> </span></b>Wednesday, January 30, 2019 at 9:32 PM<br class=""><b class="">To:<span class="gmail-m_-4093945600506763570Apple-converted-space"> </span></b>"Arsenault, Matthew" <<a href="mailto:Matthew.Arsenault@amd.com" target="_blank" class="">Matthew.Arsenault@amd.com</a>><br class=""><b class="">Cc:<span class="gmail-m_-4093945600506763570Apple-converted-space"> </span></b>llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>><br class=""><b class="">Subject:<span class="gmail-m_-4093945600506763570Apple-converted-space"> </span></b>Re: [llvm-dev] MachineIRBuilder API<u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><u class=""></u> <u class=""></u></div></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">Hi Matt,<span class="gmail-m_-4093945600506763570Apple-converted-space"> </span><u class=""></u><u class=""></u></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><u class=""></u> <u class=""></u></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">Personally, I like that it follows the same pattern as MachineInstrBuilder used elsewhere in MIR. It would certainly be nice to create whole expressions at once though.<u class=""></u><u class=""></u></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><u class=""></u> <u class=""></u></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">I believe that nested SelectionDAG-style get*() functions have an ordering problem when used for MIR that wasn't a problem for SelectionDAG due to the difference in underlying representation. The DAG didn't really care which evaluation order happened as the de-duplication and unordered nature of the DAG produced the same result either way. For MIR, each builder needs to insert into a linear list so the evaluation order of those insertions matters. For example:<u class=""></u><u class=""></u></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">getAdd(getSub(a, b), getMul(c, d))<u class=""></u><u class=""></u></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">could produce either:<u class=""></u><u class=""></u></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">%0 = G_SUB %a, %b<u class=""></u><u class=""></u></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">%1 = G_MUL %c, %d<u class=""></u><u class=""></u></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">%2 = G_ADD %0, %1<u class=""></u><u class=""></u></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">or:<u class=""></u><u class=""></u></div></div><div class=""><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">%0 = G_MUL %c, %d<u class=""></u><u class=""></u></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">%1 = G_SUB %a, %b<u class=""></u><u class=""></u></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">%2 = G_ADD %1, %0<u class=""></u><u class=""></u></div></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">depending on the (indeterminate) evaluation order of the arguments to getAdd(). The G_ADD is always last because getSub() and getMul() must execute before getAdd() but AFAIK there's nothing that controls the relative order that getSub() and getMul() are evaluated and inserted beyond saying that they aren't interleaved. If I'm interpreting<span class="gmail-m_-4093945600506763570Apple-converted-space"> </span><a href="https://en.cppreference.com/w/cpp/language/eval_order" style="color:purple;text-decoration:underline" target="_blank" class="">https://en.cppreference.com/w/cpp/language/eval_order</a> correctly, C++17 makes it more explicit than the old rules (rule 15 in particular).<u class=""></u><u class=""></u></div></div><div class=""><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><br class=""><br class=""><u class=""></u><u class=""></u></div><blockquote style="margin-top:5pt;margin-bottom:5pt" type="cite" class=""><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">On Jan 30, 2019, at 16:55, Arsenault, Matthew via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" style="color:purple;text-decoration:underline" target="_blank" class="">llvm-dev@lists.llvm.org</a>> wrote:<u class=""></u><u class=""></u></div></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><u class=""></u> <u class=""></u></div><div class=""><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">Hi,<span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""> <span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">I’m finding the API for MachineIRBuilder to be pretty annoying to use compared to SelectionDAG. I think it’s making the majority of code more verbose and unwieldly for anything less than trivial. I think changing it to behave more like the DAG.get* functions would make it easier to use, and decrease the mental overhead when porting code from SelectionDAG.<span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""> <span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">The main issue is needing to create and/or manage the registers used separately from the instruction creation. Normally you have to create a generic virtual register with the correct output type. When a lot of intermediate values are needed, this can get pretty messy. There is an alternative provided, but I don’t think it’s really any better. You can construct a DstOp from an LLT, which will create a new register. You would then need to use the returned instruction, get the destination register from the output and use that. This doesn’t allow you to naturally compose operations by using the return value of a build* function to another. I also find this aspect to be pretty error prone, as I discovered it by accident when the registers I had already created weren’t being used.<span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""> <span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">The current set of build* functions all return MachineInstrBuilder, or effectively the inserted instruction. This seems reasonable for some odd low level cases where you are building an instruction that won’t be inserted yet, or you don’t know the operands ahead of time. For the majority of code, I don’t see how this is useful. Most places should be using a buildFooInstr type of instruction, which creates and inserts a specific opcode (or set of similar behaving opcodes) with all of the necessary operands. The instruction is already inserted, and can’t have additional operands added, so there isn’t really anything to do with it.<span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""> <span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">It would be more helpful if these were returning the register / logical value, similar to what you get with DAG.getNode(). In the odd case you actually want the instruction, you could check the instruction before the insert point.<span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""> <span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">Does anyone feel strongly that these functions should be returning the builder? What I would like to do is either replace and complete the current set of buildOpcode functions with ones which return the output register value, or add an alternative set which do. Is it worth having two sets of functions (a buildFoo and getFoo set?). The same issue applies with opcodes producing multiple results, such as buildUnmerge, but in that case I would probably change these to a SmallVectorImpl out argument.<span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""> <span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">Another minor issue I’ve run into is when trying to add convenience functions with constants (e.g. shift creation with materializing the amount constant). With an overload using a SrcOp constructible from “unsigned”, and one using an integer type, the wrong one gets called and ends up creating a constant with the value of the register. I think this is more a symptom of using a plain unsigned for registers, but fixing this longstanding mistake everywhere would be a very large project.<span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""> <span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div class=""><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class="">-Matt<span style="font-size:12pt" class=""><u class=""></u><u class=""></u></span></div></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><span style="font-size:9pt;font-family:Helvetica" class="">_______________________________________________<br class="">LLVM Developers mailing list<br class=""></span><a href="mailto:llvm-dev@lists.llvm.org" style="color:purple;text-decoration:underline" target="_blank" class=""><span style="font-size:9pt;font-family:Helvetica;color:rgb(149,79,114)" class="">llvm-dev@lists.llvm.org</span></a><span style="font-size:9pt;font-family:Helvetica" class=""><br class=""></span><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" style="color:purple;text-decoration:underline" target="_blank" class=""><span style="font-size:9pt;font-family:Helvetica;color:rgb(149,79,114)" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</span></a><u class=""></u><u class=""></u></div></div></blockquote></div><div style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:Calibri,sans-serif" class=""><u class=""></u> <u class=""></u></div></div></div></div><span style="color:rgb(255,255,255);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline" class="">_______________________________________________</span><br style="color:rgb(255,255,255);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none" class=""><span style="color:rgb(255,255,255);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline" class="">LLVM Developers mailing list</span><br style="color:rgb(255,255,255);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none" class=""><span style="color:rgb(255,255,255);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline" class=""><a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a></span><br style="color:rgb(255,255,255);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none" class=""><span style="color:rgb(255,255,255);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text-decoration:none;float:none;display:inline" class=""><a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></span></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
</blockquote></div><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div dir="ltr" class="gmail_signature">Regards,<br class="">Aditya<br class=""></div>
</div></blockquote></div><br class=""></div></body></html>