1 //===-- ARM64/ARM64MCCodeEmitter.cpp - Convert ARM64 code to machine code -===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the ARM64MCCodeEmitter class.
12 //===----------------------------------------------------------------------===//
14 #include "MCTargetDesc/ARM64AddressingModes.h"
15 #include "MCTargetDesc/ARM64FixupKinds.h"
16 #include "MCTargetDesc/ARM64MCExpr.h"
17 #include "Utils/ARM64BaseInfo.h"
18 #include "llvm/MC/MCCodeEmitter.h"
19 #include "llvm/MC/MCContext.h"
20 #include "llvm/MC/MCInst.h"
21 #include "llvm/MC/MCInstrInfo.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCSubtargetInfo.h"
24 #include "llvm/ADT/Statistic.h"
25 #include "llvm/Support/raw_ostream.h"
28 #define DEBUG_TYPE "mccodeemitter"
30 STATISTIC(MCNumEmitted, "Number of MC instructions emitted.");
31 STATISTIC(MCNumFixups, "Number of MC fixups created.");
35 class ARM64MCCodeEmitter : public MCCodeEmitter {
38 ARM64MCCodeEmitter(const ARM64MCCodeEmitter &); // DO NOT IMPLEMENT
39 void operator=(const ARM64MCCodeEmitter &); // DO NOT IMPLEMENT
41 ARM64MCCodeEmitter(const MCInstrInfo &mcii, const MCSubtargetInfo &sti,
45 ~ARM64MCCodeEmitter() {}
47 // getBinaryCodeForInstr - TableGen'erated function for getting the
48 // binary encoding for an instruction.
49 uint64_t getBinaryCodeForInstr(const MCInst &MI,
50 SmallVectorImpl<MCFixup> &Fixups,
51 const MCSubtargetInfo &STI) const;
53 /// getMachineOpValue - Return binary encoding of operand. If the machine
54 /// operand requires relocation, record the relocation and return zero.
55 unsigned getMachineOpValue(const MCInst &MI, const MCOperand &MO,
56 SmallVectorImpl<MCFixup> &Fixups,
57 const MCSubtargetInfo &STI) const;
59 /// getAMIndexed8OpValue - Return encoding info for base register
60 /// and 12-bit unsigned immediate attached to a load, store or prfm
61 /// instruction. If operand requires a relocation, record it and
62 /// return zero in that part of the encoding.
63 template <uint32_t FixupKind>
64 uint32_t getAMIndexed8OpValue(const MCInst &MI, unsigned OpIdx,
65 SmallVectorImpl<MCFixup> &Fixups,
66 const MCSubtargetInfo &STI) const;
68 /// getAdrLabelOpValue - Return encoding info for 21-bit immediate ADR label
70 uint32_t getAdrLabelOpValue(const MCInst &MI, unsigned OpIdx,
71 SmallVectorImpl<MCFixup> &Fixups,
72 const MCSubtargetInfo &STI) const;
74 /// getAddSubImmOpValue - Return encoding for the 12-bit immediate value and
75 /// the 2-bit shift field.
76 uint32_t getAddSubImmOpValue(const MCInst &MI, unsigned OpIdx,
77 SmallVectorImpl<MCFixup> &Fixups,
78 const MCSubtargetInfo &STI) const;
80 /// getCondBranchTargetOpValue - Return the encoded value for a conditional
82 uint32_t getCondBranchTargetOpValue(const MCInst &MI, unsigned OpIdx,
83 SmallVectorImpl<MCFixup> &Fixups,
84 const MCSubtargetInfo &STI) const;
86 /// getLoadLiteralOpValue - Return the encoded value for a load-literal
87 /// pc-relative address.
88 uint32_t getLoadLiteralOpValue(const MCInst &MI, unsigned OpIdx,
89 SmallVectorImpl<MCFixup> &Fixups,
90 const MCSubtargetInfo &STI) const;
92 /// getTestBranchTargetOpValue - Return the encoded value for a test-bit-and-
94 uint32_t getTestBranchTargetOpValue(const MCInst &MI, unsigned OpIdx,
95 SmallVectorImpl<MCFixup> &Fixups,
96 const MCSubtargetInfo &STI) const;
98 /// getBranchTargetOpValue - Return the encoded value for an unconditional
100 uint32_t getBranchTargetOpValue(const MCInst &MI, unsigned OpIdx,
101 SmallVectorImpl<MCFixup> &Fixups,
102 const MCSubtargetInfo &STI) const;
104 /// getMoveWideImmOpValue - Return the encoded value for the immediate operand
105 /// of a MOVZ or MOVK instruction.
106 uint32_t getMoveWideImmOpValue(const MCInst &MI, unsigned OpIdx,
107 SmallVectorImpl<MCFixup> &Fixups,
108 const MCSubtargetInfo &STI) const;
110 /// getVecShifterOpValue - Return the encoded value for the vector shifter.
111 uint32_t getVecShifterOpValue(const MCInst &MI, unsigned OpIdx,
112 SmallVectorImpl<MCFixup> &Fixups,
113 const MCSubtargetInfo &STI) const;
115 /// getMoveVecShifterOpValue - Return the encoded value for the vector move
117 uint32_t getMoveVecShifterOpValue(const MCInst &MI, unsigned OpIdx,
118 SmallVectorImpl<MCFixup> &Fixups,
119 const MCSubtargetInfo &STI) const;
121 /// getFixedPointScaleOpValue - Return the encoded value for the
122 // FP-to-fixed-point scale factor.
123 uint32_t getFixedPointScaleOpValue(const MCInst &MI, unsigned OpIdx,
124 SmallVectorImpl<MCFixup> &Fixups,
125 const MCSubtargetInfo &STI) const;
127 uint32_t getVecShiftR64OpValue(const MCInst &MI, unsigned OpIdx,
128 SmallVectorImpl<MCFixup> &Fixups,
129 const MCSubtargetInfo &STI) const;
130 uint32_t getVecShiftR32OpValue(const MCInst &MI, unsigned OpIdx,
131 SmallVectorImpl<MCFixup> &Fixups,
132 const MCSubtargetInfo &STI) const;
133 uint32_t getVecShiftR16OpValue(const MCInst &MI, unsigned OpIdx,
134 SmallVectorImpl<MCFixup> &Fixups,
135 const MCSubtargetInfo &STI) const;
136 uint32_t getVecShiftR8OpValue(const MCInst &MI, unsigned OpIdx,
137 SmallVectorImpl<MCFixup> &Fixups,
138 const MCSubtargetInfo &STI) const;
139 uint32_t getVecShiftL64OpValue(const MCInst &MI, unsigned OpIdx,
140 SmallVectorImpl<MCFixup> &Fixups,
141 const MCSubtargetInfo &STI) const;
142 uint32_t getVecShiftL32OpValue(const MCInst &MI, unsigned OpIdx,
143 SmallVectorImpl<MCFixup> &Fixups,
144 const MCSubtargetInfo &STI) const;
145 uint32_t getVecShiftL16OpValue(const MCInst &MI, unsigned OpIdx,
146 SmallVectorImpl<MCFixup> &Fixups,
147 const MCSubtargetInfo &STI) const;
148 uint32_t getVecShiftL8OpValue(const MCInst &MI, unsigned OpIdx,
149 SmallVectorImpl<MCFixup> &Fixups,
150 const MCSubtargetInfo &STI) const;
152 /// getSIMDShift64OpValue - Return the encoded value for the
153 // shift-by-immediate AdvSIMD instructions.
154 uint32_t getSIMDShift64OpValue(const MCInst &MI, unsigned OpIdx,
155 SmallVectorImpl<MCFixup> &Fixups,
156 const MCSubtargetInfo &STI) const;
158 uint32_t getSIMDShift64_32OpValue(const MCInst &MI, unsigned OpIdx,
159 SmallVectorImpl<MCFixup> &Fixups,
160 const MCSubtargetInfo &STI) const;
162 uint32_t getSIMDShift32OpValue(const MCInst &MI, unsigned OpIdx,
163 SmallVectorImpl<MCFixup> &Fixups,
164 const MCSubtargetInfo &STI) const;
166 uint32_t getSIMDShift16OpValue(const MCInst &MI, unsigned OpIdx,
167 SmallVectorImpl<MCFixup> &Fixups,
168 const MCSubtargetInfo &STI) const;
170 unsigned fixMOVZ(const MCInst &MI, unsigned EncodedValue,
171 const MCSubtargetInfo &STI) const;
173 void EmitByte(unsigned char C, raw_ostream &OS) const { OS << (char)C; }
175 void EmitConstant(uint64_t Val, unsigned Size, raw_ostream &OS) const {
176 // Output the constant in little endian byte order.
177 for (unsigned i = 0; i != Size; ++i) {
178 EmitByte(Val & 255, OS);
183 void EncodeInstruction(const MCInst &MI, raw_ostream &OS,
184 SmallVectorImpl<MCFixup> &Fixups,
185 const MCSubtargetInfo &STI) const override;
187 unsigned fixMulHigh(const MCInst &MI, unsigned EncodedValue,
188 const MCSubtargetInfo &STI) const;
190 template<int hasRs, int hasRt2> unsigned
191 fixLoadStoreExclusive(const MCInst &MI, unsigned EncodedValue,
192 const MCSubtargetInfo &STI) const;
194 unsigned fixOneOperandFPComparison(const MCInst &MI, unsigned EncodedValue,
195 const MCSubtargetInfo &STI) const;
198 } // end anonymous namespace
200 MCCodeEmitter *llvm::createARM64MCCodeEmitter(const MCInstrInfo &MCII,
201 const MCRegisterInfo &MRI,
202 const MCSubtargetInfo &STI,
204 return new ARM64MCCodeEmitter(MCII, STI, Ctx);
207 /// getMachineOpValue - Return binary encoding of operand. If the machine
208 /// operand requires relocation, record the relocation and return zero.
210 ARM64MCCodeEmitter::getMachineOpValue(const MCInst &MI, const MCOperand &MO,
211 SmallVectorImpl<MCFixup> &Fixups,
212 const MCSubtargetInfo &STI) const {
214 return Ctx.getRegisterInfo()->getEncodingValue(MO.getReg());
216 assert(MO.isImm() && "did not expect relocated expression");
217 return static_cast<unsigned>(MO.getImm());
220 assert(0 && "Unable to encode MCOperand!");
224 template <uint32_t FixupKind>
226 ARM64MCCodeEmitter::getAMIndexed8OpValue(const MCInst &MI, unsigned OpIdx,
227 SmallVectorImpl<MCFixup> &Fixups,
228 const MCSubtargetInfo &STI) const {
229 unsigned BaseReg = MI.getOperand(OpIdx).getReg();
230 BaseReg = Ctx.getRegisterInfo()->getEncodingValue(BaseReg);
232 const MCOperand &MO = MI.getOperand(OpIdx + 1);
236 ImmVal = static_cast<uint32_t>(MO.getImm());
238 assert(MO.isExpr() && "unable to encode load/store imm operand");
239 MCFixupKind Kind = MCFixupKind(FixupKind);
240 Fixups.push_back(MCFixup::Create(0, MO.getExpr(), Kind, MI.getLoc()));
244 return BaseReg | (ImmVal << 5);
247 /// getAdrLabelOpValue - Return encoding info for 21-bit immediate ADR label
250 ARM64MCCodeEmitter::getAdrLabelOpValue(const MCInst &MI, unsigned OpIdx,
251 SmallVectorImpl<MCFixup> &Fixups,
252 const MCSubtargetInfo &STI) const {
253 const MCOperand &MO = MI.getOperand(OpIdx);
255 // If the destination is an immediate, we have nothing to do.
258 assert(MO.isExpr() && "Unexpected ADR target type!");
259 const MCExpr *Expr = MO.getExpr();
261 MCFixupKind Kind = MI.getOpcode() == ARM64::ADR
262 ? MCFixupKind(ARM64::fixup_arm64_pcrel_adr_imm21)
263 : MCFixupKind(ARM64::fixup_arm64_pcrel_adrp_imm21);
264 Fixups.push_back(MCFixup::Create(0, Expr, Kind, MI.getLoc()));
268 // All of the information is in the fixup.
272 /// getAddSubImmOpValue - Return encoding for the 12-bit immediate value and
273 /// the 2-bit shift field. The shift field is stored in bits 13-14 of the
276 ARM64MCCodeEmitter::getAddSubImmOpValue(const MCInst &MI, unsigned OpIdx,
277 SmallVectorImpl<MCFixup> &Fixups,
278 const MCSubtargetInfo &STI) const {
279 // Suboperands are [imm, shifter].
280 const MCOperand &MO = MI.getOperand(OpIdx);
281 const MCOperand &MO1 = MI.getOperand(OpIdx + 1);
282 assert(ARM64_AM::getShiftType(MO1.getImm()) == ARM64_AM::LSL &&
283 "unexpected shift type for add/sub immediate");
284 unsigned ShiftVal = ARM64_AM::getShiftValue(MO1.getImm());
285 assert((ShiftVal == 0 || ShiftVal == 12) &&
286 "unexpected shift value for add/sub immediate");
288 return MO.getImm() | (ShiftVal == 0 ? 0 : (1 << 12));
289 assert(MO.isExpr() && "Unable to encode MCOperand!");
290 const MCExpr *Expr = MO.getExpr();
291 assert(ShiftVal == 0 && "shift not allowed on add/sub immediate with fixup");
293 // Encode the 12 bits of the fixup.
294 MCFixupKind Kind = MCFixupKind(ARM64::fixup_arm64_add_imm12);
295 Fixups.push_back(MCFixup::Create(0, Expr, Kind, MI.getLoc()));
302 /// getCondBranchTargetOpValue - Return the encoded value for a conditional
304 uint32_t ARM64MCCodeEmitter::getCondBranchTargetOpValue(
305 const MCInst &MI, unsigned OpIdx, SmallVectorImpl<MCFixup> &Fixups,
306 const MCSubtargetInfo &STI) const {
307 const MCOperand &MO = MI.getOperand(OpIdx);
309 // If the destination is an immediate, we have nothing to do.
312 assert(MO.isExpr() && "Unexpected target type!");
314 MCFixupKind Kind = MCFixupKind(ARM64::fixup_arm64_pcrel_branch19);
315 Fixups.push_back(MCFixup::Create(0, MO.getExpr(), Kind, MI.getLoc()));
319 // All of the information is in the fixup.
323 /// getLoadLiteralOpValue - Return the encoded value for a load-literal
324 /// pc-relative address.
326 ARM64MCCodeEmitter::getLoadLiteralOpValue(const MCInst &MI, unsigned OpIdx,
327 SmallVectorImpl<MCFixup> &Fixups,
328 const MCSubtargetInfo &STI) const {
329 const MCOperand &MO = MI.getOperand(OpIdx);
331 // If the destination is an immediate, we have nothing to do.
334 assert(MO.isExpr() && "Unexpected target type!");
336 MCFixupKind Kind = MCFixupKind(ARM64::fixup_arm64_ldr_pcrel_imm19);
337 Fixups.push_back(MCFixup::Create(0, MO.getExpr(), Kind, MI.getLoc()));
341 // All of the information is in the fixup.
346 ARM64MCCodeEmitter::getMoveWideImmOpValue(const MCInst &MI, unsigned OpIdx,
347 SmallVectorImpl<MCFixup> &Fixups,
348 const MCSubtargetInfo &STI) const {
349 const MCOperand &MO = MI.getOperand(OpIdx);
353 assert(MO.isExpr() && "Unexpected movz/movk immediate");
355 Fixups.push_back(MCFixup::Create(
356 0, MO.getExpr(), MCFixupKind(ARM64::fixup_arm64_movw), MI.getLoc()));
363 /// getTestBranchTargetOpValue - Return the encoded value for a test-bit-and-
365 uint32_t ARM64MCCodeEmitter::getTestBranchTargetOpValue(
366 const MCInst &MI, unsigned OpIdx, SmallVectorImpl<MCFixup> &Fixups,
367 const MCSubtargetInfo &STI) const {
368 const MCOperand &MO = MI.getOperand(OpIdx);
370 // If the destination is an immediate, we have nothing to do.
373 assert(MO.isExpr() && "Unexpected ADR target type!");
375 MCFixupKind Kind = MCFixupKind(ARM64::fixup_arm64_pcrel_branch14);
376 Fixups.push_back(MCFixup::Create(0, MO.getExpr(), Kind, MI.getLoc()));
380 // All of the information is in the fixup.
384 /// getBranchTargetOpValue - Return the encoded value for an unconditional
387 ARM64MCCodeEmitter::getBranchTargetOpValue(const MCInst &MI, unsigned OpIdx,
388 SmallVectorImpl<MCFixup> &Fixups,
389 const MCSubtargetInfo &STI) const {
390 const MCOperand &MO = MI.getOperand(OpIdx);
392 // If the destination is an immediate, we have nothing to do.
395 assert(MO.isExpr() && "Unexpected ADR target type!");
397 MCFixupKind Kind = MI.getOpcode() == ARM64::BL
398 ? MCFixupKind(ARM64::fixup_arm64_pcrel_call26)
399 : MCFixupKind(ARM64::fixup_arm64_pcrel_branch26);
400 Fixups.push_back(MCFixup::Create(0, MO.getExpr(), Kind, MI.getLoc()));
404 // All of the information is in the fixup.
408 /// getVecShifterOpValue - Return the encoded value for the vector shifter:
415 ARM64MCCodeEmitter::getVecShifterOpValue(const MCInst &MI, unsigned OpIdx,
416 SmallVectorImpl<MCFixup> &Fixups,
417 const MCSubtargetInfo &STI) const {
418 const MCOperand &MO = MI.getOperand(OpIdx);
419 assert(MO.isImm() && "Expected an immediate value for the shift amount!");
421 switch (MO.getImm()) {
434 assert(false && "Invalid value for vector shift amount!");
439 ARM64MCCodeEmitter::getSIMDShift64OpValue(const MCInst &MI, unsigned OpIdx,
440 SmallVectorImpl<MCFixup> &Fixups,
441 const MCSubtargetInfo &STI) const {
442 const MCOperand &MO = MI.getOperand(OpIdx);
443 assert(MO.isImm() && "Expected an immediate value for the shift amount!");
444 return 64 - (MO.getImm());
448 ARM64MCCodeEmitter::getSIMDShift64_32OpValue(const MCInst &MI, unsigned OpIdx,
449 SmallVectorImpl<MCFixup> &Fixups,
450 const MCSubtargetInfo &STI) const {
451 const MCOperand &MO = MI.getOperand(OpIdx);
452 assert(MO.isImm() && "Expected an immediate value for the shift amount!");
453 return 64 - (MO.getImm() | 32);
457 ARM64MCCodeEmitter::getSIMDShift32OpValue(const MCInst &MI, unsigned OpIdx,
458 SmallVectorImpl<MCFixup> &Fixups,
459 const MCSubtargetInfo &STI) const {
460 const MCOperand &MO = MI.getOperand(OpIdx);
461 assert(MO.isImm() && "Expected an immediate value for the shift amount!");
462 return 32 - (MO.getImm() | 16);
466 ARM64MCCodeEmitter::getSIMDShift16OpValue(const MCInst &MI, unsigned OpIdx,
467 SmallVectorImpl<MCFixup> &Fixups,
468 const MCSubtargetInfo &STI) const {
469 const MCOperand &MO = MI.getOperand(OpIdx);
470 assert(MO.isImm() && "Expected an immediate value for the shift amount!");
471 return 16 - (MO.getImm() | 8);
474 /// getFixedPointScaleOpValue - Return the encoded value for the
475 // FP-to-fixed-point scale factor.
476 uint32_t ARM64MCCodeEmitter::getFixedPointScaleOpValue(
477 const MCInst &MI, unsigned OpIdx, SmallVectorImpl<MCFixup> &Fixups,
478 const MCSubtargetInfo &STI) const {
479 const MCOperand &MO = MI.getOperand(OpIdx);
480 assert(MO.isImm() && "Expected an immediate value for the scale amount!");
481 return 64 - MO.getImm();
485 ARM64MCCodeEmitter::getVecShiftR64OpValue(const MCInst &MI, unsigned OpIdx,
486 SmallVectorImpl<MCFixup> &Fixups,
487 const MCSubtargetInfo &STI) const {
488 const MCOperand &MO = MI.getOperand(OpIdx);
489 assert(MO.isImm() && "Expected an immediate value for the scale amount!");
490 return 64 - MO.getImm();
494 ARM64MCCodeEmitter::getVecShiftR32OpValue(const MCInst &MI, unsigned OpIdx,
495 SmallVectorImpl<MCFixup> &Fixups,
496 const MCSubtargetInfo &STI) const {
497 const MCOperand &MO = MI.getOperand(OpIdx);
498 assert(MO.isImm() && "Expected an immediate value for the scale amount!");
499 return 32 - MO.getImm();
503 ARM64MCCodeEmitter::getVecShiftR16OpValue(const MCInst &MI, unsigned OpIdx,
504 SmallVectorImpl<MCFixup> &Fixups,
505 const MCSubtargetInfo &STI) const {
506 const MCOperand &MO = MI.getOperand(OpIdx);
507 assert(MO.isImm() && "Expected an immediate value for the scale amount!");
508 return 16 - MO.getImm();
512 ARM64MCCodeEmitter::getVecShiftR8OpValue(const MCInst &MI, unsigned OpIdx,
513 SmallVectorImpl<MCFixup> &Fixups,
514 const MCSubtargetInfo &STI) const {
515 const MCOperand &MO = MI.getOperand(OpIdx);
516 assert(MO.isImm() && "Expected an immediate value for the scale amount!");
517 return 8 - MO.getImm();
521 ARM64MCCodeEmitter::getVecShiftL64OpValue(const MCInst &MI, unsigned OpIdx,
522 SmallVectorImpl<MCFixup> &Fixups,
523 const MCSubtargetInfo &STI) const {
524 const MCOperand &MO = MI.getOperand(OpIdx);
525 assert(MO.isImm() && "Expected an immediate value for the scale amount!");
526 return MO.getImm() - 64;
530 ARM64MCCodeEmitter::getVecShiftL32OpValue(const MCInst &MI, unsigned OpIdx,
531 SmallVectorImpl<MCFixup> &Fixups,
532 const MCSubtargetInfo &STI) const {
533 const MCOperand &MO = MI.getOperand(OpIdx);
534 assert(MO.isImm() && "Expected an immediate value for the scale amount!");
535 return MO.getImm() - 32;
539 ARM64MCCodeEmitter::getVecShiftL16OpValue(const MCInst &MI, unsigned OpIdx,
540 SmallVectorImpl<MCFixup> &Fixups,
541 const MCSubtargetInfo &STI) const {
542 const MCOperand &MO = MI.getOperand(OpIdx);
543 assert(MO.isImm() && "Expected an immediate value for the scale amount!");
544 return MO.getImm() - 16;
548 ARM64MCCodeEmitter::getVecShiftL8OpValue(const MCInst &MI, unsigned OpIdx,
549 SmallVectorImpl<MCFixup> &Fixups,
550 const MCSubtargetInfo &STI) const {
551 const MCOperand &MO = MI.getOperand(OpIdx);
552 assert(MO.isImm() && "Expected an immediate value for the scale amount!");
553 return MO.getImm() - 8;
556 /// getMoveVecShifterOpValue - Return the encoded value for the vector move
559 ARM64MCCodeEmitter::getMoveVecShifterOpValue(const MCInst &MI, unsigned OpIdx,
560 SmallVectorImpl<MCFixup> &Fixups,
561 const MCSubtargetInfo &STI) const {
562 const MCOperand &MO = MI.getOperand(OpIdx);
564 "Expected an immediate value for the move shift amount!");
565 unsigned ShiftVal = ARM64_AM::getShiftValue(MO.getImm());
566 assert((ShiftVal == 8 || ShiftVal == 16) && "Invalid shift amount!");
567 return ShiftVal == 8 ? 0 : 1;
570 unsigned ARM64MCCodeEmitter::fixMOVZ(const MCInst &MI, unsigned EncodedValue,
571 const MCSubtargetInfo &STI) const {
572 // If one of the signed fixup kinds is applied to a MOVZ instruction, the
573 // eventual result could be either a MOVZ or a MOVN. It's the MCCodeEmitter's
574 // job to ensure that any bits possibly affected by this are 0. This means we
575 // must zero out bit 30 (essentially emitting a MOVN).
576 MCOperand UImm16MO = MI.getOperand(1);
578 // Nothing to do if there's no fixup.
579 if (UImm16MO.isImm())
582 const ARM64MCExpr *A64E = cast<ARM64MCExpr>(UImm16MO.getExpr());
583 switch (A64E->getKind()) {
584 case ARM64MCExpr::VK_DTPREL_G2:
585 case ARM64MCExpr::VK_DTPREL_G1:
586 case ARM64MCExpr::VK_DTPREL_G0:
587 case ARM64MCExpr::VK_GOTTPREL_G1:
588 case ARM64MCExpr::VK_TPREL_G2:
589 case ARM64MCExpr::VK_TPREL_G1:
590 case ARM64MCExpr::VK_TPREL_G0:
591 return EncodedValue & ~(1u << 30);
593 // Nothing to do for an unsigned fixup.
598 return EncodedValue & ~(1u << 30);
601 void ARM64MCCodeEmitter::EncodeInstruction(const MCInst &MI, raw_ostream &OS,
602 SmallVectorImpl<MCFixup> &Fixups,
603 const MCSubtargetInfo &STI) const {
604 if (MI.getOpcode() == ARM64::TLSDESCCALL) {
605 // This is a directive which applies an R_AARCH64_TLSDESC_CALL to the
606 // following (BLR) instruction. It doesn't emit any code itself so it
607 // doesn't go through the normal TableGenerated channels.
608 MCFixupKind Fixup = MCFixupKind(ARM64::fixup_arm64_tlsdesc_call);
609 Fixups.push_back(MCFixup::Create(0, MI.getOperand(0).getExpr(), Fixup));
613 uint64_t Binary = getBinaryCodeForInstr(MI, Fixups, STI);
614 EmitConstant(Binary, 4, OS);
615 ++MCNumEmitted; // Keep track of the # of mi's emitted.
619 ARM64MCCodeEmitter::fixMulHigh(const MCInst &MI,
620 unsigned EncodedValue,
621 const MCSubtargetInfo &STI) const {
622 // The Ra field of SMULH and UMULH is unused: it should be assembled as 31
623 // (i.e. all bits 1) but is ignored by the processor.
624 EncodedValue |= 0x1f << 10;
628 template<int hasRs, int hasRt2> unsigned
629 ARM64MCCodeEmitter::fixLoadStoreExclusive(const MCInst &MI,
630 unsigned EncodedValue,
631 const MCSubtargetInfo &STI) const {
632 if (!hasRs) EncodedValue |= 0x001F0000;
633 if (!hasRt2) EncodedValue |= 0x00007C00;
639 ARM64MCCodeEmitter::fixOneOperandFPComparison(const MCInst &MI,
640 unsigned EncodedValue,
641 const MCSubtargetInfo &STI) const {
642 // The Rm field of FCMP and friends is unused - it should be assembled
643 // as 0, but is ignored by the processor.
644 EncodedValue &= ~(0x1f << 16);
648 #include "ARM64GenMCCodeEmitter.inc"