xref: /aosp_15_r20/external/llvm/lib/MC/MCInstrDesc.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===------ llvm/MC/MCInstrDesc.cpp- Instruction Descriptors --------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file defines methods on the MCOperandInfo and MCInstrDesc classes, which
11*9880d681SAndroid Build Coastguard Worker // are used to describe target instructions and their operands.
12*9880d681SAndroid Build Coastguard Worker //
13*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
14*9880d681SAndroid Build Coastguard Worker 
15*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCInstrDesc.h"
16*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCInst.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCRegisterInfo.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCSubtargetInfo.h"
19*9880d681SAndroid Build Coastguard Worker 
20*9880d681SAndroid Build Coastguard Worker using namespace llvm;
21*9880d681SAndroid Build Coastguard Worker 
getDeprecatedInfo(MCInst & MI,const MCSubtargetInfo & STI,std::string & Info) const22*9880d681SAndroid Build Coastguard Worker bool MCInstrDesc::getDeprecatedInfo(MCInst &MI, const MCSubtargetInfo &STI,
23*9880d681SAndroid Build Coastguard Worker                                     std::string &Info) const {
24*9880d681SAndroid Build Coastguard Worker   if (ComplexDeprecationInfo)
25*9880d681SAndroid Build Coastguard Worker     return ComplexDeprecationInfo(MI, STI, Info);
26*9880d681SAndroid Build Coastguard Worker   if (DeprecatedFeature != -1 && STI.getFeatureBits()[DeprecatedFeature]) {
27*9880d681SAndroid Build Coastguard Worker     // FIXME: it would be nice to include the subtarget feature here.
28*9880d681SAndroid Build Coastguard Worker     Info = "deprecated";
29*9880d681SAndroid Build Coastguard Worker     return true;
30*9880d681SAndroid Build Coastguard Worker   }
31*9880d681SAndroid Build Coastguard Worker   return false;
32*9880d681SAndroid Build Coastguard Worker }
mayAffectControlFlow(const MCInst & MI,const MCRegisterInfo & RI) const33*9880d681SAndroid Build Coastguard Worker bool MCInstrDesc::mayAffectControlFlow(const MCInst &MI,
34*9880d681SAndroid Build Coastguard Worker                                        const MCRegisterInfo &RI) const {
35*9880d681SAndroid Build Coastguard Worker   if (isBranch() || isCall() || isReturn() || isIndirectBranch())
36*9880d681SAndroid Build Coastguard Worker     return true;
37*9880d681SAndroid Build Coastguard Worker   unsigned PC = RI.getProgramCounter();
38*9880d681SAndroid Build Coastguard Worker   if (PC == 0)
39*9880d681SAndroid Build Coastguard Worker     return false;
40*9880d681SAndroid Build Coastguard Worker   if (hasDefOfPhysReg(MI, PC, RI))
41*9880d681SAndroid Build Coastguard Worker     return true;
42*9880d681SAndroid Build Coastguard Worker   // A variadic instruction may define PC in the variable operand list.
43*9880d681SAndroid Build Coastguard Worker   // There's currently no indication of which entries in a variable
44*9880d681SAndroid Build Coastguard Worker   // list are defs and which are uses. While that's the case, this function
45*9880d681SAndroid Build Coastguard Worker   // needs to assume they're defs in order to be conservatively correct.
46*9880d681SAndroid Build Coastguard Worker   for (int i = NumOperands, e = MI.getNumOperands(); i != e; ++i) {
47*9880d681SAndroid Build Coastguard Worker     if (MI.getOperand(i).isReg() &&
48*9880d681SAndroid Build Coastguard Worker         RI.isSubRegisterEq(PC, MI.getOperand(i).getReg()))
49*9880d681SAndroid Build Coastguard Worker       return true;
50*9880d681SAndroid Build Coastguard Worker   }
51*9880d681SAndroid Build Coastguard Worker   return false;
52*9880d681SAndroid Build Coastguard Worker }
53*9880d681SAndroid Build Coastguard Worker 
hasImplicitDefOfPhysReg(unsigned Reg,const MCRegisterInfo * MRI) const54*9880d681SAndroid Build Coastguard Worker bool MCInstrDesc::hasImplicitDefOfPhysReg(unsigned Reg,
55*9880d681SAndroid Build Coastguard Worker                                           const MCRegisterInfo *MRI) const {
56*9880d681SAndroid Build Coastguard Worker   if (const MCPhysReg *ImpDefs = ImplicitDefs)
57*9880d681SAndroid Build Coastguard Worker     for (; *ImpDefs; ++ImpDefs)
58*9880d681SAndroid Build Coastguard Worker       if (*ImpDefs == Reg || (MRI && MRI->isSubRegister(Reg, *ImpDefs)))
59*9880d681SAndroid Build Coastguard Worker         return true;
60*9880d681SAndroid Build Coastguard Worker   return false;
61*9880d681SAndroid Build Coastguard Worker }
62*9880d681SAndroid Build Coastguard Worker 
hasDefOfPhysReg(const MCInst & MI,unsigned Reg,const MCRegisterInfo & RI) const63*9880d681SAndroid Build Coastguard Worker bool MCInstrDesc::hasDefOfPhysReg(const MCInst &MI, unsigned Reg,
64*9880d681SAndroid Build Coastguard Worker                                   const MCRegisterInfo &RI) const {
65*9880d681SAndroid Build Coastguard Worker   for (int i = 0, e = NumDefs; i != e; ++i)
66*9880d681SAndroid Build Coastguard Worker     if (MI.getOperand(i).isReg() &&
67*9880d681SAndroid Build Coastguard Worker         RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg()))
68*9880d681SAndroid Build Coastguard Worker       return true;
69*9880d681SAndroid Build Coastguard Worker   return hasImplicitDefOfPhysReg(Reg, &RI);
70*9880d681SAndroid Build Coastguard Worker }
71