MCInstrDesc.cpp 2.6 KB

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