LLVM 24.0.0git
MipsMCCodeEmitter.cpp
Go to the documentation of this file.
1//===-- MipsMCCodeEmitter.cpp - Convert Mips Code to Machine Code ---------===//
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 implements the MipsMCCodeEmitter class.
10//
11//===----------------------------------------------------------------------===//
12
13#include "MipsMCCodeEmitter.h"
18#include "llvm/ADT/APFloat.h"
19#include "llvm/ADT/APInt.h"
21#include "llvm/MC/MCContext.h"
22#include "llvm/MC/MCExpr.h"
23#include "llvm/MC/MCFixup.h"
24#include "llvm/MC/MCInst.h"
26#include "llvm/MC/MCInstrDesc.h"
27#include "llvm/MC/MCInstrInfo.h"
30#include "llvm/MC/MCValue.h"
34#include <cassert>
35#include <cstdint>
36
37using namespace llvm;
38
39#define DEBUG_TYPE "mccodeemitter"
40
41#define GET_INSTRMAP_INFO
42#include "MipsGenInstrInfo.inc"
43#undef GET_INSTRMAP_INFO
44
45namespace llvm {
46
48 MCContext &Ctx) {
49 return new MipsMCCodeEmitter(MCII, Ctx, false);
50}
51
53 MCContext &Ctx) {
54 return new MipsMCCodeEmitter(MCII, Ctx, true);
55}
56
57} // end namespace llvm
58
82
83// If the D<shift> instruction has a shift amount that is greater
84// than 31 (checked in calling routine), lower it to a D<shift>32 instruction
85static void LowerLargeShift(MCInst& Inst) {
86 assert(Inst.getNumOperands() == 3 && "Invalid no. of operands for shift!");
87 assert(Inst.getOperand(2).isImm());
88
89 int64_t Shift = Inst.getOperand(2).getImm();
90 if (Shift <= 31)
91 return; // Do nothing
92 Shift -= 32;
93
94 // saminus32
95 Inst.getOperand(2).setImm(Shift);
96
97 switch (Inst.getOpcode()) {
98 default:
99 // Calling function is not synchronized
100 llvm_unreachable("Unexpected shift instruction");
101 case Mips::DSLL:
102 Inst.setOpcode(Mips::DSLL32);
103 return;
104 case Mips::DSRL:
105 Inst.setOpcode(Mips::DSRL32);
106 return;
107 case Mips::DSRA:
108 Inst.setOpcode(Mips::DSRA32);
109 return;
110 case Mips::DROTR:
111 Inst.setOpcode(Mips::DROTR32);
112 return;
113 }
114}
115
116// Fix a bad compact branch encoding for beqc/bnec.
117void MipsMCCodeEmitter::LowerCompactBranch(MCInst& Inst) const {
118 // Encoding may be illegal !(rs < rt), but this situation is
119 // easily fixed.
120 MCRegister RegOp0 = Inst.getOperand(0).getReg();
121 MCRegister RegOp1 = Inst.getOperand(1).getReg();
122
123 unsigned Reg0 = Ctx.getRegisterInfo()->getEncodingValue(RegOp0);
124 unsigned Reg1 = Ctx.getRegisterInfo()->getEncodingValue(RegOp1);
125
126 if (Inst.getOpcode() == Mips::BNEC || Inst.getOpcode() == Mips::BEQC ||
127 Inst.getOpcode() == Mips::BNEC64 || Inst.getOpcode() == Mips::BEQC64) {
128 assert(Reg0 != Reg1 && "Instruction has bad operands ($rs == $rt)!");
129 if (Reg0 < Reg1)
130 return;
131 } else if (Inst.getOpcode() == Mips::BNVC || Inst.getOpcode() == Mips::BOVC) {
132 if (Reg0 >= Reg1)
133 return;
134 } else if (Inst.getOpcode() == Mips::BNVC_MMR6 ||
135 Inst.getOpcode() == Mips::BOVC_MMR6) {
136 if (Reg1 >= Reg0)
137 return;
138 } else
139 llvm_unreachable("Cannot rewrite unknown branch!");
140
141 Inst.getOperand(0).setReg(RegOp1);
142 Inst.getOperand(1).setReg(RegOp0);
143}
144
145bool MipsMCCodeEmitter::isMicroMips(const MCSubtargetInfo &STI) const {
146 return STI.hasFeature(Mips::FeatureMicroMips);
147}
148
149bool MipsMCCodeEmitter::isMips32r6(const MCSubtargetInfo &STI) const {
150 return STI.hasFeature(Mips::FeatureMips32r6);
151}
152
153bool MipsMCCodeEmitter::isNanoMips(const MCSubtargetInfo &STI) const {
154 return STI.hasFeature(Mips::FeatureNanoMips);
155}
156
157void MipsMCCodeEmitter::EmitByte(unsigned char C, raw_ostream &OS) const {
158 OS << (char)C;
159}
160
161/// encodeInstruction - Emit the instruction.
162/// Size the instruction with Desc.getSize().
166 const MCSubtargetInfo &STI) const {
167 if (MI.getOpcode() == Mips::PseudoGOTLoadGlobal ||
168 MI.getOpcode() == Mips::PseudoGOTLoadLocal) {
169 expandGOTLoad(MI, CB, Fixups, STI);
170 return;
171 }
172
173 // Non-pseudo instructions that get changed for direct object
174 // only based on operand values.
175 // If this list of instructions get much longer we will move
176 // the check to a function call. Until then, this is more efficient.
177 MCInst TmpInst = MI;
178 switch (MI.getOpcode()) {
179 // If shift amount is >= 32 it the inst needs to be lowered further
180 case Mips::DSLL:
181 case Mips::DSRL:
182 case Mips::DSRA:
183 case Mips::DROTR:
184 LowerLargeShift(TmpInst);
185 break;
186 // Compact branches, enforce encoding restrictions.
187 case Mips::BEQC:
188 case Mips::BNEC:
189 case Mips::BEQC64:
190 case Mips::BNEC64:
191 case Mips::BOVC:
192 case Mips::BOVC_MMR6:
193 case Mips::BNVC:
194 case Mips::BNVC_MMR6:
195 LowerCompactBranch(TmpInst);
196 }
197
198 size_t N = Fixups.size();
199 uint64_t Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
200
201 // Check for unimplemented opcodes.
202 // Unfortunately in MIPS both NOP and SLL will come in with Binary == 0
203 // so we have to special check for them.
204 const unsigned Opcode = TmpInst.getOpcode();
205 if ((Opcode != Mips::NOP) && (Opcode != Mips::SLL) &&
206 (Opcode != Mips::SLL_MM) && (Opcode != Mips::SLL_MMR6) && !Binary)
207 llvm_unreachable("unimplemented opcode in encodeInstruction()");
208
209 int NewOpcode = -1;
210 if (isMicroMips(STI)) {
211 if (isMips32r6(STI)) {
212 NewOpcode = Mips::MipsR62MicroMipsR6(Opcode, Mips::Arch_micromipsr6);
213 if (NewOpcode == -1)
214 NewOpcode = Mips::Std2MicroMipsR6(Opcode, Mips::Arch_micromipsr6);
215 }
216 else
217 NewOpcode = Mips::Std2MicroMips(Opcode, Mips::Arch_micromips);
218
219 // Check whether it is Dsp instruction.
220 if (NewOpcode == -1)
221 NewOpcode = Mips::Dsp2MicroMips(Opcode, Mips::Arch_mmdsp);
222
223 if (NewOpcode != -1) {
224 if (Fixups.size() > N)
225 Fixups.pop_back();
226
227 TmpInst.setOpcode (NewOpcode);
228 Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
229 }
230
231 if (((MI.getOpcode() == Mips::MOVEP_MM) ||
232 (MI.getOpcode() == Mips::MOVEP_MMR6))) {
233 unsigned RegPair = getMovePRegPairOpValue(MI, 0, Fixups, STI);
234 Binary = (Binary & 0xFFFFFC7F) | (RegPair << 7);
235 }
236 }
237
238 const MCInstrDesc &Desc = MCII.get(TmpInst.getOpcode());
239
240 // Get byte count of instruction
241 unsigned Size = Desc.getSize();
242 if (!Size)
243 llvm_unreachable("Desc.getSize() returns 0");
244
245 auto Endian =
247 if (Size == 2) {
249 } else if (IsLittleEndian && Size == 4 &&
250 (isMicroMips(STI) || isNanoMips(STI))) {
251 support::endian::write<uint16_t>(CB, Binary >> 16, Endian);
252 support::endian::write<uint16_t>(CB, Binary & 0xffff, Endian);
253 } else if (IsLittleEndian && Size == 6 && isNanoMips(STI)) {
254 support::endian::write<uint16_t>(CB, Binary >> 32, Endian);
255 support::endian::write<uint16_t>(CB, Binary >> 16, Endian);
256 support::endian::write<uint16_t>(CB, Binary & 0xffff, Endian);
257 } else {
259 }
260}
261
262/// Expand PseudoGOTLoadGlobal and PseudoGOTLoadLocal into the sequence that
263/// MipsAsmParser::loadAndAddSymbolAddress emits when the binding of the
264/// symbol is already known:
265///
266/// Global: lw $rd, %got(sym)($gp)
267/// >addiu $rd, $rd, offset
268/// Global call: lw $25, %call16(sym)($gp)
269/// Local (O32): lw $rd, %got(sym+offset)($gp)
270/// addiu $rd, $rd, %lo(sym+offset)
271/// Local (N32/N64): ld $rd, %got_disp(sym)($gp)
272/// >daddiu $rd, $rd, offset
273///
274/// On MIPS I, a nop goes between the load and the addiu.
275void MipsMCCodeEmitter::expandGOTLoad(const MCInst &MI,
278 const MCSubtargetInfo &STI) const {
279 MCRegister DstReg = MI.getOperand(0).getReg();
280 MCRegister GPReg = MI.getOperand(1).getReg();
281 const MCExpr *SymExpr = MI.getOperand(2).getExpr();
282 unsigned Flags = MI.getOperand(3).getImm();
283 bool IsLocal = MI.getOpcode() == Mips::PseudoGOTLoadLocal;
284 bool IsPtr64 = Flags & MipsII::GOTLoad_Ptr64;
285 unsigned LoadOpc = IsPtr64 ? Mips::LD : Mips::LW;
286 unsigned AddiuOpc = IsPtr64 ? Mips::DADDiu : Mips::ADDiu;
287
288 MCValue Res;
289 [[maybe_unused]] bool Ok = SymExpr->evaluateAsRelocatable(Res, nullptr);
290 assert(Ok && Res.getAddSym() && !Res.getSubSym() &&
291 "expected a symbol plus an optional constant");
292 const MCExpr *Sym = MCSymbolRefExpr::create(Res.getAddSym(), Ctx);
293 int64_t Offset = Res.getConstant();
294
296 auto AddInst = [&](unsigned Opc, MCRegister Rd, MCRegister Rs,
297 const MCExpr *Expr) {
298 Insts.push_back(MCInstBuilder(Opc).addReg(Rd).addReg(Rs).addExpr(Expr));
299 };
300 // MIPS I has no load interlock, so the addiu that uses the loaded register
301 // needs a nop before it, as with GNU as.
302 auto AddLoadDelayNop = [&]() {
303 if (!STI.hasFeature(Mips::FeatureMips2))
304 Insts.push_back(
305 MCInstBuilder(Mips::SLL).addReg(Mips::R0).addReg(Mips::R0).addImm(0));
306 };
307 auto AddOffset = [&]() {
308 if (Offset != 0) {
309 AddLoadDelayNop();
310 AddInst(AddiuOpc, DstReg, DstReg, MCConstantExpr::create(Offset, Ctx));
311 }
312 };
313
314 if (!IsLocal && (Flags & MipsII::GOTLoad_Call)) {
315 assert(Offset == 0 && "unexpected offset for a call");
316 AddInst(LoadOpc, DstReg, GPReg,
318 } else if (!IsLocal) {
319 AddInst(LoadOpc, DstReg, GPReg,
321 AddOffset();
322 } else if (Flags & MipsII::GOTLoad_NewABI) {
323 AddInst(LoadOpc, DstReg, GPReg,
325 AddOffset();
326 } else {
327 AddInst(LoadOpc, DstReg, GPReg,
328 MCSpecifierExpr::create(SymExpr, Mips::S_GOT, Ctx));
329 AddLoadDelayNop();
330 AddInst(AddiuOpc, DstReg, DstReg,
331 MCSpecifierExpr::create(SymExpr, Mips::S_LO, Ctx));
332 }
333
334 // Fixup offsets are relative to the start of the instruction being encoded,
335 // so rebase the fixups of each expanded instruction onto the pseudo.
336 size_t Start = CB.size();
337 for (const MCInst &Inst : Insts) {
338 size_t InstOffset = CB.size() - Start;
339 size_t N = Fixups.size();
340 encodeInstruction(Inst, CB, Fixups, STI);
341 for (size_t I = N, E = Fixups.size(); I != E; ++I)
342 Fixups[I].setOffset(Fixups[I].getOffset() + InstOffset);
343 }
344}
345
346/// getBranchTargetOpValue - Return binary encoding of the branch
347/// target operand. If the machine operand requires relocation,
348/// record the relocation and return zero.
350getBranchTargetOpValue(const MCInst &MI, unsigned OpNo,
352 const MCSubtargetInfo &STI) const {
353 const MCOperand &MO = MI.getOperand(OpNo);
354
355 // If the destination is an immediate, divide by 4.
356 if (MO.isImm()) return MO.getImm() >> 2;
357
358 assert(MO.isExpr() &&
359 "getBranchTargetOpValue expects only expressions or immediates");
360
361 const MCExpr *FixupExpression = MCBinaryExpr::createAdd(
362 MO.getExpr(), MCConstantExpr::create(-4, Ctx), Ctx);
363 addFixup(Fixups, 0, FixupExpression, Mips::fixup_Mips_PC16);
364 return 0;
365}
366
367/// getBranchTargetOpValue1SImm16 - Return binary encoding of the branch
368/// target operand. If the machine operand requires relocation,
369/// record the relocation and return zero.
371getBranchTargetOpValue1SImm16(const MCInst &MI, unsigned OpNo,
373 const MCSubtargetInfo &STI) const {
374 const MCOperand &MO = MI.getOperand(OpNo);
375
376 // If the destination is an immediate, divide by 2.
377 if (MO.isImm()) return MO.getImm() >> 1;
378
379 assert(MO.isExpr() &&
380 "getBranchTargetOpValue expects only expressions or immediates");
381
382 const MCExpr *FixupExpression = MCBinaryExpr::createAdd(
383 MO.getExpr(), MCConstantExpr::create(-4, Ctx), Ctx);
384 addFixup(Fixups, 0, FixupExpression, Mips::fixup_Mips_PC16);
385 return 0;
386}
387
388/// getBranchTargetOpValueMMR6 - Return binary encoding of the branch
389/// target operand. If the machine operand requires relocation,
390/// record the relocation and return zero.
392getBranchTargetOpValueMMR6(const MCInst &MI, unsigned OpNo,
394 const MCSubtargetInfo &STI) const {
395 const MCOperand &MO = MI.getOperand(OpNo);
396
397 // If the destination is an immediate, divide by 2.
398 if (MO.isImm())
399 return MO.getImm() >> 1;
400
401 assert(MO.isExpr() &&
402 "getBranchTargetOpValueMMR6 expects only expressions or immediates");
403
404 const MCExpr *FixupExpression = MCBinaryExpr::createAdd(
405 MO.getExpr(), MCConstantExpr::create(-2, Ctx), Ctx);
406 addFixup(Fixups, 0, FixupExpression, Mips::fixup_Mips_PC16);
407 return 0;
408}
409
410/// getBranchTargetOpValueLsl2MMR6 - Return binary encoding of the branch
411/// target operand. If the machine operand requires relocation,
412/// record the relocation and return zero.
414getBranchTargetOpValueLsl2MMR6(const MCInst &MI, unsigned OpNo,
416 const MCSubtargetInfo &STI) const {
417 const MCOperand &MO = MI.getOperand(OpNo);
418
419 // If the destination is an immediate, divide by 4.
420 if (MO.isImm())
421 return MO.getImm() >> 2;
422
423 assert(MO.isExpr() &&
424 "getBranchTargetOpValueLsl2MMR6 expects only expressions or immediates");
425
426 const MCExpr *FixupExpression = MCBinaryExpr::createAdd(
427 MO.getExpr(), MCConstantExpr::create(-4, Ctx), Ctx);
428 addFixup(Fixups, 0, FixupExpression, Mips::fixup_Mips_PC16);
429 return 0;
430}
431
432/// getBranchTarget7OpValueMM - Return binary encoding of the microMIPS branch
433/// target operand. If the machine operand requires relocation,
434/// record the relocation and return zero.
436getBranchTarget7OpValueMM(const MCInst &MI, unsigned OpNo,
438 const MCSubtargetInfo &STI) const {
439 const MCOperand &MO = MI.getOperand(OpNo);
440
441 // If the destination is an immediate, divide by 2.
442 if (MO.isImm()) return MO.getImm() >> 1;
443
444 assert(MO.isExpr() &&
445 "getBranchTargetOpValueMM expects only expressions or immediates");
446
447 const MCExpr *Expr = MO.getExpr();
448 addFixup(Fixups, 0, Expr, Mips::fixup_MICROMIPS_PC7_S1);
449 return 0;
450}
451
452/// getBranchTargetOpValueMMPC10 - Return binary encoding of the microMIPS
453/// 10-bit branch target operand. If the machine operand requires relocation,
454/// record the relocation and return zero.
456getBranchTargetOpValueMMPC10(const MCInst &MI, unsigned OpNo,
458 const MCSubtargetInfo &STI) const {
459 const MCOperand &MO = MI.getOperand(OpNo);
460
461 // If the destination is an immediate, divide by 2.
462 if (MO.isImm()) return MO.getImm() >> 1;
463
464 assert(MO.isExpr() &&
465 "getBranchTargetOpValuePC10 expects only expressions or immediates");
466
467 const MCExpr *Expr = MO.getExpr();
468 addFixup(Fixups, 0, Expr, Mips::fixup_MICROMIPS_PC10_S1);
469 return 0;
470}
471
472/// getBranchTargetOpValue - Return binary encoding of the microMIPS branch
473/// target operand. If the machine operand requires relocation,
474/// record the relocation and return zero.
476getBranchTargetOpValueMM(const MCInst &MI, unsigned OpNo,
478 const MCSubtargetInfo &STI) const {
479 const MCOperand &MO = MI.getOperand(OpNo);
480
481 // If the destination is an immediate, divide by 2.
482 if (MO.isImm()) return MO.getImm() >> 1;
483
484 assert(MO.isExpr() &&
485 "getBranchTargetOpValueMM expects only expressions or immediates");
486
487 const MCExpr *Expr = MO.getExpr();
488 addFixup(Fixups, 0, Expr, Mips::fixup_MICROMIPS_PC16_S1);
489 return 0;
490}
491
492/// getBranchTarget21OpValue - Return binary encoding of the branch
493/// target operand. If the machine operand requires relocation,
494/// record the relocation and return zero.
496getBranchTarget21OpValue(const MCInst &MI, unsigned OpNo,
498 const MCSubtargetInfo &STI) const {
499 const MCOperand &MO = MI.getOperand(OpNo);
500
501 // If the destination is an immediate, divide by 4.
502 if (MO.isImm()) return MO.getImm() >> 2;
503
504 assert(MO.isExpr() &&
505 "getBranchTarget21OpValue expects only expressions or immediates");
506
507 const MCExpr *FixupExpression = MCBinaryExpr::createAdd(
508 MO.getExpr(), MCConstantExpr::create(-4, Ctx), Ctx);
509 addFixup(Fixups, 0, FixupExpression, Mips::fixup_MIPS_PC21_S2);
510 return 0;
511}
512
513/// getBranchTarget21OpValueMM - Return binary encoding of the branch
514/// target operand for microMIPS. If the machine operand requires
515/// relocation, record the relocation and return zero.
517getBranchTarget21OpValueMM(const MCInst &MI, unsigned OpNo,
519 const MCSubtargetInfo &STI) const {
520 const MCOperand &MO = MI.getOperand(OpNo);
521
522 // If the destination is an immediate, divide by 4.
523 if (MO.isImm()) return MO.getImm() >> 2;
524
525 assert(MO.isExpr() &&
526 "getBranchTarget21OpValueMM expects only expressions or immediates");
527
528 const MCExpr *FixupExpression = MCBinaryExpr::createAdd(
529 MO.getExpr(), MCConstantExpr::create(-4, Ctx), Ctx);
530 addFixup(Fixups, 0, FixupExpression, Mips::fixup_MICROMIPS_PC21_S1);
531 return 0;
532}
533
534/// getBranchTarget26OpValue - Return binary encoding of the branch
535/// target operand. If the machine operand requires relocation,
536/// record the relocation and return zero.
538getBranchTarget26OpValue(const MCInst &MI, unsigned OpNo,
540 const MCSubtargetInfo &STI) const {
541 const MCOperand &MO = MI.getOperand(OpNo);
542
543 // If the destination is an immediate, divide by 4.
544 if (MO.isImm()) return MO.getImm() >> 2;
545
546 assert(MO.isExpr() &&
547 "getBranchTarget26OpValue expects only expressions or immediates");
548
549 const MCExpr *FixupExpression = MCBinaryExpr::createAdd(
550 MO.getExpr(), MCConstantExpr::create(-4, Ctx), Ctx);
551 addFixup(Fixups, 0, FixupExpression, Mips::fixup_MIPS_PC26_S2);
552 return 0;
553}
554
555/// getBranchTarget26OpValueMM - Return binary encoding of the branch
556/// target operand. If the machine operand requires relocation,
557/// record the relocation and return zero.
559 const MCInst &MI, unsigned OpNo, SmallVectorImpl<MCFixup> &Fixups,
560 const MCSubtargetInfo &STI) const {
561 const MCOperand &MO = MI.getOperand(OpNo);
562
563 // If the destination is an immediate, divide by 2.
564 if (MO.isImm())
565 return MO.getImm() >> 1;
566
567 assert(MO.isExpr() &&
568 "getBranchTarget26OpValueMM expects only expressions or immediates");
569
570 const MCExpr *FixupExpression = MCBinaryExpr::createAdd(
571 MO.getExpr(), MCConstantExpr::create(-4, Ctx), Ctx);
572 addFixup(Fixups, 0, FixupExpression, Mips::fixup_MICROMIPS_PC26_S1);
573 return 0;
574}
575
576/// getJumpOffset16OpValue - Return binary encoding of the jump
577/// target operand. If the machine operand requires relocation,
578/// record the relocation and return zero.
580getJumpOffset16OpValue(const MCInst &MI, unsigned OpNo,
582 const MCSubtargetInfo &STI) const {
583 const MCOperand &MO = MI.getOperand(OpNo);
584
585 if (MO.isImm()) return MO.getImm();
586
587 assert(MO.isExpr() &&
588 "getJumpOffset16OpValue expects only expressions or an immediate");
589
590 const MCExpr *Expr = MO.getExpr();
593 addFixup(Fixups, 0, Expr, MCFixupKind(FixupKind));
594 return 0;
595}
596
597/// getJumpTargetOpValue - Return binary encoding of the jump
598/// target operand. If the machine operand requires relocation,
599/// record the relocation and return zero.
601getJumpTargetOpValue(const MCInst &MI, unsigned OpNo,
603 const MCSubtargetInfo &STI) const {
604 const MCOperand &MO = MI.getOperand(OpNo);
605 // If the destination is an immediate, divide by 4.
606 if (MO.isImm()) return MO.getImm()>>2;
607
608 assert(MO.isExpr() &&
609 "getJumpTargetOpValue expects only expressions or an immediate");
610
611 const MCExpr *Expr = MO.getExpr();
612 addFixup(Fixups, 0, Expr, Mips::fixup_Mips_26);
613 return 0;
614}
615
617getJumpTargetOpValueMM(const MCInst &MI, unsigned OpNo,
619 const MCSubtargetInfo &STI) const {
620 const MCOperand &MO = MI.getOperand(OpNo);
621 // If the destination is an immediate, divide by 2.
622 if (MO.isImm()) return MO.getImm() >> 1;
623
624 assert(MO.isExpr() &&
625 "getJumpTargetOpValueMM expects only expressions or an immediate");
626
627 const MCExpr *Expr = MO.getExpr();
628 addFixup(Fixups, 0, Expr, Mips::fixup_MICROMIPS_26_S1);
629 return 0;
630}
631
633getUImm5Lsl2Encoding(const MCInst &MI, unsigned OpNo,
635 const MCSubtargetInfo &STI) const {
636 const MCOperand &MO = MI.getOperand(OpNo);
637 if (MO.isImm()) {
638 // The immediate is encoded as 'immediate << 2'.
639 unsigned Res = getMachineOpValue(MI, MO, Fixups, STI);
640 assert((Res & 3) == 0);
641 return Res >> 2;
642 }
643
644 assert(MO.isExpr() &&
645 "getUImm5Lsl2Encoding expects only expressions or an immediate");
646
647 return 0;
648}
649
651getSImm3Lsa2Value(const MCInst &MI, unsigned OpNo,
653 const MCSubtargetInfo &STI) const {
654 const MCOperand &MO = MI.getOperand(OpNo);
655 if (MO.isImm()) {
656 int Value = MO.getImm();
657 return Value >> 2;
658 }
659
660 return 0;
661}
662
664getUImm6Lsl2Encoding(const MCInst &MI, unsigned OpNo,
666 const MCSubtargetInfo &STI) const {
667 const MCOperand &MO = MI.getOperand(OpNo);
668 if (MO.isImm()) {
669 unsigned Value = MO.getImm();
670 return Value >> 2;
671 }
672
673 return 0;
674}
675
677getSImm9AddiuspValue(const MCInst &MI, unsigned OpNo,
679 const MCSubtargetInfo &STI) const {
680 const MCOperand &MO = MI.getOperand(OpNo);
681 if (MO.isImm()) {
682 unsigned Binary = (MO.getImm() >> 2) & 0x0000ffff;
683 return (((Binary & 0x8000) >> 7) | (Binary & 0x00ff));
684 }
685
686 return 0;
687}
688
691 const MCSubtargetInfo &STI) const {
692 MCExpr::ExprKind Kind = Expr->getKind();
693 if (Kind == MCExpr::Specifier) {
694 const auto *MipsExpr = cast<MCSpecifierExpr>(Expr);
695
697 switch (MipsExpr->getSpecifier()) {
698 case Mips::S_None:
699 case Mips::S_Special:
700 llvm_unreachable("Unhandled fixup kind!");
701 break;
702 case Mips::S_DTPREL:
703 // MEK_DTPREL is used for marking TLS DIEExpr only
704 // and contains a regular sub-expression.
705 return getExprOpValue(MipsExpr->getSubExpr(), Fixups, STI);
708 break;
711 break;
715 break;
719 break;
720 case Mips::S_GOTTPREL:
721 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GOTTPREL
723 break;
724 case Mips::S_GOT:
725 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GOT16
727 break;
728 case Mips::S_GOT_CALL:
729 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_CALL16
731 break;
732 case Mips::S_GOT_DISP:
733 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GOT_DISP
735 break;
736 case Mips::S_GOT_HI16:
738 break;
739 case Mips::S_GOT_LO16:
741 break;
742 case Mips::S_GOT_PAGE:
743 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GOT_PAGE
745 break;
746 case Mips::S_GOT_OFST:
747 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GOT_OFST
749 break;
750 case Mips::S_GPREL:
752 break;
753 case Mips::S_LO:
754 // Check for %lo(%neg(%gp_rel(X)))
755 if (Mips::isGpOff(*MipsExpr))
756 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GPOFF_LO
758 else
759 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_LO16
761 break;
762 case Mips::S_HIGHEST:
763 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_HIGHEST
765 break;
766 case Mips::S_HIGHER:
767 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_HIGHER
769 break;
770 case Mips::S_HI:
771 // Check for %hi(%neg(%gp_rel(X)))
772 if (Mips::isGpOff(*MipsExpr))
773 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_GPOFF_HI
775 else
776 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_HI16
778 break;
781 break;
784 break;
785 case Mips::S_TLSGD:
786 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_TLS_GD
788 break;
789 case Mips::S_TLSLDM:
790 FixupKind = isMicroMips(STI) ? Mips::fixup_MICROMIPS_TLS_LDM
792 break;
793 case Mips::S_TPREL_HI:
796 break;
797 case Mips::S_TPREL_LO:
800 break;
801 case Mips::S_NEG:
802 FixupKind =
804 break;
805 }
806 addFixup(Fixups, 0, MipsExpr, MCFixupKind(FixupKind));
807 return 0;
808 }
809
810 Ctx.reportError(Expr->getLoc(), "expected an immediate");
811 return 0;
812}
813
814/// getMachineOpValue - Return binary encoding of operand. If the machine
815/// operand requires relocation, record the relocation and return zero.
817getMachineOpValue(const MCInst &MI, const MCOperand &MO,
819 const MCSubtargetInfo &STI) const {
820 if (MO.isReg()) {
821 MCRegister Reg = MO.getReg();
822 unsigned RegNo = Ctx.getRegisterInfo()->getEncodingValue(Reg);
823 return RegNo;
824 } else if (MO.isImm()) {
825 return static_cast<unsigned>(MO.getImm());
826 } else if (MO.isDFPImm()) {
827 return static_cast<unsigned>(bit_cast<double>(MO.getDFPImm()));
828 }
829 // TODO: Set EncoderMethod to "getImmOpValue" for imm Operand so that
830 // getMachineOpValue will not be called for isExpr code paths.
831 assert(MO.isExpr());
832 return getImmOpValue(MI, MO, Fixups, STI);
833}
834
837 const MCSubtargetInfo &STI) const {
838 if (MO.isImm())
839 return MO.getImm();
840 assert(MO.isExpr() && "getImmOpValue expects only expressions or immediates");
841 const MCExpr *Expr = MO.getExpr();
842 int64_t Res;
843 if (Expr->evaluateAsAbsolute(Res))
844 return Res;
845 unsigned MIFrm = MipsII::getFormat(MCII.get(MI.getOpcode()).TSFlags);
846 if (!isa<MCSpecifierExpr>(Expr) && MIFrm == MipsII::FrmI) {
847 addFixup(Fixups, 0, Expr, Mips::fixup_Mips_AnyImm16);
848 return 0;
849 }
850 return getExprOpValue(Expr, Fixups, STI);
851}
852
853template <unsigned Shift>
854unsigned
857 const MCSubtargetInfo &STI) const {
858 return getMachineOpValue(MI, MI.getOperand(OpNo), Fixups, STI) >> Shift;
859}
860
861template <unsigned FromEnd, unsigned Shift>
862unsigned
865 const MCSubtargetInfo &STI) const {
866 return getScaledImmOpValue<Shift>(MI, MI.getNumOperands() - FromEnd, Fixups,
867 STI);
868}
869
870// FIXME: should be called getMSBEncoding
871//
872unsigned
875 const MCSubtargetInfo &STI) const {
876 assert(MI.getOperand(OpNo-1).isImm());
877 assert(MI.getOperand(OpNo).isImm());
878 unsigned Position = getMachineOpValue(MI, MI.getOperand(OpNo-1), Fixups, STI);
879 unsigned Size = getMachineOpValue(MI, MI.getOperand(OpNo), Fixups, STI);
880
881 return Position + Size - 1;
882}
883
884template <unsigned Bits, int Offset>
885unsigned
888 const MCSubtargetInfo &STI) const {
889 assert(MI.getOperand(OpNo).isImm());
890 unsigned Value = getMachineOpValue(MI, MI.getOperand(OpNo), Fixups, STI);
891 Value -= Offset;
892 return Value;
893}
894
895unsigned
898 const MCSubtargetInfo &STI) const {
899 const MCOperand &MO = MI.getOperand(OpNo);
900 if (MO.isImm()) {
901 // The immediate is encoded as 'immediate << 2'.
902 unsigned Res = getMachineOpValue(MI, MO, Fixups, STI);
903 assert((Res & 3) == 0);
904 return Res >> 2;
905 }
906
907 assert(MO.isExpr() &&
908 "getSimm19Lsl2Encoding expects only expressions or an immediate");
909
910 const MCExpr *Expr = MO.getExpr();
913 addFixup(Fixups, 0, Expr, MCFixupKind(FixupKind));
914 return 0;
915}
916
917unsigned
920 const MCSubtargetInfo &STI) const {
921 const MCOperand &MO = MI.getOperand(OpNo);
922 if (MO.isImm()) {
923 // The immediate is encoded as 'immediate << 3'.
924 unsigned Res = getMachineOpValue(MI, MI.getOperand(OpNo), Fixups, STI);
925 assert((Res & 7) == 0);
926 return Res >> 3;
927 }
928
929 assert(MO.isExpr() &&
930 "getSimm18Lsl2Encoding expects only expressions or an immediate");
931
932 const MCExpr *Expr = MO.getExpr();
935 addFixup(Fixups, 0, Expr, MCFixupKind(FixupKind));
936 return 0;
937}
938
939unsigned
942 const MCSubtargetInfo &STI) const {
943 assert(MI.getOperand(OpNo).isImm());
944 const MCOperand &MO = MI.getOperand(OpNo);
945 return MO.getImm() % 8;
946}
947
948unsigned
951 const MCSubtargetInfo &STI) const {
952 assert(MI.getOperand(OpNo).isImm());
953 const MCOperand &MO = MI.getOperand(OpNo);
954 unsigned Value = MO.getImm();
955 switch (Value) {
956 case 128: return 0x0;
957 case 1: return 0x1;
958 case 2: return 0x2;
959 case 3: return 0x3;
960 case 4: return 0x4;
961 case 7: return 0x5;
962 case 8: return 0x6;
963 case 15: return 0x7;
964 case 16: return 0x8;
965 case 31: return 0x9;
966 case 32: return 0xa;
967 case 63: return 0xb;
968 case 64: return 0xc;
969 case 255: return 0xd;
970 case 32768: return 0xe;
971 case 65535: return 0xf;
972 }
973 llvm_unreachable("Unexpected value");
974}
975
976unsigned
979 const MCSubtargetInfo &STI) const {
980 unsigned res = 0;
981
982 // Register list operand is always first operand of instruction and it is
983 // placed before memory operand (register + imm).
984
985 for (unsigned I = OpNo, E = MI.getNumOperands() - 2; I < E; ++I) {
986 MCRegister Reg = MI.getOperand(I).getReg();
987 unsigned RegNo = Ctx.getRegisterInfo()->getEncodingValue(Reg);
988 if (RegNo != 31)
989 res++;
990 else
991 res |= 0x10;
992 }
993 return res;
994}
995
996unsigned
999 const MCSubtargetInfo &STI) const {
1000 return (MI.getNumOperands() - 4);
1001}
1002
1003unsigned
1006 const MCSubtargetInfo &STI) const {
1007 unsigned res = 0;
1008
1009 if (MI.getOperand(0).getReg() == Mips::R5 &&
1010 MI.getOperand(1).getReg() == Mips::R6)
1011 res = 0;
1012 else if (MI.getOperand(0).getReg() == Mips::R5 &&
1013 MI.getOperand(1).getReg() == Mips::R7)
1014 res = 1;
1015 else if (MI.getOperand(0).getReg() == Mips::R6 &&
1016 MI.getOperand(1).getReg() == Mips::R7)
1017 res = 2;
1018 else if (MI.getOperand(0).getReg() == Mips::R4 &&
1019 MI.getOperand(1).getReg() == Mips::R21)
1020 res = 3;
1021 else if (MI.getOperand(0).getReg() == Mips::R4 &&
1022 MI.getOperand(1).getReg() == Mips::R22)
1023 res = 4;
1024 else if (MI.getOperand(0).getReg() == Mips::R4 &&
1025 MI.getOperand(1).getReg() == Mips::R5)
1026 res = 5;
1027 else if (MI.getOperand(0).getReg() == Mips::R4 &&
1028 MI.getOperand(1).getReg() == Mips::R6)
1029 res = 6;
1030 else if (MI.getOperand(0).getReg() == Mips::R4 &&
1031 MI.getOperand(1).getReg() == Mips::R7)
1032 res = 7;
1033
1034 return res;
1035}
1036
1037unsigned
1040 const MCSubtargetInfo &STI) const {
1041 assert(((OpNo == 2) || (OpNo == 3)) &&
1042 "Unexpected OpNo for movep operand encoding!");
1043
1044 MCOperand Op = MI.getOperand(OpNo);
1045 assert(Op.isReg() && "Operand of movep is not a register!");
1046 switch (Op.getReg().id()) {
1047 default:
1048 llvm_unreachable("Unknown register for movep!");
1049 case Mips::R0:
1050 return 0;
1051 case Mips::R17:
1052 return 1;
1053 case Mips::R2:
1054 return 2;
1055 case Mips::R3:
1056 return 3;
1057 case Mips::R16:
1058 return 4;
1059 case Mips::R18:
1060 return 5;
1061 case Mips::R19:
1062 return 6;
1063 case Mips::R20:
1064 return 7;
1065 }
1066}
1067
1068unsigned
1071 const MCSubtargetInfo &STI) const {
1072 const MCOperand &MO = MI.getOperand(OpNo);
1073 assert(MO.isImm() && "getSimm23Lsl2Encoding expects only an immediate");
1074 // The immediate is encoded as 'immediate >> 2'.
1075 unsigned Res = static_cast<unsigned>(MO.getImm());
1076 assert((Res & 3) == 0);
1077 return Res >> 2;
1078}
1079
1080#include "MipsGenMCCodeEmitter.inc"
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file declares a class to represent arbitrary precision floating point values and provide a varie...
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
IRTranslator LLVM IR MI
unsigned Opc
#define I(x, y, z)
Definition MD5.cpp:57
static void LowerLargeShift(MCInst &Inst)
This file defines the SmallVector class.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:339
MCCodeEmitter - Generic instruction encoding interface.
static LLVM_ABI const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition MCExpr.cpp:212
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:31
LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const
Try to evaluate the expression to a relocatable value, i.e.
Definition MCExpr.cpp:450
@ Specifier
Expression with a relocation specifier.
Definition MCExpr.h:42
ExprKind getKind() const
Definition MCExpr.h:82
SMLoc getLoc() const
Definition MCExpr.h:83
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, bool PCRel=false)
Consider bit fields if we need more flags.
Definition MCFixup.h:90
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:187
unsigned getNumOperands() const
Definition MCInst.h:211
unsigned getOpcode() const
Definition MCInst.h:201
void setOpcode(unsigned Op)
Definition MCInst.h:200
const MCOperand & getOperand(unsigned i) const
Definition MCInst.h:209
Describe properties that are true of each instruction in the target description file.
Interface to description of machine instruction set.
Definition MCInstrInfo.h:27
Instances of this class represent operands of the MCInst class.
Definition MCInst.h:39
void setImm(int64_t Val)
Definition MCInst.h:88
int64_t getImm() const
Definition MCInst.h:83
bool isImm() const
Definition MCInst.h:65
void setReg(MCRegister Reg)
Set the register number.
Definition MCInst.h:78
bool isReg() const
Definition MCInst.h:64
MCRegister getReg() const
Returns the register number.
Definition MCInst.h:72
bool isDFPImm() const
Definition MCInst.h:67
const MCExpr * getExpr() const
Definition MCInst.h:117
uint64_t getDFPImm() const
Definition MCInst.h:103
bool isExpr() const
Definition MCInst.h:68
Wrapper class representing physical registers and target specific virtual registers.
Definition MCRegister.h:42
static const MCSpecifierExpr * create(const MCExpr *Expr, Spec S, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.cpp:743
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:210
const MCSymbol * getAddSym() const
Definition MCValue.h:49
int64_t getConstant() const
Definition MCValue.h:44
const MCSymbol * getSubSym() const
Definition MCValue.h:51
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.
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
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
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.
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...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
LLVM Value Representation.
Definition Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static unsigned getFormat(uint64_t TSFlags)
@ fixup_MICROMIPS_TLS_TPREL_LO16
@ fixup_MICROMIPS_TLS_TPREL_HI16
@ fixup_MICROMIPS_TLS_DTPREL_HI16
@ fixup_MICROMIPS_TLS_DTPREL_LO16
@ fixup_Mips_Branch_PCRel
bool isGpOff(const MCSpecifierExpr &E)
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
Definition Endian.h:82
This is an optimization pass for GlobalISel generic memory operations.
MCCodeEmitter * createMipsMCCodeEmitterEL(const MCInstrInfo &MCII, MCContext &Ctx)
MCCodeEmitter * createMipsMCCodeEmitterEB(const MCInstrInfo &MCII, MCContext &Ctx)
@ Offset
Definition DWP.cpp:577
Op::Description Desc
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
uint16_t MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition MCFixup.h:22
static Lanai::Fixups FixupKind(const MCExpr *Expr)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind)
To bit_cast(const From &from) noexcept
Definition bit.h:90
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
#define N