Pete Cooper | 80735a2 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 1 | //===------ llvm/MC/MCInstrDesc.cpp- Instruction Descriptors --------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Pete Cooper | 80735a2 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines methods on the MCOperandInfo and MCInstrDesc classes, which |
| 10 | // are used to describe target instructions and their operands. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/MC/MCInstrDesc.h" |
| 15 | #include "llvm/MC/MCInst.h" |
Pete Cooper | 3de83e4 | 2015-05-15 21:58:42 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCRegisterInfo.h" |
| 17 | #include "llvm/MC/MCSubtargetInfo.h" |
Pete Cooper | 80735a2 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace llvm; |
| 20 | |
Duncan P. N. Exon Smith | ad98745 | 2015-07-08 17:30:55 +0000 | [diff] [blame] | 21 | bool MCInstrDesc::getDeprecatedInfo(MCInst &MI, const MCSubtargetInfo &STI, |
Pete Cooper | 80735a2 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 22 | std::string &Info) const { |
| 23 | if (ComplexDeprecationInfo) |
| 24 | return ComplexDeprecationInfo(MI, STI, Info); |
Michael Kuperstein | db0712f | 2015-05-26 10:47:10 +0000 | [diff] [blame] | 25 | if (DeprecatedFeature != -1 && STI.getFeatureBits()[DeprecatedFeature]) { |
Pete Cooper | 80735a2 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 26 | // FIXME: it would be nice to include the subtarget feature here. |
| 27 | Info = "deprecated"; |
| 28 | return true; |
| 29 | } |
| 30 | return false; |
| 31 | } |
| 32 | bool MCInstrDesc::mayAffectControlFlow(const MCInst &MI, |
| 33 | const MCRegisterInfo &RI) const { |
| 34 | if (isBranch() || isCall() || isReturn() || isIndirectBranch()) |
| 35 | return true; |
| 36 | unsigned PC = RI.getProgramCounter(); |
| 37 | if (PC == 0) |
| 38 | return false; |
| 39 | if (hasDefOfPhysReg(MI, PC, RI)) |
| 40 | return true; |
Pete Cooper | 80735a2 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 41 | return false; |
| 42 | } |
| 43 | |
| 44 | bool MCInstrDesc::hasImplicitDefOfPhysReg(unsigned Reg, |
| 45 | const MCRegisterInfo *MRI) const { |
Craig Topper | e5e035a3 | 2015-12-05 07:13:35 +0000 | [diff] [blame] | 46 | if (const MCPhysReg *ImpDefs = ImplicitDefs) |
Pete Cooper | 80735a2 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 47 | for (; *ImpDefs; ++ImpDefs) |
| 48 | if (*ImpDefs == Reg || (MRI && MRI->isSubRegister(Reg, *ImpDefs))) |
| 49 | return true; |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | bool MCInstrDesc::hasDefOfPhysReg(const MCInst &MI, unsigned Reg, |
| 54 | const MCRegisterInfo &RI) const { |
| 55 | for (int i = 0, e = NumDefs; i != e; ++i) |
| 56 | if (MI.getOperand(i).isReg() && |
| 57 | RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg())) |
| 58 | return true; |
Oliver Stannard | 4cf35b4 | 2018-12-03 10:32:42 +0000 | [diff] [blame] | 59 | if (variadicOpsAreDefs()) |
| 60 | for (int i = NumOperands - 1, e = MI.getNumOperands(); i != e; ++i) |
| 61 | if (MI.getOperand(i).isReg() && |
| 62 | RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg())) |
| 63 | return true; |
Pete Cooper | 80735a2 | 2015-05-15 21:29:43 +0000 | [diff] [blame] | 64 | return hasImplicitDefOfPhysReg(Reg, &RI); |
| 65 | } |