<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Some more information on what I have so far. I'll actually focus on the longjmp side, as the problem is probably easier.
<div><br>
</div>
<div>I need to get the SETHI / OR combination inserted where the comment "<span style="font-size: 13.3333px;"><font face="Courier New">*** Need to use the SETHI / OR combination here. ***</font>" appears in the code below, but I'm not sure that this is done
anywhere near this piece of code, so I'll include all the relevant parts that I can find of my current implementation.</span><br>
<div><br>
</div>
<div>First, some def's in SparcInstrInfo.td:</div>
<div><br>
</div>
<div>
<div><font face="Courier New">def SPsjlj_longjmp: SDNode<"SPISD::EH_SJLJ_LONGJMP",</font></div>
<div><font face="Courier New"> SDTSPeh_sjlj_longjmp,</font></div>
<div><font face="Courier New"> [SDNPHasChain, SDNPSideEffect]>;</font></div>
</div>
<div><font face="Courier New"><br>
</font>
<div>
<div><font face="Courier New">let hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {</font></div>
<div><span style="font-size: 10pt;"><font face="Courier New"> let isTerminator = 1 in</font></span></div>
<div><font face="Courier New"> def EH_SJLJ_LONGJMP32ri : Pseudo<(outs), (ins MEMri:$buf),</font></div>
<div><font face="Courier New"> "#EH_SJLJ_LONGJMP32",</font></div>
<div><font face="Courier New"> [(SPsjlj_longjmp ADDRri:$buf)]>,</font></div>
<div><font face="Courier New"> Requires<[Is32Bit]>;</font></div>
<div><font face="Courier New"> def EH_SJLJ_LONGJMP32rr : Pseudo<(outs), (ins MEMrr:$buf),</font></div>
<div><font face="Courier New"> "#EH_SJLJ_LONGJMP32",</font></div>
<div><font face="Courier New"> [(SPsjlj_longjmp ADDRrr:$buf)]>,</font></div>
<div><font face="Courier New"> Requires<[Is32Bit]>;</font></div>
<div><font face="Courier New">}</font></div>
</div>
<div><br>
</div>
<div>SparcISelLowering.cpp, of course, sets this as<font face="Courier New"> <span style="font-size: 10pt;">setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom);</span></font></div>
<div><span style="font-size: 10pt;"><br>
</span></div>
<div><span style="font-size: 10pt;">I also have these functions in SparcISelLowering.cpp:</span></div>
<div><span style="font-size: 10pt;"><font face="Courier New"><br>
</font></span></div>
<div>
<div><font face="Courier New">SDValue SparcTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG,</font></div>
<div><font face="Courier New"> const SparcTargetLowering &TLI, bool hasHardQuad) const {</font></div>
<div><font face="Courier New"> SDLoc DL(Op);</font></div>
<div><font face="Courier New"> return DAG.getNode(SPISD::EH_SJLJ_LONGJMP, DL, MVT::Other, Op.getOperand(0));</font></div>
<div><font face="Courier New">}</font></div>
<div style="font-size: 10pt;"><font face="Courier New"><br>
</font></div>
</div>
<div>
<div><font face="Courier New">MachineBasicBlock * SparcTargetLowering::</font></div>
<div><font face="Courier New">EmitInstrWithCustomInserter(MachineInstr *MI,</font></div>
<div><font face="Courier New"> MachineBasicBlock *BB) const</font></div>
<div><font face="Courier New">{</font></div>
<div><font face="Courier New"> switch (MI->getOpcode()) {</font></div>
<div><span style="font-size: 10pt;"><font face="Courier New">... [ Other code first]</font></span></div>
<div><span style="font-size: 10pt;"><font face="Courier New"> case SP::EH_SJLJ_LONGJMP32rr:</font></span></div>
<div><font face="Courier New"> case SP::EH_SJLJ_LONGJMP32ri:</font></div>
<div><font face="Courier New"> return emitEHSjLjLongJmp(MI, BB);</font></div>
<div><font face="Courier New"> }</font></div>
<div><font face="Courier New">}</font></div>
<div><font face="Courier New"><br>
</font></div>
<div>
<div><font face="Courier New">MachineBasicBlock* SparcTargetLowering::</font></div>
<div><font face="Courier New">emitEHSjLjLongJmp(MachineInstr *MI,</font></div>
<div><font face="Courier New"> MachineBasicBlock *MBB) const</font></div>
<div><font face="Courier New">{</font></div>
<div><font face="Courier New"> DebugLoc DL = MI->getDebugLoc();</font></div>
<div><font face="Courier New"> const TargetInstrInfo *TII = Subtarget->getInstrInfo();</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New"> MachineFunction *MF = MBB->getParent();</font></div>
<div><font face="Courier New"> MachineRegisterInfo &MRI = MF->getRegInfo();</font></div>
<div><font face="Courier New"> MachineInstrBuilder MIB;</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New"> // Memory Reference</font></div>
<div><font face="Courier New"> MachineInstr::mmo_iterator MMOBegin = MI->memoperands_begin();</font></div>
<div><font face="Courier New"> MachineInstr::mmo_iterator MMOEnd = MI->memoperands_end();</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New"> MVT PVT = getPointerTy(MF->getDataLayout());</font></div>
<div><font face="Courier New"> unsigned PtrSize = PVT.getStoreSize();</font></div>
<div><font face="Courier New"> assert(PVT == MVT::i32 && "Invalid Pointer Size!");</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New"> unsigned ArgReg = MI->getOperand(0).getReg();</font></div>
<div><font face="Courier New"> unsigned Buf = MRI.createVirtualRegister(&SP::IntRegsRegClass);</font></div>
<div><font face="Courier New"> unsigned JmpLoc = MRI.createVirtualRegister(&SP::IntRegsRegClass);</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New"> // *** Need to use the SETHI / OR combination here. ***</font></div>
<div><font face="Courier New"> </font></div>
<div><font face="Courier New">// MIB = BuildMI(*MBB, MI, DL, TII->get(SP::ORri))</font></div>
<div><font face="Courier New">// .addReg(Buf)</font></div>
<div><font face="Courier New">// .addReg(ArgReg)</font></div>
<div><font face="Courier New">// .addImm(0);</font></div>
<div><font face="Courier New">// MIB.setMemRefs(MMOBegin, MMOEnd);</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New"> // Instruction to load jmp location</font></div>
<div><font face="Courier New"> MIB = BuildMI(*MBB, MI, DL, TII->get(SP::LDri))</font></div>
<div><font face="Courier New"> .addReg(JmpLoc)</font></div>
<div><font face="Courier New"> .addReg(Buf)</font></div>
<div><font face="Courier New"> .addImm(PtrSize);</font></div>
<div><font face="Courier New"> MIB.setMemRefs(MMOBegin, MMOEnd);</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New"> // TO DO: If we do 64-bit handling, this perhaps should be FLUSHW, not TA 3</font></div>
<div><font face="Courier New"> const long int TRAP_COND_ALWAYS = 0x08;</font></div>
<div><font face="Courier New"> MIB = BuildMI(*MBB, MI, DL, TII->get(SP::TRAPri), SP::G0).addImm(3).addImm(TRAP_COND_ALWAYS);</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New"> // Instruction to restore FP</font></div>
<div><font face="Courier New"> const unsigned FP = SP::I6;</font></div>
<div><font face="Courier New"> MIB = BuildMI(*MBB, MI, DL, TII->get(SP::LDri))</font></div>
<div><font face="Courier New"> .addReg(FP)</font></div>
<div><font face="Courier New"> .addReg(Buf)</font></div>
<div><font face="Courier New"> .addImm(0);</font></div>
<div><font face="Courier New"> MIB.setMemRefs(MMOBegin, MMOEnd);</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New"> // Instruction to restore SP</font></div>
<div><font face="Courier New"> const unsigned SP = SP::O6;</font></div>
<div><font face="Courier New"> MIB = BuildMI(*MBB, MI, DL, TII->get(SP::LDri))</font></div>
<div><font face="Courier New"> .addReg(SP)</font></div>
<div><font face="Courier New"> .addReg(Buf)</font></div>
<div><font face="Courier New"> .addImm(2 * PtrSize);</font></div>
<div><font face="Courier New"> MIB.setMemRefs(MMOBegin, MMOEnd);</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New"> // Instruction to restore I7</font></div>
<div><font face="Courier New"> MIB = BuildMI(*MBB, MI, DL, TII->get(SP::LDri))</font></div>
<div><font face="Courier New"> .addReg(SP::I7)</font></div>
<div><font face="Courier New"> .addReg(Buf)</font></div>
<div><font face="Courier New"> .addImm(3 * PtrSize);</font></div>
<div><font face="Courier New"> MIB.setMemRefs(MMOBegin, MMOEnd);</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New"> // Jump to I7</font></div>
<div><font face="Courier New"> BuildMI(*MBB, MI, DL, TII->get(SP::JMPLrr)).addReg(SP::G0).addReg(JmpLoc).addReg(SP::G0);</font></div>
<div><font face="Courier New"><br>
</font></div>
<div><font face="Courier New"> MI->eraseFromParent();</font></div>
<div><font face="Courier New"> return MBB;</font></div>
<div><font face="Courier New">}</font></div>
</div>
<div><br>
</div>
<div><br>
</div>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div id="divRpF129997" style="direction: ltr;"><font face="Tahoma" size="2" color="#000000"><b>From:</b> Chris.Dewhurst<br>
<b>Sent:</b> 15 April 2016 15:15<br>
<b>To:</b> llvm-dev@lists.llvm.org<br>
<b>Subject:</b> [Sparc] Load address with SETHI<br>
</font><br>
</div>
<div></div>
<div>
<div style="direction:ltr; font-family:Tahoma; color:#000000; font-size:10pt">Hi,
<div><br>
</div>
<div>I'm trying to implement __builtin_setjmp / __builtin_longjmp for Sparc processors. I think I'm very close, but I can't work out how to issue BuildMI-type instructions to load the address of the recovery location (set in setjmp) into a register using the
SETHI / OR combination. I can't see any equivalent code anywhere else in Sparc.</div>
<div><br>
</div>
<div>I imagine this is similar if I try to make a CALLRi or CALLrr call, but looking through the code there isn't yielding any obvious solution to me.</div>
<div><br>
</div>
<div>Would anyone be able to point me at a relevant piece of code that can do this, or is already doing it for Sparc?</div>
<div><br>
</div>
<div>Best Regards,</div>
<div>Chris Dewhurst / Lero, University of Limerick, Ireland.</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>