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 bool isNanoMips(const MCSubtargetInfo &STI) const;
38
39public:
40 MipsMCCodeEmitter(const MCInstrInfo &mcii, MCContext &Ctx_, bool IsLittle)
41 : MCII(mcii), Ctx(Ctx_), IsLittleEndian(IsLittle) {}
44 ~MipsMCCodeEmitter() override = default;
45
46 void EmitByte(unsigned char C, raw_ostream &OS) const;
47
50 const MCSubtargetInfo &STI) const override;
51
52 // getBinaryCodeForInstr - TableGen'erated function for getting the
53 // binary encoding for an instruction.
56 const MCSubtargetInfo &STI) const;
57
58 // getJumpTargetOpValue - Return binary encoding of the jump
59 // target operand. If the machine operand requires relocation,
60 // record the relocation and return zero.
61 unsigned getJumpTargetOpValue(const MCInst &MI, unsigned OpNo,
63 const MCSubtargetInfo &STI) const;
64
65 // getBranchJumpOpValueMM - Return binary encoding of the microMIPS jump
66 // target operand. If the machine operand requires relocation,
67 // record the relocation and return zero.
68 unsigned getJumpTargetOpValueMM(const MCInst &MI, unsigned OpNo,
70 const MCSubtargetInfo &STI) const;
71
72 // getUImm5Lsl2Encoding - Return binary encoding of the microMIPS jump
73 // target operand.
74 unsigned getUImm5Lsl2Encoding(const MCInst &MI, unsigned OpNo,
76 const MCSubtargetInfo &STI) const;
77
78 unsigned getSImm3Lsa2Value(const MCInst &MI, unsigned OpNo,
80 const MCSubtargetInfo &STI) const;
81
82 unsigned getUImm6Lsl2Encoding(const MCInst &MI, unsigned OpNo,
84 const MCSubtargetInfo &STI) const;
85
86 // getSImm9AddiuspValue - Return binary encoding of the microMIPS addiusp
87 // instruction immediate operand.
88 unsigned getSImm9AddiuspValue(const MCInst &MI, unsigned OpNo,
90 const MCSubtargetInfo &STI) const;
91
92 // getBranchTargetOpValue - Return binary encoding of the branch
93 // target operand. If the machine operand requires relocation,
94 // record the relocation and return zero.
95 unsigned getBranchTargetOpValue(const MCInst &MI, unsigned OpNo,
97 const MCSubtargetInfo &STI) const;
98
99 // getBranchTargetOpValue1SImm16 - Return binary encoding of the branch
100 // target operand. If the machine operand requires relocation,
101 // record the relocation and return zero.
102 unsigned getBranchTargetOpValue1SImm16(const MCInst &MI, unsigned OpNo,
104 const MCSubtargetInfo &STI) const;
105
106 // getBranchTargetOpValueMMR6 - Return binary encoding of the branch
107 // target operand. If the machine operand requires relocation,
108 // record the relocation and return zero.
109 unsigned getBranchTargetOpValueMMR6(const MCInst &MI, unsigned OpNo,
111 const MCSubtargetInfo &STI) const;
112
113 // getBranchTargetOpValueLsl2MMR6 - Return binary encoding of the branch
114 // target operand. If the machine operand requires relocation,
115 // record the relocation and return zero.
116 unsigned getBranchTargetOpValueLsl2MMR6(const MCInst &MI, unsigned OpNo,
118 const MCSubtargetInfo &STI) const;
119
120 // getBranchTarget7OpValue - Return binary encoding of the microMIPS branch
121 // target operand. If the machine operand requires relocation,
122 // record the relocation and return zero.
123 unsigned getBranchTarget7OpValueMM(const MCInst &MI, unsigned OpNo,
125 const MCSubtargetInfo &STI) const;
126
127 // getBranchTargetOpValueMMPC10 - Return binary encoding of the microMIPS
128 // 10-bit branch target operand. If the machine operand requires relocation,
129 // record the relocation and return zero.
130 unsigned getBranchTargetOpValueMMPC10(const MCInst &MI, unsigned OpNo,
132 const MCSubtargetInfo &STI) const;
133
134 // getBranchTargetOpValue - Return binary encoding of the microMIPS branch
135 // target operand. If the machine operand requires relocation,
136 // record the relocation and return zero.
137 unsigned getBranchTargetOpValueMM(const MCInst &MI, unsigned OpNo,
139 const MCSubtargetInfo &STI) const;
140
141 // getBranchTarget21OpValue - Return binary encoding of the branch
142 // offset operand. If the machine operand requires relocation,
143 // record the relocation and return zero.
144 unsigned getBranchTarget21OpValue(const MCInst &MI, unsigned OpNo,
146 const MCSubtargetInfo &STI) const;
147
148 // getBranchTarget21OpValueMM - Return binary encoding of the branch
149 // offset operand for microMIPS. If the machine operand requires
150 // relocation,record the relocation and return zero.
151 unsigned getBranchTarget21OpValueMM(const MCInst &MI, unsigned OpNo,
153 const MCSubtargetInfo &STI) const;
154
155 // getBranchTarget26OpValue - Return binary encoding of the branch
156 // offset operand. If the machine operand requires relocation,
157 // record the relocation and return zero.
158 unsigned getBranchTarget26OpValue(const MCInst &MI, unsigned OpNo,
160 const MCSubtargetInfo &STI) const;
161
162 // getBranchTarget26OpValueMM - Return binary encoding of the branch
163 // offset operand. If the machine operand requires relocation,
164 // record the relocation and return zero.
165 unsigned getBranchTarget26OpValueMM(const MCInst &MI, unsigned OpNo,
167 const MCSubtargetInfo &STI) const;
168
169 // getJumpOffset16OpValue - Return binary encoding of the jump
170 // offset operand. If the machine operand requires relocation,
171 // record the relocation and return zero.
172 unsigned getJumpOffset16OpValue(const MCInst &MI, unsigned OpNo,
174 const MCSubtargetInfo &STI) const;
175
176 // getMachineOpValue - Return binary encoding of operand. If the machin
177 // operand requires relocation, record the relocation and return zero.
178 unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO,
180 const MCSubtargetInfo &STI) const;
181 unsigned getImmOpValue(const MCInst &MI, const MCOperand &MO,
183 const MCSubtargetInfo &STI) const;
184
185 template <unsigned Shift>
186 unsigned getScaledImmOpValue(const MCInst &MI, unsigned OpNo,
188 const MCSubtargetInfo &STI) const;
189 template <unsigned FromEnd, unsigned Shift = 0>
190 unsigned getOperandFromEndValue(const MCInst &MI, unsigned OpNo,
192 const MCSubtargetInfo &STI) const;
193 unsigned getSizeInsEncoding(const MCInst &MI, unsigned OpNo,
195 const MCSubtargetInfo &STI) const;
196
197 /// Subtract Offset then encode as a N-bit unsigned integer.
198 template <unsigned Bits, int Offset>
199 unsigned getUImmWithOffsetEncoding(const MCInst &MI, unsigned OpNo,
201 const MCSubtargetInfo &STI) const;
202
203 unsigned getSimm19Lsl2Encoding(const MCInst &MI, unsigned OpNo,
205 const MCSubtargetInfo &STI) const;
206
207 unsigned getSimm18Lsl3Encoding(const MCInst &MI, unsigned OpNo,
209 const MCSubtargetInfo &STI) const;
210
211 unsigned getUImm3Mod8Encoding(const MCInst &MI, unsigned OpNo,
213 const MCSubtargetInfo &STI) const;
214 unsigned getUImm4AndValue(const MCInst &MI, unsigned OpNo,
216 const MCSubtargetInfo &STI) const;
217
218 unsigned getMovePRegPairOpValue(const MCInst &MI, unsigned OpNo,
220 const MCSubtargetInfo &STI) const;
221 unsigned getMovePRegSingleOpValue(const MCInst &MI, unsigned OpNo,
223 const MCSubtargetInfo &STI) const;
224
225 unsigned getSimm23Lsl2Encoding(const MCInst &MI, unsigned OpNo,
227 const MCSubtargetInfo &STI) const;
228
229 unsigned getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups,
230 const MCSubtargetInfo &STI) const;
231
232 unsigned getRegisterListOpValue(const MCInst &MI, unsigned OpNo,
234 const MCSubtargetInfo &STI) const;
235
236 unsigned getRegisterListOpValue16(const MCInst &MI, unsigned OpNo,
238 const MCSubtargetInfo &STI) const;
239
240private:
241 void LowerCompactBranch(MCInst& Inst) const;
242
243 void expandGOTLoad(const MCInst &MI, SmallVectorImpl<char> &CB,
245 const MCSubtargetInfo &STI) const;
246};
247
248} // end namespace llvm
249
250#endif // LLVM_LIB_TARGET_MIPS_MCTARGETDESC_MIPSMCCODEEMITTER_H
uint64_t 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:84
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:65
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 getOperandFromEndValue(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 getScaledImmOpValue(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
~MipsMCCodeEmitter() override=default
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 getUImm5Lsl2Encoding(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 getBranchTarget7OpValueMM(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
getBranchTarget7OpValueMM - Return binary encoding of the microMIPS branch target operand.
unsigned getUImm6Lsl2Encoding(const MCInst &MI, unsigned OpNo, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const
void EmitByte(unsigned char C, raw_ostream &OS) 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.