Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:14

0001 //===-- llvm/MC/MCInstrInfo.h - Target Instruction Info ---------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file describes the target machine instruction set.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_MC_MCINSTRINFO_H
0014 #define LLVM_MC_MCINSTRINFO_H
0015 
0016 #include "llvm/ADT/StringRef.h"
0017 #include "llvm/MC/MCInstrDesc.h"
0018 #include <cassert>
0019 
0020 namespace llvm {
0021 
0022 class MCSubtargetInfo;
0023 
0024 //---------------------------------------------------------------------------
0025 /// Interface to description of machine instruction set.
0026 class MCInstrInfo {
0027 public:
0028   using ComplexDeprecationPredicate = bool (*)(MCInst &,
0029                                                const MCSubtargetInfo &,
0030                                                std::string &);
0031 
0032 private:
0033   const MCInstrDesc *LastDesc;      // Raw array to allow static init'n
0034   const unsigned *InstrNameIndices; // Array for name indices in InstrNameData
0035   const char *InstrNameData;        // Instruction name string pool
0036   // Subtarget feature that an instruction is deprecated on, if any
0037   // -1 implies this is not deprecated by any single feature. It may still be
0038   // deprecated due to a "complex" reason, below.
0039   const uint8_t *DeprecatedFeatures;
0040   // A complex method to determine if a certain instruction is deprecated or
0041   // not, and return the reason for deprecation.
0042   const ComplexDeprecationPredicate *ComplexDeprecationInfos;
0043   unsigned NumOpcodes;              // Number of entries in the desc array
0044 
0045 public:
0046   /// Initialize MCInstrInfo, called by TableGen auto-generated routines.
0047   /// *DO NOT USE*.
0048   void InitMCInstrInfo(const MCInstrDesc *D, const unsigned *NI, const char *ND,
0049                        const uint8_t *DF,
0050                        const ComplexDeprecationPredicate *CDI, unsigned NO) {
0051     LastDesc = D + NO - 1;
0052     InstrNameIndices = NI;
0053     InstrNameData = ND;
0054     DeprecatedFeatures = DF;
0055     ComplexDeprecationInfos = CDI;
0056     NumOpcodes = NO;
0057   }
0058 
0059   unsigned getNumOpcodes() const { return NumOpcodes; }
0060 
0061   /// Return the machine instruction descriptor that corresponds to the
0062   /// specified instruction opcode.
0063   const MCInstrDesc &get(unsigned Opcode) const {
0064     assert(Opcode < NumOpcodes && "Invalid opcode!");
0065     // The table is indexed backwards from the last entry.
0066     return *(LastDesc - Opcode);
0067   }
0068 
0069   /// Returns the name for the instructions with the given opcode.
0070   StringRef getName(unsigned Opcode) const {
0071     assert(Opcode < NumOpcodes && "Invalid opcode!");
0072     return StringRef(&InstrNameData[InstrNameIndices[Opcode]]);
0073   }
0074 
0075   /// Returns true if a certain instruction is deprecated and if so
0076   /// returns the reason in \p Info.
0077   bool getDeprecatedInfo(MCInst &MI, const MCSubtargetInfo &STI,
0078                          std::string &Info) const;
0079 };
0080 
0081 } // End llvm namespace
0082 
0083 #endif