33#define DEBUG_TYPE "mccodeemitter"
35STATISTIC(MCNumEmitted,
"Number of MC instructions emitted");
36STATISTIC(MCNumFixups,
"Number of MC fixups created");
40 RISCVMCCodeEmitter(
const RISCVMCCodeEmitter &) =
delete;
41 void operator=(
const RISCVMCCodeEmitter &) =
delete;
47 : Ctx(ctx), MCII(MCII) {}
49 ~RISCVMCCodeEmitter()
override =
default;
51 void encodeInstruction(
const MCInst &
MI, SmallVectorImpl<char> &CB,
52 SmallVectorImpl<MCFixup> &Fixups,
53 const MCSubtargetInfo &STI)
const override;
55 void expandFunctionCall(
const MCInst &
MI, SmallVectorImpl<char> &CB,
56 SmallVectorImpl<MCFixup> &Fixups,
57 const MCSubtargetInfo &STI)
const;
59 void expandTLSDESCCall(
const MCInst &
MI, SmallVectorImpl<char> &CB,
60 SmallVectorImpl<MCFixup> &Fixups,
61 const MCSubtargetInfo &STI)
const;
63 void expandAddTPRel(
const MCInst &
MI, SmallVectorImpl<char> &CB,
64 SmallVectorImpl<MCFixup> &Fixups,
65 const MCSubtargetInfo &STI)
const;
67 void expandLongCondBr(
const MCInst &
MI, SmallVectorImpl<char> &CB,
68 SmallVectorImpl<MCFixup> &Fixups,
69 const MCSubtargetInfo &STI)
const;
71 void expandFunctionCallLpad(
const MCInst &
MI, SmallVectorImpl<char> &CB,
72 SmallVectorImpl<MCFixup> &Fixups,
73 const MCSubtargetInfo &STI)
const;
75 void expandQCLongCondBrImm(
const MCInst &
MI, SmallVectorImpl<char> &CB,
76 SmallVectorImpl<MCFixup> &Fixups,
77 const MCSubtargetInfo &STI,
unsigned Size)
const;
79 void expandPseudoQCAccess(
const MCInst &
MI, SmallVectorImpl<char> &CB,
80 SmallVectorImpl<MCFixup> &Fixups,
81 const MCSubtargetInfo &STI)
const;
85 uint64_t getBinaryCodeForInstr(
const MCInst &
MI,
86 SmallVectorImpl<MCFixup> &Fixups,
87 const MCSubtargetInfo &STI)
const;
91 uint64_t getMachineOpValue(
const MCInst &
MI,
const MCOperand &MO,
92 SmallVectorImpl<MCFixup> &Fixups,
93 const MCSubtargetInfo &STI)
const;
95 uint64_t getImmOpValueMinus1(
const MCInst &
MI,
unsigned OpNo,
96 SmallVectorImpl<MCFixup> &Fixups,
97 const MCSubtargetInfo &STI)
const;
99 uint64_t getImmOpValueSlist(
const MCInst &
MI,
unsigned OpNo,
100 SmallVectorImpl<MCFixup> &Fixups,
101 const MCSubtargetInfo &STI)
const;
103 template <
unsigned N>
104 unsigned getImmOpValueAsrN(
const MCInst &
MI,
unsigned OpNo,
105 SmallVectorImpl<MCFixup> &Fixups,
106 const MCSubtargetInfo &STI)
const;
108 uint64_t getImmOpValueZibi(
const MCInst &
MI,
unsigned OpNo,
109 SmallVectorImpl<MCFixup> &Fixups,
110 const MCSubtargetInfo &STI)
const;
112 uint64_t getImmOpValue(
const MCInst &
MI,
unsigned OpNo,
113 SmallVectorImpl<MCFixup> &Fixups,
114 const MCSubtargetInfo &STI)
const;
116 unsigned getYBNDSWImmOpValue(
const MCInst &
MI,
unsigned OpNo,
117 SmallVectorImpl<MCFixup> &Fixups,
118 const MCSubtargetInfo &STI)
const;
120 unsigned getVMaskReg(
const MCInst &
MI,
unsigned OpNo,
121 SmallVectorImpl<MCFixup> &Fixups,
122 const MCSubtargetInfo &STI)
const;
124 unsigned getRlistOpValue(
const MCInst &
MI,
unsigned OpNo,
125 SmallVectorImpl<MCFixup> &Fixups,
126 const MCSubtargetInfo &STI)
const;
128 unsigned getRlistS0OpValue(
const MCInst &
MI,
unsigned OpNo,
129 SmallVectorImpl<MCFixup> &Fixups,
130 const MCSubtargetInfo &STI)
const;
136 return new RISCVMCCodeEmitter(Ctx, MCII);
143 case ELF::R_RISCV_CALL_PLT:
169void RISCVMCCodeEmitter::expandFunctionCall(
const MCInst &
MI,
176 if (
MI.getOpcode() == RISCV::PseudoTAIL) {
179 }
else if (
MI.getOpcode() == RISCV::PseudoCALLReg) {
181 Ra =
MI.getOperand(0).getReg();
182 }
else if (
MI.getOpcode() == RISCV::PseudoCALL) {
185 }
else if (
MI.getOpcode() == RISCV::PseudoJump) {
187 Ra =
MI.getOperand(0).getReg();
191 assert(
Func.isExpr() &&
"Expected expression");
193 const MCExpr *CallExpr =
Func.getExpr();
197 if (
MI.getOpcode() == RISCV::PseudoTAIL ||
198 MI.getOpcode() == RISCV::PseudoJump)
200 TmpInst = MCInstBuilder(RISCV::JAL).addReg(RISCV::X0).
addOperand(FuncOp);
203 TmpInst = MCInstBuilder(RISCV::JAL).addReg(Ra).
addOperand(FuncOp);
204 Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
209 TmpInst = MCInstBuilder(RISCV::AUIPC).addReg(Ra).addExpr(CallExpr);
210 Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
213 if (
MI.getOpcode() == RISCV::PseudoTAIL ||
214 MI.getOpcode() == RISCV::PseudoJump)
216 TmpInst = MCInstBuilder(RISCV::JALR).addReg(RISCV::X0).addReg(Ra).addImm(0);
219 TmpInst = MCInstBuilder(RISCV::JALR).addReg(Ra).addReg(Ra).addImm(0);
220 Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
227void RISCVMCCodeEmitter::expandFunctionCallLpad(
228 const MCInst &
MI, SmallVectorImpl<char> &CB,
229 SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI)
const {
230 bool IsIndirect =
MI.getOpcode() == RISCV::PseudoCALLIndirectLpadAlign;
235 const MCOperand &
Func =
MI.getOperand(0);
236 assert(
Func.isExpr() &&
"Expected expression for call target");
241 MCSubtargetInfo NoRelaxSTI(STI);
243 NoRelaxSTI.ToggleFeature(RISCV::FeatureRelax);
246 MCInstBuilder(RISCV::AUIPC).addReg(RISCV::X1).addExpr(
Func.getExpr());
247 Binary = getBinaryCodeForInstr(TmpInst, Fixups, NoRelaxSTI);
250 TmpInst = MCInstBuilder(RISCV::JALR)
254 Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
257 TmpInst = MCInstBuilder(RISCV::JALR)
259 .addReg(
MI.getOperand(0).getReg())
261 Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
266 TmpInst = MCInstBuilder(RISCV::AUIPC)
268 .addImm(
MI.getOperand(1).getImm());
269 Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
273void RISCVMCCodeEmitter::expandTLSDESCCall(
const MCInst &
MI,
274 SmallVectorImpl<char> &CB,
275 SmallVectorImpl<MCFixup> &Fixups,
276 const MCSubtargetInfo &STI)
const {
277 MCOperand SrcSymbol =
MI.getOperand(3);
279 "Expected expression as first input to TLSDESCCALL");
281 MCRegister Link =
MI.getOperand(0).getReg();
282 MCRegister Dest =
MI.getOperand(1).getReg();
283 int64_t
Imm =
MI.getOperand(2).getImm();
284 addFixup(Fixups, 0, Expr, ELF::R_RISCV_TLSDESC_CALL);
286 MCInstBuilder(RISCV::JALR).addReg(Link).addReg(Dest).addImm(Imm);
288 uint32_t
Binary = getBinaryCodeForInstr(
Call, Fixups, STI);
293void RISCVMCCodeEmitter::expandAddTPRel(
const MCInst &
MI,
294 SmallVectorImpl<char> &CB,
295 SmallVectorImpl<MCFixup> &Fixups,
296 const MCSubtargetInfo &STI)
const {
297 MCOperand DestReg =
MI.getOperand(0);
298 MCOperand SrcReg =
MI.getOperand(1);
299 MCOperand TPReg =
MI.getOperand(2);
301 "Expected thread pointer as second input to TP-relative add");
303 MCOperand SrcSymbol =
MI.getOperand(3);
305 "Expected expression as third input to TP-relative add");
308 assert(Expr && Expr->getSpecifier() == ELF::R_RISCV_TPREL_ADD &&
309 "Expected tprel_add relocation on TP-relative symbol");
311 addFixup(Fixups, 0, Expr, ELF::R_RISCV_TPREL_ADD);
313 Fixups.back().setLinkerRelaxable();
316 MCInst TmpInst = MCInstBuilder(RISCV::ADD)
320 uint32_t
Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
328 case RISCV::PseudoLongBEQ:
330 case RISCV::PseudoLongBNE:
332 case RISCV::PseudoLongBEQI:
334 case RISCV::PseudoLongBNEI:
336 case RISCV::PseudoLongBLT:
338 case RISCV::PseudoLongBGE:
340 case RISCV::PseudoLongBLTU:
342 case RISCV::PseudoLongBGEU:
344 case RISCV::PseudoLongQC_BEQI:
345 return RISCV::QC_BNEI;
346 case RISCV::PseudoLongQC_BNEI:
347 return RISCV::QC_BEQI;
348 case RISCV::PseudoLongQC_BLTI:
349 return RISCV::QC_BGEI;
350 case RISCV::PseudoLongQC_BGEI:
351 return RISCV::QC_BLTI;
352 case RISCV::PseudoLongQC_BLTUI:
353 return RISCV::QC_BGEUI;
354 case RISCV::PseudoLongQC_BGEUI:
355 return RISCV::QC_BLTUI;
356 case RISCV::PseudoLongQC_E_BEQI:
357 return RISCV::QC_E_BNEI;
358 case RISCV::PseudoLongQC_E_BNEI:
359 return RISCV::QC_E_BEQI;
360 case RISCV::PseudoLongQC_E_BLTI:
361 return RISCV::QC_E_BGEI;
362 case RISCV::PseudoLongQC_E_BGEI:
363 return RISCV::QC_E_BLTI;
364 case RISCV::PseudoLongQC_E_BLTUI:
365 return RISCV::QC_E_BGEUI;
366 case RISCV::PseudoLongQC_E_BGEUI:
367 return RISCV::QC_E_BLTUI;
373void RISCVMCCodeEmitter::expandLongCondBr(
const MCInst &
MI,
374 SmallVectorImpl<char> &CB,
375 SmallVectorImpl<MCFixup> &Fixups,
376 const MCSubtargetInfo &STI)
const {
377 MCRegister SrcReg1 =
MI.getOperand(0).getReg();
378 const MCOperand &Src2 =
MI.getOperand(1);
379 const MCOperand &SrcSymbol =
MI.getOperand(2);
380 unsigned Opcode =
MI.getOpcode();
382 Opcode == RISCV::PseudoLongBNE || Opcode == RISCV::PseudoLongBEQ;
384 bool UseCompressedBr =
false;
385 if (IsEqTest && STI.
hasFeature(RISCV::FeatureStdExtZca)) {
386 MCRegister SrcReg2 = Src2.
getReg();
387 if (RISCV::X8 <= SrcReg1.
id() && SrcReg1.
id() <= RISCV::X15 &&
388 SrcReg2.
id() == RISCV::X0) {
389 UseCompressedBr =
true;
390 }
else if (RISCV::X8 <= SrcReg2.
id() && SrcReg2.
id() <= RISCV::X15 &&
391 SrcReg1.
id() == RISCV::X0) {
393 UseCompressedBr =
true;
398 if (UseCompressedBr) {
400 Opcode == RISCV::PseudoLongBNE ? RISCV::C_BEQZ : RISCV::C_BNEZ;
401 MCInst TmpInst = MCInstBuilder(InvOpc).addReg(SrcReg1).addImm(6);
402 uint16_t
Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
408 MCInstBuilder(InvOpc).addReg(SrcReg1).
addOperand(Src2).addImm(8);
409 uint32_t
Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
415 size_t FixupStartIndex =
Fixups.size();
419 MCInstBuilder(RISCV::JAL).addReg(RISCV::X0).
addOperand(SrcSymbol);
420 uint32_t
Binary = getBinaryCodeForInstr(TmpInst, Fixups, STI);
424 Fixups.resize(FixupStartIndex);
429 Fixups.back().setLinkerRelaxable();
435void RISCVMCCodeEmitter::expandQCLongCondBrImm(
const MCInst &
MI,
436 SmallVectorImpl<char> &CB,
437 SmallVectorImpl<MCFixup> &Fixups,
438 const MCSubtargetInfo &STI,
439 unsigned Size)
const {
440 MCRegister SrcReg1 =
MI.getOperand(0).getReg();
441 auto BrImm =
MI.getOperand(1).getImm();
442 MCOperand SrcSymbol =
MI.getOperand(2);
443 unsigned Opcode =
MI.getOpcode();
452 MCInstBuilder(InvOpc).addReg(SrcReg1).addImm(BrImm).addImm(8);
453 uint32_t BrBinary = getBinaryCodeForInstr(TmpBr, Fixups, STI);
457 MCInstBuilder(InvOpc).addReg(SrcReg1).addImm(BrImm).addImm(10);
459 getBinaryCodeForInstr(TmpBr, Fixups, STI) & 0xffff'ffff'ffffu;
460 SmallVector<char, 8> Encoding;
462 assert(Encoding[6] == 0 && Encoding[7] == 0 &&
463 "Unexpected encoding for 48-bit instruction");
469 size_t FixupStartIndex =
Fixups.size();
472 MCInstBuilder(RISCV::JAL).addReg(RISCV::X0).addOperand(SrcSymbol);
473 uint32_t JBinary = getBinaryCodeForInstr(TmpJ, Fixups, STI);
476 Fixups.resize(FixupStartIndex);
480 Fixups.back().setLinkerRelaxable();
484void RISCVMCCodeEmitter::expandPseudoQCAccess(
485 const MCInst &
MI, SmallVectorImpl<char> &CB,
486 SmallVectorImpl<MCFixup> &Fixups,
const MCSubtargetInfo &STI)
const {
489 switch (
MI.getOpcode()) {
490#define QC_ACCESS_CASE(_Suffix) \
491 case RISCV::PseudoQCAccess##_Suffix: \
492 AccessOpc = RISCV::_Suffix; \
515 MCInst TmpAccess = MCInstBuilder(AccessOpc)
516 .addOperand(
MI.getOperand(0))
517 .addOperand(
MI.getOperand(1))
518 .addOperand(
MI.getOperand(2));
525 uint16_t AccessBinary = getBinaryCodeForInstr(TmpAccess, Fixups, STI);
531 uint32_t AccessBinary = getBinaryCodeForInstr(TmpAccess, Fixups, STI);
543 const MCOperand &AccessSymbol =
MI.getOperand(3);
544 assert(AccessSymbol.
isExpr() &&
"Expected expression in PseudoQCAccess");
548 "Expected qc.access specifier on symbol");
552 Fixups.back().setLinkerRelaxable();
555void RISCVMCCodeEmitter::encodeInstruction(
const MCInst &
MI,
556 SmallVectorImpl<char> &CB,
557 SmallVectorImpl<MCFixup> &Fixups,
558 const MCSubtargetInfo &STI)
const {
559 const MCInstrDesc &
Desc = MCII.
get(
MI.getOpcode());
566 switch (
MI.getOpcode()) {
569 case RISCV::PseudoCALLReg:
570 case RISCV::PseudoCALL:
571 case RISCV::PseudoTAIL:
572 case RISCV::PseudoJump:
573 expandFunctionCall(
MI, CB, Fixups, STI);
576 case RISCV::PseudoCALLLpadAlign:
577 expandFunctionCallLpad(
MI, CB, Fixups, STI);
580 case RISCV::PseudoCALLIndirectLpadAlign:
581 expandFunctionCallLpad(
MI, CB, Fixups, STI);
584 case RISCV::PseudoAddTPRel:
585 expandAddTPRel(
MI, CB, Fixups, STI);
588 case RISCV::PseudoLongBEQ:
589 case RISCV::PseudoLongBNE:
590 case RISCV::PseudoLongBEQI:
591 case RISCV::PseudoLongBNEI:
592 case RISCV::PseudoLongBLT:
593 case RISCV::PseudoLongBGE:
594 case RISCV::PseudoLongBLTU:
595 case RISCV::PseudoLongBGEU:
596 expandLongCondBr(
MI, CB, Fixups, STI);
599 case RISCV::PseudoLongQC_BEQI:
600 case RISCV::PseudoLongQC_BNEI:
601 case RISCV::PseudoLongQC_BLTI:
602 case RISCV::PseudoLongQC_BGEI:
603 case RISCV::PseudoLongQC_BLTUI:
604 case RISCV::PseudoLongQC_BGEUI:
605 expandQCLongCondBrImm(
MI, CB, Fixups, STI, 4);
608 case RISCV::PseudoLongQC_E_BEQI:
609 case RISCV::PseudoLongQC_E_BNEI:
610 case RISCV::PseudoLongQC_E_BLTI:
611 case RISCV::PseudoLongQC_E_BGEI:
612 case RISCV::PseudoLongQC_E_BLTUI:
613 case RISCV::PseudoLongQC_E_BGEUI:
614 expandQCLongCondBrImm(
MI, CB, Fixups, STI, 6);
617 case RISCV::PseudoTLSDESCCall:
618 expandTLSDESCCall(
MI, CB, Fixups, STI);
621 case RISCV::PseudoQCAccessLB:
622 case RISCV::PseudoQCAccessLBU:
623 case RISCV::PseudoQCAccessLH:
624 case RISCV::PseudoQCAccessLHU:
625 case RISCV::PseudoQCAccessLW:
626 case RISCV::PseudoQCAccessSB:
627 case RISCV::PseudoQCAccessSH:
628 case RISCV::PseudoQCAccessSW:
629 case RISCV::PseudoQCAccessC_LBU:
630 case RISCV::PseudoQCAccessC_LH:
631 case RISCV::PseudoQCAccessC_LHU:
632 case RISCV::PseudoQCAccessC_LW:
633 case RISCV::PseudoQCAccessC_SB:
634 case RISCV::PseudoQCAccessC_SH:
635 case RISCV::PseudoQCAccessC_SW:
636 expandPseudoQCAccess(
MI, CB, Fixups, STI);
645 uint16_t
Bits = getBinaryCodeForInstr(
MI, Fixups, STI);
650 uint32_t
Bits = getBinaryCodeForInstr(
MI, Fixups, STI);
655 uint64_t
Bits = getBinaryCodeForInstr(
MI, Fixups, STI) & 0xffff'ffff'ffffu;
656 SmallVector<char, 8> Encoding;
658 assert(Encoding[6] == 0 && Encoding[7] == 0 &&
659 "Unexpected encoding for 48-bit instruction");
665 uint64_t
Bits = getBinaryCodeForInstr(
MI, Fixups, STI);
675RISCVMCCodeEmitter::getMachineOpValue(
const MCInst &
MI,
const MCOperand &MO,
676 SmallVectorImpl<MCFixup> &Fixups,
677 const MCSubtargetInfo &STI)
const {
690RISCVMCCodeEmitter::getImmOpValueMinus1(
const MCInst &
MI,
unsigned OpNo,
691 SmallVectorImpl<MCFixup> &Fixups,
692 const MCSubtargetInfo &STI)
const {
693 const MCOperand &MO =
MI.getOperand(OpNo);
696 uint64_t Res = MO.
getImm();
705RISCVMCCodeEmitter::getImmOpValueSlist(
const MCInst &
MI,
unsigned OpNo,
706 SmallVectorImpl<MCFixup> &Fixups,
707 const MCSubtargetInfo &STI)
const {
708 const MCOperand &MO =
MI.getOperand(OpNo);
709 assert(MO.
isImm() &&
"Slist operand must be immediate");
711 uint64_t Res = MO.
getImm();
736RISCVMCCodeEmitter::getImmOpValueAsrN(
const MCInst &
MI,
unsigned OpNo,
737 SmallVectorImpl<MCFixup> &Fixups,
738 const MCSubtargetInfo &STI)
const {
739 const MCOperand &MO =
MI.getOperand(OpNo);
742 uint64_t Res = MO.
getImm();
743 assert((Res & ((1 <<
N) - 1)) == 0 &&
"LSB is non-zero");
747 return getImmOpValue(
MI, OpNo, Fixups, STI);
751RISCVMCCodeEmitter::getImmOpValueZibi(
const MCInst &
MI,
unsigned OpNo,
752 SmallVectorImpl<MCFixup> &Fixups,
753 const MCSubtargetInfo &STI)
const {
754 const MCOperand &MO =
MI.getOperand(OpNo);
755 assert(MO.
isImm() &&
"Zibi operand must be an immediate");
756 int64_t Res = MO.
getImm();
763uint64_t RISCVMCCodeEmitter::getImmOpValue(
const MCInst &
MI,
unsigned OpNo,
764 SmallVectorImpl<MCFixup> &Fixups,
765 const MCSubtargetInfo &STI)
const {
766 bool EnableRelax = STI.
hasFeature(RISCV::FeatureRelax);
767 const MCOperand &MO =
MI.getOperand(OpNo);
769 MCInstrDesc
const &
Desc = MCII.
get(
MI.getOpcode());
777 "getImmOpValue expects only expressions or immediates");
778 const MCExpr *Expr = MO.
getExpr();
788 bool RelaxCandidate =
false;
789 auto AsmRelaxToLinkerRelaxable = [&]() ->
void {
790 if (!STI.
hasFeature(RISCV::FeatureExactAssembly))
791 RelaxCandidate =
true;
798 switch (RVExpr->getSpecifier()) {
801 "invalid specifier");
803 case ELF::R_RISCV_TPREL_ADD:
809 "ELF::R_RISCV_TPREL_ADD should not represent an instruction operand");
815 "S_QC_ACCESS should not represent an instruction operand");
823 RelaxCandidate =
true;
825 case ELF::R_RISCV_HI20:
827 RelaxCandidate =
true;
836 RelaxCandidate =
true;
840 RelaxCandidate =
true;
844 RelaxCandidate =
true;
853 RelaxCandidate =
true;
861 RelaxCandidate =
true;
865 RelaxCandidate =
true;
867 case ELF::R_RISCV_GOT_HI20:
868 case ELF::R_RISCV_TPREL_HI20:
869 case ELF::R_RISCV_TLSDESC_HI20:
870 RelaxCandidate =
true;
877 RelaxCandidate =
true;
881 AsmRelaxToLinkerRelaxable();
885 AsmRelaxToLinkerRelaxable();
889 AsmRelaxToLinkerRelaxable();
893 if (STI.
hasFeature(RISCV::FeatureVendorXqcili))
894 AsmRelaxToLinkerRelaxable();
900 AsmRelaxToLinkerRelaxable();
903 RelaxCandidate =
true;
906 RelaxCandidate =
true;
918 if (EnableRelax && RelaxCandidate)
919 Fixups.back().setLinkerRelaxable();
926RISCVMCCodeEmitter::getYBNDSWImmOpValue(
const MCInst &
MI,
unsigned OpNo,
927 SmallVectorImpl<MCFixup> &Fixups,
928 const MCSubtargetInfo &STI)
const {
929 unsigned Imm = getImmOpValue(
MI, OpNo, Fixups, STI);
936 if (Imm > 0 && Imm <= 255)
940 if (Imm >= 256 && Imm <= 504 && (Imm % 8) == 0) {
943 unsigned MultipleOf8 = (
Imm - 256) >> 3;
944 unsigned OddMultiple = MultipleOf8 & 1;
945 unsigned Bits3To0 = MultipleOf8 >> 1;
946 return 256 | (OddMultiple << 4) | Bits3To0;
949 if (Imm >= 512 && Imm <= 4080 && (Imm % 16) == 0)
950 return 256 | (
Imm >> 4);
954unsigned RISCVMCCodeEmitter::getVMaskReg(
const MCInst &
MI,
unsigned OpNo,
955 SmallVectorImpl<MCFixup> &Fixups,
956 const MCSubtargetInfo &STI)
const {
957 MCOperand MO =
MI.getOperand(OpNo);
965 case RISCV::NoRegister:
970unsigned RISCVMCCodeEmitter::getRlistOpValue(
const MCInst &
MI,
unsigned OpNo,
971 SmallVectorImpl<MCFixup> &Fixups,
972 const MCSubtargetInfo &STI)
const {
973 const MCOperand &MO =
MI.getOperand(OpNo);
974 assert(MO.
isImm() &&
"Rlist operand must be immediate");
976 assert(Imm >= 4 &&
"EABI is currently not implemented");
980RISCVMCCodeEmitter::getRlistS0OpValue(
const MCInst &
MI,
unsigned OpNo,
981 SmallVectorImpl<MCFixup> &Fixups,
982 const MCSubtargetInfo &STI)
const {
983 const MCOperand &MO =
MI.getOperand(OpNo);
984 assert(MO.
isImm() &&
"Rlist operand must be immediate");
986 assert(Imm >= 4 &&
"EABI is currently not implemented");
991#include "RISCVGenMCCodeEmitter.inc"
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind, bool PCRel=false)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define QC_ACCESS_CASE(_Suffix)
static unsigned getInvertedBranchOp(unsigned BrOp)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
MCCodeEmitter - Generic instruction encoding interface.
Context object for machine code objects.
const MCRegisterInfo * getRegisterInfo() const
const Triple & getTargetTriple() const
Base class for the full range of assembler expressions which are needed for parsing.
@ SymbolRef
References to labels and assigned expressions.
@ Specifier
Expression with a relocation specifier.
@ Binary
Binary expressions.
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, bool PCRel=false)
Consider bit fields if we need more flags.
Instances of this class represent a single low-level machine instruction.
void addOperand(const MCOperand Op)
unsigned getSize() const
Return the number of bytes in the encoding of this instruction, or zero if the encoding size cannot b...
Interface to description of machine instruction set.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
static MCOperand createExpr(const MCExpr *Val)
MCRegister getReg() const
Returns the register number.
const MCExpr * getExpr() const
uint16_t getEncodingValue(MCRegister Reg) const
Returns the encoding for Reg.
constexpr unsigned id() const
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const Triple & getTargetTriple() const
const FeatureBitset & getFeatureBits() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void append(ItTy in_start, ItTy in_end)
Add the specified range to the end of the SmallVector.
void truncate(size_type N)
Like resize, but requires that N is less than size().
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
LLVM Value Representation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ InstFormatNDS_BRANCH_10
static unsigned getFormat(uint64_t TSFlags)
static MCRegister getTailExpandUseRegNo(const FeatureBitset &FeatureBits)
@ fixup_riscv_pcrel_lo12_i
@ fixup_riscv_pcrel_lo12_s
@ fixup_riscv_nds_branch_10
@ fixup_riscv_qc_e_call_plt
@ fixup_riscv_qc_e_branch
bool isValidYBNDSWImm(int64_t Imm)
NodeAddr< FuncNode * > Func
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
MCCodeEmitter * createRISCVMCCodeEmitter(const MCInstrInfo &MCII, MCContext &Ctx)
static Lanai::Fixups FixupKind(const MCExpr *Expr)
static void addFixup(SmallVectorImpl< MCFixup > &Fixups, uint32_t Offset, const MCExpr *Value, uint16_t Kind)
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.