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