LLVM  14.0.0git
MCInstrInfo.h
Go to the documentation of this file.
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/MC/MCInstrDesc.h"
17 #include <cassert>
18 
19 namespace llvm {
20 
21 class MCSubtargetInfo;
22 
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 
31 private:
32  const MCInstrDesc *Desc; // 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 
44 public:
45  /// Initialize MCInstrInfo, called by TableGen auto-generated routines.
46  /// *DO NOT USE*.
47  void InitMCInstrInfo(const MCInstrDesc *D, const unsigned *NI, const char *ND,
48  const uint8_t *DF,
49  const ComplexDeprecationPredicate *CDI, unsigned NO) {
50  Desc = D;
51  InstrNameIndices = NI;
52  InstrNameData = ND;
53  DeprecatedFeatures = DF;
54  ComplexDeprecationInfos = CDI;
55  NumOpcodes = NO;
56  }
57 
58  unsigned getNumOpcodes() const { return NumOpcodes; }
59 
60  /// Return the machine instruction descriptor that corresponds to the
61  /// specified instruction opcode.
62  const MCInstrDesc &get(unsigned Opcode) const {
63  assert(Opcode < NumOpcodes && "Invalid opcode!");
64  return Desc[Opcode];
65  }
66 
67  /// Returns the name for the instructions with the given opcode.
68  StringRef getName(unsigned Opcode) const {
69  assert(Opcode < NumOpcodes && "Invalid opcode!");
70  return StringRef(&InstrNameData[InstrNameIndices[Opcode]]);
71  }
72 
73  /// Returns true if a certain instruction is deprecated and if so
74  /// returns the reason in \p Info.
75  bool getDeprecatedInfo(MCInst &MI, const MCSubtargetInfo &STI,
76  std::string &Info) const;
77 };
78 
79 } // End llvm namespace
80 
81 #endif
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
MCInstrDesc.h
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::MCInstrInfo::ComplexDeprecationPredicate
bool(*)(MCInst &, const MCSubtargetInfo &, std::string &) ComplexDeprecationPredicate
Definition: MCInstrInfo.h:29
llvm::MCInstrDesc
Describe properties that are true of each instruction in the target description file.
Definition: MCInstrDesc.h:195
llvm::MCInstrInfo::getDeprecatedInfo
bool getDeprecatedInfo(MCInst &MI, const MCSubtargetInfo &STI, std::string &Info) const
Returns true if a certain instruction is deprecated and if so returns the reason in Info.
Definition: MCInstrInfo.cpp:15
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
DF
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::MCInstrInfo::getName
StringRef getName(unsigned Opcode) const
Returns the name for the instructions with the given opcode.
Definition: MCInstrInfo.h:68
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::MCInstrInfo
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:25
llvm::MCInstrInfo::getNumOpcodes
unsigned getNumOpcodes() const
Definition: MCInstrInfo.h:58
llvm::MCInstrInfo::get
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
Definition: MCInstrInfo.h:62
llvm::MCInstrInfo::InitMCInstrInfo
void InitMCInstrInfo(const MCInstrDesc *D, const unsigned *NI, const char *ND, const uint8_t *DF, const ComplexDeprecationPredicate *CDI, unsigned NO)
Initialize MCInstrInfo, called by TableGen auto-generated routines.
Definition: MCInstrInfo.h:47
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75