<div dir="ltr"><div>There isn't really enough information here to understand exactly what you need, but it almost certainly won't require you to use ReplaceNode. <span style="font-family:monospace">ISelDAGToDAG</span> is a place where you do instruction selection and instruction selection needs machine SD nodes by definition - you can't have target independent nodes after selection. It really sounds like you are interested in writing a DAGCombine transformation. Of course, it is possible that you need a specific custom legalization which is a little different, but I will assume you need a DAG combine as your question sounds the most like a DAG combine.</div><div><br></div><div>The way you would accomplish this is to mark the input node as one for which you have a DAG combine. You accomplish this using <span style="font-family:monospace">setTargetDAGCombine(<node>)</span>. Looks like RISCV has a handful of nodes for which they have combines. Then in <span style="font-family:monospace">RISCVTargetLowering::PerformDAGCombine()</span>, you will add your node to the switch and dispatch to the function that performs your DAG combine. You can follow the example of <span style="font-family:monospace">ISD::AND in RISCVISelLowering.cpp</span> which gets combined in <span style="font-family:monospace">performANDCombine()</span>.</div><div><br></div><div>I hope this helps, but I realize that I may be completely off in terms of what you are after.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Aug 7, 2021 at 12:05 PM Ben Shi 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"><div style="line-height:1.7;color:rgb(0,0,0);font-size:14px;font-family:Arial"><div style="margin:0px">Hello,</div><div style="margin:0px"><br></div><div style="margin:0px">I would like to make some DAG transform in RISCV's ISelDAGToDAG, but I find the ReplaceNode() requests</div><div style="margin:0px"><br></div><div style="margin:0px">the new Node to be a MachineNode( usually created be curDAG->getMachineNode with the opcode set to RISCV::xxxx).</div><div style="margin:0px"><br></div><div style="margin:0px">Can I just pass it a SDNode (with opcode set to anoher ISD::xxx, not RISCV::xxx) ? It seems LLVM will crash.</div><div style="margin:0px"><br></div><div style="margin:0px">Because I want to change the opcode to ADD, can I avoid the complexity of selecting ADDW/ADDI/ADDIW for a machine node in different cases?</div><div style="margin:0px"><br></div><div style="margin:0px">Ben Shi</div><div style="margin:0px"><br></div></div>_______________________________________________<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>