[BOLT] Add createCondBranch() and createLongUncondBranch() (#85315)

Add MCPlusBuilder interface for creating two new branch types.
This commit is contained in:
Maksim Panchenko
2024-03-14 15:28:22 -07:00
committed by GitHub
parent f9e557961e
commit 49b8a99a0f
2 changed files with 30 additions and 0 deletions

View File

@@ -1558,6 +1558,13 @@ public:
llvm_unreachable("not implemented");
}
/// Create a version of unconditional jump that has the largest span for a
/// single instruction with direct target.
virtual void createLongUncondBranch(MCInst &Inst, const MCSymbol *Target,
MCContext *Ctx) const {
llvm_unreachable("not implemented");
}
/// Creates a new call instruction in Inst and sets its operand to
/// Target.
virtual void createCall(MCInst &Inst, const MCSymbol *Target,
@@ -1675,6 +1682,12 @@ public:
return Inst.getOpcode() == TargetOpcode::CFI_INSTRUCTION;
}
/// Create a conditional branch with a target-specific conditional code \p CC.
virtual void createCondBranch(MCInst &Inst, const MCSymbol *Target,
unsigned CC, MCContext *Ctx) const {
llvm_unreachable("not implemented");
}
/// Reverses the branch condition in Inst and update its taken target to TBB.
///
/// Returns true on success.

View File

@@ -2734,6 +2734,14 @@ public:
MCSymbolRefExpr::create(TBB, MCSymbolRefExpr::VK_None, *Ctx)));
}
void createLongUncondBranch(MCInst &Inst, const MCSymbol *Target,
MCContext *Ctx) const override {
Inst.setOpcode(X86::JMP_4);
Inst.clear();
Inst.addOperand(MCOperand::createExpr(
MCSymbolRefExpr::create(Target, MCSymbolRefExpr::VK_None, *Ctx)));
}
void createCall(MCInst &Inst, const MCSymbol *Target,
MCContext *Ctx) override {
Inst.setOpcode(X86::CALL64pcrel32);
@@ -2759,6 +2767,15 @@ public:
Inst.setOpcode(X86::TRAP);
}
void createCondBranch(MCInst &Inst, const MCSymbol *Target, unsigned CC,
MCContext *Ctx) const override {
Inst.setOpcode(X86::JCC_1);
Inst.clear();
Inst.addOperand(MCOperand::createExpr(
MCSymbolRefExpr::create(Target, MCSymbolRefExpr::VK_None, *Ctx)));
Inst.addOperand(MCOperand::createImm(CC));
}
bool reverseBranchCondition(MCInst &Inst, const MCSymbol *TBB,
MCContext *Ctx) const override {
unsigned InvCC = getInvertedCondCode(getCondCode(Inst));