Skip to content

Commit 49b8a99

Browse files
authored
[BOLT] Add createCondBranch() and createLongUncondBranch() (#85315)
Add MCPlusBuilder interface for creating two new branch types.
1 parent f9e5579 commit 49b8a99

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,13 @@ class MCPlusBuilder {
15581558
llvm_unreachable("not implemented");
15591559
}
15601560

1561+
/// Create a version of unconditional jump that has the largest span for a
1562+
/// single instruction with direct target.
1563+
virtual void createLongUncondBranch(MCInst &Inst, const MCSymbol *Target,
1564+
MCContext *Ctx) const {
1565+
llvm_unreachable("not implemented");
1566+
}
1567+
15611568
/// Creates a new call instruction in Inst and sets its operand to
15621569
/// Target.
15631570
virtual void createCall(MCInst &Inst, const MCSymbol *Target,
@@ -1675,6 +1682,12 @@ class MCPlusBuilder {
16751682
return Inst.getOpcode() == TargetOpcode::CFI_INSTRUCTION;
16761683
}
16771684

1685+
/// Create a conditional branch with a target-specific conditional code \p CC.
1686+
virtual void createCondBranch(MCInst &Inst, const MCSymbol *Target,
1687+
unsigned CC, MCContext *Ctx) const {
1688+
llvm_unreachable("not implemented");
1689+
}
1690+
16781691
/// Reverses the branch condition in Inst and update its taken target to TBB.
16791692
///
16801693
/// Returns true on success.

bolt/lib/Target/X86/X86MCPlusBuilder.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,14 @@ class X86MCPlusBuilder : public MCPlusBuilder {
27342734
MCSymbolRefExpr::create(TBB, MCSymbolRefExpr::VK_None, *Ctx)));
27352735
}
27362736

2737+
void createLongUncondBranch(MCInst &Inst, const MCSymbol *Target,
2738+
MCContext *Ctx) const override {
2739+
Inst.setOpcode(X86::JMP_4);
2740+
Inst.clear();
2741+
Inst.addOperand(MCOperand::createExpr(
2742+
MCSymbolRefExpr::create(Target, MCSymbolRefExpr::VK_None, *Ctx)));
2743+
}
2744+
27372745
void createCall(MCInst &Inst, const MCSymbol *Target,
27382746
MCContext *Ctx) override {
27392747
Inst.setOpcode(X86::CALL64pcrel32);
@@ -2759,6 +2767,15 @@ class X86MCPlusBuilder : public MCPlusBuilder {
27592767
Inst.setOpcode(X86::TRAP);
27602768
}
27612769

2770+
void createCondBranch(MCInst &Inst, const MCSymbol *Target, unsigned CC,
2771+
MCContext *Ctx) const override {
2772+
Inst.setOpcode(X86::JCC_1);
2773+
Inst.clear();
2774+
Inst.addOperand(MCOperand::createExpr(
2775+
MCSymbolRefExpr::create(Target, MCSymbolRefExpr::VK_None, *Ctx)));
2776+
Inst.addOperand(MCOperand::createImm(CC));
2777+
}
2778+
27622779
bool reverseBranchCondition(MCInst &Inst, const MCSymbol *TBB,
27632780
MCContext *Ctx) const override {
27642781
unsigned InvCC = getInvertedCondCode(getCondCode(Inst));

0 commit comments

Comments
 (0)