MCInstrInfo.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/MC/MCInstrInfo.h - Target Instruction Info ---------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file describes the target machine instruction set.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_MC_MCINSTRINFO_H
  18. #define LLVM_MC_MCINSTRINFO_H
  19. #include "llvm/ADT/StringRef.h"
  20. #include "llvm/MC/MCInstrDesc.h"
  21. #include <cassert>
  22. namespace llvm {
  23. class MCSubtargetInfo;
  24. //---------------------------------------------------------------------------
  25. /// Interface to description of machine instruction set.
  26. class MCInstrInfo {
  27. public:
  28. using ComplexDeprecationPredicate = bool (*)(MCInst &,
  29. const MCSubtargetInfo &,
  30. std::string &);
  31. private:
  32. const MCInstrDesc *LastDesc; // Raw array to allow static init'n
  33. const unsigned *InstrNameIndices; // Array for name indices in InstrNameData
  34. const char *InstrNameData; // Instruction name string pool
  35. // Subtarget feature that an instruction is deprecated on, if any
  36. // -1 implies this is not deprecated by any single feature. It may still be
  37. // deprecated due to a "complex" reason, below.
  38. const uint8_t *DeprecatedFeatures;
  39. // A complex method to determine if a certain instruction is deprecated or
  40. // not, and return the reason for deprecation.
  41. const ComplexDeprecationPredicate *ComplexDeprecationInfos;
  42. unsigned NumOpcodes; // Number of entries in the desc array
  43. public:
  44. /// Initialize MCInstrInfo, called by TableGen auto-generated routines.
  45. /// *DO NOT USE*.
  46. void InitMCInstrInfo(const MCInstrDesc *D, const unsigned *NI, const char *ND,
  47. const uint8_t *DF,
  48. const ComplexDeprecationPredicate *CDI, unsigned NO) {
  49. LastDesc = D + NO - 1;
  50. InstrNameIndices = NI;
  51. InstrNameData = ND;
  52. DeprecatedFeatures = DF;
  53. ComplexDeprecationInfos = CDI;
  54. NumOpcodes = NO;
  55. }
  56. unsigned getNumOpcodes() const { return NumOpcodes; }
  57. /// Return the machine instruction descriptor that corresponds to the
  58. /// specified instruction opcode.
  59. const MCInstrDesc &get(unsigned Opcode) const {
  60. assert(Opcode < NumOpcodes && "Invalid opcode!");
  61. // The table is indexed backwards from the last entry.
  62. return *(LastDesc - Opcode);
  63. }
  64. /// Returns the name for the instructions with the given opcode.
  65. StringRef getName(unsigned Opcode) const {
  66. assert(Opcode < NumOpcodes && "Invalid opcode!");
  67. return StringRef(&InstrNameData[InstrNameIndices[Opcode]]);
  68. }
  69. /// Returns true if a certain instruction is deprecated and if so
  70. /// returns the reason in \p Info.
  71. bool getDeprecatedInfo(MCInst &MI, const MCSubtargetInfo &STI,
  72. std::string &Info) const;
  73. };
  74. } // End llvm namespace
  75. #endif
  76. #ifdef __GNUC__
  77. #pragma GCC diagnostic pop
  78. #endif