blob: 95e8325b9db0d9d5034034824624f6020e9a8604 [file] [log] [blame]
Pete Cooper80735a22015-05-15 21:29:43 +00001//===------ 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"
17
18using namespace llvm;
19
20bool MCInstrDesc::getDeprecatedInfo(MCInst &MI, MCSubtargetInfo &STI,
21 std::string &Info) const {
22 if (ComplexDeprecationInfo)
23 return ComplexDeprecationInfo(MI, STI, Info);
24 if ((DeprecatedFeatureMask & STI.getFeatureBits()) != 0) {
25 // FIXME: it would be nice to include the subtarget feature here.
26 Info = "deprecated";
27 return true;
28 }
29 return false;
30}
31bool MCInstrDesc::mayAffectControlFlow(const MCInst &MI,
32 const MCRegisterInfo &RI) const {
33 if (isBranch() || isCall() || isReturn() || isIndirectBranch())
34 return true;
35 unsigned PC = RI.getProgramCounter();
36 if (PC == 0)
37 return false;
38 if (hasDefOfPhysReg(MI, PC, RI))
39 return true;
40 // A variadic instruction may define PC in the variable operand list.
41 // There's currently no indication of which entries in a variable
42 // list are defs and which are uses. While that's the case, this function
43 // needs to assume they're defs in order to be conservatively correct.
44 for (int i = NumOperands, e = MI.getNumOperands(); i != e; ++i) {
45 if (MI.getOperand(i).isReg() &&
46 RI.isSubRegisterEq(PC, MI.getOperand(i).getReg()))
47 return true;
48 }
49 return false;
50}
51
52bool MCInstrDesc::hasImplicitDefOfPhysReg(unsigned Reg,
53 const MCRegisterInfo *MRI) const {
54 if (const uint16_t *ImpDefs = ImplicitDefs)
55 for (; *ImpDefs; ++ImpDefs)
56 if (*ImpDefs == Reg || (MRI && MRI->isSubRegister(Reg, *ImpDefs)))
57 return true;
58 return false;
59}
60
61bool MCInstrDesc::hasDefOfPhysReg(const MCInst &MI, unsigned Reg,
62 const MCRegisterInfo &RI) const {
63 for (int i = 0, e = NumDefs; i != e; ++i)
64 if (MI.getOperand(i).isReg() &&
65 RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg()))
66 return true;
67 return hasImplicitDefOfPhysReg(Reg, &RI);
68}