[llvm] [BOLT] Add createCondBranch() and createLongUncondBranch() (PR #85315)
Maksim Panchenko via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 14 14:26:39 PDT 2024
https://github.com/maksfb created https://github.com/llvm/llvm-project/pull/85315
Add MCPlusBuilder interface for creating two new branch types.
>From 529f1c322f98ebc4370c300960afabc738c45ac7 Mon Sep 17 00:00:00 2001
From: Maksim Panchenko <maks at fb.com>
Date: Wed, 13 Dec 2023 15:31:02 -0800
Subject: [PATCH] [BOLT] Add createCondBranch() and createLongUncondBranch()
Add MCPlusBuilder interface for creating two new branch types.
---
bolt/include/bolt/Core/MCPlusBuilder.h | 13 +++++++++++++
bolt/lib/Target/X86/X86MCPlusBuilder.cpp | 17 +++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h
index 9220414b2e9501..96b58f54162344 100644
--- a/bolt/include/bolt/Core/MCPlusBuilder.h
+++ b/bolt/include/bolt/Core/MCPlusBuilder.h
@@ -1558,6 +1558,13 @@ class MCPlusBuilder {
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 @@ class MCPlusBuilder {
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.
diff --git a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp
index 273296f45aba73..de55fbe51764dd 100644
--- a/bolt/lib/Target/X86/X86MCPlusBuilder.cpp
+++ b/bolt/lib/Target/X86/X86MCPlusBuilder.cpp
@@ -2734,6 +2734,14 @@ class X86MCPlusBuilder : public MCPlusBuilder {
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 @@ class X86MCPlusBuilder : public MCPlusBuilder {
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));
More information about the llvm-commits
mailing list