LLVM 22.0.0git
MCAssembler.cpp
Go to the documentation of this file.
1//===- lib/MC/MCAssembler.cpp - Assembler Backend Implementation ----------===//
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
10#include "llvm/ADT/ArrayRef.h"
12#include "llvm/ADT/Statistic.h"
13#include "llvm/ADT/StringRef.h"
14#include "llvm/ADT/Twine.h"
16#include "llvm/MC/MCAsmInfo.h"
18#include "llvm/MC/MCCodeView.h"
19#include "llvm/MC/MCContext.h"
20#include "llvm/MC/MCDwarf.h"
21#include "llvm/MC/MCExpr.h"
22#include "llvm/MC/MCFixup.h"
23#include "llvm/MC/MCInst.h"
25#include "llvm/MC/MCSFrame.h"
26#include "llvm/MC/MCSection.h"
27#include "llvm/MC/MCSymbol.h"
28#include "llvm/MC/MCValue.h"
31#include "llvm/Support/Debug.h"
34#include "llvm/Support/LEB128.h"
36#include <cassert>
37#include <cstdint>
38#include <tuple>
39#include <utility>
40
41using namespace llvm;
42
43namespace llvm {
44class MCSubtargetInfo;
45}
46
47#define DEBUG_TYPE "assembler"
48
49namespace {
50namespace stats {
51
52STATISTIC(EmittedFragments, "Number of emitted assembler fragments - total");
53STATISTIC(EmittedRelaxableFragments,
54 "Number of emitted assembler fragments - relaxable");
55STATISTIC(EmittedDataFragments,
56 "Number of emitted assembler fragments - data");
57STATISTIC(EmittedAlignFragments,
58 "Number of emitted assembler fragments - align");
59STATISTIC(EmittedFillFragments,
60 "Number of emitted assembler fragments - fill");
61STATISTIC(EmittedNopsFragments, "Number of emitted assembler fragments - nops");
62STATISTIC(EmittedOrgFragments, "Number of emitted assembler fragments - org");
63STATISTIC(Fixups, "Number of fixups");
64STATISTIC(FixupEvalForRelax, "Number of fixup evaluations for relaxation");
65STATISTIC(ObjectBytes, "Number of emitted object file bytes");
66STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps");
67STATISTIC(RelaxedInstructions, "Number of relaxed instructions");
68
69} // end namespace stats
70} // end anonymous namespace
71
72// FIXME FIXME FIXME: There are number of places in this file where we convert
73// what is a 64-bit assembler value used for computation into a value in the
74// object file, which may truncate it. We should detect that truncation where
75// invalid and report errors back.
76
77/* *** */
78
80 std::unique_ptr<MCAsmBackend> Backend,
81 std::unique_ptr<MCCodeEmitter> Emitter,
82 std::unique_ptr<MCObjectWriter> Writer)
83 : Context(Context), Backend(std::move(Backend)),
84 Emitter(std::move(Emitter)), Writer(std::move(Writer)) {
85 if (this->Backend)
86 this->Backend->setAssembler(this);
87 if (this->Writer)
88 this->Writer->setAssembler(this);
89}
90
92 HasLayout = false;
93 HasFinalLayout = false;
94 RelaxAll = false;
95 Sections.clear();
96 Symbols.clear();
97 ThumbFuncs.clear();
98
99 // reset objects owned by us
100 if (getBackendPtr())
101 getBackendPtr()->reset();
102 if (getEmitterPtr())
103 getEmitterPtr()->reset();
104 if (Writer)
105 Writer->reset();
106}
107
109 if (Section.isRegistered())
110 return false;
111 Sections.push_back(&Section);
112 Section.setIsRegistered(true);
113 return true;
114}
115
116bool MCAssembler::isThumbFunc(const MCSymbol *Symbol) const {
117 if (ThumbFuncs.count(Symbol))
118 return true;
119
120 if (!Symbol->isVariable())
121 return false;
122
123 const MCExpr *Expr = Symbol->getVariableValue();
124
125 MCValue V;
126 if (!Expr->evaluateAsRelocatable(V, nullptr))
127 return false;
128
129 if (V.getSubSym() || V.getSpecifier())
130 return false;
131
132 auto *Sym = V.getAddSym();
133 if (!Sym || V.getSpecifier())
134 return false;
135
136 if (!isThumbFunc(Sym))
137 return false;
138
139 ThumbFuncs.insert(Symbol); // Cache it.
140 return true;
141}
142
143bool MCAssembler::evaluateFixup(const MCFragment &F, MCFixup &Fixup,
145 bool RecordReloc, uint8_t *Data) const {
146 if (RecordReloc)
147 ++stats::Fixups;
148
149 // FIXME: This code has some duplication with recordRelocation. We should
150 // probably merge the two into a single callback that tries to evaluate a
151 // fixup and records a relocation if one is needed.
152
153 // On error claim to have completely evaluated the fixup, to prevent any
154 // further processing from being done.
155 const MCExpr *Expr = Fixup.getValue();
156 Value = 0;
157 if (!Expr->evaluateAsRelocatable(Target, this)) {
158 reportError(Fixup.getLoc(), "expected relocatable expression");
159 return true;
160 }
161
162 bool IsResolved = false;
163 if (auto State = getBackend().evaluateFixup(F, Fixup, Target, Value)) {
164 IsResolved = *State;
165 } else {
166 const MCSymbol *Add = Target.getAddSym();
167 const MCSymbol *Sub = Target.getSubSym();
168 Value += Target.getConstant();
169 if (Add && Add->isDefined())
171 if (Sub && Sub->isDefined())
173
174 if (Fixup.isPCRel()) {
175 Value -= getFragmentOffset(F) + Fixup.getOffset();
176 if (Add && !Sub && !Add->isUndefined() && !Add->isAbsolute()) {
178 *Add, F, false, true);
179 }
180 } else {
181 IsResolved = Target.isAbsolute();
182 }
183 }
184
185 if (!RecordReloc)
186 return IsResolved;
187
188 if (IsResolved && mc::isRelocRelocation(Fixup.getKind()))
189 IsResolved = false;
190 getBackend().applyFixup(F, Fixup, Target, Data, Value, IsResolved);
191 return true;
192}
193
195 assert(getBackendPtr() && "Requires assembler backend");
196 switch (F.getKind()) {
206 return F.getSize();
207 case MCFragment::FT_Fill: {
208 auto &FF = static_cast<const MCFillFragment &>(F);
209 int64_t NumValues = 0;
210 if (!FF.getNumValues().evaluateKnownAbsolute(NumValues, *this)) {
211 recordError(FF.getLoc(), "expected assembly-time absolute expression");
212 return 0;
213 }
214 int64_t Size = NumValues * FF.getValueSize();
215 if (Size < 0) {
216 recordError(FF.getLoc(), "invalid number of bytes");
217 return 0;
218 }
219 return Size;
220 }
221
223 return cast<MCNopsFragment>(F).getNumBytes();
224
226 return cast<MCBoundaryAlignFragment>(F).getSize();
227
229 return 4;
230
231 case MCFragment::FT_Org: {
234 if (!OF.getOffset().evaluateAsValue(Value, *this)) {
235 recordError(OF.getLoc(), "expected assembly-time absolute expression");
236 return 0;
237 }
238
239 uint64_t FragmentOffset = getFragmentOffset(OF);
240 int64_t TargetLocation = Value.getConstant();
241 if (const auto *SA = Value.getAddSym()) {
242 uint64_t Val;
243 if (!getSymbolOffset(*SA, Val)) {
244 recordError(OF.getLoc(), "expected absolute expression");
245 return 0;
246 }
247 TargetLocation += Val;
248 }
249 int64_t Size = TargetLocation - FragmentOffset;
250 if (Size < 0 || Size >= 0x40000000) {
251 recordError(OF.getLoc(), "invalid .org offset '" + Twine(TargetLocation) +
252 "' (at offset '" + Twine(FragmentOffset) +
253 "')");
254 return 0;
255 }
256 return Size;
257 }
258 }
259
260 llvm_unreachable("invalid fragment kind");
261}
262
263// Simple getSymbolOffset helper for the non-variable case.
264static bool getLabelOffset(const MCAssembler &Asm, const MCSymbol &S,
265 bool ReportError, uint64_t &Val) {
266 if (!S.getFragment()) {
267 if (ReportError)
268 reportFatalUsageError("cannot evaluate undefined symbol '" + S.getName() +
269 "'");
270 return false;
271 }
272 Val = Asm.getFragmentOffset(*S.getFragment()) + S.getOffset();
273 return true;
274}
275
276static bool getSymbolOffsetImpl(const MCAssembler &Asm, const MCSymbol &S,
277 bool ReportError, uint64_t &Val) {
278 if (!S.isVariable())
279 return getLabelOffset(Asm, S, ReportError, Val);
280
281 // If SD is a variable, evaluate it.
284 reportFatalUsageError("cannot evaluate equated symbol '" + S.getName() +
285 "'");
286
287 uint64_t Offset = Target.getConstant();
288
289 const MCSymbol *A = Target.getAddSym();
290 if (A) {
291 uint64_t ValA;
292 // FIXME: On most platforms, `Target`'s component symbols are labels from
293 // having been simplified during evaluation, but on Mach-O they can be
294 // variables due to PR19203. This, and the line below for `B` can be
295 // restored to call `getLabelOffset` when PR19203 is fixed.
296 if (!getSymbolOffsetImpl(Asm, *A, ReportError, ValA))
297 return false;
298 Offset += ValA;
299 }
300
301 const MCSymbol *B = Target.getSubSym();
302 if (B) {
303 uint64_t ValB;
304 if (!getSymbolOffsetImpl(Asm, *B, ReportError, ValB))
305 return false;
306 Offset -= ValB;
307 }
308
309 Val = Offset;
310 return true;
311}
312
314 return getSymbolOffsetImpl(*this, S, false, Val);
315}
316
318 uint64_t Val;
319 getSymbolOffsetImpl(*this, S, true, Val);
320 return Val;
321}
322
323const MCSymbol *MCAssembler::getBaseSymbol(const MCSymbol &Symbol) const {
324 assert(HasLayout);
325 if (!Symbol.isVariable())
326 return &Symbol;
327
328 const MCExpr *Expr = Symbol.getVariableValue();
330 if (!Expr->evaluateAsValue(Value, *this)) {
331 reportError(Expr->getLoc(), "expression could not be evaluated");
332 return nullptr;
333 }
334
335 const MCSymbol *SymB = Value.getSubSym();
336 if (SymB) {
337 reportError(Expr->getLoc(),
338 Twine("symbol '") + SymB->getName() +
339 "' could not be evaluated in a subtraction expression");
340 return nullptr;
341 }
342
343 const MCSymbol *A = Value.getAddSym();
344 if (!A)
345 return nullptr;
346
347 const MCSymbol &ASym = *A;
348 if (ASym.isCommon()) {
349 reportError(Expr->getLoc(), "Common symbol '" + ASym.getName() +
350 "' cannot be used in assignment expr");
351 return nullptr;
352 }
353
354 return &ASym;
355}
356
358 const MCFragment &F = *Sec.curFragList()->Tail;
359 assert(HasLayout && F.getKind() == MCFragment::FT_Data);
360 return getFragmentOffset(F) + F.getSize();
361}
362
364 // Virtual sections have no file size.
365 if (Sec.isBssSection())
366 return 0;
367 return getSectionAddressSize(Sec);
368}
369
371 bool Changed = !Symbol.isRegistered();
372 if (Changed) {
373 Symbol.setIsRegistered(true);
374 Symbols.push_back(&Symbol);
375 }
376 return Changed;
377}
378
379void MCAssembler::addRelocDirective(RelocDirective RD) {
380 relocDirectives.push_back(RD);
381}
382
383/// Write the fragment \p F to the output file.
384static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
385 const MCFragment &F) {
386 // FIXME: Embed in fragments instead?
387 uint64_t FragmentSize = Asm.computeFragmentSize(F);
388
389 llvm::endianness Endian = Asm.getBackend().Endian;
390
391 // This variable (and its dummy usage) is to participate in the assert at
392 // the end of the function.
393 uint64_t Start = OS.tell();
394 (void) Start;
395
396 ++stats::EmittedFragments;
397
398 switch (F.getKind()) {
407 if (F.getKind() == MCFragment::FT_Data)
408 ++stats::EmittedDataFragments;
409 else if (F.getKind() == MCFragment::FT_Relaxable)
410 ++stats::EmittedRelaxableFragments;
411 const auto &EF = cast<MCFragment>(F);
412 OS << StringRef(EF.getContents().data(), EF.getContents().size());
413 OS << StringRef(EF.getVarContents().data(), EF.getVarContents().size());
414 } break;
415
417 ++stats::EmittedAlignFragments;
418 OS << StringRef(F.getContents().data(), F.getContents().size());
419 assert(F.getAlignFillLen() &&
420 "Invalid virtual align in concrete fragment!");
421
422 uint64_t Count = (FragmentSize - F.getFixedSize()) / F.getAlignFillLen();
423 assert((FragmentSize - F.getFixedSize()) % F.getAlignFillLen() == 0 &&
424 "computeFragmentSize computed size is incorrect");
425
426 // In the nops mode, call the backend hook to write `Count` nops.
427 if (F.hasAlignEmitNops()) {
428 if (!Asm.getBackend().writeNopData(OS, Count, F.getSubtargetInfo()))
429 reportFatalInternalError("unable to write nop sequence of " +
430 Twine(Count) + " bytes");
431 } else {
432 // Otherwise, write out in multiples of the value size.
433 for (uint64_t i = 0; i != Count; ++i) {
434 switch (F.getAlignFillLen()) {
435 default:
436 llvm_unreachable("Invalid size!");
437 case 1:
438 OS << char(F.getAlignFill());
439 break;
440 case 2:
441 support::endian::write<uint16_t>(OS, F.getAlignFill(), Endian);
442 break;
443 case 4:
444 support::endian::write<uint32_t>(OS, F.getAlignFill(), Endian);
445 break;
446 case 8:
447 support::endian::write<uint64_t>(OS, F.getAlignFill(), Endian);
448 break;
449 }
450 }
451 }
452 } break;
453
454 case MCFragment::FT_Fill: {
455 ++stats::EmittedFillFragments;
457 uint64_t V = FF.getValue();
458 unsigned VSize = FF.getValueSize();
459 const unsigned MaxChunkSize = 16;
460 char Data[MaxChunkSize];
461 assert(0 < VSize && VSize <= MaxChunkSize && "Illegal fragment fill size");
462 // Duplicate V into Data as byte vector to reduce number of
463 // writes done. As such, do endian conversion here.
464 for (unsigned I = 0; I != VSize; ++I) {
465 unsigned index = Endian == llvm::endianness::little ? I : (VSize - I - 1);
466 Data[I] = uint8_t(V >> (index * 8));
467 }
468 for (unsigned I = VSize; I < MaxChunkSize; ++I)
469 Data[I] = Data[I - VSize];
470
471 // Set to largest multiple of VSize in Data.
472 const unsigned NumPerChunk = MaxChunkSize / VSize;
473 // Set ChunkSize to largest multiple of VSize in Data
474 const unsigned ChunkSize = VSize * NumPerChunk;
475
476 // Do copies by chunk.
477 StringRef Ref(Data, ChunkSize);
478 for (uint64_t I = 0, E = FragmentSize / ChunkSize; I != E; ++I)
479 OS << Ref;
480
481 // do remainder if needed.
482 unsigned TrailingCount = FragmentSize % ChunkSize;
483 if (TrailingCount)
484 OS.write(Data, TrailingCount);
485 break;
486 }
487
488 case MCFragment::FT_Nops: {
489 ++stats::EmittedNopsFragments;
491
492 int64_t NumBytes = NF.getNumBytes();
493 int64_t ControlledNopLength = NF.getControlledNopLength();
494 int64_t MaximumNopLength =
495 Asm.getBackend().getMaximumNopSize(*NF.getSubtargetInfo());
496
497 assert(NumBytes > 0 && "Expected positive NOPs fragment size");
498 assert(ControlledNopLength >= 0 && "Expected non-negative NOP size");
499
500 if (ControlledNopLength > MaximumNopLength) {
501 Asm.reportError(NF.getLoc(), "illegal NOP size " +
502 std::to_string(ControlledNopLength) +
503 ". (expected within [0, " +
504 std::to_string(MaximumNopLength) + "])");
505 // Clamp the NOP length as reportError does not stop the execution
506 // immediately.
507 ControlledNopLength = MaximumNopLength;
508 }
509
510 // Use maximum value if the size of each NOP is not specified
511 if (!ControlledNopLength)
512 ControlledNopLength = MaximumNopLength;
513
514 while (NumBytes) {
515 uint64_t NumBytesToEmit =
516 (uint64_t)std::min(NumBytes, ControlledNopLength);
517 assert(NumBytesToEmit && "try to emit empty NOP instruction");
518 if (!Asm.getBackend().writeNopData(OS, NumBytesToEmit,
519 NF.getSubtargetInfo())) {
520 report_fatal_error("unable to write nop sequence of the remaining " +
521 Twine(NumBytesToEmit) + " bytes");
522 break;
523 }
524 NumBytes -= NumBytesToEmit;
525 }
526 break;
527 }
528
531 if (!Asm.getBackend().writeNopData(OS, FragmentSize, BF.getSubtargetInfo()))
532 report_fatal_error("unable to write nop sequence of " +
533 Twine(FragmentSize) + " bytes");
534 break;
535 }
536
540 break;
541 }
542
543 case MCFragment::FT_Org: {
544 ++stats::EmittedOrgFragments;
546
547 for (uint64_t i = 0, e = FragmentSize; i != e; ++i)
548 OS << char(OF.getValue());
549
550 break;
551 }
552
553 }
554
555 assert(OS.tell() - Start == FragmentSize &&
556 "The stream should advance by fragment size");
557}
558
560 const MCSection *Sec) const {
561 assert(getBackendPtr() && "Expected assembler backend");
562
563 if (Sec->isBssSection()) {
564 assert(getSectionFileSize(*Sec) == 0 && "Invalid size for section!");
565
566 // Ensure no fixups or non-zero bytes are written to BSS sections, catching
567 // errors in both input assembly code and MCStreamer API usage. Location is
568 // not tracked for efficiency.
569 auto Fn = [](char c) { return c != 0; };
570 for (const MCFragment &F : *Sec) {
571 bool HasNonZero = false;
572 switch (F.getKind()) {
573 default:
574 reportFatalInternalError("BSS section '" + Sec->getName() +
575 "' contains invalid fragment");
576 break;
579 HasNonZero =
580 any_of(F.getContents(), Fn) || any_of(F.getVarContents(), Fn);
581 break;
583 // Disallowed for API usage. AsmParser changes non-zero fill values to
584 // 0.
585 assert(F.getAlignFill() == 0 && "Invalid align in virtual section!");
586 break;
588 HasNonZero = cast<MCFillFragment>(F).getValue() != 0;
589 break;
591 HasNonZero = cast<MCOrgFragment>(F).getValue() != 0;
592 break;
593 }
594 if (HasNonZero) {
595 reportError(SMLoc(), "BSS section '" + Sec->getName() +
596 "' cannot have non-zero bytes");
597 break;
598 }
599 if (F.getFixups().size() || F.getVarFixups().size()) {
601 "BSS section '" + Sec->getName() + "' cannot have fixups");
602 break;
603 }
604 }
605
606 return;
607 }
608
609 uint64_t Start = OS.tell();
610 (void)Start;
611
612 for (const MCFragment &F : *Sec)
613 writeFragment(OS, *this, F);
614
616 assert(getContext().hadError() ||
617 OS.tell() - Start == getSectionAddressSize(*Sec));
618}
619
621 assert(getBackendPtr() && "Expected assembler backend");
622 DEBUG_WITH_TYPE("mc-dump-pre", {
623 errs() << "assembler backend - pre-layout\n--\n";
624 dump();
625 });
626
627 // Assign section ordinals.
628 unsigned SectionIndex = 0;
629 for (MCSection &Sec : *this) {
630 Sec.setOrdinal(SectionIndex++);
631
632 // Chain together fragments from all subsections.
633 if (Sec.Subsections.size() > 1) {
634 MCFragment Dummy;
635 MCFragment *Tail = &Dummy;
636 for (auto &[_, List] : Sec.Subsections) {
637 assert(List.Head);
638 Tail->Next = List.Head;
639 Tail = List.Tail;
640 }
641 Sec.Subsections.clear();
642 Sec.Subsections.push_back({0u, {Dummy.getNext(), Tail}});
643 Sec.CurFragList = &Sec.Subsections[0].second;
644
645 unsigned FragmentIndex = 0;
646 for (MCFragment &Frag : Sec)
647 Frag.setLayoutOrder(FragmentIndex++);
648 }
649 }
650
651 // Layout until everything fits.
652 this->HasLayout = true;
653 for (MCSection &Sec : *this)
654 layoutSection(Sec);
655 unsigned FirstStable = Sections.size();
656 while ((FirstStable = relaxOnce(FirstStable)) > 0)
657 if (getContext().hadError())
658 return;
659
660 // Some targets might want to adjust fragment offsets. If so, perform another
661 // layout iteration.
662 if (getBackend().finishLayout(*this))
663 for (MCSection &Sec : *this)
664 layoutSection(Sec);
665
667
668 DEBUG_WITH_TYPE("mc-dump", {
669 errs() << "assembler backend - final-layout\n--\n";
670 dump(); });
671
672 // Allow the object writer a chance to perform post-layout binding (for
673 // example, to set the index fields in the symbol data).
675
676 // Fragment sizes are finalized. For RISC-V linker relaxation, this flag
677 // helps check whether a PC-relative fixup is fully resolved.
678 this->HasFinalLayout = true;
679
680 // Resolve .reloc offsets and add fixups.
681 for (auto &PF : relocDirectives) {
682 MCValue Res;
683 auto &O = PF.Offset;
684 if (!O.evaluateAsValue(Res, *this)) {
685 getContext().reportError(O.getLoc(), ".reloc offset is not relocatable");
686 continue;
687 }
688 auto *Sym = Res.getAddSym();
689 auto *F = Sym ? Sym->getFragment() : nullptr;
690 auto *Sec = F ? F->getParent() : nullptr;
691 if (Res.getSubSym() || !Sec) {
692 getContext().reportError(O.getLoc(),
693 ".reloc offset is not relative to a section");
694 continue;
695 }
696
697 uint64_t Offset = Sym ? Sym->getOffset() + Res.getConstant() : 0;
698 F->addFixup(MCFixup::create(Offset, PF.Expr, PF.Kind));
699 }
700
701 // Evaluate and apply the fixups, generating relocation entries as necessary.
702 for (MCSection &Sec : *this) {
703 for (MCFragment &F : Sec) {
704 // Process fragments with fixups here.
705 auto Contents = F.getContents();
706 for (MCFixup &Fixup : F.getFixups()) {
707 uint64_t FixedValue;
710 Fixup.getOffset() <= F.getFixedSize());
711 auto *Data =
712 reinterpret_cast<uint8_t *>(Contents.data() + Fixup.getOffset());
713 evaluateFixup(F, Fixup, Target, FixedValue,
714 /*RecordReloc=*/true, Data);
715 }
716 // In the variable part, fixup offsets are relative to the fixed part's
717 // start.
718 for (MCFixup &Fixup : F.getVarFixups()) {
719 uint64_t FixedValue;
722 (Fixup.getOffset() >= F.getFixedSize() &&
723 Fixup.getOffset() <= F.getSize()));
724 auto *Data = reinterpret_cast<uint8_t *>(
725 F.getVarContents().data() + (Fixup.getOffset() - F.getFixedSize()));
726 evaluateFixup(F, Fixup, Target, FixedValue,
727 /*RecordReloc=*/true, Data);
728 }
729 }
730 }
731}
732
734 layout();
735
736 // Write the object file.
737 stats::ObjectBytes += getWriter().writeObject();
738
739 HasLayout = false;
740 assert(PendingErrors.empty());
741}
742
743bool MCAssembler::fixupNeedsRelaxation(const MCFragment &F,
744 const MCFixup &Fixup) const {
745 ++stats::FixupEvalForRelax;
748 bool Resolved = evaluateFixup(F, const_cast<MCFixup &>(Fixup), Target, Value,
749 /*RecordReloc=*/false, {});
751 Resolved);
752}
753
754void MCAssembler::relaxInstruction(MCFragment &F) {
756 "Expected CodeEmitter defined for relaxInstruction");
757 // If this inst doesn't ever need relaxation, ignore it. This occurs when we
758 // are intentionally pushing out inst fragments, or because we relaxed a
759 // previous instruction to one that doesn't need relaxation.
760 if (!getBackend().mayNeedRelaxation(F.getOpcode(), F.getOperands(),
761 *F.getSubtargetInfo()))
762 return;
763
764 bool DoRelax = false;
765 for (const MCFixup &Fixup : F.getVarFixups())
766 if ((DoRelax = fixupNeedsRelaxation(F, Fixup)))
767 break;
768 if (!DoRelax)
769 return;
770
771 ++stats::RelaxedInstructions;
772
773 // TODO Refactor relaxInstruction to accept MCFragment and remove
774 // `setInst`.
775 MCInst Relaxed = F.getInst();
776 getBackend().relaxInstruction(Relaxed, *F.getSubtargetInfo());
777
778 // Encode the new instruction.
779 F.setInst(Relaxed);
782 getEmitter().encodeInstruction(Relaxed, Data, Fixups, *F.getSubtargetInfo());
783 F.setVarContents(Data);
784 F.setVarFixups(Fixups);
785}
786
787void MCAssembler::relaxLEB(MCFragment &F) {
788 unsigned PadTo = F.getVarSize();
789 int64_t Value;
790 F.clearVarFixups();
791 // Use evaluateKnownAbsolute for Mach-O as a hack: .subsections_via_symbols
792 // requires that .uleb128 A-B is foldable where A and B reside in different
793 // fragments. This is used by __gcc_except_table.
795 ? F.getLEBValue().evaluateKnownAbsolute(Value, *this)
796 : F.getLEBValue().evaluateAsAbsolute(Value, *this);
797 if (!Abs) {
798 bool Relaxed, UseZeroPad;
799 std::tie(Relaxed, UseZeroPad) = getBackend().relaxLEB128(F, Value);
800 if (!Relaxed) {
801 reportError(F.getLEBValue().getLoc(),
802 Twine(F.isLEBSigned() ? ".s" : ".u") +
803 "leb128 expression is not absolute");
804 F.setLEBValue(MCConstantExpr::create(0, Context));
805 }
806 uint8_t Tmp[10]; // maximum size: ceil(64/7)
807 PadTo = std::max(PadTo, encodeULEB128(uint64_t(Value), Tmp));
808 if (UseZeroPad)
809 Value = 0;
810 }
811 uint8_t Data[16];
812 size_t Size = 0;
813 // The compiler can generate EH table assembly that is impossible to assemble
814 // without either adding padding to an LEB fragment or adding extra padding
815 // to a later alignment fragment. To accommodate such tables, relaxation can
816 // only increase an LEB fragment size here, not decrease it. See PR35809.
817 if (F.isLEBSigned())
818 Size = encodeSLEB128(Value, Data, PadTo);
819 else
820 Size = encodeULEB128(Value, Data, PadTo);
821 F.setVarContents({reinterpret_cast<char *>(Data), Size});
822}
823
824/// Check if the branch crosses the boundary.
825///
826/// \param StartAddr start address of the fused/unfused branch.
827/// \param Size size of the fused/unfused branch.
828/// \param BoundaryAlignment alignment requirement of the branch.
829/// \returns true if the branch cross the boundary.
830static bool mayCrossBoundary(uint64_t StartAddr, uint64_t Size,
831 Align BoundaryAlignment) {
832 uint64_t EndAddr = StartAddr + Size;
833 return (StartAddr >> Log2(BoundaryAlignment)) !=
834 ((EndAddr - 1) >> Log2(BoundaryAlignment));
835}
836
837/// Check if the branch is against the boundary.
838///
839/// \param StartAddr start address of the fused/unfused branch.
840/// \param Size size of the fused/unfused branch.
841/// \param BoundaryAlignment alignment requirement of the branch.
842/// \returns true if the branch is against the boundary.
844 Align BoundaryAlignment) {
845 uint64_t EndAddr = StartAddr + Size;
846 return (EndAddr & (BoundaryAlignment.value() - 1)) == 0;
847}
848
849/// Check if the branch needs padding.
850///
851/// \param StartAddr start address of the fused/unfused branch.
852/// \param Size size of the fused/unfused branch.
853/// \param BoundaryAlignment alignment requirement of the branch.
854/// \returns true if the branch needs padding.
855static bool needPadding(uint64_t StartAddr, uint64_t Size,
856 Align BoundaryAlignment) {
857 return mayCrossBoundary(StartAddr, Size, BoundaryAlignment) ||
858 isAgainstBoundary(StartAddr, Size, BoundaryAlignment);
859}
860
861void MCAssembler::relaxBoundaryAlign(MCBoundaryAlignFragment &BF) {
862 // BoundaryAlignFragment that doesn't need to align any fragment should not be
863 // relaxed.
864 if (!BF.getLastFragment())
865 return;
866
867 uint64_t AlignedOffset = getFragmentOffset(BF);
868 uint64_t AlignedSize = 0;
869 for (const MCFragment *F = BF.getNext();; F = F->getNext()) {
870 AlignedSize += computeFragmentSize(*F);
871 if (F == BF.getLastFragment())
872 break;
873 }
874
875 Align BoundaryAlignment = BF.getAlignment();
876 uint64_t NewSize = needPadding(AlignedOffset, AlignedSize, BoundaryAlignment)
877 ? offsetToAlignment(AlignedOffset, BoundaryAlignment)
878 : 0U;
879 if (NewSize == BF.getSize())
880 return;
881 BF.setSize(NewSize);
882}
883
884void MCAssembler::relaxDwarfLineAddr(MCFragment &F) {
885 if (getBackend().relaxDwarfLineAddr(F))
886 return;
887
888 MCContext &Context = getContext();
889 int64_t AddrDelta;
890 bool Abs = F.getDwarfAddrDelta().evaluateKnownAbsolute(AddrDelta, *this);
891 assert(Abs && "We created a line delta with an invalid expression");
892 (void)Abs;
893 SmallVector<char, 8> Data;
895 F.getDwarfLineDelta(), AddrDelta, Data);
896 F.setVarContents(Data);
897 F.clearVarFixups();
898}
899
900void MCAssembler::relaxDwarfCallFrameFragment(MCFragment &F) {
901 if (getBackend().relaxDwarfCFA(F))
902 return;
903
904 MCContext &Context = getContext();
905 int64_t Value;
906 bool Abs = F.getDwarfAddrDelta().evaluateAsAbsolute(Value, *this);
907 if (!Abs) {
908 reportError(F.getDwarfAddrDelta().getLoc(),
909 "invalid CFI advance_loc expression");
910 F.setDwarfAddrDelta(MCConstantExpr::create(0, Context));
911 return;
912 }
913
914 SmallVector<char, 8> Data;
916 F.setVarContents(Data);
917 F.clearVarFixups();
918}
919
920void MCAssembler::relaxSFrameFragment(MCFragment &F) {
921 assert(F.getKind() == MCFragment::FT_SFrame);
922 MCContext &C = getContext();
923 int64_t Value;
924 bool Abs = F.getSFrameAddrDelta().evaluateAsAbsolute(Value, *this);
925 if (!Abs) {
926 C.reportError(F.getSFrameAddrDelta().getLoc(),
927 "invalid CFI advance_loc expression in sframe");
928 F.setSFrameAddrDelta(MCConstantExpr::create(0, C));
929 return;
930 }
931
933 MCSFrameEmitter::encodeFuncOffset(Context, Value, Data, F.getSFrameFDE());
934 F.setVarContents(Data);
935 F.clearVarFixups();
936}
937
938bool MCAssembler::relaxFragment(MCFragment &F) {
939 auto Size = computeFragmentSize(F);
940 switch (F.getKind()) {
941 default:
942 return false;
944 assert(!getRelaxAll() && "Did not expect a FT_Relaxable in RelaxAll mode");
945 relaxInstruction(F);
946 break;
948 relaxLEB(F);
949 break;
951 relaxDwarfLineAddr(F);
952 break;
954 relaxDwarfCallFrameFragment(F);
955 break;
957 relaxSFrameFragment(F);
958 break;
960 relaxBoundaryAlign(static_cast<MCBoundaryAlignFragment &>(F));
961 break;
964 *this, static_cast<MCCVInlineLineTableFragment &>(F));
965 break;
968 *this, static_cast<MCCVDefRangeFragment &>(F));
969 break;
972 return F.getNext()->Offset - F.Offset != Size;
973 }
974 return computeFragmentSize(F) != Size;
975}
976
977void MCAssembler::layoutSection(MCSection &Sec) {
978 uint64_t Offset = 0;
979 for (MCFragment &F : Sec) {
980 F.Offset = Offset;
981 if (F.getKind() == MCFragment::FT_Align) {
982 Offset += F.getFixedSize();
983 unsigned Size = offsetToAlignment(Offset, F.getAlignment());
984 // In the nops mode, RISC-V style linker relaxation might adjust the size
985 // and add a fixup, even if `Size` is originally 0.
986 bool AlignFixup = false;
987 if (F.hasAlignEmitNops()) {
988 AlignFixup = getBackend().relaxAlign(F, Size);
989 // If the backend does not handle the fragment specially, pad with nops,
990 // but ensure that the padding is larger than the minimum nop size.
991 if (!AlignFixup)
992 while (Size % getBackend().getMinimumNopSize())
993 Size += F.getAlignment().value();
994 }
995 if (!AlignFixup && Size > F.getAlignMaxBytesToEmit())
996 Size = 0;
997 // Update the variable tail size, offset by FixedSize to prevent ubsan
998 // pointer-overflow in evaluateFixup. The content is ignored.
999 F.VarContentStart = F.getFixedSize();
1000 F.VarContentEnd = F.VarContentStart + Size;
1001 if (F.VarContentEnd > F.getParent()->ContentStorage.size())
1002 F.getParent()->ContentStorage.resize(F.VarContentEnd);
1003 Offset += Size;
1004 } else {
1006 }
1007 }
1008}
1009
1010unsigned MCAssembler::relaxOnce(unsigned FirstStable) {
1011 ++stats::RelaxationSteps;
1012 PendingErrors.clear();
1013
1014 unsigned Res = 0;
1015 for (unsigned I = 0; I != FirstStable; ++I) {
1016 // Assume each iteration finalizes at least one extra fragment. If the
1017 // layout does not converge after N+1 iterations, bail out.
1018 auto &Sec = *Sections[I];
1019 auto MaxIter = Sec.curFragList()->Tail->getLayoutOrder() + 1;
1020 for (;;) {
1021 bool Changed = false;
1022 for (MCFragment &F : Sec)
1023 if (F.getKind() != MCFragment::FT_Data && relaxFragment(F))
1024 Changed = true;
1025
1026 if (!Changed)
1027 break;
1028 // If any fragment changed size, it might impact the layout of subsequent
1029 // sections. Therefore, we must re-evaluate all sections.
1030 FirstStable = Sections.size();
1031 Res = I;
1032 if (--MaxIter == 0)
1033 break;
1034 layoutSection(Sec);
1035 }
1036 }
1037 // The subsequent relaxOnce call only needs to visit Sections [0,Res) if no
1038 // change occurred.
1039 return Res;
1040}
1041
1042void MCAssembler::reportError(SMLoc L, const Twine &Msg) const {
1043 getContext().reportError(L, Msg);
1044}
1045
1046void MCAssembler::recordError(SMLoc Loc, const Twine &Msg) const {
1047 PendingErrors.emplace_back(Loc, Msg.str());
1048}
1049
1051 for (auto &Err : PendingErrors)
1052 reportError(Err.first, Err.second);
1053 PendingErrors.clear();
1054}
1055
1056#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1058 raw_ostream &OS = errs();
1060 // Scan symbols and build a map of fragments to their corresponding symbols.
1061 // For variable symbols, we don't want to call their getFragment, which might
1062 // modify `Fragment`.
1063 for (const MCSymbol &Sym : symbols())
1064 if (!Sym.isVariable())
1065 if (auto *F = Sym.getFragment())
1066 FragToSyms.try_emplace(F).first->second.push_back(&Sym);
1067
1068 OS << "Sections:[";
1069 for (const MCSection &Sec : *this) {
1070 OS << '\n';
1071 Sec.dump(&FragToSyms);
1072 }
1073 OS << "\n]\n";
1074}
1075#endif
1076
1078 if (auto *E = getValue())
1079 return E->getLoc();
1080 return {};
1081}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:638
#define _
static bool getSymbolOffsetImpl(const MCAssembler &Asm, const MCSymbol &S, bool ReportError, uint64_t &Val)
static bool needPadding(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch needs padding.
static void writeFragment(raw_ostream &OS, const MCAssembler &Asm, const MCFragment &F)
Write the fragment F to the output file.
static bool mayCrossBoundary(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch crosses the boundary.
static bool isAgainstBoundary(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch is against the boundary.
static bool getLabelOffset(const MCAssembler &Asm, const MCSymbol &S, bool ReportError, uint64_t &Val)
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
PowerPC TLS Dynamic Call Fixup
if(PassOpts->AAPipeline)
This file defines the SmallVector class.
static Split data
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define DEBUG_WITH_TYPE(TYPE,...)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Definition Debug.h:72
void encodeInlineLineTable(const MCAssembler &Asm, MCCVInlineLineTableFragment &F)
Encodes the binary annotations once we have a layout.
void encodeDefRange(const MCAssembler &Asm, MCCVDefRangeFragment &F)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition DenseMap.h:229
virtual void relaxInstruction(MCInst &Inst, const MCSubtargetInfo &STI) const
Relax the instruction in the given fragment to the next wider instruction.
virtual bool relaxAlign(MCFragment &F, unsigned &Size)
virtual std::pair< bool, bool > relaxLEB128(MCFragment &, int64_t &Value) const
virtual bool fixupNeedsRelaxationAdvanced(const MCFragment &, const MCFixup &, const MCValue &, uint64_t, bool Resolved) const
Target specific predicate for whether a given fixup requires the associated instruction to be relaxed...
virtual void reset()
lifetime management
virtual void applyFixup(const MCFragment &, const MCFixup &, const MCValue &Target, uint8_t *Data, uint64_t Value, bool IsResolved)=0
MCContext & getContext() const
LLVM_ABI bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const
LLVM_ABI uint64_t getSectionAddressSize(const MCSection &Sec) const
LLVM_ABI void Finish()
Finish - Do final processing and write the object to the output stream.
LLVM_ABI void reportError(SMLoc L, const Twine &Msg) const
LLVM_ABI void writeSectionData(raw_ostream &OS, const MCSection *Section) const
Emit the section contents to OS.
LLVM_ABI void dump() const
LLVM_ABI void layout()
MCObjectWriter & getWriter() const
MCCodeEmitter * getEmitterPtr() const
LLVM_ABI void addRelocDirective(RelocDirective RD)
bool getRelaxAll() const
MCCodeEmitter & getEmitter() const
LLVM_ABI void recordError(SMLoc L, const Twine &Msg) const
LLVM_ABI MCAssembler(MCContext &Context, std::unique_ptr< MCAsmBackend > Backend, std::unique_ptr< MCCodeEmitter > Emitter, std::unique_ptr< MCObjectWriter > Writer)
Construct a new assembler instance.
LLVM_ABI bool isThumbFunc(const MCSymbol *Func) const
Check whether a given symbol has been flagged with .thumb_func.
MCAsmBackend & getBackend() const
LLVM_ABI bool registerSection(MCSection &Section)
LLVM_ABI void flushPendingErrors() const
LLVM_ABI uint64_t computeFragmentSize(const MCFragment &F) const
Compute the effective fragment size.
LLVM_ABI const MCSymbol * getBaseSymbol(const MCSymbol &Symbol) const
MCAsmBackend * getBackendPtr() const
iterator_range< pointee_iterator< typename SmallVector< const MCSymbol *, 0 >::const_iterator > > symbols() const
LLVM_ABI uint64_t getSectionFileSize(const MCSection &Sec) const
LLVM_ABI void reset()
Reuse an assembler instance.
LLVM_ABI bool registerSymbol(const MCSymbol &Symbol)
uint64_t getFragmentOffset(const MCFragment &F) const
MCDwarfLineTableParams getDWARFLinetableParams() const
Represents required padding such that a particular other set of fragments does not cross a particular...
Definition MCSection.h:484
void setSize(uint64_t Value)
Definition MCSection.h:501
const MCFragment * getLastFragment() const
Definition MCSection.h:506
const MCSubtargetInfo * getSubtargetInfo() const
Definition MCSection.h:512
virtual void encodeInstruction(const MCInst &Inst, SmallVectorImpl< char > &CB, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
Encode the given Inst to bytes and append to CB.
virtual void reset()
Lifetime management.
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 CodeViewContext & getCVContext()
LLVM_ABI void reportError(SMLoc L, const Twine &Msg)
static LLVM_ABI void encodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
Definition MCDwarf.cpp:1982
static LLVM_ABI void encode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, SmallVectorImpl< char > &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
Definition MCDwarf.cpp:745
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
LLVM_ABI bool evaluateAsValue(MCValue &Res, const MCAssembler &Asm) const
Try to evaluate the expression to the form (a - b + constant) where neither a nor b are variables.
Definition MCExpr.cpp:453
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
SMLoc getLoc() const
Definition MCExpr.h:86
uint8_t getValueSize() const
Definition MCSection.h:346
uint64_t getValue() const
Definition MCSection.h:345
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition MCFixup.h:61
const MCExpr * getValue() const
Definition MCFixup.h:101
LLVM_ABI SMLoc getLoc() const
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
MCFragment * getNext() const
Definition MCSection.h:161
int64_t getControlledNopLength() const
Definition MCSection.h:375
int64_t getNumBytes() const
Definition MCSection.h:374
const MCSubtargetInfo * getSubtargetInfo() const
Definition MCSection.h:379
SMLoc getLoc() const
Definition MCSection.h:377
virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCSymbol &SymA, const MCFragment &FB, bool InSet, bool IsPCRel) const
bool getSubsectionsViaSymbols() const
virtual void executePostLayoutBinding()
Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...
virtual uint64_t writeObject()=0
Write the object file and returns the number of bytes written.
static void encodeFuncOffset(MCContext &C, uint64_t Offset, SmallVectorImpl< char > &Out, MCFragment *FDEFrag)
Definition MCSFrame.cpp:451
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:521
bool isBssSection() const
Check whether this section is "virtual", that is has no actual object file contents.
Definition MCSection.h:637
void dump(DenseMap< const MCFragment *, SmallVector< const MCSymbol *, 0 > > *FragToSyms=nullptr) const
Definition MCSection.cpp:36
void setOrdinal(unsigned Value)
Definition MCSection.h:614
FragList * curFragList() const
Definition MCSection.h:628
Generic base class for all target subtargets.
Represents a symbol table index fragment.
Definition MCSection.h:411
const MCSymbol * getSymbol()
Definition MCSection.h:417
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
bool isCommon() const
Is this a 'common' symbol.
Definition MCSymbol.h:344
StringRef getName() const
getName - Get the symbol name.
Definition MCSymbol.h:188
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition MCSymbol.h:267
uint32_t getIndex() const
Get the (implementation defined) index.
Definition MCSymbol.h:280
const MCExpr * getVariableValue() const
Get the expression of the variable symbol.
Definition MCSymbol.h:270
MCFragment * getFragment() const
Definition MCSymbol.h:346
uint64_t getOffset() const
Definition MCSymbol.h:289
const MCSymbol * getAddSym() const
Definition MCValue.h:49
int64_t getConstant() const
Definition MCValue.h:44
const MCSymbol * getSubSym() const
Definition MCValue.h:51
Represents a location in source code.
Definition SMLoc.h:23
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM_ABI std::string str() const
Return the twine contents as a std::string.
Definition Twine.cpp:17
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
uint64_t tell() const
tell - Return the current offset with the file.
raw_ostream & write(unsigned char C)
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ Tail
Attemps to make calls as fast as possible while guaranteeing that tail call optimization can always b...
Definition CallingConv.h:76
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
bool isRelocRelocation(MCFixupKind FixupKind)
Definition MCFixup.h:135
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
Definition Endian.h:92
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
Definition Error.cpp:177
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1712
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:167
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
uint64_t offsetToAlignment(uint64_t Value, Align Alignment)
Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...
Definition Alignment.h:197
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ Ref
The access may reference the value stored in memory.
Definition ModRef.h:32
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
@ Sub
Subtraction of integers.
@ Add
Sum of integers.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1847
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:565
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition LEB128.h:81
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition Alignment.h:208
endianness
Definition bit.h:71
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:180
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:851
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:85