MCInstrDesc.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. #include "llvm/MC/MCInstrDesc.h"
  14. #include "llvm/MC/MCInst.h"
  15. #include "llvm/MC/MCRegisterInfo.h"
  16. using namespace llvm;
  17. bool MCInstrDesc::mayAffectControlFlow(const MCInst &MI,
  18. const MCRegisterInfo &RI) const {
  19. if (isBranch() || isCall() || isReturn() || isIndirectBranch())
  20. return true;
  21. unsigned PC = RI.getProgramCounter();
  22. if (PC == 0)
  23. return false;
  24. if (hasDefOfPhysReg(MI, PC, RI))
  25. return true;
  26. return false;
  27. }
  28. bool MCInstrDesc::hasImplicitDefOfPhysReg(unsigned Reg,
  29. const MCRegisterInfo *MRI) const {
  30. for (MCPhysReg ImpDef : implicit_defs())
  31. if (ImpDef == Reg || (MRI && MRI->isSubRegister(Reg, ImpDef)))
  32. return true;
  33. return false;
  34. }
  35. bool MCInstrDesc::hasDefOfPhysReg(const MCInst &MI, unsigned Reg,
  36. const MCRegisterInfo &RI) const {
  37. for (int i = 0, e = NumDefs; i != e; ++i)
  38. if (MI.getOperand(i).isReg() &&
  39. RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg()))
  40. return true;
  41. if (variadicOpsAreDefs())
  42. for (int i = NumOperands - 1, e = MI.getNumOperands(); i != e; ++i)
  43. if (MI.getOperand(i).isReg() &&
  44. RI.isSubRegisterEq(Reg, MI.getOperand(i).getReg()))
  45. return true;
  46. return hasImplicitDefOfPhysReg(Reg, &RI);
  47. }