<div dir="ltr">Are multi-output patterns in TableGen supposed to work, or is that a known limitation in the current implementation?<div><br></div><div>If I have TableGen code like the following...</div><div><br></div><div>
<div><font face="courier new, monospace">1242 def SDTTestNode : SDTypeProfile<2, 1, [SDTCisSameAs<0, 1>]>;</font></div><div><font face="courier new, monospace">1243 def TestNode : SDNode<"NVPTXISD::TestNode", SDTTestNode>;</font></div>
<div><font face="courier new, monospace">1244 </font></div><div><font face="courier new, monospace">1245 def MyTestNode : NVPTXInst<(outs Int32Regs:$dst0, Int32Regs:$dst1),</font></div><div><font face="courier new, monospace">1246 (ins Int32Regs:$a),</font></div>
<div><font face="courier new, monospace">1247 "test $dst0, $dst1, $a;",</font></div><div><font face="courier new, monospace">1248 [(set Int32Regs:$dst0, Int32Regs:$dst1, (TestNode Int32Regs:$a))]>;</font></div>
<div><br></div><div style>... TableGen crashes with the following stack trace:</div><div><br></div><div><div><font face="courier new, monospace">#0 0x00007fff8f372212 in __pthread_kill ()</font></div><div><font face="courier new, monospace">#1 0x00007fff8dc0eaf4 in pthread_kill ()</font></div>
<div><font face="courier new, monospace">#2 0x00000001003a978b in raise (sig=6) at Signals.inc:345</font></div><div><font face="courier new, monospace">#3 0x00000001003a9842 in abort () at Signals.inc:362</font></div><div>
<font face="courier new, monospace">#4 0x00000001003a9821 in __assert_rtn (func=0x1003d0d14 "operator[]", file=0x1003b169e "/Users/jholewinski/projects/llvm/src/llvm/include/llvm/ADT/SmallVector.h", line=139, expr=0x1003b16e7 "begin() + idx < end()") at Signals.inc:358</font></div>
<div><font face="courier new, monospace">#5 0x00000001000ca394 in llvm::SmallVectorTemplateCommon<llvm::EEVT::TypeSet, void>::operator[] (this=0x10384fed0, idx=1) at SmallVector.h:139</font></div><div><font face="courier new, monospace">#6 0x00000001000c965b in llvm::TreePatternNode::getExtType (this=0x10384fed0, ResNo=1) at CodeGenDAGPatterns.h:349</font></div>
<div><font face="courier new, monospace">#7 0x00000001000bd615 in llvm::CodeGenDAGPatterns::ParseInstructions (this=0x7fff5fbff0b0) at /Users/jholewinski/projects/llvm/src/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:2782</font></div>
<div><font face="courier new, monospace">#8 0x00000001000b7143 in llvm::CodeGenDAGPatterns::CodeGenDAGPatterns (this=0x7fff5fbff0b0, R=@0x7fff5fbff670) at /Users/jholewinski/projects/llvm/src/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:2077</font></div>
<div><font face="courier new, monospace">#9 0x00000001000b6a3d in llvm::CodeGenDAGPatterns::CodeGenDAGPatterns (this=0x7fff5fbff0b0, R=@0x7fff5fbff670) at /Users/jholewinski/projects/llvm/src/llvm/utils/TableGen/CodeGenDAGPatterns.cpp:2091</font></div>
<div><font face="courier new, monospace">#10 0x000000010024cd15 in InstrInfoEmitter (this=0x7fff5fbff0a8, R=@0x7fff5fbff670) at /Users/jholewinski/projects/llvm/src/llvm/utils/TableGen/InstrInfoEmitter.cpp:39</font></div>
<div><font face="courier new, monospace">#11 0x0000000100248e8d in InstrInfoEmitter (this=0x7fff5fbff0a8, R=@0x7fff5fbff670) at /Users/jholewinski/projects/llvm/src/llvm/utils/TableGen/InstrInfoEmitter.cpp:39</font></div>
<div><font face="courier new, monospace">#12 0x0000000100248e36 in llvm::EmitInstrInfo (RK=@0x7fff5fbff670, OS=@0x7fff5fbff518) at /Users/jholewinski/projects/llvm/src/llvm/utils/TableGen/InstrInfoEmitter.cpp:420</font></div>
<div><font face="courier new, monospace">#13 0x00000001002d0930 in LLVMTableGenMain (OS=@0x7fff5fbff518, Records=@0x7fff5fbff670) at /Users/jholewinski/projects/llvm/src/llvm/utils/TableGen/TableGen.cpp:106</font></div><div>
<font face="courier new, monospace">#14 0x00000001002e8385 in llvm::TableGenMain (argv0=0x7fff5fbffa88 "/Users/jholewinski/projects/llvm/build/bin/llvm-tblgen", MainFn=0x1002d0880 <LLVMTableGenMain>) at /Users/jholewinski/projects/llvm/src/llvm/lib/TableGen/Main.cpp:117</font></div>
<div><font face="courier new, monospace">#15 0x00000001002d0864 in main (argc=11, argv=0x7fff5fbff8f8) at /Users/jholewinski/projects/llvm/src/llvm/utils/TableGen/TableGen.cpp:181</font></div><div><br></div><div><br></div>
<div style>The fault occurs in CodeGenDAGPatterns.cpp:</div><div style><br></div><div style><div><font face="courier new, monospace">2781 for (unsigned i = 0; i != NumResults; ++i)</font></div><div><font face="courier new, monospace">2782 ResultPattern->setType(i, Res0Node->getExtType(i));</font></div>
</div><div><br></div><div style>Res0Node has only 1 type, but it is expected to have 2.</div><div style><br></div><div style><br></div><div style>Looking at the X86 back-end code, it looks like there do exist multi-output instructions, but they all use physical (implicit) registers for the second destination, not arbitrary register types. And if I change the second destination to be a certain physical register, this problem goes away in my code. Is this just not a supported case currently? Or am I doing something wrong?</div>
<div style><br></div><div style>This is my first time looking into the TableGen internals, so I can't spot anything obviously wrong with the TableGen tool code.</div><div style><br></div>-- <br><br><div>Thanks,</div><div>
<br></div><div>Justin Holewinski</div>
</div></div></div>