blob: d54aeba89edc5f85d7ec25319c00e855c84bd5cc [file] [log] [blame]
Pete Cooper80735a22015-05-15 21:29:43 +00001//===------ llvm/MC/MCInstrDesc.cpp- Instruction Descriptors --------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Cooper80735a22015-05-15 21:29:43 +00006//
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 Cooper3de83e42015-05-15 21:58:42 +000016#include "llvm/MC/MCRegisterInfo.h"
17#include "llvm/MC/MCSubtargetInfo.h"
Pete Cooper80735a22015-05-15 21:29:43 +000018
19using namespace llvm;
20
Duncan P. N. Exon Smithad987452015-07-08 17:30:55 +000021bool MCInstrDesc::getDeprecatedInfo(MCInst &MI, const MCSubtargetInfo &STI,
Pete Cooper80735a22015-05-15 21:29:43 +000022 std::string &Info) const {
23 if (ComplexDeprecationInfo)
24 return ComplexDeprecationInfo(MI, STI, Info);
Michael Kupersteindb0712f2015-05-26 10:47:10 +000025 if (DeprecatedFeature != -1 && STI.getFeatureBits()[DeprecatedFeature]) {
Pete Cooper80735a22015-05-15 21:29:43 +000026 // FIXME: it would be nice to include the subtarget feature here.
27 Info = "deprecated";
28 return true;
29 }
30 return false;
31}
32bool 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 Cooper80735a22015-05-15 21:29:43 +000041 return false;
42}
43
44bool MCInstrDesc::hasImplicitDefOfPhysReg(unsigned Reg,
45 const MCRegisterInfo *MRI) const {
Craig Toppere5e035a32015-12-05 07:13:35 +000046 if (const MCPhysReg *ImpDefs = ImplicitDefs)
Pete Cooper80735a22015-05-15 21:29:43 +000047 for (; *ImpDefs; ++ImpDefs)
48 if (*ImpDefs == Reg || (MRI && MRI->isSubRegister(Reg, *ImpDefs)))
49 return true;
50 return false;
51}
52
53bool 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 Stannard4cf35b42018-12-03 10:32:42 +000059 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 Cooper80735a22015-05-15 21:29:43 +000064 return hasImplicitDefOfPhysReg(Reg, &RI);
65}