Skip to content

[CodeGen] Cache Opcode in MachineInstr #96797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion llvm/include/llvm/CodeGen/MachineInstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -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; }
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/CodeGen/MachineInstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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());
Expand All @@ -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) {
Expand Down
Loading