LLVM  14.0.0git
MCInstrDesc.cpp
Go to the documentation of this file.
1 //===------ llvm/MC/MCInstrDesc.cpp- Instruction Descriptors --------------===//
2 //
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
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"
16 #include "llvm/MC/MCRegisterInfo.h"
18 
19 using namespace llvm;
20 
22  const MCRegisterInfo &RI) const {
23  if (isBranch() || isCall() || isReturn() || isIndirectBranch())
24  return true;
25  unsigned PC = RI.getProgramCounter();
26  if (PC == 0)
27  return false;
28  if (hasDefOfPhysReg(MI, PC, RI))
29  return true;
30  return false;
31 }
32 
34  const MCRegisterInfo *MRI) const {
35  if (const MCPhysReg *ImpDefs = ImplicitDefs)
36  for (; *ImpDefs; ++ImpDefs)
37  if (*ImpDefs == Reg || (MRI && MRI->isSubRegister(Reg, *ImpDefs)))
38  return true;
39  return false;
40 }
41 
42 bool MCInstrDesc::hasDefOfPhysReg(const MCInst &MI, unsigned Reg,
43  const MCRegisterInfo &RI) const {
44  for (int i = 0, e = NumDefs; i != e; ++i)
45  if (MI.getOperand(i).isReg() &&
46  RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg()))
47  return true;
48  if (variadicOpsAreDefs())
49  for (int i = NumOperands - 1, e = MI.getNumOperands(); i != e; ++i)
50  if (MI.getOperand(i).isReg() &&
51  RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg()))
52  return true;
53  return hasImplicitDefOfPhysReg(Reg, &RI);
54 }
i
i
Definition: README.txt:29
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:103
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
Reg
unsigned Reg
Definition: MachineSink.cpp:1566
llvm::MCInstrDesc::isBranch
bool isBranch() const
Returns true if this is a conditional, unconditional, or indirect branch.
Definition: MCInstrDesc.h:298
MCInstrDesc.h
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::MCInstrDesc::isIndirectBranch
bool isIndirectBranch() const
Return true if this is an indirect branch, such as a branch through a register.
Definition: MCInstrDesc.h:302
llvm::MCInstrDesc::NumDefs
unsigned char NumDefs
Definition: MCInstrDesc.h:199
MCInst.h
MCSubtargetInfo.h
llvm::MCRegisterInfo::isSubRegisterEq
bool isSubRegisterEq(MCRegister RegA, MCRegister RegB) const
Returns true if RegB is a sub-register of RegA or if RegB == RegA.
Definition: MCRegisterInfo.h:568
llvm::MCInstrDesc::hasImplicitDefOfPhysReg
bool hasImplicitDefOfPhysReg(unsigned Reg, const MCRegisterInfo *MRI=nullptr) const
Return true if this instruction implicitly defines the specified physical register.
Definition: MCInstrDesc.cpp:33
llvm::MCInstrDesc::NumOperands
unsigned short NumOperands
Definition: MCInstrDesc.h:198
llvm::MCInstrDesc::isCall
bool isCall() const
Return true if the instruction is a call.
Definition: MCInstrDesc.h:279
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
MCRegisterInfo.h
llvm::MCInstrDesc::variadicOpsAreDefs
bool variadicOpsAreDefs() const
Return true if variadic operands of this instruction are definitions.
Definition: MCInstrDesc.h:409
llvm::MCInstrDesc::hasDefOfPhysReg
bool hasDefOfPhysReg(const MCInst &MI, unsigned Reg, const MCRegisterInfo &RI) const
Return true if this instruction defines the specified physical register, either explicitly or implici...
Definition: MCInstrDesc.cpp:42
llvm::MCRegisterInfo
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Definition: MCRegisterInfo.h:135
MRI
unsigned const MachineRegisterInfo * MRI
Definition: AArch64AdvSIMDScalarPass.cpp:105
llvm::MCInstrDesc::mayAffectControlFlow
bool mayAffectControlFlow(const MCInst &MI, const MCRegisterInfo &RI) const
Return true if this is a branch or an instruction which directly writes to the program counter.
Definition: MCInstrDesc.cpp:21
uint16_t
llvm::MCRegisterInfo::getProgramCounter
MCRegister getProgramCounter() const
Return the register which is the program counter.
Definition: MCRegisterInfo.h:442
llvm::MCInstrDesc::isReturn
bool isReturn() const
Return true if the instruction is a return.
Definition: MCInstrDesc.h:267
llvm::MCInstrDesc::ImplicitDefs
const MCPhysReg * ImplicitDefs
Definition: MCInstrDesc.h:205