[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


Hi,

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())
      addPass(createThumb2SizeReductionPass());

    // Constant island pass work on unbundled instructions.
    addPass(&UnpackMachineBundlesID);
  }

  addPass(createARMConstantIslandPass());
  addPass(createARMPreEmitPass());//
<------------------------------- 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,
Sebastien



More information about the llvm-dev mailing list