[LLVMdev] ARM backend: How to insert a NOP, and prevent its optimization ?

sebastien riou matic at nimp.co.uk
Fri Jan 24 14:48:35 PST 2014


I have a MachineFunctionPass which should insert a NOP. To get
started, I inserted a mov r4,r4 with the line below:
AddDefaultPred(BuildMI(MBB, MBBI, dl, TII.get(ARM::tMOVr),
ARM::R4).addReg(ARM::R4, RegState::Kill));

Now how to modify that to insert a thumb2 NOP ? all my attempts end up
in seg faults...
Any special trick to garantee that the inserted NOP will not be
optimized away if another MachineFunctionPass execute after my pass ?

>From previous post, my understanding is that my pass "ARMPreEmitPass"
is not guaranteed to be the last to be executed, even if registered
like this:
bool ARMPassConfig::addPreEmitPass() {
  if (getARMSubtarget().isThumb2()) {
    if (!getARMSubtarget().prefers32BitThumb())

    // Constant island pass work on unbundled instructions.

<------------------------------- my custom stuff
  return true;

As far as I can see, it is always executed after ARMConstantIslandPass
when I run llc, but after that there are still a few passes:
0xb3895e0     Made Modification 'ARM pre-emit pass' on Function 'calleeSave8'...
0xb3895e0      Freeing Pass 'ARM pre-emit pass' on Function 'calleeSave8'...
0xb3895e0     Executing Pass 'MachineDominator Tree Construction' on
Function 'calleeSave8'...
0xb3895e0     Executing Pass 'Machine Natural Loop Construction' on
Function 'calleeSave8'...
0xb3895e0     Executing Pass 'ARM Assembly / Object Emitter' on
Function 'calleeSave8'...

What "MachineDominator ..." and "Machine Natural Loop ..." are doing ?
Are they a threat to any NOP that I would insert in my pass ?

Best regards,

More information about the llvm-dev mailing list