[llvm-dev] Need Help to find bug in DelaySlot filler pass

vivek pandya via llvm-dev llvm-dev at lists.llvm.org
Fri Apr 28 03:19:10 PDT 2017


Hello LLVM Devs,

I have implemented delay slot filler pass for an architecture but I am
getting problem in BasisBlock start label emission. Please provide some
hints to solve this bug.

For indirect branch with dealy slots for following case :
addk r29,r3,r0
br r27
.LBB0_9:

it generates follwoing:
brd r27
addk r29,r3,r0
# BB#9:

so after investigating it I found that it returns true from

bool AsmPrinter::
isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB)

because of no terminators in predecessor basic block
and so it does not print label in void AsmPrinter::EmitBasicBlockStart.

here is relevant code for my delay slot filler pass which is very similar
to
Sparc PC's delay slot filler pass.

bool Filler::runOnMachineBasicBlock(MachineBasicBlock &MBB) {
  bool Changed = false;
  Subtarget = &MBB.getParent()->getSubtarget<XXXSubtarget>();
  const TargetInstrInfo *TII = Subtarget->getInstrInfo();

  for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end(); ) {
    MachineBasicBlock::iterator MI = I;
    ++I;

    // If MI has no delay slot, skip.
    if (!MI->hasDelaySlot())
      continue;

    MachineBasicBlock::iterator D = MBB.end();

    if (!DisableDelaySlotFiller)
      D = findDelayInstr(MBB, MI);

    ++FilledSlots;
    Changed = true;

    if (D == MBB.end()) {
      BuildMI(MBB, I, MI->getDebugLoc(), TII->get(XXX::NOP));
    } else {
      MBB.splice(I, &MBB, D);
    }

    MIBundleBuilder(MBB, MI, --I);
  }
  return Changed;
}

MachineBasicBlock::iterator
Filler::findDelayInstr(MachineBasicBlock &MBB,
                       MachineBasicBlock::iterator slot)
{
  SmallSet<unsigned, 32> RegDefs;
  SmallSet<unsigned, 32> RegUses;
  bool sawLoad = false;
  bool sawStore = false;

  if (slot == MBB.begin())
    return MBB.end();

    insertDefsUses(slot, RegDefs, RegUses);

  bool done = false;

  MachineBasicBlock::iterator I = slot;

  while (!done) {
    done = (I == MBB.begin());

    if (!done)
      --I;

    // skip debug value
    if (I->isDebugValue())
      continue;

    if (I->hasUnmodeledSideEffects() || I->hasDelaySlot() ||
isDelayFiller(MBB, I) || hasImmInstruction(I) ||  I->isBranch()
        || I->isCall() || I->isReturn() || I->isBarrier() ||
I->isInlineAsm())
      break;

    if (delayHasHazard(I, sawLoad, sawStore, RegDefs, RegUses)) {
      insertDefsUses(I, RegDefs, RegUses);
      continue;
    }

    return I;
  }
  return MBB.end();
}

Sincerely,
Vivek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170428/fa553d18/attachment.html>


More information about the llvm-dev mailing list