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::iterator MBBI; ← points to where the epilogue would be inserted
if (MBBI != MBB.begin() ? MBBI->getPrevNode()->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:
CALL … ← call I am trying to detect
EH_LABEL … <–| these two get eliminated in the final
JMP <–| 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?