Skip to content

Commit 199d8f2

Browse files
aengelkeAlexisPerry
authored andcommitted
[CodeGen] Cache Opcode in MachineInstr (llvm#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.
1 parent 7d1ba2f commit 199d8f2

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

llvm/include/llvm/CodeGen/MachineInstr.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ class MachineInstr
304304
/// defined by this instruction.
305305
unsigned DebugInstrNum;
306306

307+
/// Cached opcode from MCID.
308+
uint16_t Opcode;
309+
307310
// Intrusive list support
308311
friend struct ilist_traits<MachineInstr>;
309312
friend struct ilist_callback_traits<MachineBasicBlock>;
@@ -563,7 +566,7 @@ class MachineInstr
563566
const MCInstrDesc &getDesc() const { return *MCID; }
564567

565568
/// Returns the opcode of this MachineInstr.
566-
unsigned getOpcode() const { return MCID->Opcode; }
569+
unsigned getOpcode() const { return Opcode; }
567570

568571
/// Retuns the total number of operands.
569572
unsigned getNumOperands() const { return NumOperands; }

llvm/lib/CodeGen/MachineInstr.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void MachineInstr::addImplicitDefUseOperands(MachineFunction &MF) {
9898
MachineInstr::MachineInstr(MachineFunction &MF, const MCInstrDesc &TID,
9999
DebugLoc DL, bool NoImp)
100100
: MCID(&TID), NumOperands(0), Flags(0), AsmPrinterFlags(0),
101-
DbgLoc(std::move(DL)), DebugInstrNum(0) {
101+
DbgLoc(std::move(DL)), DebugInstrNum(0), Opcode(TID.Opcode) {
102102
assert(DbgLoc.hasTrivialDestructor() && "Expected trivial destructor");
103103

104104
// Reserve space for the expected number of operands.
@@ -117,7 +117,8 @@ MachineInstr::MachineInstr(MachineFunction &MF, const MCInstrDesc &TID,
117117
/// uniqueness.
118118
MachineInstr::MachineInstr(MachineFunction &MF, const MachineInstr &MI)
119119
: MCID(&MI.getDesc()), NumOperands(0), Flags(0), AsmPrinterFlags(0),
120-
Info(MI.Info), DbgLoc(MI.getDebugLoc()), DebugInstrNum(0) {
120+
Info(MI.Info), DbgLoc(MI.getDebugLoc()), DebugInstrNum(0),
121+
Opcode(MI.getOpcode()) {
121122
assert(DbgLoc.hasTrivialDestructor() && "Expected trivial destructor");
122123

123124
CapOperands = OperandCapacity::get(MI.getNumOperands());
@@ -143,6 +144,7 @@ void MachineInstr::setDesc(const MCInstrDesc &TID) {
143144
if (getParent())
144145
getMF()->handleChangeDesc(*this, TID);
145146
MCID = &TID;
147+
Opcode = TID.Opcode;
146148
}
147149

148150
void MachineInstr::moveBefore(MachineInstr *MovePos) {

0 commit comments

Comments
 (0)