[llvm] [MC,X86] De-virtualize emitPrefix (PR #97008)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 27 23:04:52 PDT 2024
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/97008
and remove x86-specific emitPrefix from the generic MCCodeEmitter.
>From 40525956b6636383ccedd6bdb36440550e7f9a91 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Thu, 27 Jun 2024 23:04:37 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.5-bogner
---
llvm/include/llvm/MC/MCCodeEmitter.h | 6 ------
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp | 2 +-
llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp | 7 ++++++-
llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h | 4 ++++
4 files changed, 11 insertions(+), 8 deletions(-)
diff --git a/llvm/include/llvm/MC/MCCodeEmitter.h b/llvm/include/llvm/MC/MCCodeEmitter.h
index e4f4b27816bb3..ceb16c9b4da78 100644
--- a/llvm/include/llvm/MC/MCCodeEmitter.h
+++ b/llvm/include/llvm/MC/MCCodeEmitter.h
@@ -30,12 +30,6 @@ class MCCodeEmitter {
/// Lifetime management
virtual void reset() {}
- /// Append the prefixes of given instruction to the code buffer.
- ///
- /// \param Inst a single low-level machine instruction.
- /// \param CB code buffer
- virtual void emitPrefix(const MCInst &Inst, SmallVectorImpl<char> &CB,
- const MCSubtargetInfo &STI) const {}
/// Encode the given \p Inst to bytes and append to \p CB.
virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
index 4567daeb5c4a0..372de5c18ac2b 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -788,7 +788,7 @@ bool X86AsmBackend::padInstructionViaPrefix(MCRelaxableFragment &RF,
const unsigned MaxPossiblePad = std::min(15 - OldSize, RemainingSize);
const unsigned RemainingPrefixSize = [&]() -> unsigned {
SmallString<15> Code;
- Emitter.emitPrefix(RF.getInst(), Code, STI);
+ X86_MC::emitPrefix(Emitter, RF.getInst(), Code, STI);
assert(Code.size() < 15 && "The number of prefixes must be less than 15.");
// TODO: It turns out we need a decent amount of plumbing for the target
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
index 72219c136c7e1..3cd0af0c7f546 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCCodeEmitter.cpp
@@ -344,7 +344,7 @@ class X86MCCodeEmitter : public MCCodeEmitter {
~X86MCCodeEmitter() override = default;
void emitPrefix(const MCInst &MI, SmallVectorImpl<char> &CB,
- const MCSubtargetInfo &STI) const override;
+ const MCSubtargetInfo &STI) const;
void encodeInstruction(const MCInst &MI, SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
@@ -1531,6 +1531,11 @@ void X86MCCodeEmitter::emitPrefix(const MCInst &MI, SmallVectorImpl<char> &CB,
emitPrefixImpl(CurOp, MI, STI, CB);
}
+void X86_MC::emitPrefix(MCCodeEmitter &MCE, const MCInst &MI,
+ SmallVectorImpl<char> &CB, const MCSubtargetInfo &STI) {
+ static_cast<X86MCCodeEmitter &>(MCE).emitPrefix(MI, CB, STI);
+}
+
void X86MCCodeEmitter::encodeInstruction(const MCInst &MI,
SmallVectorImpl<char> &CB,
SmallVectorImpl<MCFixup> &Fixups,
diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h
index 9e68d0c670329..96a7823b04ad8 100644
--- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h
+++ b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.h
@@ -13,6 +13,7 @@
#ifndef LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCTARGETDESC_H
#define LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCTARGETDESC_H
+#include "llvm/ADT/SmallVector.h"
#include <memory>
#include <string>
@@ -93,6 +94,9 @@ MCSubtargetInfo *createX86MCSubtargetInfo(const Triple &TT, StringRef CPU,
void emitInstruction(MCObjectStreamer &, const MCInst &Inst,
const MCSubtargetInfo &STI);
+
+void emitPrefix(MCCodeEmitter &MCE, const MCInst &MI, SmallVectorImpl<char> &CB,
+ const MCSubtargetInfo &STI);
}
MCCodeEmitter *createX86MCCodeEmitter(const MCInstrInfo &MCII,
More information about the llvm-commits
mailing list