<div dir="ltr"><div><div><div><div><div><div>I'm struggling for a while with the following problem:<br></div>I have added couple of intrinsics which output result to the global register.<br>They have form of: void intrinsic1(int,int) void intrinsic2(int,int,int).<br>
Hence, they were getting removed from DAG on the first combine.<br></div>I was able to enforce their place in DAG by creating control flow dependency between them.<br></div><br>That solved all problems in DAG, but llc fails in assert at InstrPrinter call. Debugging shows that for 1-arg instruction, InstrPrinter tries to access second arg.<br>
</div>So, it looks like adding root to DAG node as first arg of type MVT::Other breaks accordance with respective instruction.<br><br></div>Now, I'm gonna get more specific and provide some code.<br></div><div>Instrisic looks in IR like that: call void @llvm.sparc.srxacc(i32 %0)<br>
<br></div>Creating node in SelectionDAGBuilder::visitIntrinsicCall:<br><br><div><div><div><div><div><div><div><div> case Intrinsic::sparc_srxacc: {<br> SDVTList nodeTys = DAG.getVTList(MVT::Other, MVT::i32);<br> SDValue Ops[2];<br>
Ops[0] = getControlRoot();<br> Ops[1] = getValue(I.getArgOperand(0));<br> SDValue srCall = DAG.getNode(ISD::SRXACC, sdl, nodeTys, Ops);<br> DAG.setRoot(srCall.getValue(0));<br> return nullptr;<br> }<br><br clear="all">
</div><div>Then, custom legalize it (SparcISelLowering):<br><br>static SDValue LowerSRXACC(SDValue Op, SelectionDAG &DAG,<br> const SparcTargetLowering &TLI) {<br> SDLoc dl(Op);<br> SDValue xacc = DAG.getRegister(SP::XACC, MVT::i32);<br>
SDVTList nodeTys = DAG.getVTList(MVT::Other, MVT::i32,<br> MVT::i32);<br> SDValue Ops[3];<br> Ops[0] = Op.getOperand(0);<br> Ops[1] = Op.getOperand(1);<br> Ops[2] = xacc;<br>
<br> return DAG.getNode(ISD::SRXACC, dl, nodeTys, Ops);<br>}<br><br></div><div>Then, select it (SparcISelDAGToDAG):<br><br> case ISD::SRXACC: {<br> SDVTList nodeTys = CurDAG->getVTList(MVT::i32);<br><br> SDValue Ops[2];<br>
Ops[0] = N->getOperand(1);<br> Ops[1] = N->getOperand(2);<br> return CurDAG->SelectNodeTo(N, SP::SRXACC, nodeTys,<br> Ops);<br> }<br><br></div><div>Corresponding instruction is:<br>
def SRXACC : F3_1<2, 0b011101,<br> (outs IntRegs:$rd), (ins IntRegs:$rs1),<br> "srxacc $rs1, $rd", []>;<br></div><div><br>Please, note:<br></div><div>My problem is of self-educational and investigative nature.<br>
</div><div>This instruction srxacc and register xacc are not real.<br></div><div>Produced code aren't supposed to work anywhere.<br></div><div>I just need llc to be able to output assembly file.<br></div><div>Thanks for your insights.<br>
</div><div><br></div><div>-- <br><div>Sincerely,</div><div>Dmitri Kovalenko</div>
</div></div></div></div></div></div></div></div></div>