1 //===-- llvm/MC/MCInstrAnalysis.h - InstrDesc target hooks ------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines the MCInstrAnalysis class which the MCTargetDescs can 11 // derive from to give additional information to MC. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "llvm/MC/MCInst.h" 16 #include "llvm/MC/MCInstrDesc.h" 17 #include "llvm/MC/MCInstrInfo.h" 18 19 namespace llvm { 20 21 class MCInstrAnalysis { 22 protected: 23 friend class Target; 24 const MCInstrInfo *Info; 25 26 public: MCInstrAnalysis(const MCInstrInfo * Info)27 MCInstrAnalysis(const MCInstrInfo *Info) : Info(Info) {} 28 ~MCInstrAnalysis()29 virtual ~MCInstrAnalysis() {} 30 isBranch(const MCInst & Inst)31 virtual bool isBranch(const MCInst &Inst) const { 32 return Info->get(Inst.getOpcode()).isBranch(); 33 } 34 isConditionalBranch(const MCInst & Inst)35 virtual bool isConditionalBranch(const MCInst &Inst) const { 36 return Info->get(Inst.getOpcode()).isBranch(); 37 } 38 isUnconditionalBranch(const MCInst & Inst)39 virtual bool isUnconditionalBranch(const MCInst &Inst) const { 40 return Info->get(Inst.getOpcode()).isUnconditionalBranch(); 41 } 42 isIndirectBranch(const MCInst & Inst)43 virtual bool isIndirectBranch(const MCInst &Inst) const { 44 return Info->get(Inst.getOpcode()).isIndirectBranch(); 45 } 46 isCall(const MCInst & Inst)47 virtual bool isCall(const MCInst &Inst) const { 48 return Info->get(Inst.getOpcode()).isCall(); 49 } 50 isReturn(const MCInst & Inst)51 virtual bool isReturn(const MCInst &Inst) const { 52 return Info->get(Inst.getOpcode()).isReturn(); 53 } 54 55 /// evaluateBranch - Given a branch instruction try to get the address the 56 /// branch targets. Otherwise return -1. 57 virtual uint64_t 58 evaluateBranch(const MCInst &Inst, uint64_t Addr, uint64_t Size) const; 59 }; 60 61 } 62