<div dir="ltr">Hi LLVM-dev,<div><br></div><div>I'm working on XRay, and one of the parts of it is the introduction of a couple of pseudo instructions -- one of which is PATCHABLE_RET, which wraps a return instruction (similar to how PATCHABLE_OP works).</div><div><br></div><div>In <a href="http://reviews.llvm.org/D19904">http://reviews.llvm.org/D19904</a>, I'm trying to find a way of making PATCHABLE_RET have a default implementation in platforms where they're not supported yet (i.e., not X86).</div><div><br></div><div>In my very limited research into this, I think I've narrowed it down to two places:</div><div><br></div><div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px">- SelectionDAGTargetInfo has some hooks for specific instructions to be lowered/handled. A default implementation could be to just unpack the operands from the PATCHABLE_* instructions. In particular I'm looking at potentially adding some more functions to <a href="https://github.com/llvm-mirror/llvm/blob/master/include/llvm/CodeGen/SelectionDAGTargetInfo.h">https://github.com/llvm-mirror/llvm/blob/master/include/llvm/CodeGen/SelectionDAGTargetInfo.h</a> specifically for the PATCHABLE_* instructions, and finding where the SelectionDAG stuff is invoked to special-case the PATCHABLE_* instructions.</div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px">- TargetLowering is another place where this might work. We can have special dispatch for the PATCHABLE_* instructions there, and also where we use a custom inserter. We can mark the instructions to use a custom inserter, have some overridable hooks in TargetLowering which by default just unpacks the operands into new MachineInstr instances, then override those in X86's specific lowering. Requisite link: <a href="http://llvm.org/docs/doxygen/html/classllvm_1_1TargetLowering.html">http://llvm.org/docs/doxygen/html/classllvm_1_1TargetLowering.html</a></div></div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px">Some questions:</div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px">1) Is this even something I need to worry about? Since PATCHABLE_RET is being inserted by a late MachineFunctionPass, it could just do this for a white-listed set of platforms. This seems not ideal.</div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px">2) Machine IR (mir) seems to be where PATCHABLE_RET might show up, and may need to be hand-crafted. Are the above two places the right places where these instructions could be intercepted, or am I missing something more fundamental?</div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px"><br></div><div style="color:rgb(33,33,33);font-family:'helvetica neue',helvetica,arial,sans-serif;font-size:13px">Thanks in advance!</div></div>