LLVM  14.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 
9 #include "llvm/MC/MCAssembler.h"
10 #include "llvm/ADT/ArrayRef.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/ADT/Statistic.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/Twine.h"
16 #include "llvm/MC/MCAsmBackend.h"
17 #include "llvm/MC/MCAsmInfo.h"
18 #include "llvm/MC/MCAsmLayout.h"
19 #include "llvm/MC/MCCodeEmitter.h"
20 #include "llvm/MC/MCCodeView.h"
21 #include "llvm/MC/MCContext.h"
22 #include "llvm/MC/MCDwarf.h"
23 #include "llvm/MC/MCExpr.h"
24 #include "llvm/MC/MCFixup.h"
26 #include "llvm/MC/MCFragment.h"
27 #include "llvm/MC/MCInst.h"
28 #include "llvm/MC/MCObjectWriter.h"
29 #include "llvm/MC/MCSection.h"
30 #include "llvm/MC/MCSectionELF.h"
31 #include "llvm/MC/MCSymbol.h"
32 #include "llvm/MC/MCValue.h"
33 #include "llvm/Support/Alignment.h"
34 #include "llvm/Support/Casting.h"
35 #include "llvm/Support/Debug.h"
38 #include "llvm/Support/LEB128.h"
41 #include <cassert>
42 #include <cstdint>
43 #include <cstring>
44 #include <tuple>
45 #include <utility>
46 
47 using namespace llvm;
48 
49 #define DEBUG_TYPE "assembler"
50 
51 namespace {
52 namespace stats {
53 
54 STATISTIC(EmittedFragments, "Number of emitted assembler fragments - total");
55 STATISTIC(EmittedRelaxableFragments,
56  "Number of emitted assembler fragments - relaxable");
57 STATISTIC(EmittedDataFragments,
58  "Number of emitted assembler fragments - data");
59 STATISTIC(EmittedCompactEncodedInstFragments,
60  "Number of emitted assembler fragments - compact encoded inst");
61 STATISTIC(EmittedAlignFragments,
62  "Number of emitted assembler fragments - align");
63 STATISTIC(EmittedFillFragments,
64  "Number of emitted assembler fragments - fill");
65 STATISTIC(EmittedNopsFragments, "Number of emitted assembler fragments - nops");
66 STATISTIC(EmittedOrgFragments, "Number of emitted assembler fragments - org");
67 STATISTIC(evaluateFixup, "Number of evaluated fixups");
68 STATISTIC(FragmentLayouts, "Number of fragment layouts");
69 STATISTIC(ObjectBytes, "Number of emitted object file bytes");
70 STATISTIC(RelaxationSteps, "Number of assembler layout and relaxation steps");
71 STATISTIC(RelaxedInstructions, "Number of relaxed instructions");
72 
73 } // end namespace stats
74 } // end anonymous namespace
75 
76 // FIXME FIXME FIXME: There are number of places in this file where we convert
77 // what is a 64-bit assembler value used for computation into a value in the
78 // object file, which may truncate it. We should detect that truncation where
79 // invalid and report errors back.
80 
81 /* *** */
82 
84  std::unique_ptr<MCAsmBackend> Backend,
85  std::unique_ptr<MCCodeEmitter> Emitter,
86  std::unique_ptr<MCObjectWriter> Writer)
87  : Context(Context), Backend(std::move(Backend)),
88  Emitter(std::move(Emitter)), Writer(std::move(Writer)),
89  BundleAlignSize(0), RelaxAll(false), SubsectionsViaSymbols(false),
90  IncrementalLinkerCompatible(false), ELFHeaderEFlags(0) {
91  VersionInfo.Major = 0; // Major version == 0 for "none specified"
92  DarwinTargetVariantVersionInfo.Major = 0;
93 }
94 
95 MCAssembler::~MCAssembler() = default;
96 
98  Sections.clear();
99  Symbols.clear();
100  IndirectSymbols.clear();
101  DataRegions.clear();
102  LinkerOptions.clear();
103  FileNames.clear();
104  ThumbFuncs.clear();
105  BundleAlignSize = 0;
106  RelaxAll = false;
107  SubsectionsViaSymbols = false;
108  IncrementalLinkerCompatible = false;
109  ELFHeaderEFlags = 0;
110  LOHContainer.reset();
111  VersionInfo.Major = 0;
112  VersionInfo.SDKVersion = VersionTuple();
113  DarwinTargetVariantVersionInfo.Major = 0;
114  DarwinTargetVariantVersionInfo.SDKVersion = VersionTuple();
115 
116  // reset objects owned by us
117  if (getBackendPtr())
118  getBackendPtr()->reset();
119  if (getEmitterPtr())
120  getEmitterPtr()->reset();
121  if (getWriterPtr())
122  getWriterPtr()->reset();
124 }
125 
127  if (Section.isRegistered())
128  return false;
129  Sections.push_back(&Section);
130  Section.setIsRegistered(true);
131  return true;
132 }
133 
135  if (ThumbFuncs.count(Symbol))
136  return true;
137 
138  if (!Symbol->isVariable())
139  return false;
140 
141  const MCExpr *Expr = Symbol->getVariableValue();
142 
143  MCValue V;
144  if (!Expr->evaluateAsRelocatable(V, nullptr, nullptr))
145  return false;
146 
147  if (V.getSymB() || V.getRefKind() != MCSymbolRefExpr::VK_None)
148  return false;
149 
150  const MCSymbolRefExpr *Ref = V.getSymA();
151  if (!Ref)
152  return false;
153 
154  if (Ref->getKind() != MCSymbolRefExpr::VK_None)
155  return false;
156 
157  const MCSymbol &Sym = Ref->getSymbol();
158  if (!isThumbFunc(&Sym))
159  return false;
160 
161  ThumbFuncs.insert(Symbol); // Cache it.
162  return true;
163 }
164 
166  // Non-temporary labels should always be visible to the linker.
167  if (!Symbol.isTemporary())
168  return true;
169 
170  if (Symbol.isUsedInReloc())
171  return true;
172 
173  return false;
174 }
175 
176 const MCSymbol *MCAssembler::getAtom(const MCSymbol &S) const {
177  // Linker visible symbols define atoms.
179  return &S;
180 
181  // Absolute and undefined symbols have no defining atom.
182  if (!S.isInSection())
183  return nullptr;
184 
185  // Non-linker visible symbols in sections which can't be atomized have no
186  // defining atom.
187  if (!getContext().getAsmInfo()->isSectionAtomizableBySymbols(
188  *S.getFragment()->getParent()))
189  return nullptr;
190 
191  // Otherwise, return the atom for the containing fragment.
192  return S.getFragment()->getAtom();
193 }
194 
195 bool MCAssembler::evaluateFixup(const MCAsmLayout &Layout,
196  const MCFixup &Fixup, const MCFragment *DF,
198  bool &WasForced) const {
199  ++stats::evaluateFixup;
200 
201  // FIXME: This code has some duplication with recordRelocation. We should
202  // probably merge the two into a single callback that tries to evaluate a
203  // fixup and records a relocation if one is needed.
204 
205  // On error claim to have completely evaluated the fixup, to prevent any
206  // further processing from being done.
207  const MCExpr *Expr = Fixup.getValue();
208  MCContext &Ctx = getContext();
209  Value = 0;
210  WasForced = false;
211  if (!Expr->evaluateAsRelocatable(Target, &Layout, &Fixup)) {
212  Ctx.reportError(Fixup.getLoc(), "expected relocatable expression");
213  return true;
214  }
215  if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
216  if (RefB->getKind() != MCSymbolRefExpr::VK_None) {
217  Ctx.reportError(Fixup.getLoc(),
218  "unsupported subtraction of qualified symbol");
219  return true;
220  }
221  }
222 
223  assert(getBackendPtr() && "Expected assembler backend");
224  bool IsTarget = getBackendPtr()->getFixupKindInfo(Fixup.getKind()).Flags &
226 
227  if (IsTarget)
228  return getBackend().evaluateTargetFixup(*this, Layout, Fixup, DF, Target,
229  Value, WasForced);
230 
231  unsigned FixupFlags = getBackendPtr()->getFixupKindInfo(Fixup.getKind()).Flags;
232  bool IsPCRel = getBackendPtr()->getFixupKindInfo(Fixup.getKind()).Flags &
234 
235  bool IsResolved = false;
236  if (IsPCRel) {
237  if (Target.getSymB()) {
238  IsResolved = false;
239  } else if (!Target.getSymA()) {
240  IsResolved = false;
241  } else {
242  const MCSymbolRefExpr *A = Target.getSymA();
243  const MCSymbol &SA = A->getSymbol();
244  if (A->getKind() != MCSymbolRefExpr::VK_None || SA.isUndefined()) {
245  IsResolved = false;
246  } else if (auto *Writer = getWriterPtr()) {
247  IsResolved = (FixupFlags & MCFixupKindInfo::FKF_Constant) ||
248  Writer->isSymbolRefDifferenceFullyResolvedImpl(
249  *this, SA, *DF, false, true);
250  }
251  }
252  } else {
253  IsResolved = Target.isAbsolute();
254  }
255 
256  Value = Target.getConstant();
257 
258  if (const MCSymbolRefExpr *A = Target.getSymA()) {
259  const MCSymbol &Sym = A->getSymbol();
260  if (Sym.isDefined())
261  Value += Layout.getSymbolOffset(Sym);
262  }
263  if (const MCSymbolRefExpr *B = Target.getSymB()) {
264  const MCSymbol &Sym = B->getSymbol();
265  if (Sym.isDefined())
266  Value -= Layout.getSymbolOffset(Sym);
267  }
268 
269  bool ShouldAlignPC = getBackend().getFixupKindInfo(Fixup.getKind()).Flags &
271  assert((ShouldAlignPC ? IsPCRel : true) &&
272  "FKF_IsAlignedDownTo32Bits is only allowed on PC-relative fixups!");
273 
274  if (IsPCRel) {
275  uint32_t Offset = Layout.getFragmentOffset(DF) + Fixup.getOffset();
276 
277  // A number of ARM fixups in Thumb mode require that the effective PC
278  // address be determined as the 32-bit aligned version of the actual offset.
279  if (ShouldAlignPC) Offset &= ~0x3;
280  Value -= Offset;
281  }
282 
283  // Let the backend force a relocation if needed.
284  if (IsResolved && getBackend().shouldForceRelocation(*this, Fixup, Target)) {
285  IsResolved = false;
286  WasForced = true;
287  }
288 
289  return IsResolved;
290 }
291 
293  const MCFragment &F) const {
294  assert(getBackendPtr() && "Requires assembler backend");
295  switch (F.getKind()) {
296  case MCFragment::FT_Data:
297  return cast<MCDataFragment>(F).getContents().size();
299  return cast<MCRelaxableFragment>(F).getContents().size();
301  return cast<MCCompactEncodedInstFragment>(F).getContents().size();
302  case MCFragment::FT_Fill: {
303  auto &FF = cast<MCFillFragment>(F);
304  int64_t NumValues = 0;
305  if (!FF.getNumValues().evaluateAsAbsolute(NumValues, Layout)) {
306  getContext().reportError(FF.getLoc(),
307  "expected assembly-time absolute expression");
308  return 0;
309  }
310  int64_t Size = NumValues * FF.getValueSize();
311  if (Size < 0) {
312  getContext().reportError(FF.getLoc(), "invalid number of bytes");
313  return 0;
314  }
315  return Size;
316  }
317 
318  case MCFragment::FT_Nops:
319  return cast<MCNopsFragment>(F).getNumBytes();
320 
321  case MCFragment::FT_LEB:
322  return cast<MCLEBFragment>(F).getContents().size();
323 
325  return cast<MCBoundaryAlignFragment>(F).getSize();
326 
328  return 4;
329 
330  case MCFragment::FT_Align: {
331  const MCAlignFragment &AF = cast<MCAlignFragment>(F);
332  unsigned Offset = Layout.getFragmentOffset(&AF);
333  unsigned Size = offsetToAlignment(Offset, Align(AF.getAlignment()));
334 
335  // Insert extra Nops for code alignment if the target define
336  // shouldInsertExtraNopBytesForCodeAlign target hook.
337  if (AF.getParent()->UseCodeAlign() && AF.hasEmitNops() &&
338  getBackend().shouldInsertExtraNopBytesForCodeAlign(AF, Size))
339  return Size;
340 
341  // If we are padding with nops, force the padding to be larger than the
342  // minimum nop size.
343  if (Size > 0 && AF.hasEmitNops()) {
344  while (Size % getBackend().getMinimumNopSize())
345  Size += AF.getAlignment();
346  }
347  if (Size > AF.getMaxBytesToEmit())
348  return 0;
349  return Size;
350  }
351 
352  case MCFragment::FT_Org: {
353  const MCOrgFragment &OF = cast<MCOrgFragment>(F);
354  MCValue Value;
355  if (!OF.getOffset().evaluateAsValue(Value, Layout)) {
357  "expected assembly-time absolute expression");
358  return 0;
359  }
360 
361  uint64_t FragmentOffset = Layout.getFragmentOffset(&OF);
362  int64_t TargetLocation = Value.getConstant();
363  if (const MCSymbolRefExpr *A = Value.getSymA()) {
364  uint64_t Val;
365  if (!Layout.getSymbolOffset(A->getSymbol(), Val)) {
366  getContext().reportError(OF.getLoc(), "expected absolute expression");
367  return 0;
368  }
369  TargetLocation += Val;
370  }
371  int64_t Size = TargetLocation - FragmentOffset;
372  if (Size < 0 || Size >= 0x40000000) {
374  OF.getLoc(), "invalid .org offset '" + Twine(TargetLocation) +
375  "' (at offset '" + Twine(FragmentOffset) + "')");
376  return 0;
377  }
378  return Size;
379  }
380 
382  return cast<MCDwarfLineAddrFragment>(F).getContents().size();
384  return cast<MCDwarfCallFrameFragment>(F).getContents().size();
386  return cast<MCCVInlineLineTableFragment>(F).getContents().size();
388  return cast<MCCVDefRangeFragment>(F).getContents().size();
390  return cast<MCPseudoProbeAddrFragment>(F).getContents().size();
392  llvm_unreachable("Should not have been added");
393  }
394 
395  llvm_unreachable("invalid fragment kind");
396 }
397 
399  MCFragment *Prev = F->getPrevNode();
400 
401  // We should never try to recompute something which is valid.
402  assert(!isFragmentValid(F) && "Attempt to recompute a valid fragment!");
403  // We should never try to compute the fragment layout if its predecessor
404  // isn't valid.
405  assert((!Prev || isFragmentValid(Prev)) &&
406  "Attempt to compute fragment before its predecessor!");
407 
408  assert(!F->IsBeingLaidOut && "Already being laid out!");
409  F->IsBeingLaidOut = true;
410 
411  ++stats::FragmentLayouts;
412 
413  // Compute fragment offset and size.
414  if (Prev)
415  F->Offset = Prev->Offset + getAssembler().computeFragmentSize(*this, *Prev);
416  else
417  F->Offset = 0;
418  F->IsBeingLaidOut = false;
419  LastValidFragment[F->getParent()] = F;
420 
421  // If bundling is enabled and this fragment has instructions in it, it has to
422  // obey the bundling restrictions. With padding, we'll have:
423  //
424  //
425  // BundlePadding
426  // |||
427  // -------------------------------------
428  // Prev |##########| F |
429  // -------------------------------------
430  // ^
431  // |
432  // F->Offset
433  //
434  // The fragment's offset will point to after the padding, and its computed
435  // size won't include the padding.
436  //
437  // When the -mc-relax-all flag is used, we optimize bundling by writting the
438  // padding directly into fragments when the instructions are emitted inside
439  // the streamer. When the fragment is larger than the bundle size, we need to
440  // ensure that it's bundle aligned. This means that if we end up with
441  // multiple fragments, we must emit bundle padding between fragments.
442  //
443  // ".align N" is an example of a directive that introduces multiple
444  // fragments. We could add a special case to handle ".align N" by emitting
445  // within-fragment padding (which would produce less padding when N is less
446  // than the bundle size), but for now we don't.
447  //
448  if (Assembler.isBundlingEnabled() && F->hasInstructions()) {
449  assert(isa<MCEncodedFragment>(F) &&
450  "Only MCEncodedFragment implementations have instructions");
451  MCEncodedFragment *EF = cast<MCEncodedFragment>(F);
452  uint64_t FSize = Assembler.computeFragmentSize(*this, *EF);
453 
454  if (!Assembler.getRelaxAll() && FSize > Assembler.getBundleAlignSize())
455  report_fatal_error("Fragment can't be larger than a bundle size");
456 
457  uint64_t RequiredBundlePadding =
458  computeBundlePadding(Assembler, EF, EF->Offset, FSize);
459  if (RequiredBundlePadding > UINT8_MAX)
460  report_fatal_error("Padding cannot exceed 255 bytes");
461  EF->setBundlePadding(static_cast<uint8_t>(RequiredBundlePadding));
462  EF->Offset += RequiredBundlePadding;
463  }
464 }
465 
466 void MCAssembler::registerSymbol(const MCSymbol &Symbol, bool *Created) {
467  bool New = !Symbol.isRegistered();
468  if (Created)
469  *Created = New;
470  if (New) {
471  Symbol.setIsRegistered(true);
472  Symbols.push_back(&Symbol);
473  }
474 }
475 
477  const MCEncodedFragment &EF,
478  uint64_t FSize) const {
479  assert(getBackendPtr() && "Expected assembler backend");
480  // Should NOP padding be written out before this fragment?
481  unsigned BundlePadding = EF.getBundlePadding();
482  if (BundlePadding > 0) {
484  "Writing bundle padding with disabled bundling");
485  assert(EF.hasInstructions() &&
486  "Writing bundle padding for a fragment without instructions");
487 
488  unsigned TotalLength = BundlePadding + static_cast<unsigned>(FSize);
489  const MCSubtargetInfo *STI = EF.getSubtargetInfo();
490  if (EF.alignToBundleEnd() && TotalLength > getBundleAlignSize()) {
491  // If the padding itself crosses a bundle boundary, it must be emitted
492  // in 2 pieces, since even nop instructions must not cross boundaries.
493  // v--------------v <- BundleAlignSize
494  // v---------v <- BundlePadding
495  // ----------------------------
496  // | Prev |####|####| F |
497  // ----------------------------
498  // ^-------------------^ <- TotalLength
499  unsigned DistanceToBoundary = TotalLength - getBundleAlignSize();
500  if (!getBackend().writeNopData(OS, DistanceToBoundary, STI))
501  report_fatal_error("unable to write NOP sequence of " +
502  Twine(DistanceToBoundary) + " bytes");
503  BundlePadding -= DistanceToBoundary;
504  }
505  if (!getBackend().writeNopData(OS, BundlePadding, STI))
506  report_fatal_error("unable to write NOP sequence of " +
507  Twine(BundlePadding) + " bytes");
508  }
509 }
510 
511 /// Write the fragment \p F to the output file.
512 static void writeFragment(raw_ostream &OS, const MCAssembler &Asm,
513  const MCAsmLayout &Layout, const MCFragment &F) {
514  // FIXME: Embed in fragments instead?
515  uint64_t FragmentSize = Asm.computeFragmentSize(Layout, F);
516 
517  support::endianness Endian = Asm.getBackend().Endian;
518 
519  if (const MCEncodedFragment *EF = dyn_cast<MCEncodedFragment>(&F))
520  Asm.writeFragmentPadding(OS, *EF, FragmentSize);
521 
522  // This variable (and its dummy usage) is to participate in the assert at
523  // the end of the function.
524  uint64_t Start = OS.tell();
525  (void) Start;
526 
527  ++stats::EmittedFragments;
528 
529  switch (F.getKind()) {
530  case MCFragment::FT_Align: {
531  ++stats::EmittedAlignFragments;
532  const MCAlignFragment &AF = cast<MCAlignFragment>(F);
533  assert(AF.getValueSize() && "Invalid virtual align in concrete fragment!");
534 
535  uint64_t Count = FragmentSize / AF.getValueSize();
536 
537  // FIXME: This error shouldn't actually occur (the front end should emit
538  // multiple .align directives to enforce the semantics it wants), but is
539  // severe enough that we want to report it. How to handle this?
540  if (Count * AF.getValueSize() != FragmentSize)
541  report_fatal_error("undefined .align directive, value size '" +
542  Twine(AF.getValueSize()) +
543  "' is not a divisor of padding size '" +
544  Twine(FragmentSize) + "'");
545 
546  // See if we are aligning with nops, and if so do that first to try to fill
547  // the Count bytes. Then if that did not fill any bytes or there are any
548  // bytes left to fill use the Value and ValueSize to fill the rest.
549  // If we are aligning with nops, ask that target to emit the right data.
550  if (AF.hasEmitNops()) {
551  if (!Asm.getBackend().writeNopData(OS, Count, AF.getSubtargetInfo()))
552  report_fatal_error("unable to write nop sequence of " +
553  Twine(Count) + " bytes");
554  break;
555  }
556 
557  // Otherwise, write out in multiples of the value size.
558  for (uint64_t i = 0; i != Count; ++i) {
559  switch (AF.getValueSize()) {
560  default: llvm_unreachable("Invalid size!");
561  case 1: OS << char(AF.getValue()); break;
562  case 2:
563  support::endian::write<uint16_t>(OS, AF.getValue(), Endian);
564  break;
565  case 4:
566  support::endian::write<uint32_t>(OS, AF.getValue(), Endian);
567  break;
568  case 8:
569  support::endian::write<uint64_t>(OS, AF.getValue(), Endian);
570  break;
571  }
572  }
573  break;
574  }
575 
576  case MCFragment::FT_Data:
577  ++stats::EmittedDataFragments;
578  OS << cast<MCDataFragment>(F).getContents();
579  break;
580 
582  ++stats::EmittedRelaxableFragments;
583  OS << cast<MCRelaxableFragment>(F).getContents();
584  break;
585 
587  ++stats::EmittedCompactEncodedInstFragments;
588  OS << cast<MCCompactEncodedInstFragment>(F).getContents();
589  break;
590 
591  case MCFragment::FT_Fill: {
592  ++stats::EmittedFillFragments;
593  const MCFillFragment &FF = cast<MCFillFragment>(F);
594  uint64_t V = FF.getValue();
595  unsigned VSize = FF.getValueSize();
596  const unsigned MaxChunkSize = 16;
597  char Data[MaxChunkSize];
598  assert(0 < VSize && VSize <= MaxChunkSize && "Illegal fragment fill size");
599  // Duplicate V into Data as byte vector to reduce number of
600  // writes done. As such, do endian conversion here.
601  for (unsigned I = 0; I != VSize; ++I) {
602  unsigned index = Endian == support::little ? I : (VSize - I - 1);
603  Data[I] = uint8_t(V >> (index * 8));
604  }
605  for (unsigned I = VSize; I < MaxChunkSize; ++I)
606  Data[I] = Data[I - VSize];
607 
608  // Set to largest multiple of VSize in Data.
609  const unsigned NumPerChunk = MaxChunkSize / VSize;
610  // Set ChunkSize to largest multiple of VSize in Data
611  const unsigned ChunkSize = VSize * NumPerChunk;
612 
613  // Do copies by chunk.
614  StringRef Ref(Data, ChunkSize);
615  for (uint64_t I = 0, E = FragmentSize / ChunkSize; I != E; ++I)
616  OS << Ref;
617 
618  // do remainder if needed.
619  unsigned TrailingCount = FragmentSize % ChunkSize;
620  if (TrailingCount)
621  OS.write(Data, TrailingCount);
622  break;
623  }
624 
625  case MCFragment::FT_Nops: {
626  ++stats::EmittedNopsFragments;
627  const MCNopsFragment &NF = cast<MCNopsFragment>(F);
628 
629  int64_t NumBytes = NF.getNumBytes();
630  int64_t ControlledNopLength = NF.getControlledNopLength();
631  int64_t MaximumNopLength =
632  Asm.getBackend().getMaximumNopSize(*NF.getSubtargetInfo());
633 
634  assert(NumBytes > 0 && "Expected positive NOPs fragment size");
635  assert(ControlledNopLength >= 0 && "Expected non-negative NOP size");
636 
637  if (ControlledNopLength > MaximumNopLength) {
638  Asm.getContext().reportError(NF.getLoc(),
639  "illegal NOP size " +
640  std::to_string(ControlledNopLength) +
641  ". (expected within [0, " +
642  std::to_string(MaximumNopLength) + "])");
643  // Clamp the NOP length as reportError does not stop the execution
644  // immediately.
645  ControlledNopLength = MaximumNopLength;
646  }
647 
648  // Use maximum value if the size of each NOP is not specified
649  if (!ControlledNopLength)
650  ControlledNopLength = MaximumNopLength;
651 
652  while (NumBytes) {
653  uint64_t NumBytesToEmit =
654  (uint64_t)std::min(NumBytes, ControlledNopLength);
655  assert(NumBytesToEmit && "try to emit empty NOP instruction");
656  if (!Asm.getBackend().writeNopData(OS, NumBytesToEmit,
657  NF.getSubtargetInfo())) {
658  report_fatal_error("unable to write nop sequence of the remaining " +
659  Twine(NumBytesToEmit) + " bytes");
660  break;
661  }
662  NumBytes -= NumBytesToEmit;
663  }
664  break;
665  }
666 
667  case MCFragment::FT_LEB: {
668  const MCLEBFragment &LF = cast<MCLEBFragment>(F);
669  OS << LF.getContents();
670  break;
671  }
672 
674  const MCBoundaryAlignFragment &BF = cast<MCBoundaryAlignFragment>(F);
675  if (!Asm.getBackend().writeNopData(OS, FragmentSize, BF.getSubtargetInfo()))
676  report_fatal_error("unable to write nop sequence of " +
677  Twine(FragmentSize) + " bytes");
678  break;
679  }
680 
682  const MCSymbolIdFragment &SF = cast<MCSymbolIdFragment>(F);
683  support::endian::write<uint32_t>(OS, SF.getSymbol()->getIndex(), Endian);
684  break;
685  }
686 
687  case MCFragment::FT_Org: {
688  ++stats::EmittedOrgFragments;
689  const MCOrgFragment &OF = cast<MCOrgFragment>(F);
690 
691  for (uint64_t i = 0, e = FragmentSize; i != e; ++i)
692  OS << char(OF.getValue());
693 
694  break;
695  }
696 
697  case MCFragment::FT_Dwarf: {
698  const MCDwarfLineAddrFragment &OF = cast<MCDwarfLineAddrFragment>(F);
699  OS << OF.getContents();
700  break;
701  }
703  const MCDwarfCallFrameFragment &CF = cast<MCDwarfCallFrameFragment>(F);
704  OS << CF.getContents();
705  break;
706  }
708  const auto &OF = cast<MCCVInlineLineTableFragment>(F);
709  OS << OF.getContents();
710  break;
711  }
713  const auto &DRF = cast<MCCVDefRangeFragment>(F);
714  OS << DRF.getContents();
715  break;
716  }
718  const MCPseudoProbeAddrFragment &PF = cast<MCPseudoProbeAddrFragment>(F);
719  OS << PF.getContents();
720  break;
721  }
723  llvm_unreachable("Should not have been added");
724  }
725 
726  assert(OS.tell() - Start == FragmentSize &&
727  "The stream should advance by fragment size");
728 }
729 
731  const MCAsmLayout &Layout) const {
732  assert(getBackendPtr() && "Expected assembler backend");
733 
734  // Ignore virtual sections.
735  if (Sec->isVirtualSection()) {
736  assert(Layout.getSectionFileSize(Sec) == 0 && "Invalid size for section!");
737 
738  // Check that contents are only things legal inside a virtual section.
739  for (const MCFragment &F : *Sec) {
740  switch (F.getKind()) {
741  default: llvm_unreachable("Invalid fragment in virtual section!");
742  case MCFragment::FT_Data: {
743  // Check that we aren't trying to write a non-zero contents (or fixups)
744  // into a virtual section. This is to support clients which use standard
745  // directives to fill the contents of virtual sections.
746  const MCDataFragment &DF = cast<MCDataFragment>(F);
747  if (DF.fixup_begin() != DF.fixup_end())
748  getContext().reportError(SMLoc(), Sec->getVirtualSectionKind() +
749  " section '" + Sec->getName() +
750  "' cannot have fixups");
751  for (unsigned i = 0, e = DF.getContents().size(); i != e; ++i)
752  if (DF.getContents()[i]) {
754  Sec->getVirtualSectionKind() +
755  " section '" + Sec->getName() +
756  "' cannot have non-zero initializers");
757  break;
758  }
759  break;
760  }
762  // Check that we aren't trying to write a non-zero value into a virtual
763  // section.
764  assert((cast<MCAlignFragment>(F).getValueSize() == 0 ||
765  cast<MCAlignFragment>(F).getValue() == 0) &&
766  "Invalid align in virtual section!");
767  break;
768  case MCFragment::FT_Fill:
769  assert((cast<MCFillFragment>(F).getValue() == 0) &&
770  "Invalid fill in virtual section!");
771  break;
772  case MCFragment::FT_Org:
773  break;
774  }
775  }
776 
777  return;
778  }
779 
780  uint64_t Start = OS.tell();
781  (void)Start;
782 
783  for (const MCFragment &F : *Sec)
784  writeFragment(OS, *this, Layout, F);
785 
786  assert(getContext().hadError() ||
787  OS.tell() - Start == Layout.getSectionAddressSize(Sec));
788 }
789 
790 std::tuple<MCValue, uint64_t, bool>
791 MCAssembler::handleFixup(const MCAsmLayout &Layout, MCFragment &F,
792  const MCFixup &Fixup) {
793  // Evaluate the fixup.
794  MCValue Target;
795  uint64_t FixedValue;
796  bool WasForced;
797  bool IsResolved = evaluateFixup(Layout, Fixup, &F, Target, FixedValue,
798  WasForced);
799  if (!IsResolved) {
800  // The fixup was unresolved, we need a relocation. Inform the object
801  // writer of the relocation, and give it an opportunity to adjust the
802  // fixup value if need be.
803  getWriter().recordRelocation(*this, Layout, &F, Fixup, Target, FixedValue);
804  }
805  return std::make_tuple(Target, FixedValue, IsResolved);
806 }
807 
809  assert(getBackendPtr() && "Expected assembler backend");
810  DEBUG_WITH_TYPE("mc-dump", {
811  errs() << "assembler backend - pre-layout\n--\n";
812  dump(); });
813 
814  // Create dummy fragments and assign section ordinals.
815  unsigned SectionIndex = 0;
816  for (MCSection &Sec : *this) {
817  // Create dummy fragments to eliminate any empty sections, this simplifies
818  // layout.
819  if (Sec.getFragmentList().empty())
820  new MCDataFragment(&Sec);
821 
822  Sec.setOrdinal(SectionIndex++);
823  }
824 
825  // Assign layout order indices to sections and fragments.
826  for (unsigned i = 0, e = Layout.getSectionOrder().size(); i != e; ++i) {
827  MCSection *Sec = Layout.getSectionOrder()[i];
828  Sec->setLayoutOrder(i);
829 
830  unsigned FragmentIndex = 0;
831  for (MCFragment &Frag : *Sec)
832  Frag.setLayoutOrder(FragmentIndex++);
833  }
834 
835  // Layout until everything fits.
836  while (layoutOnce(Layout)) {
837  if (getContext().hadError())
838  return;
839  // Size of fragments in one section can depend on the size of fragments in
840  // another. If any fragment has changed size, we have to re-layout (and
841  // as a result possibly further relax) all.
842  for (MCSection &Sec : *this)
843  Layout.invalidateFragmentsFrom(&*Sec.begin());
844  }
845 
846  DEBUG_WITH_TYPE("mc-dump", {
847  errs() << "assembler backend - post-relaxation\n--\n";
848  dump(); });
849 
850  // Finalize the layout, including fragment lowering.
851  finishLayout(Layout);
852 
853  DEBUG_WITH_TYPE("mc-dump", {
854  errs() << "assembler backend - final-layout\n--\n";
855  dump(); });
856 
857  // Allow the object writer a chance to perform post-layout binding (for
858  // example, to set the index fields in the symbol data).
859  getWriter().executePostLayoutBinding(*this, Layout);
860 
861  // Evaluate and apply the fixups, generating relocation entries as necessary.
862  for (MCSection &Sec : *this) {
863  for (MCFragment &Frag : Sec) {
865  MutableArrayRef<char> Contents;
866  const MCSubtargetInfo *STI = nullptr;
867 
868  // Process MCAlignFragment and MCEncodedFragmentWithFixups here.
869  switch (Frag.getKind()) {
870  default:
871  continue;
872  case MCFragment::FT_Align: {
873  MCAlignFragment &AF = cast<MCAlignFragment>(Frag);
874  // Insert fixup type for code alignment if the target define
875  // shouldInsertFixupForCodeAlign target hook.
876  if (Sec.UseCodeAlign() && AF.hasEmitNops())
877  getBackend().shouldInsertFixupForCodeAlign(*this, Layout, AF);
878  continue;
879  }
880  case MCFragment::FT_Data: {
881  MCDataFragment &DF = cast<MCDataFragment>(Frag);
882  Fixups = DF.getFixups();
883  Contents = DF.getContents();
884  STI = DF.getSubtargetInfo();
885  assert(!DF.hasInstructions() || STI != nullptr);
886  break;
887  }
889  MCRelaxableFragment &RF = cast<MCRelaxableFragment>(Frag);
890  Fixups = RF.getFixups();
891  Contents = RF.getContents();
892  STI = RF.getSubtargetInfo();
893  assert(!RF.hasInstructions() || STI != nullptr);
894  break;
895  }
897  MCCVDefRangeFragment &CF = cast<MCCVDefRangeFragment>(Frag);
898  Fixups = CF.getFixups();
899  Contents = CF.getContents();
900  break;
901  }
902  case MCFragment::FT_Dwarf: {
903  MCDwarfLineAddrFragment &DF = cast<MCDwarfLineAddrFragment>(Frag);
904  Fixups = DF.getFixups();
905  Contents = DF.getContents();
906  break;
907  }
909  MCDwarfCallFrameFragment &DF = cast<MCDwarfCallFrameFragment>(Frag);
910  Fixups = DF.getFixups();
911  Contents = DF.getContents();
912  break;
913  }
915  MCPseudoProbeAddrFragment &PF = cast<MCPseudoProbeAddrFragment>(Frag);
916  Fixups = PF.getFixups();
917  Contents = PF.getContents();
918  break;
919  }
920  }
921  for (const MCFixup &Fixup : Fixups) {
922  uint64_t FixedValue;
923  bool IsResolved;
924  MCValue Target;
925  std::tie(Target, FixedValue, IsResolved) =
926  handleFixup(Layout, Frag, Fixup);
927  getBackend().applyFixup(*this, Fixup, Target, Contents, FixedValue,
928  IsResolved, STI);
929  }
930  }
931  }
932 }
933 
935  // Create the layout object.
936  MCAsmLayout Layout(*this);
937  layout(Layout);
938 
939  // Write the object file.
940  stats::ObjectBytes += getWriter().writeObject(*this, Layout);
941 }
942 
943 bool MCAssembler::fixupNeedsRelaxation(const MCFixup &Fixup,
944  const MCRelaxableFragment *DF,
945  const MCAsmLayout &Layout) const {
946  assert(getBackendPtr() && "Expected assembler backend");
947  MCValue Target;
948  uint64_t Value;
949  bool WasForced;
950  bool Resolved = evaluateFixup(Layout, Fixup, DF, Target, Value, WasForced);
951  if (Target.getSymA() &&
952  Target.getSymA()->getKind() == MCSymbolRefExpr::VK_X86_ABS8 &&
953  Fixup.getKind() == FK_Data_1)
954  return false;
955  return getBackend().fixupNeedsRelaxationAdvanced(Fixup, Resolved, Value, DF,
956  Layout, WasForced);
957 }
958 
959 bool MCAssembler::fragmentNeedsRelaxation(const MCRelaxableFragment *F,
960  const MCAsmLayout &Layout) const {
961  assert(getBackendPtr() && "Expected assembler backend");
962  // If this inst doesn't ever need relaxation, ignore it. This occurs when we
963  // are intentionally pushing out inst fragments, or because we relaxed a
964  // previous instruction to one that doesn't need relaxation.
965  if (!getBackend().mayNeedRelaxation(F->getInst(), *F->getSubtargetInfo()))
966  return false;
967 
968  for (const MCFixup &Fixup : F->getFixups())
969  if (fixupNeedsRelaxation(Fixup, F, Layout))
970  return true;
971 
972  return false;
973 }
974 
975 bool MCAssembler::relaxInstruction(MCAsmLayout &Layout,
977  assert(getEmitterPtr() &&
978  "Expected CodeEmitter defined for relaxInstruction");
979  if (!fragmentNeedsRelaxation(&F, Layout))
980  return false;
981 
982  ++stats::RelaxedInstructions;
983 
984  // FIXME-PERF: We could immediately lower out instructions if we can tell
985  // they are fully resolved, to avoid retesting on later passes.
986 
987  // Relax the fragment.
988 
989  MCInst Relaxed = F.getInst();
990  getBackend().relaxInstruction(Relaxed, *F.getSubtargetInfo());
991 
992  // Encode the new instruction.
993  //
994  // FIXME-PERF: If it matters, we could let the target do this. It can
995  // probably do so more efficiently in many cases.
998  raw_svector_ostream VecOS(Code);
999  getEmitter().encodeInstruction(Relaxed, VecOS, Fixups, *F.getSubtargetInfo());
1000 
1001  // Update the fragment.
1002  F.setInst(Relaxed);
1003  F.getContents() = Code;
1004  F.getFixups() = Fixups;
1005 
1006  return true;
1007 }
1008 
1009 bool MCAssembler::relaxLEB(MCAsmLayout &Layout, MCLEBFragment &LF) {
1010  uint64_t OldSize = LF.getContents().size();
1011  int64_t Value;
1012  bool Abs = LF.getValue().evaluateKnownAbsolute(Value, Layout);
1013  if (!Abs)
1014  report_fatal_error("sleb128 and uleb128 expressions must be absolute");
1016  Data.clear();
1018  // The compiler can generate EH table assembly that is impossible to assemble
1019  // without either adding padding to an LEB fragment or adding extra padding
1020  // to a later alignment fragment. To accommodate such tables, relaxation can
1021  // only increase an LEB fragment size here, not decrease it. See PR35809.
1022  if (LF.isSigned())
1023  encodeSLEB128(Value, OSE, OldSize);
1024  else
1025  encodeULEB128(Value, OSE, OldSize);
1026  return OldSize != LF.getContents().size();
1027 }
1028 
1029 /// Check if the branch crosses the boundary.
1030 ///
1031 /// \param StartAddr start address of the fused/unfused branch.
1032 /// \param Size size of the fused/unfused branch.
1033 /// \param BoundaryAlignment alignment requirement of the branch.
1034 /// \returns true if the branch cross the boundary.
1035 static bool mayCrossBoundary(uint64_t StartAddr, uint64_t Size,
1036  Align BoundaryAlignment) {
1037  uint64_t EndAddr = StartAddr + Size;
1038  return (StartAddr >> Log2(BoundaryAlignment)) !=
1039  ((EndAddr - 1) >> Log2(BoundaryAlignment));
1040 }
1041 
1042 /// Check if the branch is against the boundary.
1043 ///
1044 /// \param StartAddr start address of the fused/unfused branch.
1045 /// \param Size size of the fused/unfused branch.
1046 /// \param BoundaryAlignment alignment requirement of the branch.
1047 /// \returns true if the branch is against the boundary.
1048 static bool isAgainstBoundary(uint64_t StartAddr, uint64_t Size,
1049  Align BoundaryAlignment) {
1050  uint64_t EndAddr = StartAddr + Size;
1051  return (EndAddr & (BoundaryAlignment.value() - 1)) == 0;
1052 }
1053 
1054 /// Check if the branch needs padding.
1055 ///
1056 /// \param StartAddr start address of the fused/unfused branch.
1057 /// \param Size size of the fused/unfused branch.
1058 /// \param BoundaryAlignment alignment requirement of the branch.
1059 /// \returns true if the branch needs padding.
1060 static bool needPadding(uint64_t StartAddr, uint64_t Size,
1061  Align BoundaryAlignment) {
1062  return mayCrossBoundary(StartAddr, Size, BoundaryAlignment) ||
1063  isAgainstBoundary(StartAddr, Size, BoundaryAlignment);
1064 }
1065 
1066 bool MCAssembler::relaxBoundaryAlign(MCAsmLayout &Layout,
1068  // BoundaryAlignFragment that doesn't need to align any fragment should not be
1069  // relaxed.
1070  if (!BF.getLastFragment())
1071  return false;
1072 
1073  uint64_t AlignedOffset = Layout.getFragmentOffset(&BF);
1074  uint64_t AlignedSize = 0;
1075  for (const MCFragment *F = BF.getLastFragment(); F != &BF;
1076  F = F->getPrevNode())
1077  AlignedSize += computeFragmentSize(Layout, *F);
1078 
1079  Align BoundaryAlignment = BF.getAlignment();
1080  uint64_t NewSize = needPadding(AlignedOffset, AlignedSize, BoundaryAlignment)
1081  ? offsetToAlignment(AlignedOffset, BoundaryAlignment)
1082  : 0U;
1083  if (NewSize == BF.getSize())
1084  return false;
1085  BF.setSize(NewSize);
1086  Layout.invalidateFragmentsFrom(&BF);
1087  return true;
1088 }
1089 
1090 bool MCAssembler::relaxDwarfLineAddr(MCAsmLayout &Layout,
1092 
1093  bool WasRelaxed;
1094  if (getBackend().relaxDwarfLineAddr(DF, Layout, WasRelaxed))
1095  return WasRelaxed;
1096 
1097  MCContext &Context = Layout.getAssembler().getContext();
1098  uint64_t OldSize = DF.getContents().size();
1099  int64_t AddrDelta;
1100  bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
1101  assert(Abs && "We created a line delta with an invalid expression");
1102  (void)Abs;
1103  int64_t LineDelta;
1104  LineDelta = DF.getLineDelta();
1105  SmallVectorImpl<char> &Data = DF.getContents();
1106  Data.clear();
1108  DF.getFixups().clear();
1109 
1110  MCDwarfLineAddr::Encode(Context, getDWARFLinetableParams(), LineDelta,
1111  AddrDelta, OSE);
1112  return OldSize != Data.size();
1113 }
1114 
1115 bool MCAssembler::relaxDwarfCallFrameFragment(MCAsmLayout &Layout,
1117  bool WasRelaxed;
1118  if (getBackend().relaxDwarfCFA(DF, Layout, WasRelaxed))
1119  return WasRelaxed;
1120 
1121  MCContext &Context = Layout.getAssembler().getContext();
1122  uint64_t OldSize = DF.getContents().size();
1123  int64_t AddrDelta;
1124  bool Abs = DF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
1125  assert(Abs && "We created call frame with an invalid expression");
1126  (void) Abs;
1127  SmallVectorImpl<char> &Data = DF.getContents();
1128  Data.clear();
1130  DF.getFixups().clear();
1131 
1132  MCDwarfFrameEmitter::EncodeAdvanceLoc(Context, AddrDelta, OSE);
1133  return OldSize != Data.size();
1134 }
1135 
1136 bool MCAssembler::relaxCVInlineLineTable(MCAsmLayout &Layout,
1138  unsigned OldSize = F.getContents().size();
1140  return OldSize != F.getContents().size();
1141 }
1142 
1143 bool MCAssembler::relaxCVDefRange(MCAsmLayout &Layout,
1145  unsigned OldSize = F.getContents().size();
1146  getContext().getCVContext().encodeDefRange(Layout, F);
1147  return OldSize != F.getContents().size();
1148 }
1149 
1150 bool MCAssembler::relaxPseudoProbeAddr(MCAsmLayout &Layout,
1152  uint64_t OldSize = PF.getContents().size();
1153  int64_t AddrDelta;
1154  bool Abs = PF.getAddrDelta().evaluateKnownAbsolute(AddrDelta, Layout);
1155  assert(Abs && "We created a pseudo probe with an invalid expression");
1156  (void)Abs;
1158  Data.clear();
1160  PF.getFixups().clear();
1161 
1162  // AddrDelta is a signed integer
1163  encodeSLEB128(AddrDelta, OSE, OldSize);
1164  return OldSize != Data.size();
1165 }
1166 
1167 bool MCAssembler::relaxFragment(MCAsmLayout &Layout, MCFragment &F) {
1168  switch(F.getKind()) {
1169  default:
1170  return false;
1172  assert(!getRelaxAll() &&
1173  "Did not expect a MCRelaxableFragment in RelaxAll mode");
1174  return relaxInstruction(Layout, cast<MCRelaxableFragment>(F));
1175  case MCFragment::FT_Dwarf:
1176  return relaxDwarfLineAddr(Layout, cast<MCDwarfLineAddrFragment>(F));
1178  return relaxDwarfCallFrameFragment(Layout,
1179  cast<MCDwarfCallFrameFragment>(F));
1180  case MCFragment::FT_LEB:
1181  return relaxLEB(Layout, cast<MCLEBFragment>(F));
1183  return relaxBoundaryAlign(Layout, cast<MCBoundaryAlignFragment>(F));
1185  return relaxCVInlineLineTable(Layout, cast<MCCVInlineLineTableFragment>(F));
1187  return relaxCVDefRange(Layout, cast<MCCVDefRangeFragment>(F));
1189  return relaxPseudoProbeAddr(Layout, cast<MCPseudoProbeAddrFragment>(F));
1190  }
1191 }
1192 
1193 bool MCAssembler::layoutSectionOnce(MCAsmLayout &Layout, MCSection &Sec) {
1194  // Holds the first fragment which needed relaxing during this layout. It will
1195  // remain NULL if none were relaxed.
1196  // When a fragment is relaxed, all the fragments following it should get
1197  // invalidated because their offset is going to change.
1198  MCFragment *FirstRelaxedFragment = nullptr;
1199 
1200  // Attempt to relax all the fragments in the section.
1201  for (MCFragment &Frag : Sec) {
1202  // Check if this is a fragment that needs relaxation.
1203  bool RelaxedFrag = relaxFragment(Layout, Frag);
1204  if (RelaxedFrag && !FirstRelaxedFragment)
1205  FirstRelaxedFragment = &Frag;
1206  }
1207  if (FirstRelaxedFragment) {
1208  Layout.invalidateFragmentsFrom(FirstRelaxedFragment);
1209  return true;
1210  }
1211  return false;
1212 }
1213 
1214 bool MCAssembler::layoutOnce(MCAsmLayout &Layout) {
1215  ++stats::RelaxationSteps;
1216 
1217  bool WasRelaxed = false;
1218  for (MCSection &Sec : *this) {
1219  while (layoutSectionOnce(Layout, Sec))
1220  WasRelaxed = true;
1221  }
1222 
1223  return WasRelaxed;
1224 }
1225 
1226 void MCAssembler::finishLayout(MCAsmLayout &Layout) {
1227  assert(getBackendPtr() && "Expected assembler backend");
1228  // The layout is done. Mark every fragment as valid.
1229  for (unsigned int i = 0, n = Layout.getSectionOrder().size(); i != n; ++i) {
1230  MCSection &Section = *Layout.getSectionOrder()[i];
1231  Layout.getFragmentOffset(&*Section.getFragmentList().rbegin());
1232  computeFragmentSize(Layout, *Section.getFragmentList().rbegin());
1233  }
1234  getBackend().finishLayout(*this, Layout);
1235 }
1236 
1237 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
1239  raw_ostream &OS = errs();
1240 
1241  OS << "<MCAssembler\n";
1242  OS << " Sections:[\n ";
1243  for (const_iterator it = begin(), ie = end(); it != ie; ++it) {
1244  if (it != begin()) OS << ",\n ";
1245  it->dump();
1246  }
1247  OS << "],\n";
1248  OS << " Symbols:[";
1249 
1250  for (const_symbol_iterator it = symbol_begin(), ie = symbol_end(); it != ie; ++it) {
1251  if (it != symbol_begin()) OS << ",\n ";
1252  OS << "(";
1253  it->dump();
1254  OS << ", Index:" << it->getIndex() << ", ";
1255  OS << ")";
1256  }
1257  OS << "]>\n";
1258 }
1259 #endif
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::MCAssembler::getBackend
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:316
llvm::MCAssembler::begin
iterator begin()
Definition: MCAssembler.h:360
i
i
Definition: README.txt:29
writeFragment
static void writeFragment(raw_ostream &OS, const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment &F)
Write the fragment F to the output file.
Definition: MCAssembler.cpp:512
llvm::MCFragment::FT_DwarfFrame
@ FT_DwarfFrame
Definition: MCFragment.h:44
llvm::raw_ostream::tell
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:135
llvm::MCAlignFragment::hasEmitNops
bool hasEmitNops() const
Definition: MCFragment.h:331
llvm::MCBoundaryAlignFragment::getSubtargetInfo
const MCSubtargetInfo * getSubtargetInfo() const
Definition: MCFragment.h:609
MCDwarf.h
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:510
MathExtras.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::MCFragment::FT_BoundaryAlign
@ FT_BoundaryAlign
Definition: MCFragment.h:46
llvm::MCAssembler::Finish
void Finish()
Finish - Do final processing and write the object to the output stream.
Definition: MCAssembler.cpp:934
llvm::MCRelaxableFragment
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:271
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCExpr::evaluateAsValue
bool evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const
Try to evaluate the expression to the form (a - b + constant) where neither a nor b are variables.
Definition: MCExpr.cpp:757
it
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions main should enable SSE DAZ mode and other fast SSE modes Think about doing i64 math in SSE regs on x86 This testcase should have no SSE instructions in it
Definition: README-SSE.txt:81
llvm::MCAsmBackend::getFixupKindInfo
virtual const MCFixupKindInfo & getFixupKindInfo(MCFixupKind Kind) const
Get information on a fixup kind.
Definition: MCAsmBackend.cpp:74
llvm::MCCVInlineLineTableFragment
Fragment representing the binary annotations produced by the .cv_inline_linetable directive.
Definition: MCFragment.h:516
llvm::MCAssembler::registerSymbol
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
Definition: MCAssembler.cpp:466
llvm::MCContext::getCVContext
CodeViewContext & getCVContext()
Definition: MCContext.cpp:908
llvm::MCDwarfCallFrameFragment
Definition: MCFragment.h:481
llvm::MCFragment::FT_CVInlineLines
@ FT_CVInlineLines
Definition: MCFragment.h:48
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
StringRef.h
llvm::MCBoundaryAlignFragment::setSize
void setSize(uint64_t Value)
Definition: MCFragment.h:598
MCCodeEmitter.h
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
llvm::MCFixupKindInfo::FKF_Constant
@ FKF_Constant
This fixup kind should be resolved if defined.
Definition: MCFixupKindInfo.h:30
MCSectionELF.h
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1175
Statistic.h
llvm::tgtok::Code
@ Code
Definition: TGLexer.h:50
llvm::MCNopsFragment::getLoc
SMLoc getLoc() const
Definition: MCFragment.h:392
ErrorHandling.h
MCFragment.h
llvm::MCSymbol::isUndefined
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:252
MCAssembler.h
llvm::MCAssembler::computeFragmentSize
uint64_t computeFragmentSize(const MCAsmLayout &Layout, const MCFragment &F) const
Compute the effective fragment size assuming it is laid out at the given SectionAddress and FragmentO...
Definition: MCAssembler.cpp:292
llvm::MCNopsFragment
Definition: MCFragment.h:371
llvm::MCSymbol::isDefined
bool isDefined() const
isDefined - Check if this symbol is defined (i.e., it has an address).
Definition: MCSymbol.h:243
llvm::MCAssembler::reset
void reset()
Reuse an assembler instance.
Definition: MCAssembler.cpp:97
mayCrossBoundary
static bool mayCrossBoundary(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch crosses the boundary.
Definition: MCAssembler.cpp:1035
llvm::MCDwarfFrameEmitter::EncodeAdvanceLoc
static void EncodeAdvanceLoc(MCContext &Context, uint64_t AddrDelta, raw_ostream &OS)
Definition: MCDwarf.cpp:1914
llvm::MCFragment::getParent
MCSection * getParent() const
Definition: MCFragment.h:96
llvm::AMDGPU::Exp::Target
Target
Definition: SIDefines.h:745
llvm::MCAsmBackend::applyFixup
virtual void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, const MCValue &Target, MutableArrayRef< char > Data, uint64_t Value, bool IsResolved, const MCSubtargetInfo *STI) const =0
Apply the Value for given Fixup into the provided data fragment, at the offset specified by the fixup...
MCFixupKindInfo.h
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:80
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:893
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::MCEncodedFragmentWithFixups::getFixups
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCFragment.h:223
llvm::MCFixupKindInfo::FKF_IsAlignedDownTo32Bits
@ FKF_IsAlignedDownTo32Bits
Should this fixup kind force a 4-byte aligned effective PC value?
Definition: MCFixupKindInfo.h:22
llvm::MCFragment::FT_CVDefRange
@ FT_CVDefRange
Definition: MCFragment.h:49
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MCAssembler::writeSectionData
void writeSectionData(raw_ostream &OS, const MCSection *Section, const MCAsmLayout &Layout) const
Emit the section contents to OS.
Definition: MCAssembler.cpp:730
llvm::MCEncodedFragment::alignToBundleEnd
bool alignToBundleEnd() const
Should this fragment be placed at the end of an aligned bundle?
Definition: MCFragment.h:157
llvm::MCSection::getFragmentList
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:164
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::MCAssembler::isThumbFunc
bool isThumbFunc(const MCSymbol *Func) const
Check whether a given symbol has been flagged with .thumb_func.
Definition: MCAssembler.cpp:134
llvm::MCExpr::evaluateAsRelocatable
bool evaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout, const MCFixup *Fixup) const
Try to evaluate the expression to a relocatable value, i.e.
Definition: MCExpr.cpp:749
Context
ManagedStatic< detail::RecordContext > Context
Definition: Record.cpp:96
llvm::MCAsmBackend::finishLayout
virtual void finishLayout(MCAssembler const &Asm, MCAsmLayout &Layout) const
Give backend an opportunity to finish layout after relaxation.
Definition: MCAsmBackend.h:201
llvm::ARMBuildAttrs::Section
@ Section
Legacy Tags.
Definition: ARMBuildAttributes.h:82
llvm::MCAlignFragment::getMaxBytesToEmit
unsigned getMaxBytesToEmit() const
Definition: MCFragment.h:329
llvm::MCFragment
Definition: MCFragment.h:31
llvm::MCBoundaryAlignFragment::getAlignment
Align getAlignment() const
Definition: MCFragment.h:600
llvm::MCAssembler::symbol_begin
symbol_iterator symbol_begin()
Definition: MCAssembler.h:371
DEBUG_WITH_TYPE
#define DEBUG_WITH_TYPE(TYPE, X)
DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.
Definition: Debug.h:64
MCAsmBackend.h
llvm::MutableArrayRef< char >
llvm::SMLoc
Represents a location in source code.
Definition: SMLoc.h:23
llvm::MCAsmLayout::invalidateFragmentsFrom
void invalidateFragmentsFrom(MCFragment *F)
Invalidate the fragments starting with F because it has been resized.
Definition: MCFragment.cpp:70
llvm::ModRefInfo::Ref
@ Ref
The access may reference the value stored in memory.
llvm::MCAlignFragment
Definition: MCFragment.h:295
SmallString.h
llvm::encodeSLEB128
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:23
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::support::little
@ little
Definition: Endian.h:27
llvm::MCAssembler::getContext
MCContext & getContext() const
Definition: MCAssembler.h:308
llvm::CodeViewContext::encodeDefRange
void encodeDefRange(MCAsmLayout &Layout, MCCVDefRangeFragment &F)
Definition: MCCodeView.cpp:605
llvm::MCLEBFragment::getContents
SmallString< 8 > & getContents()
Definition: MCFragment.h:447
llvm::ARM_PROC::A
@ A
Definition: ARMBaseInfo.h:34
Twine.h
llvm::Log2
unsigned Log2(Align A)
Returns the log2 of the alignment.
Definition: Alignment.h:207
MCContext.h
llvm::MCSymbolIdFragment
Represents a symbol table index fragment.
Definition: MCFragment.h:499
llvm::MCSection::setLayoutOrder
void setLayoutOrder(unsigned Value)
Definition: MCSection.h:145
MCSymbol.h
llvm::MCLOHContainer::reset
void reset()
Definition: MCLinkerOptimizationHint.h:176
MCInst.h
false
Definition: StackSlotColoring.cpp:142
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::AArch64::Fixups
Fixups
Definition: AArch64FixupKinds.h:17
llvm::raw_ostream::write
raw_ostream & write(unsigned char C)
Definition: raw_ostream.cpp:219
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:143
llvm::STATISTIC
STATISTIC(NumFunctions, "Total number of functions")
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::MCOrgFragment::getLoc
SMLoc getLoc() const
Definition: MCFragment.h:421
llvm::MCAsmLayout::layoutFragment
void layoutFragment(MCFragment *Fragment)
Perform layout for a single fragment, assuming that the previous fragment has already been laid out c...
Definition: MCAssembler.cpp:398
llvm::VersionTuple
Represents a version number in the form major[.minor[.subminor[.build]]].
Definition: VersionTuple.h:29
llvm::MCExpr::evaluateKnownAbsolute
bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const
Definition: MCExpr.cpp:561
llvm::MCObjectWriter::recordRelocation
virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)=0
Record a relocation entry.
llvm::MCAssembler::getEmitterPtr
MCCodeEmitter * getEmitterPtr() const
Definition: MCAssembler.h:312
llvm::MCAsmBackend::reset
virtual void reset()
lifetime management
Definition: MCAsmBackend.h:63
llvm::MCValue::getSymA
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:45
Align
uint64_t Align
Definition: ELFObjHandler.cpp:82
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::MCFragment::hasInstructions
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
Definition: MCFragment.h:107
llvm::MCFixupKindInfo::Flags
unsigned Flags
Flags describing additional information on this fixup kind.
Definition: MCFixupKindInfo.h:45
DF
static RegisterPass< DebugifyFunctionPass > DF("debugify-function", "Attach debug info to a function")
llvm::MCSymbol::getIndex
uint32_t getIndex() const
Get the (implementation defined) index.
Definition: MCSymbol.h:309
llvm::SmallString< 256 >
llvm::MCDwarfLineAddr::Encode
static void Encode(MCContext &Context, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta, raw_ostream &OS)
Utility function to encode a Dwarf pair of LineDelta and AddrDeltas.
Definition: MCDwarf.cpp:675
llvm::MCDwarfLineAddrFragment
Definition: MCFragment.h:457
llvm::MCAsmLayout::getSectionOrder
llvm::SmallVectorImpl< MCSection * > & getSectionOrder()
Definition: MCAsmLayout.h:69
llvm::MCAsmLayout::getSectionFileSize
uint64_t getSectionFileSize(const MCSection *Sec) const
Get the data size of the given section, as emitted to the object file.
Definition: MCFragment.cpp:204
llvm::MCFragment::FT_LEB
@ FT_LEB
Definition: MCFragment.h:45
llvm::MCAssembler::getWriterPtr
MCObjectWriter * getWriterPtr() const
Definition: MCAssembler.h:314
llvm::MCEncodedFragment
Interface implemented by fragments that contain encoded instructions and/or data.
Definition: MCFragment.h:125
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::MCAssembler::getEmitter
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:318
llvm::MCAlignFragment::getValueSize
unsigned getValueSize() const
Definition: MCFragment.h:327
index
splat index
Definition: README_ALTIVEC.txt:181
uint64_t
llvm::MCPseudoProbeAddrFragment
Definition: MCFragment.h:616
llvm::MCFragment::FT_Org
@ FT_Org
Definition: MCFragment.h:42
llvm::CodeViewContext::encodeInlineLineTable
void encodeInlineLineTable(MCAsmLayout &Layout, MCCVInlineLineTableFragment &F)
Encodes the binary annotations once we have a layout.
Definition: MCCodeView.cpp:461
LEB128.h
llvm::numbers::e
constexpr double e
Definition: MathExtras.h:57
llvm::MCEncodedFragment::setBundlePadding
void setBundlePadding(uint8_t N)
Set the padding size for this fragment.
Definition: MCFragment.h:169
llvm::MCFixupKindInfo::FKF_IsPCRel
@ FKF_IsPCRel
Is this fixup kind PCrelative? This is used by the assembler backend to evaluate fixup values in a ta...
Definition: MCFixupKindInfo.h:19
llvm::MCAssembler::symbol_end
symbol_iterator symbol_end()
Definition: MCAssembler.h:374
llvm::MCAssembler::getBundleAlignSize
unsigned getBundleAlignSize() const
Definition: MCAssembler.h:349
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::MCBoundaryAlignFragment::getLastFragment
const MCFragment * getLastFragment() const
Definition: MCFragment.h:603
llvm::MCAssembler::isSymbolLinkerVisible
bool isSymbolLinkerVisible(const MCSymbol &SD) const
Check whether a particular symbol is visible to the linker and is required in the symbol table,...
Definition: MCAssembler.cpp:165
llvm::MCAssembler::MCAssembler
MCAssembler(MCContext &Context, std::unique_ptr< MCAsmBackend > Backend, std::unique_ptr< MCCodeEmitter > Emitter, std::unique_ptr< MCObjectWriter > Writer)
Construct a new assembler instance.
Definition: MCAssembler.cpp:83
ArrayRef.h
llvm::MCAsmBackend::shouldInsertFixupForCodeAlign
virtual bool shouldInsertFixupForCodeAlign(MCAssembler &Asm, const MCAsmLayout &Layout, MCAlignFragment &AF)
Hook which indicates if the target requires a fixup to be generated when handling an align directive ...
Definition: MCAsmBackend.h:108
llvm::MCAssembler::getAtom
const MCSymbol * getAtom(const MCSymbol &S) const
Find the symbol which defines the atom containing the given symbol, or null if there is no such symbo...
Definition: MCAssembler.cpp:176
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
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:1707
llvm::MCFillFragment
Definition: MCFragment.h:344
llvm::MCAsmBackend::fixupNeedsRelaxationAdvanced
virtual bool fixupNeedsRelaxationAdvanced(const MCFixup &Fixup, bool Resolved, uint64_t Value, const MCRelaxableFragment *DF, const MCAsmLayout &Layout, const bool WasForced) const
Target specific predicate for whether a given fixup requires the associated instruction to be relaxed...
Definition: MCAsmBackend.cpp:104
llvm::MCContext::reportError
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:963
llvm::MCFragment::FT_SymbolId
@ FT_SymbolId
Definition: MCFragment.h:47
llvm::MCAssembler::getRelaxAll
bool getRelaxAll() const
Definition: MCAssembler.h:344
llvm::MCFragment::FT_PseudoProbe
@ FT_PseudoProbe
Definition: MCFragment.h:50
llvm::MCAssembler::~MCAssembler
~MCAssembler()
llvm::FK_Data_1
@ FK_Data_1
A one-byte fixup.
Definition: MCFixup.h:23
llvm::MCPseudoProbeAddrFragment::getAddrDelta
const MCExpr & getAddrDelta() const
Definition: MCFragment.h:626
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
llvm::MCOrgFragment
Definition: MCFragment.h:401
llvm::MCFragment::FT_Align
@ FT_Align
Definition: MCFragment.h:36
llvm::MCFixupKindInfo::FKF_IsTarget
@ FKF_IsTarget
Should this fixup be evaluated in a target dependent manner?
Definition: MCFixupKindInfo.h:25
MCSection.h
llvm::MCSymbolRefExpr::VK_X86_ABS8
@ VK_X86_ABS8
Definition: MCExpr.h:227
llvm::MCFillFragment::getValue
uint64_t getValue() const
Definition: MCFragment.h:360
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
MCAsmInfo.h
Fixup
PowerPC TLS Dynamic Call Fixup
Definition: PPCTLSDynamicCall.cpp:233
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::MCSection::isVirtualSection
virtual bool isVirtualSection() const =0
Check whether this section is "virtual", that is has no actual object file contents.
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
llvm::MCLEBFragment::getValue
const MCExpr & getValue() const
Definition: MCFragment.h:443
llvm::MCFragment::FT_Data
@ FT_Data
Definition: MCFragment.h:37
llvm::MCAlignFragment::getValue
int64_t getValue() const
Definition: MCFragment.h:325
uint32_t
MCFixup.h
llvm::MCBoundaryAlignFragment::getSize
uint64_t getSize() const
Definition: MCFragment.h:597
llvm::MCAsmBackend::relaxInstruction
virtual void relaxInstruction(MCInst &Inst, const MCSubtargetInfo &STI) const
Relax the instruction in the given fragment to the next wider instruction.
Definition: MCAsmBackend.h:166
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
llvm::MCSymbolIdFragment::getSymbol
const MCSymbol * getSymbol()
Definition: MCFragment.h:506
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MCOrgFragment::getValue
uint8_t getValue() const
Definition: MCFragment.h:419
llvm::MCAsmLayout::getFragmentOffset
uint64_t getFragmentOffset(const MCFragment *F) const
Get the offset of the given fragment inside its containing section.
Definition: MCFragment.cpp:96
MCAsmLayout.h
MCObjectWriter.h
llvm::MCFragment::FT_Dwarf
@ FT_Dwarf
Definition: MCFragment.h:43
llvm::MCAssembler::layout
void layout(MCAsmLayout &Layout)
Definition: MCAssembler.cpp:808
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
needPadding
static bool needPadding(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch needs padding.
Definition: MCAssembler.cpp:1060
Alignment.h
stats
Definition: MCAssembler.cpp:52
llvm::MCCodeEmitter::reset
virtual void reset()
Lifetime management.
Definition: MCCodeEmitter.h:31
MCCodeView.h
std
Definition: BitVector.h:850
EndianStream.h
llvm::MCObjectWriter::reset
virtual void reset()
lifetime management
Definition: MCObjectWriter.h:43
llvm::MCFragment::FT_Nops
@ FT_Nops
Definition: MCFragment.h:40
llvm::MCAsmBackend::evaluateTargetFixup
virtual bool evaluateTargetFixup(const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFixup &Fixup, const MCFragment *DF, const MCValue &Target, uint64_t &Value, bool &WasForced)
Definition: MCAsmBackend.h:114
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
isAgainstBoundary
static bool isAgainstBoundary(uint64_t StartAddr, uint64_t Size, Align BoundaryAlignment)
Check if the branch is against the boundary.
Definition: MCAssembler.cpp:1048
llvm::MCObjectWriter::executePostLayoutBinding
virtual void executePostLayoutBinding(MCAssembler &Asm, const MCAsmLayout &Layout)=0
Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...
llvm::Align::value
uint64_t value() const
This is a hole in the type system and should not be abused.
Definition: Alignment.h:85
llvm::MCAssembler::getLOHContainer
MCLOHContainer & getLOHContainer()
Definition: MCAssembler.h:447
llvm::MCEncodedFragment::getSubtargetInfo
const MCSubtargetInfo * getSubtargetInfo() const
Retrieve the MCSubTargetInfo in effect when the instruction was encoded.
Definition: MCFragment.h:173
Casting.h
llvm::MCNopsFragment::getNumBytes
int64_t getNumBytes() const
Definition: MCFragment.h:389
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::MCValue::getRefKind
uint32_t getRefKind() const
Definition: MCValue.h:47
llvm::MCAsmLayout::getSymbolOffset
bool getSymbolOffset(const MCSymbol &S, uint64_t &Val) const
Get the offset of the given symbol, as computed in the current layout.
Definition: MCFragment.cpp:152
llvm::MCEncodedFragment::getBundlePadding
uint8_t getBundlePadding() const
Get the padding size that must be inserted before this fragment.
Definition: MCFragment.h:165
llvm::MCAlignFragment::getAlignment
unsigned getAlignment() const
Definition: MCFragment.h:323
llvm::MCObjectWriter::writeObject
virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout)=0
Write the object file and returns the number of bytes written.
MCValue.h
llvm::MCFragment::FT_Relaxable
@ FT_Relaxable
Definition: MCFragment.h:41
llvm::MCAlignFragment::getSubtargetInfo
const MCSubtargetInfo * getSubtargetInfo() const
Definition: MCFragment.h:337
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:83
llvm::MCAssembler::registerSection
bool registerSection(MCSection &Section)
Definition: MCAssembler.cpp:126
llvm::MCAssembler::end
iterator end()
Definition: MCAssembler.h:363
llvm::MCSection::begin
iterator begin()
Definition: MCSection.h:177
llvm::MCLEBFragment
Definition: MCFragment.h:428
llvm::computeBundlePadding
uint64_t computeBundlePadding(const MCAssembler &Assembler, const MCEncodedFragment *F, uint64_t FOffset, uint64_t FSize)
Compute the amount of padding required before the fragment F to obey bundling restrictions,...
Definition: MCFragment.cpp:213
llvm::MCFragment::FT_Fill
@ FT_Fill
Definition: MCFragment.h:39
llvm::MCNopsFragment::getSubtargetInfo
const MCSubtargetInfo * getSubtargetInfo() const
Definition: MCFragment.h:394
SmallVector.h
llvm::MCSection::UseCodeAlign
virtual bool UseCodeAlign() const =0
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
llvm::to_string
std::string to_string(const T &Value)
Definition: ScopedPrinter.h:87
llvm::MCAssembler::dump
void dump() const
Definition: MCAssembler.cpp:1238
llvm::raw_svector_ostream
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:661
llvm::encodeULEB128
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:80
llvm::support::endianness
endianness
Definition: Endian.h:27
llvm::SmallVectorImpl< char >
llvm::MCAssembler::writeFragmentPadding
void writeFragmentPadding(raw_ostream &OS, const MCEncodedFragment &F, uint64_t FSize) const
Write the necessary bundle padding to OS.
Definition: MCAssembler.cpp:476
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCFillFragment::getValueSize
uint8_t getValueSize() const
Definition: MCFragment.h:361
llvm::MCAsmLayout::getAssembler
MCAssembler & getAssembler() const
Get the assembler object this is a layout for.
Definition: MCAsmLayout.h:50
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
llvm::MCSymbolRefExpr::VK_None
@ VK_None
Definition: MCExpr.h:195
llvm::MCAssembler::getBackendPtr
MCAsmBackend * getBackendPtr() const
Definition: MCAssembler.h:310
llvm::MCFragment::FT_Dummy
@ FT_Dummy
Definition: MCFragment.h:51
llvm::pointee_iterator
An iterator type that allows iterating over the pointees via some other iterator.
Definition: iterator.h:320
llvm::MCContext::hadError
bool hadError()
Definition: MCContext.h:813
llvm::MCAsmLayout::getSectionAddressSize
uint64_t getSectionAddressSize(const MCSection *Sec) const
Get the address space size of the given section, as it effects layout.
Definition: MCFragment.cpp:198
llvm::MCAssembler::getDWARFLinetableParams
MCDwarfLineTableParams getDWARFLinetableParams() const
Definition: MCAssembler.h:322
raw_ostream.h
n
The same transformation can work with an even modulo with the addition of a and shrink the compare RHS by the same amount Unless the target supports that transformation probably isn t worthwhile The transformation can also easily be made to work with non zero equality for n
Definition: README.txt:685
llvm::MCDataFragment
Fragment for data and encoded instructions.
Definition: MCFragment.h:242
llvm::MCAssembler::isBundlingEnabled
bool isBundlingEnabled() const
Definition: MCAssembler.h:347
MCExpr.h
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
llvm::MCCVDefRangeFragment
Fragment representing the .cv_def_range directive.
Definition: MCFragment.h:549
llvm::offsetToAlignment
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:196
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::MCOrgFragment::getOffset
const MCExpr & getOffset() const
Definition: MCFragment.h:417
llvm::MCLEBFragment::isSigned
bool isSigned() const
Definition: MCFragment.h:445
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
Debug.h
llvm::MCValue::getSymB
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:46
llvm::MCEncodedFragmentWithContents::getContents
SmallVectorImpl< char > & getContents()
Definition: MCFragment.h:197
llvm::MCFragment::FT_CompactEncodedInst
@ FT_CompactEncodedInst
Definition: MCFragment.h:38
llvm::MCNopsFragment::getControlledNopLength
int64_t getControlledNopLength() const
Definition: MCFragment.h:390
llvm::MCCodeEmitter::encodeInstruction
virtual void encodeInstruction(const MCInst &Inst, raw_ostream &OS, SmallVectorImpl< MCFixup > &Fixups, const MCSubtargetInfo &STI) const =0
EncodeInstruction - Encode the given Inst to bytes on the output stream OS.
llvm::MCSection::setOrdinal
void setOrdinal(unsigned Value)
Definition: MCSection.h:142
llvm::MCBoundaryAlignFragment
Represents required padding such that a particular other set of fragments does not cross a particular...
Definition: MCFragment.h:579
llvm::MCAssembler::getWriter
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:320