LLVM 24.0.0git
MipsMCCodeEmitter.h
Go to the documentation of this file.
1//===- MipsMCCodeEmitter.h - Convert Mips Code to Machine Code --*- 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 defines the MipsMCCodeEmitter class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCCODEEMITTER_H
14#define LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCCODEEMITTER_H
15
17#include <cstdint>
18
19namespace llvm {
20
21class MCContext;
22class MCExpr;
23class MCFixup;
24class MCInst;
25class MCInstrInfo;
26class MCOperand;
27class MCSubtargetInfo;
28class raw_ostream;
29
31 const MCInstrInfo &MCII;
32 MCContext &Ctx;
33 bool IsLittleEndian;
34
35 bool isMicroMips(const MCSubtargetInfo &STI) const;
36 bool isMips32r6(const MCSubtargetInfo &STI) const;
37
38public:
39 MipsMCCodeEmitter(const MCInstrInfo &mcii, MCContext &Ctx_, bool IsLittle)
40 : MCII(mcii), Ctx(Ctx_), IsLittleEndian(IsLittle) {}
43 ~MipsMCCodeEmitter() override = default;
44
45 void EmitByte(unsigned char C, raw_ostream &OS) const;
46
49 const MCSubtargetInfo &STI) const override;
50
51 // getBinaryCodeForInstr - TableGen'erated function for getting the
52 // binary encoding for an instruction.
55 const MCSubtargetInfo &STI) const;
56
57 // getJumpTargetOpValue - Return binary encoding of the jump
58 // target operand. If the machine operand requires relocation,
59 // record the relocation and return zero.
60 unsigned getJumpTargetOpValue(const MCInst &MI, unsigned OpNo,
62 const MCSubtargetInfo &STI) const;
63
64 // getBranchJumpOpValueMM - Return binary encoding of the microMIPS jump
65 // target operand. If the machine operand requires relocation,
66 // record the relocation and return zero.
67 unsigned getJumpTargetOpValueMM(const MCInst &MI, unsigned OpNo,
69 const MCSubtargetInfo &STI) const;
70
71 // getUImm5Lsl2Encoding - Return binary encoding of the microMIPS jump
72 // target operand.
73 unsigned getUImm5Lsl2Encoding(const MCInst &MI, unsigned OpNo,
75 const MCSubtargetInfo &STI) const;
76
77 unsigned getSImm3Lsa2Value(const MCInst &MI, unsigned OpNo,
79 const MCSubtargetInfo &STI) const;
80
81 unsigned getUImm6Lsl2Encoding(const MCInst &MI, unsigned OpNo,
83 const MCSubtargetInfo &STI) const;
84
85 // getSImm9AddiuspValue - Return binary encoding of the microMIPS addiusp
86 // instruction immediate operand.
87 unsigned getSImm9AddiuspValue(const MCInst &MI, unsigned OpNo,
89 const MCSubtargetInfo &STI) const;
90
91 // getBranchTargetOpValue - Return binary encoding of the branch
92 // target operand. If the machine operand requires relocation,
93 // record the relocation and return zero.
94 unsigned getBranchTargetOpValue(const MCInst &MI, unsigned OpNo,
96 const MCSubtargetInfo &STI) const;
97
98 // getBranchTargetOpValue1SImm16 - Return binary encoding of the branch
99 // target operand. If the machine operand requires relocation,
100 // record the relocation and return zero.
101 unsigned getBranchTargetOpValue1SImm16(const MCInst &MI, unsigned OpNo,
103 const MCSubtargetInfo &STI) const;
104
105 // getBranchTargetOpValueMMR6 - Return binary encoding of the branch
106 // target operand. If the machine operand requires relocation,
107 // record the relocation and return zero.
108 unsigned getBranchTargetOpValueMMR6(const MCInst &MI, unsigned OpNo,
110 const MCSubtargetInfo &STI) const;
111
112 // getBranchTargetOpValueLsl2MMR6 - Return binary encoding of the branch
113 // target operand. If the machine operand requires relocation,
114 // record the relocation and return zero.
115 unsigned getBranchTargetOpValueLsl2MMR6(const MCInst &MI, unsigned OpNo,
117 const MCSubtargetInfo &STI) const;
118
119 // getBranchTarget7OpValue - Return binary encoding of the microMIPS branch
120 // target operand. If the machine operand requires relocation,
121 // record the relocation and return zero.
122 unsigned getBranchTarget7OpValueMM(const MCInst &MI, unsigned OpNo,
124 const MCSubtargetInfo &STI) const;
125
126 // getBranchTargetOpValueMMPC10 - Return binary encoding of the microMIPS
127 // 10-bit branch target operand. If the machine operand requires relocation,
128 // record the relocation and return zero.
129 unsigned getBranchTargetOpValueMMPC10(const MCInst &MI, unsigned OpNo,
131 const MCSubtargetInfo &STI) const;
132
133 // getBranchTargetOpValue - Return binary encoding of the microMIPS branch
134 // target operand. If the machine operand requires relocation,
135 // record the relocation and return zero.
136 unsigned getBranchTargetOpValueMM(const MCInst &MI, unsigned OpNo,
138 const MCSubtargetInfo &STI) const;
139
140 // getBranchTarget21OpValue - Return binary encoding of the branch
141 // offset operand. If the machine operand requires relocation,
142 // record the relocation and return zero.
143 unsigned getBranchTarget21OpValue(const MCInst &MI, unsigned OpNo,
145 const MCSubtargetInfo &STI) const;
146
147 // getBranchTarget21OpValueMM - Return binary encoding of the branch
148 // offset operand for microMIPS. If the machine operand requires
149 // relocation,record the relocation and return zero.
150 unsigned getBranchTarget21OpValueMM(const MCInst &MI, unsigned OpNo,
152 const MCSubtargetInfo &STI) const;
153
154 // getBranchTarget26OpValue - Return binary encoding of the branch
155 // offset operand. If the machine operand requires relocation,
156 // record the relocation and return zero.
157 unsigned getBranchTarget26OpValue(const MCInst &MI, unsigned OpNo,
159 const MCSubtargetInfo &STI) const;
160
161 // getBranchTarget26OpValueMM - Return binary encoding of the branch
162 // offset operand. If the machine operand requires relocation,
163 // record the relocation and return zero.
164 unsigned getBranchTarget26OpValueMM(const MCInst &MI, unsigned OpNo,
166 const MCSubtargetInfo &STI) const;
167
168 // getJumpOffset16OpValue - Return binary encoding of the jump
169 // offset operand. If the machine operand requires relocation,
170 // record the relocation and return zero.
171 unsigned getJumpOffset16OpValue(const MCInst &MI, unsigned OpNo,
173 const MCSubtargetInfo &STI) const;
174
175 // getMachineOpValue - Return binary encoding of operand. If the machin
176 // operand requires relocation, record the relocation and return zero.
177 unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO,
179 const MCSubtargetInfo &STI) const;
180 unsigned getImmOpValue(const MCInst &MI, const MCOperand &MO,
182 const MCSubtargetInfo &STI) const;
183
184 template <unsigned ShiftAmount = 0>
185 unsigned getMemEncoding(const MCInst &MI, unsigned OpNo,
187 const MCSubtargetInfo &STI) const;
188 unsigned getMemEncodingMMImm4(const MCInst &MI, unsigned OpNo,
190 const MCSubtargetInfo &STI) const;
191 unsigned getMemEncodingMMImm4Lsl1(const MCInst &MI, unsigned OpNo,
193 const MCSubtargetInfo &STI) const;
194 unsigned getMemEncodingMMImm4Lsl2(const MCInst &MI, unsigned OpNo,
196 const MCSubtargetInfo &STI) const;
197 unsigned getMemEncodingMMSPImm5Lsl2(const MCInst &MI, unsigned OpNo,
199 const MCSubtargetInfo &STI) const;
200 unsigned getMemEncodingMMGPImm7Lsl2(const MCInst &MI, unsigned OpNo,
202 const MCSubtargetInfo &STI) const;
203 unsigned getMemEncodingMMImm9(const MCInst &MI, unsigned OpNo,
205 const MCSubtargetInfo &STI) const;
206 unsigned getMemEncodingMMImm11(const MCInst &MI, unsigned OpNo,
208 const MCSubtargetInfo &STI) const;
209 unsigned getMemEncodingMMImm12(const MCInst &MI, unsigned OpNo,
211 const MCSubtargetInfo &STI) const;
212 unsigned getMemEncodingMMImm16(const MCInst &MI, unsigned OpNo,
214 const MCSubtargetInfo &STI) const;
215 unsigned getMemEncodingMMImm4sp(const MCInst &MI, unsigned OpNo,
217 const MCSubtargetInfo &STI) const;
218 unsigned getSizeInsEncoding(const MCInst &MI, unsigned OpNo,
220 const MCSubtargetInfo &STI) const;
221
222 /// Subtract Offset then encode as a N-bit unsigned integer.
223 template <unsigned Bits, int Offset>
224 unsigned getUImmWithOffsetEncoding(const MCInst &MI, unsigned OpNo,
226 const MCSubtargetInfo &STI) const;
227
228 unsigned getSimm19Lsl2Encoding(const MCInst &MI, unsigned OpNo,
230 const MCSubtargetInfo &STI) const;
231
232 unsigned getSimm18Lsl3Encoding(const MCInst &MI, unsigned OpNo,
234 const MCSubtargetInfo &STI) const;
235
236 unsigned getUImm3Mod8Encoding(const MCInst &MI, unsigned OpNo,
238 const MCSubtargetInfo &STI) const;
239 unsigned getUImm4AndValue(const MCInst &MI, unsigned OpNo,
241 const MCSubtargetInfo &STI) const;
242
243 unsigned getMovePRegPairOpValue(const MCInst &MI, unsigned OpNo,
245 const MCSubtargetInfo &STI) const;
246 unsigned getMovePRegSingleOpValue(const MCInst &MI, unsigned OpNo,
248 const MCSubtargetInfo &STI) const;
249
250 unsigned getSimm23Lsl2Encoding(const MCInst &MI, unsigned OpNo,
252 const MCSubtargetInfo &STI) const;
253
254 unsigned getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups,
255 const MCSubtargetInfo &STI) const;
256
257 unsigned getRegisterListOpValue(const MCInst &MI, unsigned OpNo,
259 const MCSubtargetInfo &STI) const;
260
261 unsigned getRegisterListOpValue16(const MCInst &MI, unsigned OpNo,
263 const MCSubtargetInfo &STI) const;
264
265private:
266 void LowerCompactBranch(MCInst& Inst) const;
267};
268
269} // end namespace llvm
270
271#endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCCODEEMITTER_H
unsigned uint64_t
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
IRTranslator LLVM IR MI
Context object for machine code objects.
Definition MCContext.h:83
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition MCFixup.h:61
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
Interface to description of machine instruction set.
Definition MCInstrInfo.h:27
Instances of this class represent operands of the MCInst class.
Definition MCInst.h:40
Generic base class for all target subtargets.
unsigned getBranchTargetOpValueLsl2MMR6(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValueLsl2MMR6 - Return binary encoding of the branch target operand.
unsigned getSimm23Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getBranchTarget21OpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget21OpValue - Return binary encoding of the branch target operand.
MipsMCCodeEmitter(const MipsMCCodeEmitter &)=delete
uint64_t getBinaryCodeForInstr(const MCInst &MI, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSimm19Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getJumpTargetOpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getMachineOpValue - Return binary encoding of operand.
unsigned getUImmWithOffsetEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Subtract Offset then encode as a N-bit unsigned integer.
unsigned getMemEncodingMMImm9(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSizeInsEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMovePRegPairOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getBranchTargetOpValueMMR6(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValueMMR6 - Return binary encoding of the branch target operand.
unsigned getBranchTargetOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValue - Return binary encoding of the branch target operand.
unsigned getRegisterListOpValue16(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMemEncodingMMGPImm7Lsl2(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
~MipsMCCodeEmitter() override=default
unsigned getMemEncodingMMSPImm5Lsl2(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMemEncodingMMImm4(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMemEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
Return binary encoding of memory related operand.
unsigned getBranchTarget26OpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget26OpValue - Return binary encoding of the branch target operand.
unsigned getBranchTarget26OpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget26OpValueMM - Return binary encoding of the branch target operand.
unsigned getImmOpValue(const MCInst &MI, const MCOperand &MO, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getBranchTargetOpValue1SImm16(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValue1SImm16 - Return binary encoding of the branch target operand.
unsigned getSimm18Lsl3Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSImm3Lsa2Value(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getJumpOffset16OpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getJumpOffset16OpValue - Return binary encoding of the jump target operand.
unsigned getBranchTargetOpValueMMPC10(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValueMMPC10 - Return binary encoding of the microMIPS 10-bit branch target operand.
unsigned getJumpTargetOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getJumpTargetOpValue - Return binary encoding of the jump target operand.
unsigned getUImm4AndValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getRegisterListOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMemEncodingMMImm11(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getUImm5Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMemEncodingMMImm4sp(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getMemEncodingMMImm16(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getExprOpValue(const MCExpr *Expr, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getBranchTargetOpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTargetOpValue - Return binary encoding of the microMIPS branch target operand.
unsigned getMovePRegSingleOpValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getSImm9AddiuspValue(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
MipsMCCodeEmitter(const MCInstrInfo &mcii, MCContext &Ctx_, bool IsLittle)
void encodeInstruction(const MCInst &MI, SmallVectorImpl< char > &CB, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const override
encodeInstruction - Emit the instruction.
unsigned getUImm3Mod8Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getBranchTarget21OpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget21OpValueMM - Return binary encoding of the branch target operand for microMIPS.
MipsMCCodeEmitter & operator=(const MipsMCCodeEmitter &)=delete
unsigned getMemEncodingMMImm4Lsl2(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getBranchTarget7OpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget7OpValueMM - Return binary encoding of the microMIPS branch target operand.
unsigned getMemEncodingMMImm12(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
unsigned getUImm6Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
void EmitByte(unsigned char C, raw_ostream &OS) const
unsigned getMemEncodingMMImm4Lsl1(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.