Hi All, For various obscure reasons I'd like to detect the condition when X86 CALL instruction immediately precedes a function epilogue in the final emitted code, and insert a NOP between them if that happens. My initial attempt at it looked like this: MachineBasicBlock& MBB; MachineBasicBlock::iterator MBBI; <-- points to where the epilogue would be inserted if (MBBI != MBB.begin() ? MBBI->getPrevNode()->isCall() : MBB.getPrevNode()->back().isCall()) { // insert NOP } However, this did not work because at the stage where I am trying to do this (in X86FrameLowering::emitEpilogue), the MBBs look like this: BB0: ... CALL ... <-- call I am trying to detect EH_LABEL ... <--| these two get eliminated in the final JMP <BB1> <--| emitted code. BB1: <-- the MBB RET <-- MBBI points here So the business of finding the previous "real" instruction is starting to look very complicated. I would need to skip over pseudo-instructions and somehow to deal with JMPs that will be eliminated later, and who knows what else... My question is, am I going about it in the wrong way? Is there an easier way to achieve what I need? thanks! Vadim -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140726/df7b912d/attachment.html>
I am currently trying to figure out where does LLVM eliminate extraneous JMPs, like the one below. Any hints? On Sat, Jul 26, 2014 at 12:19 PM, Vadim Chugunov <vadimcn at gmail.com> wrote:> Hi All, > > For various obscure reasons I'd like to detect the condition when X86 CALL > instruction immediately precedes a function epilogue in the final emitted > code, and insert a NOP between them if that happens. > > My initial attempt at it looked like this: > > MachineBasicBlock& MBB; > MachineBasicBlock::iterator MBBI; <-- points to where the epilogue would > be inserted > if (MBBI != MBB.begin() ? MBBI->getPrevNode()->isCall() : > > MBB.getPrevNode()->back().isCall()) { > // insert NOP > } > > However, this did not work because at the stage where I am trying to do > this (in X86FrameLowering::emitEpilogue), the MBBs look like this: > > BB0: > ... > CALL ... <-- call I am trying to detect > EH_LABEL ... <--| these two get eliminated in the final > JMP <BB1> <--| emitted code. > > BB1: <-- the MBB > RET <-- MBBI points here > > So the business of finding the previous "real" instruction is starting to > look very complicated. I would need to skip over pseudo-instructions and > somehow to deal with JMPs that will be eliminated later, and who knows what > else... > > My question is, am I going about it in the wrong way? Is there an > easier way to achieve what I need? > > thanks! > Vadim >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140728/21d72e41/attachment.html>
Hi Vadim, On 29 July 2014 04:02, Vadim Chugunov <vadimcn at gmail.com> wrote:> I am currently trying to figure out where does LLVM eliminate extraneous > JMPs, like the one below. Any hints?There are quite a few places that could be doing it in lib/CodeGen[1]. They all use the TargetInstrInfo hooks, though, so that's the place to start looking: AnalyzeBranch, RemoveBranch and InsertBranch. This particular one might be TailDuplication.cpp, but you should run "llc -print-after-all" to find out exactly which pass is doing it. Cheers. Tim.
Reasonably Related Threads
- [LLVMdev] [lldb-dev] RFC: LLVM should require a working C++11 <thread>, <mutex>, and <atomic>
- [LLVMdev] Emit code for 'unreachable'
- [LLVMdev] Argument Lowering Redux
- [LLVMdev] Emit code for 'unreachable'
- [LLVMdev] RFC: How to represent SEH (__try / __except) in LLVM IR