在放松期间发出伪指令

时间:2017-05-03 14:40:32

标签: llvm code-generation machine-code

在LLVM后端,我想发出伪指令作为真实(非伪)指令的放宽。问题是,我无法找到在我的TargetPassConfig中添加伪指令扩展器传递的方法,以便它将应用于我AsmBackend::relaxInstruction的输出。

MCAssembler::relaxInstruction,这似乎是放松的驱动因素,它将放松的结果直接传递给指令编码器:

bool MCAssembler::relaxInstruction(MCAsmLayout &Layout,
                                   MCRelaxableFragment &F) {
  if (!fragmentNeedsRelaxation(&F, Layout))
    return false;

  ++stats::RelaxedInstructions;

  // FIXME-PERF: We could immediately lower out instructions if we can tell
  // they are fully resolved, to avoid retesting on later passes.

  // Relax the fragment.

  MCInst Relaxed;
  getBackend().relaxInstruction(F.getInst(), F.getSubtargetInfo(), Relaxed);

  // Encode the new instruction.
  //
  // FIXME-PERF: If it matters, we could let the target do this. It can
  // probably do so more efficiently in many cases.
  SmallVector<MCFixup, 4> Fixups;
  SmallString<256> Code;
  raw_svector_ostream VecOS(Code);
  getEmitter().encodeInstruction(Relaxed, VecOS, Fixups, F.getSubtargetInfo());

  // Update the fragment.
  F.setInst(Relaxed);
  F.getContents() = Code;
  F.getFixups() = Fixups;

  return true;
}

对我来说,这意味着我自己&#34;我自己&#34;确保我的后端relaxInstruction没有发出任何伪指令。那么如何将我的伪指令扩展器传递挂钩到我的relaxInstruction

1 个答案:

答案 0 :(得分:1)

在目标CodeEmitter::encodeInstruction内,通常会调用getBinaryCodeForInstr。在此调用之前,您可以将伪指令扩展为两个真实的指令吗?