• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- llvm/MC/MCInstrDesc.h - Instruction Descriptors -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the MCOperandInfo and MCInstrDesc classes, which
11 // are used to describe target instructions and their operands.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 /* Capstone Disassembly Engine */
16 /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */
17 
18 #ifndef CS_LLVM_MC_MCINSTRDESC_H
19 #define CS_LLVM_MC_MCINSTRDESC_H
20 
21 #include "capstone/platform.h"
22 
23 //===----------------------------------------------------------------------===//
24 // Machine Operand Flags and Description
25 //===----------------------------------------------------------------------===//
26 
27 // Operand constraints
28 enum MCOI_OperandConstraint {
29 	MCOI_TIED_TO = 0,    // Must be allocated the same register as.
30 	MCOI_EARLY_CLOBBER   // Operand is an early clobber register operand
31 };
32 
33 /// OperandFlags - These are flags set on operands, but should be considered
34 /// private, all access should go through the MCOperandInfo accessors.
35 /// See the accessors for a description of what these are.
36 enum MCOI_OperandFlags {
37 	MCOI_LookupPtrRegClass = 0,
38 	MCOI_Predicate,
39 	MCOI_OptionalDef
40 };
41 
42 /// Operand Type - Operands are tagged with one of the values of this enum.
43 enum MCOI_OperandType {
44 	MCOI_OPERAND_UNKNOWN,
45 	MCOI_OPERAND_IMMEDIATE,
46 	MCOI_OPERAND_REGISTER,
47 	MCOI_OPERAND_MEMORY,
48 	MCOI_OPERAND_PCREL
49 };
50 
51 
52 /// MCOperandInfo - This holds information about one operand of a machine
53 /// instruction, indicating the register class for register operands, etc.
54 ///
55 typedef struct MCOperandInfo {
56 	/// RegClass - This specifies the register class enumeration of the operand
57 	/// if the operand is a register.  If isLookupPtrRegClass is set, then this is
58 	/// an index that is passed to TargetRegisterInfo::getPointerRegClass(x) to
59 	/// get a dynamic register class.
60 	int16_t RegClass;
61 
62 	/// Flags - These are flags from the MCOI::OperandFlags enum.
63 	uint8_t Flags;
64 
65 	/// OperandType - Information about the type of the operand.
66 	uint8_t OperandType;
67 
68 	/// Lower 16 bits are used to specify which constraints are set. The higher 16
69 	/// bits are used to specify the value of constraints (4 bits each).
70 	uint32_t Constraints;
71 	/// Currently no other information.
72 } MCOperandInfo;
73 
74 
75 //===----------------------------------------------------------------------===//
76 // Machine Instruction Flags and Description
77 //===----------------------------------------------------------------------===//
78 
79 /// MCInstrDesc flags - These should be considered private to the
80 /// implementation of the MCInstrDesc class.  Clients should use the predicate
81 /// methods on MCInstrDesc, not use these directly.  These all correspond to
82 /// bitfields in the MCInstrDesc::Flags field.
83 enum {
84 	MCID_Variadic = 0,
85 	MCID_HasOptionalDef,
86 	MCID_Pseudo,
87 	MCID_Return,
88 	MCID_Call,
89 	MCID_Barrier,
90 	MCID_Terminator,
91 	MCID_Branch,
92 	MCID_IndirectBranch,
93 	MCID_Compare,
94 	MCID_MoveImm,
95 	MCID_Bitcast,
96 	MCID_Select,
97 	MCID_DelaySlot,
98 	MCID_FoldableAsLoad,
99 	MCID_MayLoad,
100 	MCID_MayStore,
101 	MCID_Predicable,
102 	MCID_NotDuplicable,
103 	MCID_UnmodeledSideEffects,
104 	MCID_Commutable,
105 	MCID_ConvertibleTo3Addr,
106 	MCID_UsesCustomInserter,
107 	MCID_HasPostISelHook,
108 	MCID_Rematerializable,
109 	MCID_CheapAsAMove,
110 	MCID_ExtraSrcRegAllocReq,
111 	MCID_ExtraDefRegAllocReq,
112 	MCID_RegSequence,
113 	MCID_ExtractSubreg,
114 	MCID_InsertSubreg
115 };
116 
117 /// MCInstrDesc - Describe properties that are true of each instruction in the
118 /// target description file.  This captures information about side effects,
119 /// register use and many other things.  There is one instance of this struct
120 /// for each target instruction class, and the MachineInstr class points to
121 /// this struct directly to describe itself.
122 typedef struct MCInstrDesc {
123 	unsigned short  Opcode;        // The opcode number
124 	unsigned char  NumOperands;   // Num of args (may be more if variable_ops)
125 	unsigned char  NumDefs;       // Num of args that are definitions
126 	unsigned short  SchedClass;    // enum identifying instr sched class
127 	unsigned char  Size;          // Number of bytes in encoding.
128 	unsigned        Flags;         // Flags identifying machine instr class
129 	uint64_t        TSFlags;       // Target Specific Flag values
130 	char ImplicitUses;  // Registers implicitly read by this instr
131 	char ImplicitDefs;  // Registers implicitly defined by this instr
132 	const MCOperandInfo *OpInfo;   // 'NumOperands' entries about operands
133 	uint64_t DeprecatedFeatureMask;// Feature bits that this is deprecated on, if any
134 	// A complex method to determine is a certain is deprecated or not, and return
135 	// the reason for deprecation.
136 	//bool (*ComplexDeprecationInfo)(MCInst &, MCSubtargetInfo &, std::string &);
137 	unsigned char ComplexDeprecationInfo;	// dummy field, just to satisfy initializer
138 } MCInstrDesc;
139 
140 bool MCOperandInfo_isPredicate(const MCOperandInfo *m);
141 
142 bool MCOperandInfo_isOptionalDef(const MCOperandInfo *m);
143 
144 #endif
145