Skip to content

Commit

Permalink
[X86][MC] Use MCInstrDesc to access CondCode operand
Browse files Browse the repository at this point in the history
BOLT may add an extra MCOperand as annotation, making the number of operands in
MCInst different from MCInstrDesc information. A recent change broke our use as
the last operand is no longer a cond code.

Partially revert 287dd01 to rely on MCInstrDesc
to access CondCode operand.

Reviewed By: skan

Differential Revision: https://reviews.llvm.org/D151930
  • Loading branch information
aaupov committed Jun 2, 2023
1 parent df1bb2e commit 15a719d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,23 @@ static unsigned getRelaxedOpcode(const MCInst &MI, bool Is16BitMode) {
: X86::getOpcodeForLongImmediateForm(Opcode);
}

static X86::CondCode getCondFromBranch(const MCInst &MI) {
static X86::CondCode getCondFromBranch(const MCInst &MI,
const MCInstrInfo &MCII) {
unsigned Opcode = MI.getOpcode();
switch (Opcode) {
default:
return X86::COND_INVALID;
case X86::JCC_1:
case X86::JCC_1: {
const MCInstrDesc &Desc = MCII.get(Opcode);
return static_cast<X86::CondCode>(
MI.getOperand(MI.getNumOperands() - 1).getImm());
MI.getOperand(Desc.getNumOperands() - 1).getImm());
}
}
}

static X86::SecondMacroFusionInstKind
classifySecondInstInMacroFusion(const MCInst &MI) {
X86::CondCode CC = getCondFromBranch(MI);
classifySecondInstInMacroFusion(const MCInst &MI, const MCInstrInfo &MCII) {
X86::CondCode CC = getCondFromBranch(MI, MCII);
return classifySecondCondCodeInMacroFusion(CC);
}

Expand Down Expand Up @@ -351,7 +354,7 @@ bool X86AsmBackend::isMacroFused(const MCInst &Cmp, const MCInst &Jcc) const {
const X86::FirstMacroFusionInstKind CmpKind =
X86::classifyFirstOpcodeInMacroFusion(Cmp.getOpcode());
const X86::SecondMacroFusionInstKind BranchKind =
classifySecondInstInMacroFusion(Jcc);
classifySecondInstInMacroFusion(Jcc, *MCII);
return X86::isMacroFused(CmpKind, BranchKind);
}

Expand Down

0 comments on commit 15a719d

Please sign in to comment.