MCInstrInfo.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/MC/MCInstrDesc.h"
  20. #include <cassert>
  21. namespace llvm {
  22. class MCSubtargetInfo;
  23. //---------------------------------------------------------------------------
  24. /// Interface to description of machine instruction set.
  25. class MCInstrInfo {
  26. public:
  27. using ComplexDeprecationPredicate = bool (*)(MCInst &,
  28. const MCSubtargetInfo &,
  29. std::string &);
  30. private:
  31. const MCInstrDesc *Desc; // Raw array to allow static init'n
  32. const unsigned *InstrNameIndices; // Array for name indices in InstrNameData
  33. const char *InstrNameData; // Instruction name string pool
  34. // Subtarget feature that an instruction is deprecated on, if any
  35. // -1 implies this is not deprecated by any single feature. It may still be
  36. // deprecated due to a "complex" reason, below.
  37. const uint8_t *DeprecatedFeatures;
  38. // A complex method to determine if a certain instruction is deprecated or
  39. // not, and return the reason for deprecation.
  40. const ComplexDeprecationPredicate *ComplexDeprecationInfos;
  41. unsigned NumOpcodes; // Number of entries in the desc array
  42. public:
  43. /// Initialize MCInstrInfo, called by TableGen auto-generated routines.
  44. /// *DO NOT USE*.
  45. void InitMCInstrInfo(const MCInstrDesc *D, const unsigned *NI, const char *ND,
  46. const uint8_t *DF,
  47. const ComplexDeprecationPredicate *CDI, unsigned NO) {
  48. Desc = D;
  49. InstrNameIndices = NI;
  50. InstrNameData = ND;
  51. DeprecatedFeatures = DF;
  52. ComplexDeprecationInfos = CDI;
  53. NumOpcodes = NO;
  54. }
  55. unsigned getNumOpcodes() const { return NumOpcodes; }
  56. /// Return the machine instruction descriptor that corresponds to the
  57. /// specified instruction opcode.
  58. const MCInstrDesc &get(unsigned Opcode) const {
  59. assert(Opcode < NumOpcodes && "Invalid opcode!");
  60. return Desc[Opcode];
  61. }
  62. /// Returns the name for the instructions with the given opcode.
  63. StringRef getName(unsigned Opcode) const {
  64. assert(Opcode < NumOpcodes && "Invalid opcode!");
  65. return StringRef(&InstrNameData[InstrNameIndices[Opcode]]);
  66. }
  67. /// Returns true if a certain instruction is deprecated and if so
  68. /// returns the reason in \p Info.
  69. bool getDeprecatedInfo(MCInst &MI, const MCSubtargetInfo &STI,
  70. std::string &Info) const;
  71. };
  72. } // End llvm namespace
  73. #endif
  74. #ifdef __GNUC__
  75. #pragma GCC diagnostic pop
  76. #endif