From 79d84987ff2b54fb512c1b78bbed17f9b387cb62 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 29 Apr 2020 23:17:14 -0700 Subject: [PATCH] [MC] Move MCInstrAnalysis::evaluateBranch to X86MCInstrAnalysis::evaluateBranch The generic implementation is actually specific to x86. It assumes the offset is relative to the end of the instruction and the immediate is not scaled (which is false on most RISC). --- lib/MC/MCInstrAnalysis.cpp | 13 ++++--------- lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/MC/MCInstrAnalysis.cpp b/lib/MC/MCInstrAnalysis.cpp index 54741fdd686..a7dc0626d0a 100644 --- a/lib/MC/MCInstrAnalysis.cpp +++ b/lib/MC/MCInstrAnalysis.cpp @@ -23,15 +23,10 @@ bool MCInstrAnalysis::clearsSuperRegisters(const MCRegisterInfo &MRI, return false; } -bool MCInstrAnalysis::evaluateBranch(const MCInst &Inst, uint64_t Addr, - uint64_t Size, uint64_t &Target) const { - if (Inst.getNumOperands() == 0 || - Info->get(Inst.getOpcode()).OpInfo[0].OperandType != MCOI::OPERAND_PCREL) - return false; - - int64_t Imm = Inst.getOperand(0).getImm(); - Target = Addr+Size+Imm; - return true; +bool MCInstrAnalysis::evaluateBranch(const MCInst & /*Inst*/, uint64_t /*Addr*/, + uint64_t /*Size*/, + uint64_t & /*Target*/) const { + return false; } Optional diff --git a/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp index 20b8b855430..b056cab7fa7 100644 --- a/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp +++ b/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp @@ -400,6 +400,9 @@ public: findPltEntries(uint64_t PltSectionVA, ArrayRef PltContents, uint64_t GotSectionVA, const Triple &TargetTriple) const override; + + bool evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size, + uint64_t &Target) const override; Optional evaluateMemoryOperandAddress(const MCInst &Inst, uint64_t Addr, uint64_t Size) const override; @@ -518,6 +521,15 @@ std::vector> X86MCInstrAnalysis::findPltEntries( } } +bool X86MCInstrAnalysis::evaluateBranch(const MCInst &Inst, uint64_t Addr, + uint64_t Size, uint64_t &Target) const { + if (Inst.getNumOperands() == 0 || + Info->get(Inst.getOpcode()).OpInfo[0].OperandType != MCOI::OPERAND_PCREL) + return false; + Target = Addr + Size + Inst.getOperand(0).getImm(); + return true; +} + Optional X86MCInstrAnalysis::evaluateMemoryOperandAddress( const MCInst &Inst, uint64_t Addr, uint64_t Size) const { const MCInstrDesc &MCID = Info->get(Inst.getOpcode());