LLVM 24.0.0git
RISCVAsmBackend.cpp
Go to the documentation of this file.
1//===-- RISCVAsmBackend.cpp - RISC-V Assembler Backend --------------------===//
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#include "RISCVAsmBackend.h"
10#include "RISCVFixupKinds.h"
11#include "llvm/ADT/APInt.h"
12#include "llvm/MC/MCAsmInfo.h"
13#include "llvm/MC/MCAssembler.h"
14#include "llvm/MC/MCContext.h"
16#include "llvm/MC/MCExpr.h"
19#include "llvm/MC/MCSymbol.h"
20#include "llvm/MC/MCValue.h"
23#include "llvm/Support/LEB128.h"
25
26using namespace llvm;
27
29 bool Is64Bit, bool IsLittleEndian,
31 : MCAsmBackend(IsLittleEndian ? llvm::endianness::little
32 : llvm::endianness::big),
33 CLOpts(RISCVMCOptions::Global), STI(STI), OSABI(OSABI), Is64Bit(Is64Bit),
35 RISCVFeatures::validate(STI.getTargetTriple(), STI.getFeatureBits());
36}
37
38std::optional<MCFixupKind> RISCVAsmBackend::getFixupKind(StringRef Name) const {
39 if (STI.getTargetTriple().isOSBinFormatELF()) {
40 unsigned Type;
42#define ELF_RELOC(NAME, ID) .Case(#NAME, ID)
43#include "llvm/BinaryFormat/ELFRelocs/RISCV.def"
44#undef ELF_RELOC
45#define ELF_RISCV_NONSTANDARD_RELOC(_VENDOR, NAME, ID) .Case(#NAME, ID)
46#include "llvm/BinaryFormat/ELFRelocs/RISCV_nonstandard.def"
47#undef ELF_RISCV_NONSTANDARD_RELOC
48 .Case("BFD_RELOC_NONE", ELF::R_RISCV_NONE)
49 .Case("BFD_RELOC_32", ELF::R_RISCV_32)
50 .Case("BFD_RELOC_64", ELF::R_RISCV_64)
51 .Default(-1u);
52 if (Type != -1u)
53 return static_cast<MCFixupKind>(FirstLiteralRelocationKind + Type);
54 }
55 return std::nullopt;
56}
57
59 const static MCFixupKindInfo Infos[] = {
60 // This table *must* be in the order that the fixup_* kinds are defined in
61 // RISCVFixupKinds.h.
62 //
63 // name offset bits flags
64 {"fixup_riscv_hi20", 12, 20, 0},
65 {"fixup_riscv_lo12_i", 20, 12, 0},
66 {"fixup_riscv_12_i", 20, 12, 0},
67 {"fixup_riscv_lo12_s", 0, 32, 0},
68 {"fixup_riscv_pcrel_hi20", 12, 20, 0},
69 {"fixup_riscv_pcrel_lo12_i", 20, 12, 0},
70 {"fixup_riscv_pcrel_lo12_s", 0, 32, 0},
71 {"fixup_riscv_jal", 12, 20, 0},
72 {"fixup_riscv_branch", 0, 32, 0},
73 {"fixup_riscv_rvc_jump", 2, 11, 0},
74 {"fixup_riscv_rvc_branch", 0, 16, 0},
75 {"fixup_riscv_rvc_imm", 0, 16, 0},
76 {"fixup_riscv_call", 0, 64, 0},
77 {"fixup_riscv_call_plt", 0, 64, 0},
78
79 // Qualcomm fixups
80 {"fixup_riscv_qc_e_branch", 0, 48, 0},
81 {"fixup_riscv_qc_e_32", 16, 32, 0},
82 {"fixup_riscv_qc_abs20_u", 0, 32, 0},
83 {"fixup_riscv_qc_e_call_plt", 0, 48, 0},
84 {"fixup_qc_access_16", 0, 0, 0},
85 {"fixup_qc_access_32", 0, 0, 0},
86
87 // Andes fixups
88 {"fixup_riscv_nds_branch_10", 0, 32, 0},
89 };
90 static_assert((std::size(Infos)) == RISCV::NumTargetFixupKinds,
91 "Not all fixup kinds added to Infos array");
92
93 // Fixup kinds from raw relocation types and .reloc directives force
94 // relocations and do not use these fields.
95 if (mc::isRelocation(Kind))
96 return {};
97
98 if (Kind < FirstTargetFixupKind)
100
102 "Invalid kind!");
103 return Infos[Kind - FirstTargetFixupKind];
104}
105
107 const MCFixup &Fixup,
108 const MCValue &,
109 uint64_t Value,
110 bool Resolved) const {
111 int64_t Offset = int64_t(Value);
112 auto Kind = Fixup.getKind();
113
114 // Return true if the symbol is unresolved.
115 if (!Resolved)
116 return true;
117
118 switch (Kind) {
119 default:
120 return false;
122 // For compressed branch instructions the immediate must be
123 // in the range [-256, 254].
124 return Offset > 254 || Offset < -256;
126 // For compressed jump instructions the immediate must be
127 // in the range [-2048, 2046].
128 return Offset > 2046 || Offset < -2048;
131 // For conditional branch instructions the immediate must be
132 // in the range [-4096, 4094].
133 return Offset > 4094 || Offset < -4096;
135 // For jump instructions the immediate must be in the range
136 // [-1048576, 1048574]
137 return Offset > 1048574 || Offset < -1048576;
139 // This fixup can never be emitted as a relocation, so always needs to be
140 // relaxed.
141 return true;
142 }
143}
144
145// Given a compressed control flow instruction this function returns
146// the expanded instruction, or the original instruction code if no
147// expansion is available.
148static unsigned getRelaxedOpcode(unsigned Opcode, ArrayRef<MCOperand> Operands,
149 const MCSubtargetInfo &STI) {
150 switch (Opcode) {
151 case RISCV::C_BEQZ:
152 return RISCV::BEQ;
153 case RISCV::C_BNEZ:
154 return RISCV::BNE;
155 case RISCV::C_J:
156 case RISCV::C_JAL: // fall through.
157 // This only relaxes one "step" - i.e. from C.J to JAL, not from C.J to
158 // QC.E.J, because we can always relax again if needed.
159 return RISCV::JAL;
160 case RISCV::C_LI:
161 if (!STI.hasFeature(RISCV::FeatureVendorXqcili))
162 break;
163 // We only need this because `QC.E.LI` can be compressed into a `C.LI`. This
164 // happens because the `simm6` MCOperandPredicate accepts bare symbols, and
165 // `QC.E.LI` is the only instruction that accepts bare symbols at parse-time
166 // and compresses to `C.LI`. `C.LI` does not itself accept bare symbols at
167 // parse time.
168 //
169 // If we have a bare symbol, we need to turn this back to a `QC.E.LI`, as we
170 // have no way to emit a relocation on a `C.LI` instruction.
171 return RISCV::QC_E_LI;
172 case RISCV::JAL: {
173 // We can only relax JAL if we have Xqcilb
174 if (!STI.hasFeature(RISCV::FeatureVendorXqcilb))
175 break;
176
177 // And only if it is using X0 or X1 for rd.
178 MCRegister Reg = Operands[0].getReg();
179 if (Reg == RISCV::X0)
180 return RISCV::QC_E_J;
181 if (Reg == RISCV::X1)
182 return RISCV::QC_E_JAL;
183
184 break;
185 }
186 case RISCV::BEQ:
187 return RISCV::PseudoLongBEQ;
188 case RISCV::BNE:
189 return RISCV::PseudoLongBNE;
190 case RISCV::BEQI:
191 return RISCV::PseudoLongBEQI;
192 case RISCV::BNEI:
193 return RISCV::PseudoLongBNEI;
194 case RISCV::BLT:
195 return RISCV::PseudoLongBLT;
196 case RISCV::BGE:
197 return RISCV::PseudoLongBGE;
198 case RISCV::BLTU:
199 return RISCV::PseudoLongBLTU;
200 case RISCV::BGEU:
201 return RISCV::PseudoLongBGEU;
202 case RISCV::QC_BEQI:
203 return RISCV::PseudoLongQC_BEQI;
204 case RISCV::QC_BNEI:
205 return RISCV::PseudoLongQC_BNEI;
206 case RISCV::QC_BLTI:
207 return RISCV::PseudoLongQC_BLTI;
208 case RISCV::QC_BGEI:
209 return RISCV::PseudoLongQC_BGEI;
210 case RISCV::QC_BLTUI:
211 return RISCV::PseudoLongQC_BLTUI;
212 case RISCV::QC_BGEUI:
213 return RISCV::PseudoLongQC_BGEUI;
214 case RISCV::QC_E_BEQI:
215 return RISCV::PseudoLongQC_E_BEQI;
216 case RISCV::QC_E_BNEI:
217 return RISCV::PseudoLongQC_E_BNEI;
218 case RISCV::QC_E_BLTI:
219 return RISCV::PseudoLongQC_E_BLTI;
220 case RISCV::QC_E_BGEI:
221 return RISCV::PseudoLongQC_E_BGEI;
222 case RISCV::QC_E_BLTUI:
223 return RISCV::PseudoLongQC_E_BLTUI;
224 case RISCV::QC_E_BGEUI:
225 return RISCV::PseudoLongQC_E_BGEUI;
226 case RISCV::CV_BEQIMM:
227 return RISCV::PseudoLongCV_BEQIMM;
228 case RISCV::CV_BNEIMM:
229 return RISCV::PseudoLongCV_BNEIMM;
230 }
231
232 // Returning the original opcode means we cannot relax the instruction.
233 return Opcode;
234}
235
237 const MCSubtargetInfo &STI) const {
238 if (STI.hasFeature(RISCV::FeatureExactAssembly))
239 return;
240
241 MCInst Res;
242 switch (Inst.getOpcode()) {
243 default:
244 llvm_unreachable("Opcode not expected!");
245 case RISCV::C_BEQZ:
246 case RISCV::C_BNEZ:
247 case RISCV::C_J:
248 case RISCV::C_JAL: {
249 [[maybe_unused]] bool Success = RISCVRVC::uncompress(Res, Inst, STI);
250 assert(Success && "Can't uncompress instruction");
251 assert(Res.getOpcode() ==
252 getRelaxedOpcode(Inst.getOpcode(), Inst.getOperands(), STI) &&
253 "Branch Relaxation Error");
254 break;
255 }
256 case RISCV::JAL: {
257 // This has to be written manually because the QC.E.J -> JAL is
258 // compression-only, so that it is not used when printing disassembly.
259 assert(STI.hasFeature(RISCV::FeatureVendorXqcilb) &&
260 "JAL is only relaxable with Xqcilb");
261 assert((Inst.getOperand(0).getReg() == RISCV::X0 ||
262 Inst.getOperand(0).getReg() == RISCV::X1) &&
263 "JAL only relaxable with rd=x0 or rd=x1");
264 Res.setOpcode(getRelaxedOpcode(Inst.getOpcode(), Inst.getOperands(), STI));
265 Res.addOperand(Inst.getOperand(1));
266 break;
267 }
268 case RISCV::C_LI: {
269 // This should only be hit when trying to relax a `C.LI` into a `QC.E.LI`
270 // because the `C.LI` has a bare symbol. We cannot use
271 // `RISCVRVC::uncompress` because it will use decompression patterns. The
272 // `QC.E.LI` compression pattern to `C.LI` is compression-only (because we
273 // don't want `c.li` ever printed as `qc.e.li`, which might be done if the
274 // pattern applied to decompression), but that doesn't help much becuase
275 // `C.LI` with a bare symbol will decompress to an `ADDI` anyway (because
276 // `simm12`'s MCOperandPredicate accepts a bare symbol and that pattern
277 // comes first), and we still cannot emit an `ADDI` with a bare symbol.
278 assert(STI.hasFeature(RISCV::FeatureVendorXqcili) &&
279 "C.LI is only relaxable with Xqcili");
280 Res.setOpcode(getRelaxedOpcode(Inst.getOpcode(), Inst.getOperands(), STI));
281 Res.addOperand(Inst.getOperand(0));
282 Res.addOperand(Inst.getOperand(1));
283 break;
284 }
285 case RISCV::BEQ:
286 case RISCV::BNE:
287 case RISCV::BEQI:
288 case RISCV::BNEI:
289 case RISCV::BLT:
290 case RISCV::BGE:
291 case RISCV::BLTU:
292 case RISCV::BGEU:
293 case RISCV::QC_BEQI:
294 case RISCV::QC_BNEI:
295 case RISCV::QC_BLTI:
296 case RISCV::QC_BGEI:
297 case RISCV::QC_BLTUI:
298 case RISCV::QC_BGEUI:
299 case RISCV::QC_E_BEQI:
300 case RISCV::QC_E_BNEI:
301 case RISCV::QC_E_BLTI:
302 case RISCV::QC_E_BGEI:
303 case RISCV::QC_E_BLTUI:
304 case RISCV::QC_E_BGEUI:
305 case RISCV::CV_BEQIMM:
306 case RISCV::CV_BNEIMM:
307 Res.setOpcode(getRelaxedOpcode(Inst.getOpcode(), Inst.getOperands(), STI));
308 Res.addOperand(Inst.getOperand(0));
309 Res.addOperand(Inst.getOperand(1));
310 Res.addOperand(Inst.getOperand(2));
311 break;
312 }
313 Inst = std::move(Res);
314}
315
316// Check if an R_RISCV_ALIGN relocation is needed for an alignment directive.
317// If conditions are met, compute the padding size and create a fixup encoding
318// the padding size in the addend.
320 // Alignments before the first linker-relaxable instruction have fixed sizes
321 // and do not require relocations. Alignments after a linker-relaxable
322 // instruction require a relocation, even if the STI specifies norelax.
323 //
324 // firstLinkerRelaxable is the layout order within the subsection, which may
325 // be smaller than the section's order. Therefore, alignments in a
326 // lower-numbered subsection may be unnecessarily treated as linker-relaxable.
327 auto *Sec = F.getParent();
328 if (F.getLayoutOrder() <= Sec->firstLinkerRelaxable())
329 return false;
330
331 // Use default handling unless the alignment is larger than the nop size.
332 const MCSubtargetInfo *STI = F.getSubtargetInfo();
333 unsigned MinNopLen =
334 CLOpts.align_rvc || STI->hasFeature(RISCV::FeatureStdExtZca) ? 2 : 4;
335 if (F.getAlignment() <= MinNopLen)
336 return false;
337
338 Size = F.getAlignment().value() - MinNopLen;
339 auto *Expr = MCConstantExpr::create(Size, getContext());
340 MCFixup Fixup =
341 MCFixup::create(0, Expr, FirstLiteralRelocationKind + ELF::R_RISCV_ALIGN);
342 F.setVarFixups({Fixup});
343 F.setLinkerRelaxable();
344 return true;
345}
346
348 int64_t LineDelta = F.getDwarfLineDelta();
349 const MCExpr &AddrDelta = F.getDwarfAddrDelta();
350 int64_t Value;
351 // If the label difference can be resolved, use the default handling, which
352 // utilizes a shorter special opcode.
353 if (AddrDelta.evaluateAsAbsolute(Value, *Asm))
354 return false;
355 [[maybe_unused]] bool IsAbsolute =
356 AddrDelta.evaluateKnownAbsolute(Value, *Asm);
357 assert(IsAbsolute && "CFA with invalid expression");
358
361
362 // INT64_MAX is a signal that this is actually a DW_LNE_end_sequence.
363 if (LineDelta != INT64_MAX) {
364 OS << uint8_t(dwarf::DW_LNS_advance_line);
365 encodeSLEB128(LineDelta, OS);
366 }
367
368 // According to the DWARF specification, the `DW_LNS_fixed_advance_pc` opcode
369 // takes a single unsigned half (unencoded) operand. The maximum encodable
370 // value is therefore 65535. Set a conservative upper bound for relaxation.
371 unsigned PCBytes;
372 if (Value > 60000) {
374 OS << uint8_t(dwarf::DW_LNS_extended_op) << uint8_t(PCBytes + 1)
375 << uint8_t(dwarf::DW_LNE_set_address);
376 OS.write_zeros(PCBytes);
377 } else {
378 PCBytes = 2;
379 OS << uint8_t(dwarf::DW_LNS_fixed_advance_pc);
381 }
382 auto Offset = OS.tell() - PCBytes;
383
384 if (LineDelta == INT64_MAX) {
385 OS << uint8_t(dwarf::DW_LNS_extended_op);
386 OS << uint8_t(1);
387 OS << uint8_t(dwarf::DW_LNE_end_sequence);
388 } else {
389 OS << uint8_t(dwarf::DW_LNS_copy);
390 }
391
392 F.setVarContents(Data);
393 F.setVarFixups({MCFixup::create(Offset, &AddrDelta,
394 MCFixup::getDataKindForSize(PCBytes))});
395 return true;
396}
397
399 const MCExpr &AddrDelta = F.getDwarfAddrDelta();
401 int64_t Value;
402 if (AddrDelta.evaluateAsAbsolute(Value, *Asm))
403 return false;
404 [[maybe_unused]] bool IsAbsolute =
405 AddrDelta.evaluateKnownAbsolute(Value, *Asm);
406 assert(IsAbsolute && "CFA with invalid expression");
407
408 assert(getContext().getAsmInfo().getMinInstAlignment() == 1 &&
409 "expected 1-byte alignment");
410 if (Value == 0) {
411 F.clearVarContents();
412 F.clearVarFixups();
413 return true;
414 }
415
416 auto AddFixups = [&Fixups, &AddrDelta](unsigned Offset,
417 std::pair<unsigned, unsigned> Fixup) {
418 const MCBinaryExpr &MBE = cast<MCBinaryExpr>(AddrDelta);
419 Fixups.push_back(MCFixup::create(Offset, MBE.getLHS(), std::get<0>(Fixup)));
420 Fixups.push_back(MCFixup::create(Offset, MBE.getRHS(), std::get<1>(Fixup)));
421 };
422
425 if (isUIntN(6, Value)) {
426 OS << uint8_t(dwarf::DW_CFA_advance_loc);
427 AddFixups(0, {ELF::R_RISCV_SET6, ELF::R_RISCV_SUB6});
428 } else if (isUInt<8>(Value)) {
429 OS << uint8_t(dwarf::DW_CFA_advance_loc1);
431 AddFixups(1, {ELF::R_RISCV_SET8, ELF::R_RISCV_SUB8});
432 } else if (isUInt<16>(Value)) {
433 OS << uint8_t(dwarf::DW_CFA_advance_loc2);
435 AddFixups(1, {ELF::R_RISCV_SET16, ELF::R_RISCV_SUB16});
436 } else if (isUInt<32>(Value)) {
437 OS << uint8_t(dwarf::DW_CFA_advance_loc4);
439 AddFixups(1, {ELF::R_RISCV_SET32, ELF::R_RISCV_SUB32});
440 } else {
441 llvm_unreachable("unsupported CFA encoding");
442 }
443 F.setVarContents(Data);
444 F.setVarFixups(Fixups);
445 return true;
446}
447
448std::pair<bool, bool> RISCVAsmBackend::relaxLEB128(MCFragment &LF,
449 int64_t &Value) const {
450 if (LF.isLEBSigned())
451 return std::make_pair(false, false);
452 const MCExpr &Expr = LF.getLEBValue();
453 if (CLOpts.uleb128_reloc) {
455 }
456 return std::make_pair(Expr.evaluateKnownAbsolute(Value, *Asm), false);
457}
458
461 const MCSubtargetInfo &STI) const {
462 // This function has access to two STIs, the member of the AsmBackend, and the
463 // one passed as an argument. The latter is more specific, so we query it for
464 // specific features.
465 if (STI.hasFeature(RISCV::FeatureExactAssembly))
466 return false;
467
468 return getRelaxedOpcode(Opcode, Operands, STI) != Opcode;
469}
470
472 const MCSubtargetInfo *STI) const {
473 // We mostly follow binutils' convention here: align to even boundary with a
474 // 0-fill padding. We emit up to 1 2-byte nop, though we use c.nop if RVC is
475 // enabled or 0-fill otherwise. The remainder is now padded with 4-byte nops.
476
477 // Instructions always are at even addresses. We must be in a data area or
478 // be unaligned due to some other reason.
479 if (Count % 2) {
480 OS.write("\0", 1);
481 Count -= 1;
482 }
483
484 // TODO: emit a mapping symbol right here
485
486 if (Count % 4 == 2) {
487 // The canonical nop with Zca is c.nop. For .balign 4, we generate a 2-byte
488 // c.nop even in a norvc region.
489 OS.write("\x01\0", 2);
490 Count -= 2;
491 }
492
493 // The canonical nop on RISC-V is addi x0, x0, 0.
494 for (; Count >= 4; Count -= 4)
495 OS.write("\x13\0\0\0", 4);
496
497 return true;
498}
499
501 MCContext &Ctx) {
502 switch (Fixup.getKind()) {
503 default:
504 llvm_unreachable("Unknown fixup kind!");
505 case FK_Data_1:
506 case FK_Data_2:
507 case FK_Data_4:
508 case FK_Data_8:
509 case FK_Data_leb128:
510 return Value;
513 return Value & 0xfff;
515 if (!isInt<12>(Value)) {
516 Ctx.reportError(Fixup.getLoc(),
517 "operand must be a constant 12-bit integer");
518 }
519 return Value & 0xfff;
522 return (((Value >> 5) & 0x7f) << 25) | ((Value & 0x1f) << 7);
525 // Add 1 if bit 11 is 1, to compensate for low 12 bits being negative.
526 return ((Value + 0x800) >> 12) & 0xfffff;
528 if (!isInt<21>(Value))
529 Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
530 if (Value & 0x1)
531 Ctx.reportError(Fixup.getLoc(), "fixup value must be 2-byte aligned");
532 // Need to produce imm[19|10:1|11|19:12] from the 21-bit Value.
533 unsigned Sbit = (Value >> 20) & 0x1;
534 unsigned Hi8 = (Value >> 12) & 0xff;
535 unsigned Mid1 = (Value >> 11) & 0x1;
536 unsigned Lo10 = (Value >> 1) & 0x3ff;
537 // Inst{31} = Sbit;
538 // Inst{30-21} = Lo10;
539 // Inst{20} = Mid1;
540 // Inst{19-12} = Hi8;
541 Value = (Sbit << 19) | (Lo10 << 9) | (Mid1 << 8) | Hi8;
542 return Value;
543 }
546 if (!isInt<13>(Value))
547 Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
548 if (Value & 0x1)
549 Ctx.reportError(Fixup.getLoc(), "fixup value must be 2-byte aligned");
550 // Need to extract imm[12], imm[10:5], imm[4:1], imm[11] from the 13-bit
551 // Value.
552 unsigned Sbit = (Value >> 12) & 0x1;
553 unsigned Hi1 = (Value >> 11) & 0x1;
554 unsigned Mid6 = (Value >> 5) & 0x3f;
555 unsigned Lo4 = (Value >> 1) & 0xf;
556 // Inst{31} = Sbit;
557 // Inst{30-25} = Mid6;
558 // Inst{11-8} = Lo4;
559 // Inst{7} = Hi1;
560 Value = (Sbit << 31) | (Mid6 << 25) | (Lo4 << 8) | (Hi1 << 7);
561 return Value;
562 }
565 // Jalr will add UpperImm with the sign-extended 12-bit LowerImm,
566 // we need to add 0x800ULL before extract upper bits to reflect the
567 // effect of the sign extension.
568 uint64_t UpperImm = (Value + 0x800ULL) & 0xfffff000ULL;
569 uint64_t LowerImm = Value & 0xfffULL;
570 return UpperImm | ((LowerImm << 20) << 32);
571 }
573 if (!isInt<12>(Value))
574 Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
575 // Need to produce offset[11|4|9:8|10|6|7|3:1|5] from the 11-bit Value.
576 unsigned Bit11 = (Value >> 11) & 0x1;
577 unsigned Bit4 = (Value >> 4) & 0x1;
578 unsigned Bit9_8 = (Value >> 8) & 0x3;
579 unsigned Bit10 = (Value >> 10) & 0x1;
580 unsigned Bit6 = (Value >> 6) & 0x1;
581 unsigned Bit7 = (Value >> 7) & 0x1;
582 unsigned Bit3_1 = (Value >> 1) & 0x7;
583 unsigned Bit5 = (Value >> 5) & 0x1;
584 Value = (Bit11 << 10) | (Bit4 << 9) | (Bit9_8 << 7) | (Bit10 << 6) |
585 (Bit6 << 5) | (Bit7 << 4) | (Bit3_1 << 1) | Bit5;
586 return Value;
587 }
589 if (!isInt<9>(Value))
590 Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
591 // Need to produce offset[8|4:3], [reg 3 bit], offset[7:6|2:1|5]
592 unsigned Bit8 = (Value >> 8) & 0x1;
593 unsigned Bit7_6 = (Value >> 6) & 0x3;
594 unsigned Bit5 = (Value >> 5) & 0x1;
595 unsigned Bit4_3 = (Value >> 3) & 0x3;
596 unsigned Bit2_1 = (Value >> 1) & 0x3;
597 Value = (Bit8 << 12) | (Bit4_3 << 10) | (Bit7_6 << 5) | (Bit2_1 << 3) |
598 (Bit5 << 2);
599 return Value;
600 }
602 if (!isInt<6>(Value))
603 Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
604 unsigned Bit5 = (Value >> 5) & 0x1;
605 unsigned Bit4_0 = Value & 0x1f;
606 Value = (Bit5 << 12) | (Bit4_0 << 2);
607 return Value;
608 }
610 if (!isInt<32>(Value))
611 Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
612 return Value & 0xffffffffu;
613 }
615 if (!isInt<20>(Value))
616 Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
617 unsigned Bit19 = (Value >> 19) & 0x1;
618 unsigned Bit14_0 = Value & 0x7fff;
619 unsigned Bit18_15 = (Value >> 15) & 0xf;
620 Value = (Bit19 << 31) | (Bit14_0 << 16) | (Bit18_15 << 12);
621 return Value;
622 }
624 if (!isInt<32>(Value))
625 Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
626 if (Value & 0x1)
627 Ctx.reportError(Fixup.getLoc(), "fixup value must be 2-byte aligned");
628 uint64_t Bit31_16 = (Value >> 16) & 0xffff;
629 uint64_t Bit12 = (Value >> 12) & 0x1;
630 uint64_t Bit10_5 = (Value >> 5) & 0x3f;
631 uint64_t Bit15_13 = (Value >> 13) & 0x7;
632 uint64_t Bit4_1 = (Value >> 1) & 0xf;
633 uint64_t Bit11 = (Value >> 11) & 0x1;
634 Value = (Bit31_16 << 32ull) | (Bit12 << 31) | (Bit10_5 << 25) |
635 (Bit15_13 << 17) | (Bit4_1 << 8) | (Bit11 << 7);
636 return Value;
637 }
640 return 0;
642 if (!isInt<11>(Value))
643 Ctx.reportError(Fixup.getLoc(), "fixup value out of range");
644 if (Value & 0x1)
645 Ctx.reportError(Fixup.getLoc(), "fixup value must be 2-byte aligned");
646 // Need to extract imm[10], imm[9:5], imm[4:1] from the 11-bit Value.
647 unsigned Sbit = (Value >> 10) & 0x1;
648 unsigned Hi5 = (Value >> 5) & 0x1f;
649 unsigned Lo4 = (Value >> 1) & 0xf;
650 // Inst{31} = Sbit;
651 // Inst{29-25} = Hi5;
652 // Inst{11-8} = Lo4;
653 Value = (Sbit << 31) | (Hi5 << 25) | (Lo4 << 8);
654 return Value;
655 }
656 }
657}
658
660 const MCFragment &F) {
661 // If the section does not contain linker-relaxable fragments, PC-relative
662 // fixups can be resolved.
663 if (!F.getParent()->isLinkerRelaxable())
664 return true;
665
666 // Otherwise, check if the offset between the symbol and fragment is fully
667 // resolved, unaffected by linker-relaxable fragments (e.g. instructions or
668 // offset-affected FT_Align fragments). Complements the generic
669 // isSymbolRefDifferenceFullyResolvedImpl.
670 if (!PCRelTemp)
672 PCRelTemp->setFragment(const_cast<MCFragment *>(&F));
673 MCValue Res;
675 MCValue::get(nullptr, PCRelTemp), Res);
676 return !Res.getSubSym();
677}
678
679// Get the corresponding PC-relative HI fixup that a S_PCREL_LO points to, and
680// optionally the fragment containing it.
681//
682// \returns nullptr if this isn't a S_PCREL_LO pointing to a known PC-relative
683// HI fixup.
685 const MCFragment **DFOut) {
686 MCValue AUIPCLoc;
687 if (!Expr.getSubExpr()->evaluateAsRelocatable(AUIPCLoc, nullptr))
688 return nullptr;
689
690 const MCSymbol *AUIPCSymbol = AUIPCLoc.getAddSym();
691 if (!AUIPCSymbol)
692 return nullptr;
693 const auto *DF = AUIPCSymbol->getFragment();
694 if (!DF)
695 return nullptr;
696
697 uint64_t Offset = AUIPCSymbol->getOffset();
698 if (DF->getContents().size() == Offset) {
699 DF = DF->getNext();
700 if (!DF)
701 return nullptr;
702 Offset = 0;
703 }
704
705 for (const MCFixup &F : DF->getFixups()) {
706 if (F.getOffset() != Offset)
707 continue;
708 auto Kind = F.getKind();
709 if (!mc::isRelocation(F.getKind())) {
710 if (Kind == RISCV::fixup_riscv_pcrel_hi20) {
711 *DFOut = DF;
712 return &F;
713 }
714 break;
715 }
716 switch (Kind) {
717 case ELF::R_RISCV_GOT_HI20:
718 case ELF::R_RISCV_TLS_GOT_HI20:
719 case ELF::R_RISCV_TLS_GD_HI20:
720 case ELF::R_RISCV_TLSDESC_HI20:
721 *DFOut = DF;
722 return &F;
723 }
724 }
725
726 return nullptr;
727}
728
729std::optional<bool> RISCVAsmBackend::evaluateFixup(const MCFragment &,
730 MCFixup &Fixup,
732 uint64_t &Value) {
733 const MCFixup *AUIPCFixup;
734 const MCFragment *AUIPCDF;
735 MCValue AUIPCTarget;
736 switch (Fixup.getKind()) {
737 default:
738 // Use default handling for `Value` and `IsResolved`.
739 return {};
742 // Never resolved in the assembler
743 return false;
746 AUIPCFixup =
747 getPCRelHiFixup(cast<MCSpecifierExpr>(*Fixup.getValue()), &AUIPCDF);
748 if (!AUIPCFixup) {
749 getContext().reportError(Fixup.getLoc(),
750 "could not find corresponding %pcrel_hi");
751 return true;
752 }
753
754 // MCAssembler::evaluateFixup will emit an error for this case when it sees
755 // the %pcrel_hi, so don't duplicate it when also seeing the %pcrel_lo.
756 const MCExpr *AUIPCExpr = AUIPCFixup->getValue();
757 if (!AUIPCExpr->evaluateAsRelocatable(AUIPCTarget, Asm))
758 return true;
759 break;
760 }
761 }
762
763 if (!AUIPCTarget.getAddSym())
764 return false;
765
766 auto &SA = static_cast<const MCSymbolELF &>(*AUIPCTarget.getAddSym());
767 if (SA.isUndefined())
768 return false;
769
770 bool IsResolved = &SA.getSection() == AUIPCDF->getParent() &&
771 SA.getBinding() == ELF::STB_LOCAL &&
772 SA.getType() != ELF::STT_GNU_IFUNC;
773 if (!IsResolved)
774 return false;
775
776 Value = Asm->getSymbolOffset(SA) + AUIPCTarget.getConstant();
777 Value -= Asm->getFragmentOffset(*AUIPCDF) + AUIPCFixup->getOffset();
778
779 return AUIPCFixup->getKind() == RISCV::fixup_riscv_pcrel_hi20 &&
780 isPCRelFixupResolved(AUIPCTarget.getAddSym(), *AUIPCDF);
781}
782
784 const MCFixup &Fixup) {
785 StringRef VendorIdentifier;
786 switch (Fixup.getKind()) {
787 default:
788 // No Vendor Relocation Required.
789 return;
796 VendorIdentifier = "QUALCOMM";
797 break;
799 VendorIdentifier = "ANDES";
800 break;
801 }
802
803 // Create a local symbol for the vendor relocation to reference. It's fine if
804 // the symbol has the same name as an existing symbol.
805 MCContext &Ctx = Asm->getContext();
806 MCSymbol *VendorSymbol = Ctx.createLocalSymbol(VendorIdentifier);
807 auto [It, Inserted] =
808 VendorSymbols.try_emplace(VendorIdentifier, VendorSymbol);
809
810 if (Inserted) {
811 // Setup the just-created symbol
812 VendorSymbol->setVariableValue(MCConstantExpr::create(0, Ctx));
813 Asm->registerSymbol(*VendorSymbol);
814 } else {
815 // Fetch the existing symbol
816 VendorSymbol = It->getValue();
817 }
818
819 MCFixup VendorFixup =
820 MCFixup::create(Fixup.getOffset(), nullptr, ELF::R_RISCV_VENDOR);
821 // Explicitly create MCValue rather than using an MCExpr and evaluating it so
822 // that the absolute vendor symbol is not evaluated to constant 0.
823 MCValue VendorTarget = MCValue::get(VendorSymbol);
824 uint64_t VendorValue;
825 Asm->getWriter().recordRelocation(F, VendorFixup, VendorTarget, VendorValue);
826}
827
829 // Some Fixups are marked as LinkerRelaxable by
830 // `RISCVMCCodeEmitter::getImmOpValue` only because they may be
831 // (assembly-)relaxed into a linker-relaxable instruction. This function
832 // should return `false` for those fixups so they do not get a `R_RISCV_RELAX`
833 // relocation emitted in addition to the relocation.
834 switch (Kind) {
835 default:
836 break;
842 return false;
843 }
844 return true;
845}
846
848 const MCValue &Target, uint64_t &FixedValue,
849 bool IsResolved) {
850 uint64_t FixedValueA, FixedValueB;
851 if (Target.getSubSym()) {
852 assert(Target.getSpecifier() == 0 &&
853 "relocatable SymA-SymB cannot have relocation specifier");
854 unsigned TA = 0, TB = 0;
855 switch (Fixup.getKind()) {
856 case llvm::FK_Data_1:
857 TA = ELF::R_RISCV_ADD8;
858 TB = ELF::R_RISCV_SUB8;
859 break;
860 case llvm::FK_Data_2:
861 TA = ELF::R_RISCV_ADD16;
862 TB = ELF::R_RISCV_SUB16;
863 break;
864 case llvm::FK_Data_4:
865 TA = ELF::R_RISCV_ADD32;
866 TB = ELF::R_RISCV_SUB32;
867 break;
868 case llvm::FK_Data_8:
869 TA = ELF::R_RISCV_ADD64;
870 TB = ELF::R_RISCV_SUB64;
871 break;
873 TA = ELF::R_RISCV_SET_ULEB128;
874 TB = ELF::R_RISCV_SUB_ULEB128;
875 break;
876 default:
877 llvm_unreachable("unsupported fixup size");
878 }
879 MCValue A = MCValue::get(Target.getAddSym(), nullptr, Target.getConstant());
880 MCValue B = MCValue::get(Target.getSubSym());
881 auto FA = MCFixup::create(Fixup.getOffset(), nullptr, TA);
882 auto FB = MCFixup::create(Fixup.getOffset(), nullptr, TB);
883 Asm->getWriter().recordRelocation(F, FA, A, FixedValueA);
884 Asm->getWriter().recordRelocation(F, FB, B, FixedValueB);
885 FixedValue = FixedValueA - FixedValueB;
886 return false;
887 }
888
889 // If linker relaxation is enabled and supported by the current fixup, then we
890 // always want to generate a relocation.
891 bool NeedsRelax = Fixup.isLinkerRelaxable() &&
893 if (NeedsRelax)
894 IsResolved = false;
895
896 if (IsResolved && Fixup.isPCRel())
897 IsResolved = isPCRelFixupResolved(Target.getAddSym(), F);
898
899 if (!IsResolved) {
900 // Some Fixups require a VENDOR relocation, record it (directly) before we
901 // add the relocation.
903
904 Asm->getWriter().recordRelocation(F, Fixup, Target, FixedValue);
905
906 if (NeedsRelax) {
907 // Some Fixups get a RELAX relocation, record it (directly) after we add
908 // the relocation.
909 MCFixup RelaxFixup =
910 MCFixup::create(Fixup.getOffset(), nullptr, ELF::R_RISCV_RELAX);
911 MCValue RelaxTarget = MCValue::get(nullptr);
912 uint64_t RelaxValue;
913 Asm->getWriter().recordRelocation(F, RelaxFixup, RelaxTarget, RelaxValue);
914 }
915 }
916
917 return false;
918}
919
920// Data fixups should be swapped for big endian cores.
921// Instruction fixups should not be swapped as RISC-V instructions
922// are always little-endian.
923static bool isDataFixup(unsigned Kind) {
924 switch (Kind) {
925 default:
926 return false;
927
928 case FK_Data_1:
929 case FK_Data_2:
930 case FK_Data_4:
931 case FK_Data_8:
932 return true;
933 }
934}
935
937 const MCValue &Target, uint8_t *Data,
938 uint64_t Value, bool IsResolved) {
939 IsResolved = addReloc(F, Fixup, Target, Value, IsResolved);
940 MCFixupKind Kind = Fixup.getKind();
941 if (mc::isRelocation(Kind))
942 return;
943 MCContext &Ctx = getContext();
945 if (!Value)
946 return; // Doesn't change encoding.
947 // Apply any target-specific value adjustments.
949
950 // Shift the value into position.
951 Value <<= Info.TargetOffset;
952
953 unsigned NumBytes = alignTo(Info.TargetSize + Info.TargetOffset, 8) / 8;
954 assert(Fixup.getOffset() + NumBytes <= F.getSize() &&
955 "Invalid fixup offset!");
956
957 // For each byte of the fragment that the fixup touches, mask in the
958 // bits from the fixup value.
959 // For big endian cores, data fixup should be swapped.
960 bool SwapValue = Endian == llvm::endianness::big && isDataFixup(Kind);
961 for (unsigned i = 0; i != NumBytes; ++i) {
962 unsigned Idx = SwapValue ? (NumBytes - 1 - i) : i;
963 Data[Idx] |= uint8_t((Value >> (i * 8)) & 0xff);
964 }
965}
966
967std::unique_ptr<MCObjectTargetWriter>
971
973public:
975 bool IsLittleEndian, const MCTargetOptions &Options)
976 : RISCVAsmBackend(STI, OSABI, Is64Bit, IsLittleEndian, Options) {}
977
978 std::unique_ptr<MCObjectTargetWriter>
979 createObjectTargetWriter() const override {
980 const Triple &TT = STI.getTargetTriple();
981 uint32_t CPUType = cantFail(MachO::getCPUType(TT));
982 uint32_t CPUSubType = cantFail(MachO::getCPUSubType(TT));
983 return createRISCVMachObjectWriter(CPUType, CPUSubType);
984 }
985
986 bool addReloc(const MCFragment &, const MCFixup &, const MCValue &,
987 uint64_t &FixedValue, bool IsResolved) override;
988
989 std::optional<bool> evaluateFixup(const MCFragment &F, MCFixup &Fixup,
990 MCValue &Target, uint64_t &Value) override {
991 const MCFixup *AUIPCFixup;
992 const MCFragment *AUIPCDF;
993 const MCFixupKind FKind = Fixup.getKind();
994 if ((FKind == RISCV::fixup_riscv_pcrel_lo12_i) ||
996 AUIPCFixup =
997 getPCRelHiFixup(cast<MCSpecifierExpr>(*Fixup.getValue()), &AUIPCDF);
998 if (!AUIPCFixup) {
999 getContext().reportError(Fixup.getLoc(),
1000 "could not find corresponding %pcrel_hi");
1001 return true;
1002 }
1003
1004 return false;
1005 }
1006
1007 // Use default handling for all other cases.
1008 return {};
1009 }
1010};
1011
1013 const MCSubtargetInfo &STI,
1014 const MCRegisterInfo &MRI,
1015 const MCTargetOptions &Options) {
1016 const Triple &TT = STI.getTargetTriple();
1017 uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS());
1018 if (TT.isOSBinFormatMachO())
1019 return new DarwinRISCVAsmBackend(STI, OSABI, TT.isArch64Bit(),
1020 TT.isLittleEndian(), Options);
1021
1022 return new RISCVAsmBackend(STI, OSABI, TT.isArch64Bit(), TT.isLittleEndian(),
1023 Options);
1024}
1025
1027 const MCValue &Target,
1028 uint64_t &FixedValue, bool IsResolved) {
1029 if (!IsResolved)
1030 Asm->getWriter().recordRelocation(F, Fixup, Target, FixedValue);
1031 return IsResolved;
1032}
static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target, uint64_t Value, MCContext &Ctx, const Triple &TheTriple, bool IsResolved)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
This file implements a class to represent arbitrary precision integral constant values and operations...
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
static LVOptions Options
Definition LVOptions.cpp:25
static unsigned getRelaxedOpcode(unsigned Opcode)
#define F(x, y, z)
Definition MD5.cpp:54
Register Reg
#define T
PowerPC TLS Dynamic Call Fixup
static bool relaxableFixupNeedsRelocation(const MCFixupKind Kind)
static bool isDataFixup(unsigned Kind)
const MCFixup * getPCRelHiFixup(const MCSpecifierExpr &Expr, const MCFragment **DFOut)
SI Fold Operands
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
std::optional< bool > evaluateFixup(const MCFragment &F, MCFixup &Fixup, MCValue &Target, uint64_t &Value) override
bool addReloc(const MCFragment &, const MCFixup &, const MCValue &, uint64_t &FixedValue, bool IsResolved) override
std::unique_ptr< MCObjectTargetWriter > createObjectTargetWriter() const override
DarwinRISCVAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI, bool Is64Bit, bool IsLittleEndian, const MCTargetOptions &Options)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Generic interface to target specific assembler backends.
const llvm::endianness Endian
MCAsmBackend(llvm::endianness Endian)
virtual MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
MCAssembler * Asm
MCContext & getContext() const
unsigned getCodePointerSize() const
Get the code pointer size in bytes.
Definition MCAsmInfo.h:454
Binary assembler expressions.
Definition MCExpr.h:298
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition MCExpr.h:445
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition MCExpr.h:448
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:83
LLVM_ABI MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
const MCAsmInfo & getAsmInfo() const
Definition MCContext.h:409
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
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
static LLVM_ABI bool evaluateSymbolicAdd(const MCAssembler *, bool, const MCValue &, const MCValue &, MCValue &)
Definition MCExpr.cpp:407
LLVM_ABI bool evaluateKnownAbsolute(int64_t &Res, const MCAssembler &Asm) const
Aggressive variant of evaluateAsRelocatable when relocations are unavailable (e.g.
Definition MCExpr.cpp:250
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition MCFixup.h:65
static MCFixupKind getDataKindForSize(unsigned Size)
Return the generic fixup kind for a value with the given size.
Definition MCFixup.h:114
const MCExpr * getValue() const
Definition MCFixup.h:105
uint32_t getOffset() const
Definition MCFixup.h:102
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
MCFixupKind getKind() const
Definition MCFixup.h:100
bool isLEBSigned() const
Definition MCSection.h:343
const MCExpr & getLEBValue() const
Definition MCSection.h:335
MCSection * getParent() const
Definition MCSection.h:181
LLVM_ABI void setVarFixups(ArrayRef< MCFixup > Fixups)
Instances of this class represent a single low-level machine instruction.
Definition MCInst.h:188
unsigned getOpcode() const
Definition MCInst.h:202
ArrayRef< MCOperand > getOperands() const
Definition MCInst.h:214
void addOperand(const MCOperand Op)
Definition MCInst.h:215
void setOpcode(unsigned Op)
Definition MCInst.h:201
const MCOperand & getOperand(unsigned i) const
Definition MCInst.h:210
MCRegister getReg() const
Returns the register number.
Definition MCInst.h:73
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Extension point for target-specific MCExpr subclasses with a relocation specifier,...
Definition MCExpr.h:494
const MCExpr * getSubExpr() const
Definition MCExpr.h:508
Generic base class for all target subtargets.
bool hasFeature(unsigned Feature) const
const Triple & getTargetTriple() const
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
LLVM_ABI void setVariableValue(const MCExpr *Value)
Definition MCSymbol.cpp:50
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition MCSymbol.h:251
MCFragment * getFragment() const
Definition MCSymbol.h:345
uint64_t getOffset() const
Definition MCSymbol.h:289
static MCValue get(const MCSymbol *SymA, const MCSymbol *SymB=nullptr, int64_t Val=0, uint32_t Specifier=0)
Definition MCValue.h:56
const MCSymbol * getAddSym() const
Definition MCValue.h:49
int64_t getConstant() const
Definition MCValue.h:44
const MCSymbol * getSubSym() const
Definition MCValue.h:51
std::optional< bool > evaluateFixup(const MCFragment &, MCFixup &, MCValue &, uint64_t &) override
std::unique_ptr< MCObjectTargetWriter > createObjectTargetWriter() const override
bool isPCRelFixupResolved(const MCSymbol *SymA, const MCFragment &F)
void relaxInstruction(MCInst &Inst, const MCSubtargetInfo &STI) const override
Relax the instruction in the given fragment to the next wider instruction.
bool relaxAlign(MCFragment &F, unsigned &Size) override
virtual bool addReloc(const MCFragment &, const MCFixup &, const MCValue &, uint64_t &FixedValue, bool IsResolved)
MCFixupKindInfo getFixupKindInfo(MCFixupKind Kind) const override
Get information on a fixup kind.
RISCVAsmBackend(const MCSubtargetInfo &STI, uint8_t OSABI, bool Is64Bit, bool IsLittleEndian, const MCTargetOptions &Options)
std::pair< bool, bool > relaxLEB128(MCFragment &LF, int64_t &Value) const override
void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target, uint8_t *Data, uint64_t Value, bool IsResolved) override
bool writeNopData(raw_ostream &OS, uint64_t Count, const MCSubtargetInfo *STI) const override
Write an (optimal) nop sequence of Count bytes to the given output.
const MCSubtargetInfo & STI
void maybeAddVendorReloc(const MCFragment &, const MCFixup &)
StringMap< MCSymbol * > VendorSymbols
bool mayNeedRelaxation(unsigned Opcode, ArrayRef< MCOperand > Operands, const MCSubtargetInfo &STI) const override
Check whether the given instruction (encoded as Opcode+Operands) may need relaxation.
const MCTargetOptions & TargetOptions
bool fixupNeedsRelaxationAdvanced(const MCFragment &, const MCFixup &, const MCValue &, uint64_t, bool) const override
Target specific predicate for whether a given fixup requires the associated instruction to be relaxed...
const RISCVMCOptions & CLOpts
std::optional< MCFixupKind > getFixupKind(StringRef Name) const override
Map a relocation name used in .reloc to a fixup kind.
bool relaxDwarfCFA(MCFragment &) const override
bool relaxDwarfLineAddr(MCFragment &) const override
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
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
raw_ostream & write_zeros(unsigned NumZeros)
write_zeros - Insert 'NumZeros' nulls.
uint64_t tell() const
tell - Return the current offset with the file.
raw_ostream & write(unsigned char C)
A raw_ostream that writes to an SmallVector or SmallString.
#define INT64_MAX
Definition DataTypes.h:71
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ STB_LOCAL
Definition ELF.h:1421
@ STT_GNU_IFUNC
Definition ELF.h:1440
LLVM_ABI Expected< uint32_t > getCPUSubType(const Triple &T)
Definition MachO.cpp:109
LLVM_ABI Expected< uint32_t > getCPUType(const Triple &T)
Definition MachO.cpp:89
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
bool uncompress(MCInst &OutInst, const MCInst &MI, const MCSubtargetInfo &STI)
bool isRelocation(MCFixupKind FixupKind)
Definition MCFixup.h:134
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.
std::unique_ptr< MCObjectTargetWriter > createRISCVELFObjectWriter(uint8_t OSABI, bool Is64Bit)
@ Offset
Definition DWP.cpp:577
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
Definition MathExtras.h:166
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition MathExtras.h:244
constexpr MCFixupKind FirstTargetFixupKind
Definition MCFixup.h:49
std::unique_ptr< MCObjectTargetWriter > createRISCVMachObjectWriter(uint32_t CPUType, uint32_t CPUSubtype)
uint16_t MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition MCFixup.h:22
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition Alignment.h:149
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:190
@ Success
The lock was released successfully.
@ Global
Append to llvm.global_dtors.
@ FK_Data_8
A eight-byte fixup.
Definition MCFixup.h:41
@ FK_Data_1
A one-byte fixup.
Definition MCFixup.h:38
@ FK_Data_4
A four-byte fixup.
Definition MCFixup.h:40
@ FK_Data_leb128
A leb128 fixup.
Definition MCFixup.h:42
@ FK_Data_2
A two-byte fixup.
Definition MCFixup.h:39
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
MCAsmBackend * createRISCVAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCRegisterInfo &MRI, const MCTargetOptions &Options)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
Definition LEB128.h:24
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
endianness
Definition bit.h:71
constexpr MCFixupKind FirstLiteralRelocationKind
Definition MCFixup.h:32
Target independent information on a fixup kind.