<div dir="ltr"><div><div><div><div><div><div><div><div>Hi Liad,<br></div>this question conflates a whole bunch of concepts at the heart of how SDAG, lowering, ISEL, etc. works. As such, it isn't likely that you'll get a particularly satisfying answer. Well formulated, targeted questions are likely to be answered in detail. Very general and vague questions such as this are not likely to receive a lot of attention from the community.<br><br></div>That being said, I think the first step would be for you to familiarize yourself with how instruction selection works. Eli has a couple of excellent blog posts regarding this:<br><a href="http://eli.thegreenplace.net/2012/11/24/life-of-an-instruction-in-llvm">http://eli.thegreenplace.net/2012/11/24/life-of-an-instruction-in-llvm</a><br><a href="http://eli.thegreenplace.net/2013/02/25/a-deeper-look-into-the-llvm-code-generator-part-1">http://eli.thegreenplace.net/2013/02/25/a-deeper-look-into-the-llvm-code-generator-part-1</a><br></div>I encourage you to look through those along with LLVM's own documentation for a target-independent code generator (<a href="http://llvm.org/docs/CodeGenerator.html">http://llvm.org/docs/CodeGenerator.html</a>). The right approach for what you're after should be quite clear once you have a thorough understanding of type/operation legalization, DAG combines and SDAG ISEL.<br><br></div>A bit more information about the actual question you asked...<br></div>The `LowerOperation` function is called during the lowering process for operations that are marked as 'Custom' through 'setOperationAction'. If an operation is marked `Expand`, the target-independent code will expand it to other operations that are likely to be available on most targets. And of course, if it is marked `Legal`, it goes straight to instruction selection unchanged.<br></div><br>Furthermore, the SDAG provides DAG Combines. These are meant to replace patterns/nodes that satisfy certain conditions with other patterns/nodes that are more likely to produce efficient code. Similarly to lowering, there's the target-independent version (in lib/CodeGen/SelectionDAG/DAGCombiner.cpp) and the target-specific versions (in your `PerformDAGCombine()`). The target-independent combines always run and you can tell the SDAG you want to try your target-specific combines for specific nodes by calling `setTargetDAGCombine()` for those nodes.<br><br></div>In effect, all of these processes replace "patterns" with other "patterns" (more specifically, [groups of] nodes with other [groups of] nodes). So can you replace a pattern with a different pattern through the .td files? Of course - all of ISEL is essentially replacing [Target]ISD nodes with machine SD nodes. The only limitation is that after ISEL, the DAG should only contain machine SD nodes, so if you want special handling post-isel, you should probably use pseudo-instructions.<br><br></div>Hope this helps.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 28, 2017 at 9:18 AM, Liad Mordekoviz via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello, <div>through my work on writing a backend, I've noticed that when I need to replace a pattern in the SelectionDAG with a different pattern the correct way to do it seems to be through the LowerOperation hook in the TargetLowering class.</div><div><br></div><div>I was wondering if there is some way to achieve the same thing using tablegen, thank you!</div></div>
<br>______________________________<wbr>_________________<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" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>