LLVM  7.0.0svn
MCObjectStreamer.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCObjectStreamer.cpp - Object File MCStreamer Interface -----===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/ADT/STLExtras.h"
12 #include "llvm/MC/MCAsmBackend.h"
13 #include "llvm/MC/MCAssembler.h"
14 #include "llvm/MC/MCCodeEmitter.h"
15 #include "llvm/MC/MCCodeView.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCDwarf.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/MC/MCObjectWriter.h"
20 #include "llvm/MC/MCSection.h"
21 #include "llvm/MC/MCSymbol.h"
23 #include "llvm/Support/SourceMgr.h"
24 using namespace llvm;
25 
27  std::unique_ptr<MCAsmBackend> TAB,
29  std::unique_ptr<MCCodeEmitter> Emitter)
30  : MCStreamer(Context), ObjectWriter(TAB->createObjectWriter(OS)),
31  TAB(std::move(TAB)), Emitter(std::move(Emitter)),
32  Assembler(llvm::make_unique<MCAssembler>(Context, *this->TAB,
33  *this->Emitter, *ObjectWriter)),
34  EmitEHFrame(true), EmitDebugFrame(false) {}
35 
37 
39  if (PendingLabels.empty())
40  return;
41  if (!F) {
42  F = new MCDataFragment();
43  MCSection *CurSection = getCurrentSectionOnly();
44  CurSection->getFragmentList().insert(CurInsertionPoint, F);
45  F->setParent(CurSection);
46  }
47  for (MCSymbol *Sym : PendingLabels) {
48  Sym->setFragment(F);
49  Sym->setOffset(FOffset);
50  }
51  PendingLabels.clear();
52 }
53 
54 // As a compile-time optimization, avoid allocating and evaluating an MCExpr
55 // tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment.
57  const MCSymbol *Lo) {
58  assert(Hi && Lo);
59  if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
60  Hi->isVariable() || Lo->isVariable())
61  return None;
62 
63  return Hi->getOffset() - Lo->getOffset();
64 }
65 
67  const MCSymbol *Lo,
68  unsigned Size) {
69  if (Optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo)) {
70  EmitIntValue(*Diff, Size);
71  return;
72  }
74 }
75 
77  const MCSymbol *Lo) {
78  if (Optional<uint64_t> Diff = absoluteSymbolDiff(Hi, Lo)) {
79  EmitULEB128IntValue(*Diff);
80  return;
81  }
83 }
84 
86  if (Assembler)
87  Assembler->reset();
88  CurInsertionPoint = MCSection::iterator();
89  EmitEHFrame = true;
90  EmitDebugFrame = false;
91  PendingLabels.clear();
93 }
94 
96  if (!getNumFrameInfos())
97  return;
98 
99  if (EmitEHFrame)
100  MCDwarfFrameEmitter::Emit(*this, MAB, true);
101 
102  if (EmitDebugFrame)
103  MCDwarfFrameEmitter::Emit(*this, MAB, false);
104 }
105 
107  assert(getCurrentSectionOnly() && "No current section!");
108 
109  if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
110  return &*std::prev(CurInsertionPoint);
111 
112  return nullptr;
113 }
114 
116  MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
117  // When bundling is enabled, we don't want to add data to a fragment that
118  // already has instructions (see MCELFStreamer::EmitInstToData for details)
119  if (!F || (Assembler->isBundlingEnabled() && !Assembler->getRelaxAll() &&
120  F->hasInstructions())) {
121  F = new MCDataFragment();
122  insert(F);
123  }
124  return F;
125 }
126 
129  dyn_cast_or_null<MCPaddingFragment>(getCurrentFragment());
130  if (!F) {
131  F = new MCPaddingFragment();
132  insert(F);
133  }
134  return F;
135 }
136 
138  Assembler->registerSymbol(Sym);
139 }
140 
142  MCStreamer::EmitCFISections(EH, Debug);
143  EmitEHFrame = EH;
144  EmitDebugFrame = Debug;
145 }
146 
148  SMLoc Loc) {
149  MCStreamer::EmitValueImpl(Value, Size, Loc);
151  flushPendingLabels(DF, DF->getContents().size());
152 
153  MCCVLineEntry::Make(this);
155 
156  // Avoid fixups when possible.
157  int64_t AbsValue;
158  if (Value->evaluateAsAbsolute(AbsValue, getAssembler())) {
159  if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
161  Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
162  return;
163  }
164  EmitIntValue(AbsValue, Size);
165  return;
166  }
167  DF->getFixups().push_back(
168  MCFixup::create(DF->getContents().size(), Value,
169  MCFixup::getKindForSize(Size, false), Loc));
170  DF->getContents().resize(DF->getContents().size() + Size, 0);
171 }
172 
173 MCSymbol *MCObjectStreamer::EmitCFILabel() {
174  MCSymbol *Label = getContext().createTempSymbol("cfi", true);
175  EmitLabel(Label);
176  return Label;
177 }
178 
179 void MCObjectStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
180  // We need to create a local symbol to avoid relocations.
181  Frame.Begin = getContext().createTempSymbol();
182  EmitLabel(Frame.Begin);
183 }
184 
185 void MCObjectStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
186  Frame.End = getContext().createTempSymbol();
187  EmitLabel(Frame.End);
188 }
189 
191  MCStreamer::EmitLabel(Symbol, Loc);
192 
193  getAssembler().registerSymbol(*Symbol);
194 
195  // If there is a current fragment, mark the symbol as pointing into it.
196  // Otherwise queue the label and set its fragment pointer when we emit the
197  // next fragment.
198  auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
199  if (F && !(getAssembler().isBundlingEnabled() &&
200  getAssembler().getRelaxAll())) {
201  Symbol->setFragment(F);
202  Symbol->setOffset(F->getContents().size());
203  } else {
204  PendingLabels.push_back(Symbol);
205  }
206 }
207 
209  MCStreamer::EmitLabel(Symbol, Loc);
210  getAssembler().registerSymbol(*Symbol);
211  auto *DF = dyn_cast_or_null<MCDataFragment>(F);
212  if (DF)
213  Symbol->setFragment(F);
214  else
215  PendingLabels.push_back(Symbol);
216 }
217 
219  int64_t IntValue;
220  if (Value->evaluateAsAbsolute(IntValue, getAssembler())) {
221  EmitULEB128IntValue(IntValue);
222  return;
223  }
224  insert(new MCLEBFragment(*Value, false));
225 }
226 
228  int64_t IntValue;
229  if (Value->evaluateAsAbsolute(IntValue, getAssembler())) {
230  EmitSLEB128IntValue(IntValue);
231  return;
232  }
233  insert(new MCLEBFragment(*Value, true));
234 }
235 
237  const MCSymbol *Symbol) {
238  report_fatal_error("This file format doesn't support weak aliases.");
239 }
240 
242  const MCExpr *Subsection) {
243  changeSectionImpl(Section, Subsection);
244 }
245 
247  const MCExpr *Subsection) {
248  assert(Section && "Cannot switch to a null section!");
249  flushPendingLabels(nullptr);
251 
252  bool Created = getAssembler().registerSection(*Section);
253 
254  int64_t IntSubsection = 0;
255  if (Subsection &&
256  !Subsection->evaluateAsAbsolute(IntSubsection, getAssembler()))
257  report_fatal_error("Cannot evaluate subsection number");
258  if (IntSubsection < 0 || IntSubsection > 8192)
259  report_fatal_error("Subsection number out of range");
260  CurInsertionPoint =
261  Section->getSubsectionInsertionPoint(unsigned(IntSubsection));
262  return Created;
263 }
264 
266  getAssembler().registerSymbol(*Symbol);
267  MCStreamer::EmitAssignment(Symbol, Value);
268 }
269 
271  return Sec.hasInstructions();
272 }
273 
275  const MCSubtargetInfo &STI, bool) {
277  EmitInstructionImpl(Inst, STI);
279 }
280 
281 void MCObjectStreamer::EmitInstructionImpl(const MCInst &Inst,
282  const MCSubtargetInfo &STI) {
283  MCStreamer::EmitInstruction(Inst, STI);
284 
286  Sec->setHasInstructions(true);
287 
288  // Now that a machine instruction has been assembled into this section, make
289  // a line entry for any .loc directive that has been seen.
290  MCCVLineEntry::Make(this);
292 
293  // If this instruction doesn't need relaxation, just emit it as data.
294  MCAssembler &Assembler = getAssembler();
295  if (!Assembler.getBackend().mayNeedRelaxation(Inst)) {
296  EmitInstToData(Inst, STI);
297  return;
298  }
299 
300  // Otherwise, relax and emit it as data if either:
301  // - The RelaxAll flag was passed
302  // - Bundling is enabled and this instruction is inside a bundle-locked
303  // group. We want to emit all such instructions into the same data
304  // fragment.
305  if (Assembler.getRelaxAll() ||
306  (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
307  MCInst Relaxed;
308  getAssembler().getBackend().relaxInstruction(Inst, STI, Relaxed);
309  while (getAssembler().getBackend().mayNeedRelaxation(Relaxed))
310  getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed);
311  EmitInstToData(Relaxed, STI);
312  return;
313  }
314 
315  // Otherwise emit to a separate fragment.
316  EmitInstToFragment(Inst, STI);
317 }
318 
320  const MCSubtargetInfo &STI) {
321  if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
322  llvm_unreachable("All instructions should have already been relaxed");
323 
324  // Always create a new, separate fragment here, because its size can change
325  // during relaxation.
326  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
327  insert(IF);
328 
329  SmallString<128> Code;
330  raw_svector_ostream VecOS(Code);
331  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
332  STI);
333  IF->getContents().append(Code.begin(), Code.end());
334 }
335 
336 #ifndef NDEBUG
337 static const char *const BundlingNotImplementedMsg =
338  "Aligned bundling is not implemented for this object format";
339 #endif
340 
341 void MCObjectStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
342  llvm_unreachable(BundlingNotImplementedMsg);
343 }
344 
345 void MCObjectStreamer::EmitBundleLock(bool AlignToEnd) {
346  llvm_unreachable(BundlingNotImplementedMsg);
347 }
348 
350  llvm_unreachable(BundlingNotImplementedMsg);
351 }
352 
353 void MCObjectStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
354  unsigned Column, unsigned Flags,
355  unsigned Isa,
356  unsigned Discriminator,
357  StringRef FileName) {
358  // In case we see two .loc directives in a row, make sure the
359  // first one gets a line entry.
361 
362  this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
363  Isa, Discriminator, FileName);
364 }
365 
366 static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
367  const MCSymbol *B) {
368  MCContext &Context = OS.getContext();
370  const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
371  const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
372  const MCExpr *AddrDelta =
373  MCBinaryExpr::create(MCBinaryExpr::Sub, ARef, BRef, Context);
374  return AddrDelta;
375 }
376 
378  MCDwarfLineTableParams Params,
379  int64_t LineDelta, const MCSymbol *Label,
380  int PointerSize) {
381  // emit the sequence to set the address
382  OS.EmitIntValue(dwarf::DW_LNS_extended_op, 1);
383  OS.EmitULEB128IntValue(PointerSize + 1);
384  OS.EmitIntValue(dwarf::DW_LNE_set_address, 1);
385  OS.EmitSymbolValue(Label, PointerSize);
386 
387  // emit the sequence for the LineDelta (from 1) and a zero address delta.
388  MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
389 }
390 
392  const MCSymbol *LastLabel,
393  const MCSymbol *Label,
394  unsigned PointerSize) {
395  if (!LastLabel) {
396  emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
397  Label, PointerSize);
398  return;
399  }
400  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
401  int64_t Res;
402  if (AddrDelta->evaluateAsAbsolute(Res, getAssembler())) {
403  MCDwarfLineAddr::Emit(this, Assembler->getDWARFLinetableParams(), LineDelta,
404  Res);
405  return;
406  }
407  insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
408 }
409 
411  const MCSymbol *Label) {
412  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
413  int64_t Res;
414  if (AddrDelta->evaluateAsAbsolute(Res, getAssembler())) {
416  return;
417  }
418  insert(new MCDwarfCallFrameFragment(*AddrDelta));
419 }
420 
421 void MCObjectStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
422  unsigned Line, unsigned Column,
423  bool PrologueEnd, bool IsStmt,
424  StringRef FileName, SMLoc Loc) {
425  // In case we see two .cv_loc directives in a row, make sure the
426  // first one gets a line entry.
427  MCCVLineEntry::Make(this);
428 
429  this->MCStreamer::EmitCVLocDirective(FunctionId, FileNo, Line, Column,
430  PrologueEnd, IsStmt, FileName, Loc);
431 }
432 
434  const MCSymbol *Begin,
435  const MCSymbol *End) {
436  getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
437  End);
438  this->MCStreamer::EmitCVLinetableDirective(FunctionId, Begin, End);
439 }
440 
442  unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
443  const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
445  *this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
446  FnEndSym);
448  PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
449 }
450 
452  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
453  StringRef FixedSizePortion) {
454  getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
455  this->MCStreamer::EmitCVDefRangeDirective(Ranges, FixedSizePortion);
456 }
457 
460 }
463 }
464 
467 }
468 
470  MCCVLineEntry::Make(this);
473  flushPendingLabels(DF, DF->getContents().size());
474  DF->getContents().append(Data.begin(), Data.end());
475 }
476 
478  int64_t Value,
479  unsigned ValueSize,
480  unsigned MaxBytesToEmit) {
481  if (MaxBytesToEmit == 0)
482  MaxBytesToEmit = ByteAlignment;
483  insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
484 
485  // Update the maximum alignment on the current section if necessary.
486  MCSection *CurSec = getCurrentSectionOnly();
487  if (ByteAlignment > CurSec->getAlignment())
488  CurSec->setAlignment(ByteAlignment);
489 }
490 
492  unsigned MaxBytesToEmit) {
493  EmitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
494  cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true);
495 }
496 
498  unsigned char Value,
499  SMLoc Loc) {
500  insert(new MCOrgFragment(*Offset, Value, Loc));
501 }
502 
504  const MCCodePaddingContext &Context) {
506 }
507 
509  const MCCodePaddingContext &Context) {
511 }
512 
513 // Associate DTPRel32 fixup with data and resize data area
516  flushPendingLabels(DF, DF->getContents().size());
517 
518  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
519  Value, FK_DTPRel_4));
520  DF->getContents().resize(DF->getContents().size() + 4, 0);
521 }
522 
523 // Associate DTPRel64 fixup with data and resize data area
526  flushPendingLabels(DF, DF->getContents().size());
527 
528  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
529  Value, FK_DTPRel_8));
530  DF->getContents().resize(DF->getContents().size() + 8, 0);
531 }
532 
533 // Associate TPRel32 fixup with data and resize data area
536  flushPendingLabels(DF, DF->getContents().size());
537 
538  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
539  Value, FK_TPRel_4));
540  DF->getContents().resize(DF->getContents().size() + 4, 0);
541 }
542 
543 // Associate TPRel64 fixup with data and resize data area
546  flushPendingLabels(DF, DF->getContents().size());
547 
548  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
549  Value, FK_TPRel_8));
550  DF->getContents().resize(DF->getContents().size() + 8, 0);
551 }
552 
553 // Associate GPRel32 fixup with data and resize data area
556  flushPendingLabels(DF, DF->getContents().size());
557 
558  DF->getFixups().push_back(
559  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
560  DF->getContents().resize(DF->getContents().size() + 4, 0);
561 }
562 
563 // Associate GPRel64 fixup with data and resize data area
566  flushPendingLabels(DF, DF->getContents().size());
567 
568  DF->getFixups().push_back(
569  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
570  DF->getContents().resize(DF->getContents().size() + 8, 0);
571 }
572 
574  const MCExpr *Expr, SMLoc Loc) {
575  int64_t OffsetValue;
576  if (!Offset.evaluateAsAbsolute(OffsetValue))
577  llvm_unreachable("Offset is not absolute");
578 
579  if (OffsetValue < 0)
580  llvm_unreachable("Offset is negative");
581 
583  flushPendingLabels(DF, DF->getContents().size());
584 
585  Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
586  if (!MaybeKind.hasValue())
587  return true;
588 
589  MCFixupKind Kind = *MaybeKind;
590 
591  if (Expr == nullptr)
592  Expr =
593  MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
594  DF->getFixups().push_back(MCFixup::create(OffsetValue, Expr, Kind, Loc));
595  return false;
596 }
597 
598 void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
599  SMLoc Loc) {
601  flushPendingLabels(DF, DF->getContents().size());
602 
603  assert(getCurrentSectionOnly() && "need a section");
604  insert(new MCFillFragment(FillValue, NumBytes, Loc));
605 }
606 
607 void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
608  int64_t Expr, SMLoc Loc) {
609  int64_t IntNumValues;
610  if (!NumValues.evaluateAsAbsolute(IntNumValues, getAssembler())) {
611  getContext().reportError(Loc, "expected absolute expression");
612  return;
613  }
614 
615  if (IntNumValues < 0) {
618  "'.fill' directive with negative repeat count has no effect");
619  return;
620  }
621 
622  int64_t NonZeroSize = Size > 4 ? 4 : Size;
623  Expr &= ~0ULL >> (64 - NonZeroSize * 8);
624  for (uint64_t i = 0, e = IntNumValues; i != e; ++i) {
625  EmitIntValue(Expr, NonZeroSize);
626  if (NonZeroSize < Size)
627  EmitIntValue(0, Size - NonZeroSize);
628  }
629 }
630 
632  getAssembler().addFileName(Filename);
633 }
634 
636  // If we are generating dwarf for assembly source files dump out the sections.
637  if (getContext().getGenDwarfForAssembly())
638  MCGenDwarfInfo::Emit(this);
639 
640  // Dump out the dwarf file & directory tables and line tables.
641  MCDwarfLineTable::Emit(this, getAssembler().getDWARFLinetableParams());
642 
643  flushPendingLabels(nullptr);
644  getAssembler().Finish();
645 }
virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName)
This implements the DWARF2 &#39;.loc fileno lineno ...&#39; assembler directive.
Definition: MCStreamer.cpp:211
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
virtual void EmitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion)
This implements the CodeView &#39;.cv_def_range&#39; assembler directive.
Definition: MCStreamer.cpp:300
Fragment for adding required padding.
Definition: MCFragment.h:333
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection)
void handleCodePaddingBasicBlockEnd(const MCCodePaddingContext &Context)
Handles all target related code padding after writing a block to an object file.
void emitLineTableForFunction(MCObjectStreamer &OS, unsigned FuncId, const MCSymbol *FuncBegin, const MCSymbol *FuncEnd)
Emits a line table substream.
Definition: MCCodeView.cpp:319
A eight-byte dtp relative fixup.
Definition: MCFixup.h:37
LLVMContext & Context
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:236
bool hasInstructions() const
Definition: MCSection.h:137
static void Make(MCObjectStreamer *MCOS, MCSection *Section)
Definition: MCDwarf.cpp:88
static const char *const BundlingNotImplementedMsg
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:313
void EmitSLEB128IntValue(int64_t Value)
Special case of EmitSLEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:135
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:115
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void EmitSymbolValue(const MCSymbol *Sym, unsigned Size, bool IsSectionRelative=false)
Special case of EmitValue that avoids the client having to pass in a MCExpr for MCSymbols.
Definition: MCStreamer.cpp:146
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:294
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
virtual void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, MCInst &Res) const =0
Relax the instruction in the given fragment to the next wider instruction.
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:136
void EmitCodePaddingBasicBlockStart(const MCCodePaddingContext &Context) override
virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &)
Emit an instruction to a special fragment, because this instruction can change its size during relaxa...
MCObjectStreamer(MCContext &Context, std::unique_ptr< MCAsmBackend > TAB, raw_pwrite_stream &OS, std::unique_ptr< MCCodeEmitter > Emitter)
void setAlignment(unsigned Value)
Definition: MCSection.h:118
virtual void reset()
State management.
Definition: MCStreamer.cpp:84
static void Make(MCObjectStreamer *MCOS)
Definition: MCCodeView.cpp:682
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta)
Definition: MCDwarf.cpp:1786
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:494
void registerSymbol(const MCSymbol &Symbol, bool *Created=nullptr)
static MCFixupKind getKindForSize(unsigned Size, bool isPCRel)
Return the generic fixup kind for a value with the given size.
Definition: MCFixup.h:102
F(f)
void EmitCVFileChecksumOffsetDirective(unsigned FileNo) override
This implements the CodeView &#39;.cv_filechecksumoffset&#39; assembler directive.
void EmitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion) override
This implements the CodeView &#39;.cv_def_range&#39; assembler directive.
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&... args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
Definition: STLExtras.h:982
void handleCodePaddingInstructionEnd(const MCInst &Inst)
Handles all target related code padding after writing an instruction to an object file...
virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo)
Emit the absolute difference between two symbols encoded with ULEB128.
Definition: MCStreamer.cpp:914
static void Emit(MCStreamer *MCOS, MCDwarfLineTableParams Params, int64_t LineDelta, uint64_t AddrDelta)
Utility function to emit the encoding to a streamer.
Definition: MCDwarf.cpp:632
bool isBundlingEnabled() const
Definition: MCAssembler.h:308
virtual void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Emit the expression Value into the output as a native integer of the given Size bytes.
Definition: MCStreamer.cpp:951
void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel, const MCSymbol *Label, unsigned PointerSize)
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
Definition: MCStreamer.cpp:887
void EmitCVStringTableDirective() override
This implements the CodeView &#39;.cv_stringtable&#39; assembler directive.
virtual void EmitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:339
unsigned getAlignment() const
Definition: MCSection.h:117
void emitInlineLineTableForFunction(MCObjectStreamer &OS, unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
Definition: MCCodeView.cpp:414
MCContext & getContext() const
Definition: MCStreamer.h:248
void PrintMessage(raw_ostream &OS, SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None, bool ShowColors=true) const
Emit a message about the specified location with the specified string.
Definition: SourceMgr.cpp:248
Definition: BitVector.h:921
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
void setHasInstructions(bool Value)
Definition: MCSection.h:138
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override
Emit an weak reference from Alias to Symbol.
MCCodeEmitter & getEmitter() const
Definition: MCAssembler.h:279
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.
A four-byte tp relative fixup.
Definition: MCFixup.h:38
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
bool EmitRelocDirective(const MCExpr &Offset, StringRef Name, const MCExpr *Expr, SMLoc Loc) override
Emit a .reloc directive.
bool registerSection(MCSection &Section)
MCSymbol * Begin
Definition: MCDwarf.h:551
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:273
bool mayHaveInstructions(MCSection &Sec) const override
void EmitBundleLock(bool AlignToEnd) override
The following instructions are a bundle-locked group.
virtual void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt, StringRef FileName, SMLoc Loc)
This implements the CodeView &#39;.cv_loc&#39; assembler directive.
Definition: MCStreamer.cpp:269
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:844
Context object for machine code objects.
Definition: MCContext.h:63
void EmitDTPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a dtprel (64-bit DTP relative) value.
void emitDefRange(MCObjectStreamer &OS, ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion)
Definition: MCCodeView.cpp:427
A four-byte gp relative fixup.
Definition: MCFixup.h:34
void emitFill(const MCExpr &NumBytes, uint64_t FillValue, SMLoc Loc=SMLoc()) override
Emit Size bytes worth of the value specified by FillValue.
void EmitFileDirective(StringRef Filename) override
Switch to a new logical file.
Streaming object file generation interface.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
bool isBundleLocked() const
Definition: MCSection.h:128
void EmitDTPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a dtprel (32-bit DTP relative) value.
SmallVectorImpl< char > & getContents()
Definition: MCFragment.h:183
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Definition: MCStreamer.cpp:111
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition: MCExpr.cpp:148
void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size) override
Emit the absolute difference between two symbols if possible.
A relaxable fragment holds on to its MCInst, since it may need to be relaxed during the assembler lay...
Definition: MCFragment.h:257
A four-byte dtp relative fixup.
Definition: MCFixup.h:36
void EmitULEB128Value(const MCExpr *Value) override
Streaming machine code generation interface.
Definition: MCStreamer.h:183
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:216
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc()) override
Emit a label for Symbol into the current section.
void visitUsedSymbol(const MCSymbol &Sym) override
void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt, StringRef FileName, SMLoc Loc) override
This implements the CodeView &#39;.cv_loc&#39; assembler directive.
virtual void EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart, const MCSymbol *FnEnd)
This implements the CodeView &#39;.cv_linetable&#39; assembler directive.
Definition: MCStreamer.cpp:290
void EmitSLEB128Value(const MCExpr *Value) override
void insert(MCFragment *F)
void EmitCodePaddingBasicBlockEnd(const MCCodePaddingContext &Context) override
void EmitCodeAlignment(unsigned ByteAlignment, unsigned MaxBytesToEmit=0) override
Emit nops until the byte alignment ByteAlignment is reached.
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
Definition: SmallVector.h:116
MCAssembler & getAssembler()
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:23
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCFragment.h:208
virtual bool mayNeedRelaxation(const MCInst &Inst) const =0
Check whether the given instruction may need relaxation.
static const unsigned End
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:577
uint64_t getOffset() const
Definition: MCSymbol.h:319
A eight-byte tp relative fixup.
Definition: MCFixup.h:39
void EmitFrames(MCAsmBackend *MAB)
const SourceMgr * getSourceManager() const
Definition: MCContext.h:286
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:390
void handleCodePaddingInstructionBegin(const MCInst &Inst)
Handles all target related code padding before writing a new instruction to an object file...
void setOffset(uint64_t Value)
Definition: MCSymbol.h:325
static MCFixup create(uint32_t Offset, const MCExpr *Value, MCFixupKind Kind, SMLoc Loc=SMLoc())
Definition: MCFixup.h:82
void emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc) override
Emit some number of copies of Value until the byte offset Offset is reached.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void clearDwarfLocSeen()
Definition: MCContext.h:565
void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0) override
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
MCPaddingFragment * getOrCreatePaddingFragment()
static const MCExpr * buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A, const MCSymbol *B)
void EmitCFISections(bool EH, bool Debug) override
void handleCodePaddingBasicBlockStart(MCObjectStreamer *OS, const MCCodePaddingContext &Context)
Handles all target related code padding when starting to write a new basic block to an object file...
void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, const MCSymbol *Label)
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override
Update streamer for a new active section.
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
Definition: MCStreamer.cpp:895
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:277
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:382
virtual void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym)
This implements the CodeView &#39;.cv_inline_linetable&#39; assembler directive.
Definition: MCStreamer.cpp:294
void EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *Begin, const MCSymbol *End) override
This implements the CodeView &#39;.cv_linetable&#39; assembler directive.
void addFileName(StringRef FileName)
Definition: MCAssembler.h:422
bool getRelaxAll() const
Definition: MCAssembler.h:305
void flushPendingLabels(MCFragment *F, uint64_t FOffset=0)
If any labels have been emitted but not assigned fragments, ensure that they get assigned, either to F if possible or to a new data fragment.
void EmitBundleAlignMode(unsigned AlignPow2) override
Set the bundle alignment mode from now on in the section.
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:330
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
Definition: MCFragment.h:115
static void Emit(MCStreamer *MCOS)
Definition: MCDwarf.cpp:1069
static void emitDwarfSetLineAddr(MCObjectStreamer &OS, MCDwarfLineTableParams Params, int64_t LineDelta, const MCSymbol *Label, int PointerSize)
iterator begin() const
Definition: StringRef.h:106
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
Definition: SmallVector.h:396
void EmitTPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a tprel (32-bit TP relative) value.
static void Emit(MCObjectStreamer *MCOS, MCDwarfLineTableParams Params)
Definition: MCDwarf.cpp:233
Basic Alias true
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Definition: SmallVector.h:120
iterator insert(iterator where, pointer New)
Definition: ilist.h:241
unsigned getNumFrameInfos()
Definition: MCStreamer.h:254
void EmitBundleUnlock() override
Ends a bundle-locked group.
void FinishImpl() override
Streamer specific finalization.
void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value) override
Emit an assignment of Value to Symbol.
void reset() override
state management
static Optional< uint64_t > absoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo)
Generic base class for all target subtargets.
void emitStringTable(MCObjectStreamer &OS)
Emits the string table substream.
Definition: MCCodeView.cpp:163
void emitFileChecksumOffset(MCObjectStreamer &OS, unsigned FileNo)
Emits the offset into the checksum table of the given file number.
Definition: MCCodeView.cpp:240
void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc()) override
Emit the expression Value into the output as a native integer of the given Size bytes.
void EmitDwarfLocDirective(unsigned FileNo, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator, StringRef FileName) override
This implements the DWARF2 &#39;.loc fileno lineno ...&#39; assembler directive.
void EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum, const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) override
This implements the CodeView &#39;.cv_inline_linetable&#39; assembler directive.
MCFragment * getCurrentFragment() const
CodeViewContext & getCVContext()
Definition: MCContext.cpp:567
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:339
const unsigned Kind
Fragment for data and encoded instructions.
Definition: MCFragment.h:226
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection)
Definition: MCSection.cpp:57
LLVM Value Representation.
Definition: Value.h:73
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:40
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
void EmitGPRel32Value(const MCExpr *Value) override
Emit the expression Value into the output as a gprel32 (32-bit GP relative) value.
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:321
Subtraction.
Definition: MCExpr.h:431
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1726
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
FragmentListType::iterator iterator
Definition: MCSection.h:53
void EmitULEB128IntValue(uint64_t Value)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:126
void EmitCVFileChecksumsDirective() override
This implements the CodeView &#39;.cv_filechecksums&#39; assembler directive.
Represents a location in source code.
Definition: SMLoc.h:24
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:385
void emitFileChecksums(MCObjectStreamer &OS)
Emits the file checksum substream.
Definition: MCCodeView.cpp:185
void setParent(MCSection *Value)
Definition: MCFragment.h:105
iterator end() const
Definition: StringRef.h:108
void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo) override
Emit the absolute difference between two symbols encoded with ULEB128.
void Finish()
Finish - Do final processing and write the object to the output stream.
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:143
void EmitGPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a gprel64 (64-bit GP relative) value.
MCDataFragment * getOrCreateDataFragment()
Get a data fragment to write into, creating a new one if the current fragment is not a data fragment...
void EmitTPRel64Value(const MCExpr *Value) override
Emit the expression Value into the output as a tprel (64-bit TP relative) value.
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool=false) override
Emit the given Instruction into the current section.
void resize(size_type N)
Definition: SmallVector.h:353