Pete Cooper | 9e51420 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 1 | //===------ llvm/MC/MCInstrDesc.cpp- Instruction Descriptors --------------===// |
| 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 methods on the MCOperandInfo and MCInstrDesc classes, which |
| 11 | // are used to describe target instructions and their operands. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/MC/MCInstrDesc.h" |
| 16 | #include "llvm/MC/MCInst.h" |
Pete Cooper | 39aa893 | 2015-05-15 21:58:42 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCRegisterInfo.h" |
| 18 | #include "llvm/MC/MCSubtargetInfo.h" |
Pete Cooper | 9e51420 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace llvm; |
| 21 | |
Duncan P. N. Exon Smith | dfcac4b | 2015-07-08 17:30:55 +0000 | [diff] [blame] | 22 | bool MCInstrDesc::getDeprecatedInfo(MCInst &MI, const MCSubtargetInfo &STI, |
Pete Cooper | 9e51420 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 23 | std::string &Info) const { |
| 24 | if (ComplexDeprecationInfo) |
| 25 | return ComplexDeprecationInfo(MI, STI, Info); |
Michael Kuperstein | d714fcf | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 26 | if (DeprecatedFeature != -1 && STI.getFeatureBits()[DeprecatedFeature]) { |
Pete Cooper | 9e51420 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 27 | // FIXME: it would be nice to include the subtarget feature here. |
| 28 | Info = "deprecated"; |
| 29 | return true; |
| 30 | } |
| 31 | return false; |
| 32 | } |
| 33 | bool MCInstrDesc::mayAffectControlFlow(const MCInst &MI, |
| 34 | const MCRegisterInfo &RI) const { |
| 35 | if (isBranch() || isCall() || isReturn() || isIndirectBranch()) |
| 36 | return true; |
| 37 | unsigned PC = RI.getProgramCounter(); |
| 38 | if (PC == 0) |
| 39 | return false; |
| 40 | if (hasDefOfPhysReg(MI, PC, RI)) |
| 41 | return true; |
Pete Cooper | 9e51420 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 42 | return false; |
| 43 | } |
| 44 | |
| 45 | bool MCInstrDesc::hasImplicitDefOfPhysReg(unsigned Reg, |
| 46 | const MCRegisterInfo *MRI) const { |
Craig Topper | 79402ee | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 47 | if (const MCPhysReg *ImpDefs = ImplicitDefs) |
Pete Cooper | 9e51420 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 48 | for (; *ImpDefs; ++ImpDefs) |
| 49 | if (*ImpDefs == Reg || (MRI && MRI->isSubRegister(Reg, *ImpDefs))) |
| 50 | return true; |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | bool MCInstrDesc::hasDefOfPhysReg(const MCInst &MI, unsigned Reg, |
| 55 | const MCRegisterInfo &RI) const { |
| 56 | for (int i = 0, e = NumDefs; i != e; ++i) |
| 57 | if (MI.getOperand(i).isReg() && |
| 58 | RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg())) |
| 59 | return true; |
Oliver Stannard | 9639b46 | 2018-12-03 10:32:42 +0000 | [diff] [blame] | 60 | if (variadicOpsAreDefs()) |
| 61 | for (int i = NumOperands - 1, e = MI.getNumOperands(); i != e; ++i) |
| 62 | if (MI.getOperand(i).isReg() && |
| 63 | RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg())) |
| 64 | return true; |
Pete Cooper | 9e51420 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 65 | return hasImplicitDefOfPhysReg(Reg, &RI); |
| 66 | } |