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