From 52eb2f65a7d28bb225ca8a0bc8c4090d324e22d9 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). --- llvm/lib/MC/MCInstrAnalysis.cpp | 13 ++++--------- .../lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/llvm/lib/MC/MCInstrAnalysis.cpp b/llvm/lib/MC/MCInstrAnalysis.cpp index 54741fdd686d..a7dc0626d0ab 100644 --- a/llvm/lib/MC/MCInstrAnalysis.cpp +++ b/llvm/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/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp index 20b8b855430d..b056cab7fa76 100644 --- a/llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp +++ b/llvm/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());