LLVM 17.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
47 void emitInstruction(uint64_t Val, unsigned Size, const MCSubtargetInfo &STI,
48 raw_ostream &OS) const;
49
52 const MCSubtargetInfo &STI) const override;
53
54 // getBinaryCodeForInstr - TableGen'erated function for getting the
55 // binary encoding for an instruction.
58 const MCSubtargetInfo &STI) const;
59
60 // getJumpTargetOpValue - Return binary encoding of the jump
61 // target operand. If the machine operand requires relocation,
62 // record the relocation and return zero.
63 unsigned getJumpTargetOpValue(const MCInst &MI, unsigned OpNo,
65 const MCSubtargetInfo &STI) const;
66
67 // getBranchJumpOpValueMM - Return binary encoding of the microMIPS jump
68 // target operand. If the machine operand requires relocation,
69 // record the relocation and return zero.
70 unsigned getJumpTargetOpValueMM(const MCInst &MI, unsigned OpNo,
72 const MCSubtargetInfo &STI) const;
73
74 // getUImm5Lsl2Encoding - Return binary encoding of the microMIPS jump
75 // target operand.
76 unsigned getUImm5Lsl2Encoding(const MCInst &MI, unsigned OpNo,
78 const MCSubtargetInfo &STI) const;
79
80 unsigned getSImm3Lsa2Value(const MCInst &MI, unsigned OpNo,
82 const MCSubtargetInfo &STI) const;
83
84 unsigned getUImm6Lsl2Encoding(const MCInst &MI, unsigned OpNo,
86 const MCSubtargetInfo &STI) const;
87
88 // getSImm9AddiuspValue - Return binary encoding of the microMIPS addiusp
89 // instruction immediate operand.
90 unsigned getSImm9AddiuspValue(const MCInst &MI, unsigned OpNo,
92 const MCSubtargetInfo &STI) const;
93
94 // getBranchTargetOpValue - Return binary encoding of the branch
95 // target operand. If the machine operand requires relocation,
96 // record the relocation and return zero.
97 unsigned getBranchTargetOpValue(const MCInst &MI, unsigned OpNo,
99 const MCSubtargetInfo &STI) const;
100
101 // getBranchTargetOpValue1SImm16 - Return binary encoding of the branch
102 // target operand. If the machine operand requires relocation,
103 // record the relocation and return zero.
104 unsigned getBranchTargetOpValue1SImm16(const MCInst &MI, unsigned OpNo,
106 const MCSubtargetInfo &STI) const;
107
108 // getBranchTargetOpValueMMR6 - Return binary encoding of the branch
109 // target operand. If the machine operand requires relocation,
110 // record the relocation and return zero.
111 unsigned getBranchTargetOpValueMMR6(const MCInst &MI, unsigned OpNo,
113 const MCSubtargetInfo &STI) const;
114
115 // getBranchTargetOpValueLsl2MMR6 - Return binary encoding of the branch
116 // target operand. If the machine operand requires relocation,
117 // record the relocation and return zero.
118 unsigned getBranchTargetOpValueLsl2MMR6(const MCInst &MI, unsigned OpNo,
120 const MCSubtargetInfo &STI) const;
121
122 // getBranchTarget7OpValue - Return binary encoding of the microMIPS branch
123 // target operand. If the machine operand requires relocation,
124 // record the relocation and return zero.
125 unsigned getBranchTarget7OpValueMM(const MCInst &MI, unsigned OpNo,
127 const MCSubtargetInfo &STI) const;
128
129 // getBranchTargetOpValueMMPC10 - Return binary encoding of the microMIPS
130 // 10-bit branch target operand. If the machine operand requires relocation,
131 // record the relocation and return zero.
132 unsigned getBranchTargetOpValueMMPC10(const MCInst &MI, unsigned OpNo,
134 const MCSubtargetInfo &STI) const;
135
136 // getBranchTargetOpValue - Return binary encoding of the microMIPS branch
137 // target operand. If the machine operand requires relocation,
138 // record the relocation and return zero.
139 unsigned getBranchTargetOpValueMM(const MCInst &MI, unsigned OpNo,
141 const MCSubtargetInfo &STI) const;
142
143 // getBranchTarget21OpValue - Return binary encoding of the branch
144 // offset operand. If the machine operand requires relocation,
145 // record the relocation and return zero.
146 unsigned getBranchTarget21OpValue(const MCInst &MI, unsigned OpNo,
148 const MCSubtargetInfo &STI) const;
149
150 // getBranchTarget21OpValueMM - Return binary encoding of the branch
151 // offset operand for microMIPS. If the machine operand requires
152 // relocation,record the relocation and return zero.
153 unsigned getBranchTarget21OpValueMM(const MCInst &MI, unsigned OpNo,
155 const MCSubtargetInfo &STI) const;
156
157 // getBranchTarget26OpValue - Return binary encoding of the branch
158 // offset operand. If the machine operand requires relocation,
159 // record the relocation and return zero.
160 unsigned getBranchTarget26OpValue(const MCInst &MI, unsigned OpNo,
162 const MCSubtargetInfo &STI) const;
163
164 // getBranchTarget26OpValueMM - Return binary encoding of the branch
165 // offset operand. If the machine operand requires relocation,
166 // record the relocation and return zero.
167 unsigned getBranchTarget26OpValueMM(const MCInst &MI, unsigned OpNo,
169 const MCSubtargetInfo &STI) const;
170
171 // getJumpOffset16OpValue - Return binary encoding of the jump
172 // offset operand. If the machine operand requires relocation,
173 // record the relocation and return zero.
174 unsigned getJumpOffset16OpValue(const MCInst &MI, unsigned OpNo,
176 const MCSubtargetInfo &STI) const;
177
178 // getMachineOpValue - Return binary encoding of operand. If the machin
179 // operand requires relocation, record the relocation and return zero.
180 unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO,
182 const MCSubtargetInfo &STI) const;
183
184 unsigned getMSAMemEncoding(const MCInst &MI, unsigned OpNo,
186 const MCSubtargetInfo &STI) const;
187
188 template <unsigned ShiftAmount = 0>
189 unsigned getMemEncoding(const MCInst &MI, unsigned OpNo,
191 const MCSubtargetInfo &STI) const;
192 unsigned getMemEncodingMMImm4(const MCInst &MI, unsigned OpNo,
194 const MCSubtargetInfo &STI) const;
195 unsigned getMemEncodingMMImm4Lsl1(const MCInst &MI, unsigned OpNo,
197 const MCSubtargetInfo &STI) const;
198 unsigned getMemEncodingMMImm4Lsl2(const MCInst &MI, unsigned OpNo,
200 const MCSubtargetInfo &STI) const;
201 unsigned getMemEncodingMMSPImm5Lsl2(const MCInst &MI, unsigned OpNo,
203 const MCSubtargetInfo &STI) const;
204 unsigned getMemEncodingMMGPImm7Lsl2(const MCInst &MI, unsigned OpNo,
206 const MCSubtargetInfo &STI) const;
207 unsigned getMemEncodingMMImm9(const MCInst &MI, unsigned OpNo,
209 const MCSubtargetInfo &STI) const;
210 unsigned getMemEncodingMMImm11(const MCInst &MI, unsigned OpNo,
212 const MCSubtargetInfo &STI) const;
213 unsigned getMemEncodingMMImm12(const MCInst &MI, unsigned OpNo,
215 const MCSubtargetInfo &STI) const;
216 unsigned getMemEncodingMMImm16(const MCInst &MI, unsigned OpNo,
218 const MCSubtargetInfo &STI) const;
219 unsigned getMemEncodingMMImm4sp(const MCInst &MI, unsigned OpNo,
221 const MCSubtargetInfo &STI) const;
222 unsigned getSizeInsEncoding(const MCInst &MI, unsigned OpNo,
224 const MCSubtargetInfo &STI) const;
225
226 /// Subtract Offset then encode as a N-bit unsigned integer.
227 template <unsigned Bits, int Offset>
228 unsigned getUImmWithOffsetEncoding(const MCInst &MI, unsigned OpNo,
230 const MCSubtargetInfo &STI) const;
231
232 unsigned getSimm19Lsl2Encoding(const MCInst &MI, unsigned OpNo,
234 const MCSubtargetInfo &STI) const;
235
236 unsigned getSimm18Lsl3Encoding(const MCInst &MI, unsigned OpNo,
238 const MCSubtargetInfo &STI) const;
239
240 unsigned getUImm3Mod8Encoding(const MCInst &MI, unsigned OpNo,
242 const MCSubtargetInfo &STI) const;
243 unsigned getUImm4AndValue(const MCInst &MI, unsigned OpNo,
245 const MCSubtargetInfo &STI) const;
246
247 unsigned getMovePRegPairOpValue(const MCInst &MI, unsigned OpNo,
249 const MCSubtargetInfo &STI) const;
250 unsigned getMovePRegSingleOpValue(const MCInst &MI, unsigned OpNo,
252 const MCSubtargetInfo &STI) const;
253
254 unsigned getSimm23Lsl2Encoding(const MCInst &MI, unsigned OpNo,
256 const MCSubtargetInfo &STI) const;
257
258 unsigned getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups,
259 const MCSubtargetInfo &STI) const;
260
261 unsigned getRegisterListOpValue(const MCInst &MI, unsigned OpNo,
263 const MCSubtargetInfo &STI) const;
264
265 unsigned getRegisterListOpValue16(const MCInst &MI, unsigned OpNo,
267 const MCSubtargetInfo &STI) const;
268
269private:
270 void LowerCompactBranch(MCInst& Inst) const;
271};
272
273} // end namespace llvm
274
275#endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCCODEEMITTER_H
uint64_t Size
IRTranslator LLVM IR MI
raw_pwrite_stream & OS
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:21
Context object for machine code objects.
Definition: MCContext.h:76
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
Interface to description of machine instruction set.
Definition: MCInstrInfo.h:26
Instances of this class represent operands of the MCInst class.
Definition: MCInst.h:36
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 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
void encodeInstruction(const MCInst &MI, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const override
encodeInstruction - Emit the instruction.
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)
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.
unsigned getMSAMemEncoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
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 emitInstruction(uint64_t Val, unsigned Size, const MCSubtargetInfo &STI, raw_ostream &OS) 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...
Definition: SmallVector.h:577
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18