[llvm] aa24e36 - [CodeGen] Cache Opcode in MachineInstr (#96797)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 27 08:10:03 PDT 2024
Author: Alexis Engelke
Date: 2024-06-27T17:10:00+02:00
New Revision: aa24e36d037caee2a4106f721a0ac2ab2a1bc335
URL: https://github.com/llvm/llvm-project/commit/aa24e36d037caee2a4106f721a0ac2ab2a1bc335
DIFF: https://github.com/llvm/llvm-project/commit/aa24e36d037caee2a4106f721a0ac2ab2a1bc335.diff
LOG: [CodeGen] Cache Opcode in MachineInstr (#96797)
This avoids the indirection through MCID when just accessing the opcode.
This uses two of the four padding bytes at the end of MachineInstr.
Added:
Modified:
llvm/include/llvm/CodeGen/MachineInstr.h
llvm/lib/CodeGen/MachineInstr.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h
index b3cb5c8b84839..229f5159fd6ef 100644
--- a/llvm/include/llvm/CodeGen/MachineInstr.h
+++ b/llvm/include/llvm/CodeGen/MachineInstr.h
@@ -304,6 +304,9 @@ class MachineInstr
/// defined by this instruction.
unsigned DebugInstrNum;
+ /// Cached opcode from MCID.
+ uint16_t Opcode;
+
// Intrusive list support
friend struct ilist_traits<MachineInstr>;
friend struct ilist_callback_traits<MachineBasicBlock>;
@@ -563,7 +566,7 @@ class MachineInstr
const MCInstrDesc &getDesc() const { return *MCID; }
/// Returns the opcode of this MachineInstr.
- unsigned getOpcode() const { return MCID->Opcode; }
+ unsigned getOpcode() const { return Opcode; }
/// Retuns the total number of operands.
unsigned getNumOperands() const { return NumOperands; }
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 198af9339c159..f0de2cad20337 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -98,7 +98,7 @@ void MachineInstr::addImplicitDefUseOperands(MachineFunction &MF) {
MachineInstr::MachineInstr(MachineFunction &MF, const MCInstrDesc &TID,
DebugLoc DL, bool NoImp)
: MCID(&TID), NumOperands(0), Flags(0), AsmPrinterFlags(0),
- DbgLoc(std::move(DL)), DebugInstrNum(0) {
+ DbgLoc(std::move(DL)), DebugInstrNum(0), Opcode(TID.Opcode) {
assert(DbgLoc.hasTrivialDestructor() && "Expected trivial destructor");
// Reserve space for the expected number of operands.
@@ -117,7 +117,8 @@ MachineInstr::MachineInstr(MachineFunction &MF, const MCInstrDesc &TID,
/// uniqueness.
MachineInstr::MachineInstr(MachineFunction &MF, const MachineInstr &MI)
: MCID(&MI.getDesc()), NumOperands(0), Flags(0), AsmPrinterFlags(0),
- Info(MI.Info), DbgLoc(MI.getDebugLoc()), DebugInstrNum(0) {
+ Info(MI.Info), DbgLoc(MI.getDebugLoc()), DebugInstrNum(0),
+ Opcode(MI.getOpcode()) {
assert(DbgLoc.hasTrivialDestructor() && "Expected trivial destructor");
CapOperands = OperandCapacity::get(MI.getNumOperands());
@@ -143,6 +144,7 @@ void MachineInstr::setDesc(const MCInstrDesc &TID) {
if (getParent())
getMF()->handleChangeDesc(*this, TID);
MCID = &TID;
+ Opcode = TID.Opcode;
}
void MachineInstr::moveBefore(MachineInstr *MovePos) {
More information about the llvm-commits
mailing list