1 //===-- RISCVMCCodeEmitter.cpp - Convert RISC-V code to machine code ------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements the RISCVMCCodeEmitter class.
11 //===----------------------------------------------------------------------===//
13 #include "MCTargetDesc/RISCVBaseInfo.h"
14 #include "MCTargetDesc/RISCVFixupKinds.h"
15 #include "MCTargetDesc/RISCVMCExpr.h"
16 #include "MCTargetDesc/RISCVMCTargetDesc.h"
17 #include "llvm/ADT/Statistic.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCCodeEmitter.h"
20 #include "llvm/MC/MCContext.h"
21 #include "llvm/MC/MCExpr.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/MC/MCInstBuilder.h"
24 #include "llvm/MC/MCInstrInfo.h"
25 #include "llvm/MC/MCRegisterInfo.h"
26 #include "llvm/MC/MCSubtargetInfo.h"
27 #include "llvm/MC/MCSymbol.h"
28 #include "llvm/Support/Casting.h"
29 #include "llvm/Support/EndianStream.h"
30 #include "llvm/Support/raw_ostream.h"
34 #define DEBUG_TYPE "mccodeemitter"
36 STATISTIC(MCNumEmitted
, "Number of MC instructions emitted");
37 STATISTIC(MCNumFixups
, "Number of MC fixups created");
40 class RISCVMCCodeEmitter
: public MCCodeEmitter
{
41 RISCVMCCodeEmitter(const RISCVMCCodeEmitter
&) = delete;
42 void operator=(const RISCVMCCodeEmitter
&) = delete;
44 MCInstrInfo
const &MCII
;
47 RISCVMCCodeEmitter(MCContext
&ctx
, MCInstrInfo
const &MCII
)
48 : Ctx(ctx
), MCII(MCII
) {}
50 ~RISCVMCCodeEmitter() override
= default;
52 void encodeInstruction(const MCInst
&MI
, SmallVectorImpl
<char> &CB
,
53 SmallVectorImpl
<MCFixup
> &Fixups
,
54 const MCSubtargetInfo
&STI
) const override
;
56 void expandFunctionCall(const MCInst
&MI
, SmallVectorImpl
<char> &CB
,
57 SmallVectorImpl
<MCFixup
> &Fixups
,
58 const MCSubtargetInfo
&STI
) const;
60 void expandTLSDESCCall(const MCInst
&MI
, SmallVectorImpl
<char> &CB
,
61 SmallVectorImpl
<MCFixup
> &Fixups
,
62 const MCSubtargetInfo
&STI
) const;
64 void expandAddTPRel(const MCInst
&MI
, SmallVectorImpl
<char> &CB
,
65 SmallVectorImpl
<MCFixup
> &Fixups
,
66 const MCSubtargetInfo
&STI
) const;
68 void expandLongCondBr(const MCInst
&MI
, SmallVectorImpl
<char> &CB
,
69 SmallVectorImpl
<MCFixup
> &Fixups
,
70 const MCSubtargetInfo
&STI
) const;
72 /// TableGen'erated function for getting the binary encoding for an
74 uint64_t getBinaryCodeForInstr(const MCInst
&MI
,
75 SmallVectorImpl
<MCFixup
> &Fixups
,
76 const MCSubtargetInfo
&STI
) const;
78 /// Return binary encoding of operand. If the machine operand requires
79 /// relocation, record the relocation and return zero.
80 unsigned getMachineOpValue(const MCInst
&MI
, const MCOperand
&MO
,
81 SmallVectorImpl
<MCFixup
> &Fixups
,
82 const MCSubtargetInfo
&STI
) const;
84 unsigned getImmOpValueAsr1(const MCInst
&MI
, unsigned OpNo
,
85 SmallVectorImpl
<MCFixup
> &Fixups
,
86 const MCSubtargetInfo
&STI
) const;
88 unsigned getImmOpValue(const MCInst
&MI
, unsigned OpNo
,
89 SmallVectorImpl
<MCFixup
> &Fixups
,
90 const MCSubtargetInfo
&STI
) const;
92 unsigned getVMaskReg(const MCInst
&MI
, unsigned OpNo
,
93 SmallVectorImpl
<MCFixup
> &Fixups
,
94 const MCSubtargetInfo
&STI
) const;
96 unsigned getRlistOpValue(const MCInst
&MI
, unsigned OpNo
,
97 SmallVectorImpl
<MCFixup
> &Fixups
,
98 const MCSubtargetInfo
&STI
) const;
100 unsigned getRegReg(const MCInst
&MI
, unsigned OpNo
,
101 SmallVectorImpl
<MCFixup
> &Fixups
,
102 const MCSubtargetInfo
&STI
) const;
104 } // end anonymous namespace
106 MCCodeEmitter
*llvm::createRISCVMCCodeEmitter(const MCInstrInfo
&MCII
,
108 return new RISCVMCCodeEmitter(Ctx
, MCII
);
111 // Expand PseudoCALL(Reg), PseudoTAIL and PseudoJump to AUIPC and JALR with
112 // relocation types. We expand those pseudo-instructions while encoding them,
113 // meaning AUIPC and JALR won't go through RISC-V MC to MC compressed
114 // instruction transformation. This is acceptable because AUIPC has no 16-bit
115 // form and C_JALR has no immediate operand field. We let linker relaxation
116 // deal with it. When linker relaxation is enabled, AUIPC and JALR have a
117 // chance to relax to JAL.
118 // If the C extension is enabled, JAL has a chance relax to C_JAL.
119 void RISCVMCCodeEmitter::expandFunctionCall(const MCInst
&MI
,
120 SmallVectorImpl
<char> &CB
,
121 SmallVectorImpl
<MCFixup
> &Fixups
,
122 const MCSubtargetInfo
&STI
) const {
126 if (MI
.getOpcode() == RISCV::PseudoTAIL
) {
127 Func
= MI
.getOperand(0);
129 } else if (MI
.getOpcode() == RISCV::PseudoCALLReg
) {
130 Func
= MI
.getOperand(1);
131 Ra
= MI
.getOperand(0).getReg();
132 } else if (MI
.getOpcode() == RISCV::PseudoCALL
) {
133 Func
= MI
.getOperand(0);
135 } else if (MI
.getOpcode() == RISCV::PseudoJump
) {
136 Func
= MI
.getOperand(1);
137 Ra
= MI
.getOperand(0).getReg();
141 assert(Func
.isExpr() && "Expected expression");
143 const MCExpr
*CallExpr
= Func
.getExpr();
145 // Emit AUIPC Ra, Func with R_RISCV_CALL relocation type.
146 TmpInst
= MCInstBuilder(RISCV::AUIPC
).addReg(Ra
).addExpr(CallExpr
);
147 Binary
= getBinaryCodeForInstr(TmpInst
, Fixups
, STI
);
148 support::endian::write(CB
, Binary
, llvm::endianness::little
);
150 if (MI
.getOpcode() == RISCV::PseudoTAIL
||
151 MI
.getOpcode() == RISCV::PseudoJump
)
152 // Emit JALR X0, Ra, 0
153 TmpInst
= MCInstBuilder(RISCV::JALR
).addReg(RISCV::X0
).addReg(Ra
).addImm(0);
155 // Emit JALR Ra, Ra, 0
156 TmpInst
= MCInstBuilder(RISCV::JALR
).addReg(Ra
).addReg(Ra
).addImm(0);
157 Binary
= getBinaryCodeForInstr(TmpInst
, Fixups
, STI
);
158 support::endian::write(CB
, Binary
, llvm::endianness::little
);
161 void RISCVMCCodeEmitter::expandTLSDESCCall(const MCInst
&MI
,
162 SmallVectorImpl
<char> &CB
,
163 SmallVectorImpl
<MCFixup
> &Fixups
,
164 const MCSubtargetInfo
&STI
) const {
165 MCOperand SrcSymbol
= MI
.getOperand(3);
166 assert(SrcSymbol
.isExpr() &&
167 "Expected expression as first input to TLSDESCCALL");
168 const RISCVMCExpr
*Expr
= dyn_cast
<RISCVMCExpr
>(SrcSymbol
.getExpr());
169 MCRegister Link
= MI
.getOperand(0).getReg();
170 MCRegister Dest
= MI
.getOperand(1).getReg();
171 MCRegister Imm
= MI
.getOperand(2).getImm();
172 Fixups
.push_back(MCFixup::create(
173 0, Expr
, MCFixupKind(RISCV::fixup_riscv_tlsdesc_call
), MI
.getLoc()));
175 MCInstBuilder(RISCV::JALR
).addReg(Link
).addReg(Dest
).addImm(Imm
);
177 uint32_t Binary
= getBinaryCodeForInstr(Call
, Fixups
, STI
);
178 support::endian::write(CB
, Binary
, llvm::endianness::little
);
181 // Expand PseudoAddTPRel to a simple ADD with the correct relocation.
182 void RISCVMCCodeEmitter::expandAddTPRel(const MCInst
&MI
,
183 SmallVectorImpl
<char> &CB
,
184 SmallVectorImpl
<MCFixup
> &Fixups
,
185 const MCSubtargetInfo
&STI
) const {
186 MCOperand DestReg
= MI
.getOperand(0);
187 MCOperand SrcReg
= MI
.getOperand(1);
188 MCOperand TPReg
= MI
.getOperand(2);
189 assert(TPReg
.isReg() && TPReg
.getReg() == RISCV::X4
&&
190 "Expected thread pointer as second input to TP-relative add");
192 MCOperand SrcSymbol
= MI
.getOperand(3);
193 assert(SrcSymbol
.isExpr() &&
194 "Expected expression as third input to TP-relative add");
196 const RISCVMCExpr
*Expr
= dyn_cast
<RISCVMCExpr
>(SrcSymbol
.getExpr());
197 assert(Expr
&& Expr
->getKind() == RISCVMCExpr::VK_RISCV_TPREL_ADD
&&
198 "Expected tprel_add relocation on TP-relative symbol");
200 // Emit the correct tprel_add relocation for the symbol.
201 Fixups
.push_back(MCFixup::create(
202 0, Expr
, MCFixupKind(RISCV::fixup_riscv_tprel_add
), MI
.getLoc()));
204 // Emit fixup_riscv_relax for tprel_add where the relax feature is enabled.
205 if (STI
.hasFeature(RISCV::FeatureRelax
)) {
206 const MCConstantExpr
*Dummy
= MCConstantExpr::create(0, Ctx
);
207 Fixups
.push_back(MCFixup::create(
208 0, Dummy
, MCFixupKind(RISCV::fixup_riscv_relax
), MI
.getLoc()));
211 // Emit a normal ADD instruction with the given operands.
212 MCInst TmpInst
= MCInstBuilder(RISCV::ADD
)
216 uint32_t Binary
= getBinaryCodeForInstr(TmpInst
, Fixups
, STI
);
217 support::endian::write(CB
, Binary
, llvm::endianness::little
);
220 static unsigned getInvertedBranchOp(unsigned BrOp
) {
223 llvm_unreachable("Unexpected branch opcode!");
224 case RISCV::PseudoLongBEQ
:
226 case RISCV::PseudoLongBNE
:
228 case RISCV::PseudoLongBLT
:
230 case RISCV::PseudoLongBGE
:
232 case RISCV::PseudoLongBLTU
:
234 case RISCV::PseudoLongBGEU
:
239 // Expand PseudoLongBxx to an inverted conditional branch and an unconditional
241 void RISCVMCCodeEmitter::expandLongCondBr(const MCInst
&MI
,
242 SmallVectorImpl
<char> &CB
,
243 SmallVectorImpl
<MCFixup
> &Fixups
,
244 const MCSubtargetInfo
&STI
) const {
245 MCRegister SrcReg1
= MI
.getOperand(0).getReg();
246 MCRegister SrcReg2
= MI
.getOperand(1).getReg();
247 MCOperand SrcSymbol
= MI
.getOperand(2);
248 unsigned Opcode
= MI
.getOpcode();
250 Opcode
== RISCV::PseudoLongBNE
|| Opcode
== RISCV::PseudoLongBEQ
;
252 bool UseCompressedBr
= false;
253 if (IsEqTest
&& (STI
.hasFeature(RISCV::FeatureStdExtC
) ||
254 STI
.hasFeature(RISCV::FeatureStdExtZca
))) {
255 if (RISCV::X8
<= SrcReg1
.id() && SrcReg1
.id() <= RISCV::X15
&&
256 SrcReg2
.id() == RISCV::X0
) {
257 UseCompressedBr
= true;
258 } else if (RISCV::X8
<= SrcReg2
.id() && SrcReg2
.id() <= RISCV::X15
&&
259 SrcReg1
.id() == RISCV::X0
) {
260 std::swap(SrcReg1
, SrcReg2
);
261 UseCompressedBr
= true;
266 if (UseCompressedBr
) {
268 Opcode
== RISCV::PseudoLongBNE
? RISCV::C_BEQZ
: RISCV::C_BNEZ
;
269 MCInst TmpInst
= MCInstBuilder(InvOpc
).addReg(SrcReg1
).addImm(6);
270 uint16_t Binary
= getBinaryCodeForInstr(TmpInst
, Fixups
, STI
);
271 support::endian::write
<uint16_t>(CB
, Binary
, llvm::endianness::little
);
274 unsigned InvOpc
= getInvertedBranchOp(Opcode
);
276 MCInstBuilder(InvOpc
).addReg(SrcReg1
).addReg(SrcReg2
).addImm(8);
277 uint32_t Binary
= getBinaryCodeForInstr(TmpInst
, Fixups
, STI
);
278 support::endian::write(CB
, Binary
, llvm::endianness::little
);
282 // Emit an unconditional jump to the destination.
284 MCInstBuilder(RISCV::JAL
).addReg(RISCV::X0
).addOperand(SrcSymbol
);
285 uint32_t Binary
= getBinaryCodeForInstr(TmpInst
, Fixups
, STI
);
286 support::endian::write(CB
, Binary
, llvm::endianness::little
);
289 if (SrcSymbol
.isExpr()) {
290 Fixups
.push_back(MCFixup::create(Offset
, SrcSymbol
.getExpr(),
291 MCFixupKind(RISCV::fixup_riscv_jal
),
296 void RISCVMCCodeEmitter::encodeInstruction(const MCInst
&MI
,
297 SmallVectorImpl
<char> &CB
,
298 SmallVectorImpl
<MCFixup
> &Fixups
,
299 const MCSubtargetInfo
&STI
) const {
300 const MCInstrDesc
&Desc
= MCII
.get(MI
.getOpcode());
301 // Get byte count of instruction.
302 unsigned Size
= Desc
.getSize();
304 // RISCVInstrInfo::getInstSizeInBytes expects that the total size of the
305 // expanded instructions for each pseudo is correct in the Size field of the
306 // tablegen definition for the pseudo.
307 switch (MI
.getOpcode()) {
310 case RISCV::PseudoCALLReg
:
311 case RISCV::PseudoCALL
:
312 case RISCV::PseudoTAIL
:
313 case RISCV::PseudoJump
:
314 expandFunctionCall(MI
, CB
, Fixups
, STI
);
317 case RISCV::PseudoAddTPRel
:
318 expandAddTPRel(MI
, CB
, Fixups
, STI
);
321 case RISCV::PseudoLongBEQ
:
322 case RISCV::PseudoLongBNE
:
323 case RISCV::PseudoLongBLT
:
324 case RISCV::PseudoLongBGE
:
325 case RISCV::PseudoLongBLTU
:
326 case RISCV::PseudoLongBGEU
:
327 expandLongCondBr(MI
, CB
, Fixups
, STI
);
330 case RISCV::PseudoTLSDESCCall
:
331 expandTLSDESCCall(MI
, CB
, Fixups
, STI
);
338 llvm_unreachable("Unhandled encodeInstruction length!");
340 uint16_t Bits
= getBinaryCodeForInstr(MI
, Fixups
, STI
);
341 support::endian::write
<uint16_t>(CB
, Bits
, llvm::endianness::little
);
345 uint32_t Bits
= getBinaryCodeForInstr(MI
, Fixups
, STI
);
346 support::endian::write(CB
, Bits
, llvm::endianness::little
);
351 ++MCNumEmitted
; // Keep track of the # of mi's emitted.
355 RISCVMCCodeEmitter::getMachineOpValue(const MCInst
&MI
, const MCOperand
&MO
,
356 SmallVectorImpl
<MCFixup
> &Fixups
,
357 const MCSubtargetInfo
&STI
) const {
360 return Ctx
.getRegisterInfo()->getEncodingValue(MO
.getReg());
363 return static_cast<unsigned>(MO
.getImm());
365 llvm_unreachable("Unhandled expression!");
370 RISCVMCCodeEmitter::getImmOpValueAsr1(const MCInst
&MI
, unsigned OpNo
,
371 SmallVectorImpl
<MCFixup
> &Fixups
,
372 const MCSubtargetInfo
&STI
) const {
373 const MCOperand
&MO
= MI
.getOperand(OpNo
);
376 unsigned Res
= MO
.getImm();
377 assert((Res
& 1) == 0 && "LSB is non-zero");
381 return getImmOpValue(MI
, OpNo
, Fixups
, STI
);
384 unsigned RISCVMCCodeEmitter::getImmOpValue(const MCInst
&MI
, unsigned OpNo
,
385 SmallVectorImpl
<MCFixup
> &Fixups
,
386 const MCSubtargetInfo
&STI
) const {
387 bool EnableRelax
= STI
.hasFeature(RISCV::FeatureRelax
);
388 const MCOperand
&MO
= MI
.getOperand(OpNo
);
390 MCInstrDesc
const &Desc
= MCII
.get(MI
.getOpcode());
391 unsigned MIFrm
= RISCVII::getFormat(Desc
.TSFlags
);
393 // If the destination is an immediate, there is nothing to do.
397 assert(MO
.isExpr() &&
398 "getImmOpValue expects only expressions or immediates");
399 const MCExpr
*Expr
= MO
.getExpr();
400 MCExpr::ExprKind Kind
= Expr
->getKind();
401 RISCV::Fixups FixupKind
= RISCV::fixup_riscv_invalid
;
402 bool RelaxCandidate
= false;
403 if (Kind
== MCExpr::Target
) {
404 const RISCVMCExpr
*RVExpr
= cast
<RISCVMCExpr
>(Expr
);
406 switch (RVExpr
->getKind()) {
407 case RISCVMCExpr::VK_RISCV_None
:
408 case RISCVMCExpr::VK_RISCV_Invalid
:
409 case RISCVMCExpr::VK_RISCV_32_PCREL
:
410 llvm_unreachable("Unhandled fixup kind!");
411 case RISCVMCExpr::VK_RISCV_TPREL_ADD
:
412 // tprel_add is only used to indicate that a relocation should be emitted
413 // for an add instruction used in TP-relative addressing. It should not be
414 // expanded as if representing an actual instruction operand and so to
415 // encounter it here is an error.
417 "VK_RISCV_TPREL_ADD should not represent an instruction operand");
418 case RISCVMCExpr::VK_RISCV_LO
:
419 if (MIFrm
== RISCVII::InstFormatI
)
420 FixupKind
= RISCV::fixup_riscv_lo12_i
;
421 else if (MIFrm
== RISCVII::InstFormatS
)
422 FixupKind
= RISCV::fixup_riscv_lo12_s
;
424 llvm_unreachable("VK_RISCV_LO used with unexpected instruction format");
425 RelaxCandidate
= true;
427 case RISCVMCExpr::VK_RISCV_HI
:
428 FixupKind
= RISCV::fixup_riscv_hi20
;
429 RelaxCandidate
= true;
431 case RISCVMCExpr::VK_RISCV_PCREL_LO
:
432 if (MIFrm
== RISCVII::InstFormatI
)
433 FixupKind
= RISCV::fixup_riscv_pcrel_lo12_i
;
434 else if (MIFrm
== RISCVII::InstFormatS
)
435 FixupKind
= RISCV::fixup_riscv_pcrel_lo12_s
;
438 "VK_RISCV_PCREL_LO used with unexpected instruction format");
439 RelaxCandidate
= true;
441 case RISCVMCExpr::VK_RISCV_PCREL_HI
:
442 FixupKind
= RISCV::fixup_riscv_pcrel_hi20
;
443 RelaxCandidate
= true;
445 case RISCVMCExpr::VK_RISCV_GOT_HI
:
446 FixupKind
= RISCV::fixup_riscv_got_hi20
;
448 case RISCVMCExpr::VK_RISCV_TPREL_LO
:
449 if (MIFrm
== RISCVII::InstFormatI
)
450 FixupKind
= RISCV::fixup_riscv_tprel_lo12_i
;
451 else if (MIFrm
== RISCVII::InstFormatS
)
452 FixupKind
= RISCV::fixup_riscv_tprel_lo12_s
;
455 "VK_RISCV_TPREL_LO used with unexpected instruction format");
456 RelaxCandidate
= true;
458 case RISCVMCExpr::VK_RISCV_TPREL_HI
:
459 FixupKind
= RISCV::fixup_riscv_tprel_hi20
;
460 RelaxCandidate
= true;
462 case RISCVMCExpr::VK_RISCV_TLS_GOT_HI
:
463 FixupKind
= RISCV::fixup_riscv_tls_got_hi20
;
465 case RISCVMCExpr::VK_RISCV_TLS_GD_HI
:
466 FixupKind
= RISCV::fixup_riscv_tls_gd_hi20
;
468 case RISCVMCExpr::VK_RISCV_CALL
:
469 FixupKind
= RISCV::fixup_riscv_call
;
470 RelaxCandidate
= true;
472 case RISCVMCExpr::VK_RISCV_CALL_PLT
:
473 FixupKind
= RISCV::fixup_riscv_call_plt
;
474 RelaxCandidate
= true;
476 case RISCVMCExpr::VK_RISCV_TLSDESC_HI
:
477 FixupKind
= RISCV::fixup_riscv_tlsdesc_hi20
;
479 case RISCVMCExpr::VK_RISCV_TLSDESC_LOAD_LO
:
480 FixupKind
= RISCV::fixup_riscv_tlsdesc_load_lo12
;
482 case RISCVMCExpr::VK_RISCV_TLSDESC_ADD_LO
:
483 FixupKind
= RISCV::fixup_riscv_tlsdesc_add_lo12
;
485 case RISCVMCExpr::VK_RISCV_TLSDESC_CALL
:
486 FixupKind
= RISCV::fixup_riscv_tlsdesc_call
;
489 } else if ((Kind
== MCExpr::SymbolRef
&&
490 cast
<MCSymbolRefExpr
>(Expr
)->getKind() ==
491 MCSymbolRefExpr::VK_None
) ||
492 Kind
== MCExpr::Binary
) {
493 // FIXME: Sub kind binary exprs have chance of underflow.
494 if (MIFrm
== RISCVII::InstFormatJ
) {
495 FixupKind
= RISCV::fixup_riscv_jal
;
496 } else if (MIFrm
== RISCVII::InstFormatB
) {
497 FixupKind
= RISCV::fixup_riscv_branch
;
498 } else if (MIFrm
== RISCVII::InstFormatCJ
) {
499 FixupKind
= RISCV::fixup_riscv_rvc_jump
;
500 } else if (MIFrm
== RISCVII::InstFormatCB
) {
501 FixupKind
= RISCV::fixup_riscv_rvc_branch
;
502 } else if (MIFrm
== RISCVII::InstFormatI
) {
503 FixupKind
= RISCV::fixup_riscv_12_i
;
507 assert(FixupKind
!= RISCV::fixup_riscv_invalid
&& "Unhandled expression!");
510 MCFixup::create(0, Expr
, MCFixupKind(FixupKind
), MI
.getLoc()));
513 // Ensure an R_RISCV_RELAX relocation will be emitted if linker relaxation is
514 // enabled and the current fixup will result in a relocation that may be
516 if (EnableRelax
&& RelaxCandidate
) {
517 const MCConstantExpr
*Dummy
= MCConstantExpr::create(0, Ctx
);
519 MCFixup::create(0, Dummy
, MCFixupKind(RISCV::fixup_riscv_relax
),
527 unsigned RISCVMCCodeEmitter::getVMaskReg(const MCInst
&MI
, unsigned OpNo
,
528 SmallVectorImpl
<MCFixup
> &Fixups
,
529 const MCSubtargetInfo
&STI
) const {
530 MCOperand MO
= MI
.getOperand(OpNo
);
531 assert(MO
.isReg() && "Expected a register.");
533 switch (MO
.getReg()) {
535 llvm_unreachable("Invalid mask register.");
538 case RISCV::NoRegister
:
543 unsigned RISCVMCCodeEmitter::getRlistOpValue(const MCInst
&MI
, unsigned OpNo
,
544 SmallVectorImpl
<MCFixup
> &Fixups
,
545 const MCSubtargetInfo
&STI
) const {
546 const MCOperand
&MO
= MI
.getOperand(OpNo
);
547 assert(MO
.isImm() && "Rlist operand must be immediate");
548 auto Imm
= MO
.getImm();
549 assert(Imm
>= 4 && "EABI is currently not implemented");
553 unsigned RISCVMCCodeEmitter::getRegReg(const MCInst
&MI
, unsigned OpNo
,
554 SmallVectorImpl
<MCFixup
> &Fixups
,
555 const MCSubtargetInfo
&STI
) const {
556 const MCOperand
&MO
= MI
.getOperand(OpNo
);
557 const MCOperand
&MO1
= MI
.getOperand(OpNo
+ 1);
558 assert(MO
.isReg() && MO1
.isReg() && "Expected registers.");
560 unsigned Op
= Ctx
.getRegisterInfo()->getEncodingValue(MO
.getReg());
561 unsigned Op1
= Ctx
.getRegisterInfo()->getEncodingValue(MO1
.getReg());
563 return Op
| Op1
<< 5;
566 #include "RISCVGenMCCodeEmitter.inc"