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 
55  const MCSymbol *Lo,
56  unsigned Size) {
57  // If not assigned to the same (valid) fragment, fallback.
58  if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
59  Hi->isVariable() || Lo->isVariable()) {
61  return;
62  }
63 
64  EmitIntValue(Hi->getOffset() - Lo->getOffset(), Size);
65 }
66 
68  if (Assembler)
69  Assembler->reset();
70  CurInsertionPoint = MCSection::iterator();
71  EmitEHFrame = true;
72  EmitDebugFrame = false;
73  PendingLabels.clear();
75 }
76 
78  if (!getNumFrameInfos())
79  return;
80 
81  if (EmitEHFrame)
82  MCDwarfFrameEmitter::Emit(*this, MAB, true);
83 
84  if (EmitDebugFrame)
85  MCDwarfFrameEmitter::Emit(*this, MAB, false);
86 }
87 
89  assert(getCurrentSectionOnly() && "No current section!");
90 
91  if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
92  return &*std::prev(CurInsertionPoint);
93 
94  return nullptr;
95 }
96 
98  MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
99  // When bundling is enabled, we don't want to add data to a fragment that
100  // already has instructions (see MCELFStreamer::EmitInstToData for details)
101  if (!F || (Assembler->isBundlingEnabled() && !Assembler->getRelaxAll() &&
102  F->hasInstructions())) {
103  F = new MCDataFragment();
104  insert(F);
105  }
106  return F;
107 }
108 
111  dyn_cast_or_null<MCPaddingFragment>(getCurrentFragment());
112  if (!F) {
113  F = new MCPaddingFragment();
114  insert(F);
115  }
116  return F;
117 }
118 
120  Assembler->registerSymbol(Sym);
121 }
122 
124  MCStreamer::EmitCFISections(EH, Debug);
125  EmitEHFrame = EH;
126  EmitDebugFrame = Debug;
127 }
128 
130  SMLoc Loc) {
131  MCStreamer::EmitValueImpl(Value, Size, Loc);
133  flushPendingLabels(DF, DF->getContents().size());
134 
135  MCCVLineEntry::Make(this);
137 
138  // Avoid fixups when possible.
139  int64_t AbsValue;
140  if (Value->evaluateAsAbsolute(AbsValue, getAssembler())) {
141  if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
143  Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
144  return;
145  }
146  EmitIntValue(AbsValue, Size);
147  return;
148  }
149  DF->getFixups().push_back(
150  MCFixup::create(DF->getContents().size(), Value,
151  MCFixup::getKindForSize(Size, false), Loc));
152  DF->getContents().resize(DF->getContents().size() + Size, 0);
153 }
154 
155 MCSymbol *MCObjectStreamer::EmitCFILabel() {
156  MCSymbol *Label = getContext().createTempSymbol("cfi", true);
157  EmitLabel(Label);
158  return Label;
159 }
160 
161 void MCObjectStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
162  // We need to create a local symbol to avoid relocations.
163  Frame.Begin = getContext().createTempSymbol();
164  EmitLabel(Frame.Begin);
165 }
166 
167 void MCObjectStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
168  Frame.End = getContext().createTempSymbol();
169  EmitLabel(Frame.End);
170 }
171 
173  MCStreamer::EmitLabel(Symbol, Loc);
174 
175  getAssembler().registerSymbol(*Symbol);
176 
177  // If there is a current fragment, mark the symbol as pointing into it.
178  // Otherwise queue the label and set its fragment pointer when we emit the
179  // next fragment.
180  auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
181  if (F && !(getAssembler().isBundlingEnabled() &&
182  getAssembler().getRelaxAll())) {
183  Symbol->setFragment(F);
184  Symbol->setOffset(F->getContents().size());
185  } else {
186  PendingLabels.push_back(Symbol);
187  }
188 }
189 
191  MCStreamer::EmitLabel(Symbol, Loc);
192  getAssembler().registerSymbol(*Symbol);
193  auto *DF = dyn_cast_or_null<MCDataFragment>(F);
194  if (DF)
195  Symbol->setFragment(F);
196  else
197  PendingLabels.push_back(Symbol);
198 }
199 
201  int64_t IntValue;
202  if (Value->evaluateAsAbsolute(IntValue, getAssembler())) {
203  EmitULEB128IntValue(IntValue);
204  return;
205  }
206  insert(new MCLEBFragment(*Value, false));
207 }
208 
210  int64_t IntValue;
211  if (Value->evaluateAsAbsolute(IntValue, getAssembler())) {
212  EmitSLEB128IntValue(IntValue);
213  return;
214  }
215  insert(new MCLEBFragment(*Value, true));
216 }
217 
219  const MCSymbol *Symbol) {
220  report_fatal_error("This file format doesn't support weak aliases.");
221 }
222 
224  const MCExpr *Subsection) {
225  changeSectionImpl(Section, Subsection);
226 }
227 
229  const MCExpr *Subsection) {
230  assert(Section && "Cannot switch to a null section!");
231  flushPendingLabels(nullptr);
233 
234  bool Created = getAssembler().registerSection(*Section);
235 
236  int64_t IntSubsection = 0;
237  if (Subsection &&
238  !Subsection->evaluateAsAbsolute(IntSubsection, getAssembler()))
239  report_fatal_error("Cannot evaluate subsection number");
240  if (IntSubsection < 0 || IntSubsection > 8192)
241  report_fatal_error("Subsection number out of range");
242  CurInsertionPoint =
243  Section->getSubsectionInsertionPoint(unsigned(IntSubsection));
244  return Created;
245 }
246 
248  getAssembler().registerSymbol(*Symbol);
249  MCStreamer::EmitAssignment(Symbol, Value);
250 }
251 
253  return Sec.hasInstructions();
254 }
255 
257  const MCSubtargetInfo &STI, bool) {
259  EmitInstructionImpl(Inst, STI);
261 }
262 
263 void MCObjectStreamer::EmitInstructionImpl(const MCInst &Inst,
264  const MCSubtargetInfo &STI) {
265  MCStreamer::EmitInstruction(Inst, STI);
266 
268  Sec->setHasInstructions(true);
269 
270  // Now that a machine instruction has been assembled into this section, make
271  // a line entry for any .loc directive that has been seen.
272  MCCVLineEntry::Make(this);
274 
275  // If this instruction doesn't need relaxation, just emit it as data.
276  MCAssembler &Assembler = getAssembler();
277  if (!Assembler.getBackend().mayNeedRelaxation(Inst)) {
278  EmitInstToData(Inst, STI);
279  return;
280  }
281 
282  // Otherwise, relax and emit it as data if either:
283  // - The RelaxAll flag was passed
284  // - Bundling is enabled and this instruction is inside a bundle-locked
285  // group. We want to emit all such instructions into the same data
286  // fragment.
287  if (Assembler.getRelaxAll() ||
288  (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
289  MCInst Relaxed;
290  getAssembler().getBackend().relaxInstruction(Inst, STI, Relaxed);
291  while (getAssembler().getBackend().mayNeedRelaxation(Relaxed))
292  getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed);
293  EmitInstToData(Relaxed, STI);
294  return;
295  }
296 
297  // Otherwise emit to a separate fragment.
298  EmitInstToFragment(Inst, STI);
299 }
300 
302  const MCSubtargetInfo &STI) {
303  if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
304  llvm_unreachable("All instructions should have already been relaxed");
305 
306  // Always create a new, separate fragment here, because its size can change
307  // during relaxation.
308  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
309  insert(IF);
310 
311  SmallString<128> Code;
312  raw_svector_ostream VecOS(Code);
313  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
314  STI);
315  IF->getContents().append(Code.begin(), Code.end());
316 }
317 
318 #ifndef NDEBUG
319 static const char *const BundlingNotImplementedMsg =
320  "Aligned bundling is not implemented for this object format";
321 #endif
322 
323 void MCObjectStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
324  llvm_unreachable(BundlingNotImplementedMsg);
325 }
326 
327 void MCObjectStreamer::EmitBundleLock(bool AlignToEnd) {
328  llvm_unreachable(BundlingNotImplementedMsg);
329 }
330 
332  llvm_unreachable(BundlingNotImplementedMsg);
333 }
334 
335 void MCObjectStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
336  unsigned Column, unsigned Flags,
337  unsigned Isa,
338  unsigned Discriminator,
339  StringRef FileName) {
340  // In case we see two .loc directives in a row, make sure the
341  // first one gets a line entry.
343 
344  this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
345  Isa, Discriminator, FileName);
346 }
347 
348 static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
349  const MCSymbol *B) {
350  MCContext &Context = OS.getContext();
352  const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
353  const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
354  const MCExpr *AddrDelta =
355  MCBinaryExpr::create(MCBinaryExpr::Sub, ARef, BRef, Context);
356  return AddrDelta;
357 }
358 
360  MCDwarfLineTableParams Params,
361  int64_t LineDelta, const MCSymbol *Label,
362  int PointerSize) {
363  // emit the sequence to set the address
364  OS.EmitIntValue(dwarf::DW_LNS_extended_op, 1);
365  OS.EmitULEB128IntValue(PointerSize + 1);
366  OS.EmitIntValue(dwarf::DW_LNE_set_address, 1);
367  OS.EmitSymbolValue(Label, PointerSize);
368 
369  // emit the sequence for the LineDelta (from 1) and a zero address delta.
370  MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
371 }
372 
374  const MCSymbol *LastLabel,
375  const MCSymbol *Label,
376  unsigned PointerSize) {
377  if (!LastLabel) {
378  emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
379  Label, PointerSize);
380  return;
381  }
382  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
383  int64_t Res;
384  if (AddrDelta->evaluateAsAbsolute(Res, getAssembler())) {
385  MCDwarfLineAddr::Emit(this, Assembler->getDWARFLinetableParams(), LineDelta,
386  Res);
387  return;
388  }
389  insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
390 }
391 
393  const MCSymbol *Label) {
394  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
395  int64_t Res;
396  if (AddrDelta->evaluateAsAbsolute(Res, getAssembler())) {
398  return;
399  }
400  insert(new MCDwarfCallFrameFragment(*AddrDelta));
401 }
402 
403 void MCObjectStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
404  unsigned Line, unsigned Column,
405  bool PrologueEnd, bool IsStmt,
406  StringRef FileName, SMLoc Loc) {
407  // In case we see two .cv_loc directives in a row, make sure the
408  // first one gets a line entry.
409  MCCVLineEntry::Make(this);
410 
411  this->MCStreamer::EmitCVLocDirective(FunctionId, FileNo, Line, Column,
412  PrologueEnd, IsStmt, FileName, Loc);
413 }
414 
416  const MCSymbol *Begin,
417  const MCSymbol *End) {
418  getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
419  End);
420  this->MCStreamer::EmitCVLinetableDirective(FunctionId, Begin, End);
421 }
422 
424  unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
425  const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
427  *this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
428  FnEndSym);
430  PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
431 }
432 
434  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
435  StringRef FixedSizePortion) {
436  getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
437  this->MCStreamer::EmitCVDefRangeDirective(Ranges, FixedSizePortion);
438 }
439 
442 }
445 }
446 
449 }
450 
452  MCCVLineEntry::Make(this);
455  flushPendingLabels(DF, DF->getContents().size());
456  DF->getContents().append(Data.begin(), Data.end());
457 }
458 
460  int64_t Value,
461  unsigned ValueSize,
462  unsigned MaxBytesToEmit) {
463  if (MaxBytesToEmit == 0)
464  MaxBytesToEmit = ByteAlignment;
465  insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
466 
467  // Update the maximum alignment on the current section if necessary.
468  MCSection *CurSec = getCurrentSectionOnly();
469  if (ByteAlignment > CurSec->getAlignment())
470  CurSec->setAlignment(ByteAlignment);
471 }
472 
474  unsigned MaxBytesToEmit) {
475  EmitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
476  cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true);
477 }
478 
480  unsigned char Value,
481  SMLoc Loc) {
482  insert(new MCOrgFragment(*Offset, Value, Loc));
483 }
484 
486  const MCCodePaddingContext &Context) {
488 }
489 
491  const MCCodePaddingContext &Context) {
493 }
494 
495 // Associate DTPRel32 fixup with data and resize data area
498  flushPendingLabels(DF, DF->getContents().size());
499 
500  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
501  Value, FK_DTPRel_4));
502  DF->getContents().resize(DF->getContents().size() + 4, 0);
503 }
504 
505 // Associate DTPRel64 fixup with data and resize data area
508  flushPendingLabels(DF, DF->getContents().size());
509 
510  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
511  Value, FK_DTPRel_8));
512  DF->getContents().resize(DF->getContents().size() + 8, 0);
513 }
514 
515 // Associate TPRel32 fixup with data and resize data area
518  flushPendingLabels(DF, DF->getContents().size());
519 
520  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
521  Value, FK_TPRel_4));
522  DF->getContents().resize(DF->getContents().size() + 4, 0);
523 }
524 
525 // Associate TPRel64 fixup with data and resize data area
528  flushPendingLabels(DF, DF->getContents().size());
529 
530  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
531  Value, FK_TPRel_8));
532  DF->getContents().resize(DF->getContents().size() + 8, 0);
533 }
534 
535 // Associate GPRel32 fixup with data and resize data area
538  flushPendingLabels(DF, DF->getContents().size());
539 
540  DF->getFixups().push_back(
541  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
542  DF->getContents().resize(DF->getContents().size() + 4, 0);
543 }
544 
545 // Associate GPRel64 fixup with data and resize data area
548  flushPendingLabels(DF, DF->getContents().size());
549 
550  DF->getFixups().push_back(
551  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
552  DF->getContents().resize(DF->getContents().size() + 8, 0);
553 }
554 
556  const MCExpr *Expr, SMLoc Loc) {
557  int64_t OffsetValue;
558  if (!Offset.evaluateAsAbsolute(OffsetValue))
559  llvm_unreachable("Offset is not absolute");
560 
561  if (OffsetValue < 0)
562  llvm_unreachable("Offset is negative");
563 
565  flushPendingLabels(DF, DF->getContents().size());
566 
567  Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
568  if (!MaybeKind.hasValue())
569  return true;
570 
571  MCFixupKind Kind = *MaybeKind;
572 
573  if (Expr == nullptr)
574  Expr =
575  MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
576  DF->getFixups().push_back(MCFixup::create(OffsetValue, Expr, Kind, Loc));
577  return false;
578 }
579 
580 void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
581  SMLoc Loc) {
583  flushPendingLabels(DF, DF->getContents().size());
584 
585  assert(getCurrentSectionOnly() && "need a section");
586  insert(new MCFillFragment(FillValue, NumBytes, Loc));
587 }
588 
589 void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
590  int64_t Expr, SMLoc Loc) {
591  int64_t IntNumValues;
592  if (!NumValues.evaluateAsAbsolute(IntNumValues, getAssembler())) {
593  getContext().reportError(Loc, "expected absolute expression");
594  return;
595  }
596 
597  if (IntNumValues < 0) {
600  "'.fill' directive with negative repeat count has no effect");
601  return;
602  }
603 
604  int64_t NonZeroSize = Size > 4 ? 4 : Size;
605  Expr &= ~0ULL >> (64 - NonZeroSize * 8);
606  for (uint64_t i = 0, e = IntNumValues; i != e; ++i) {
607  EmitIntValue(Expr, NonZeroSize);
608  if (NonZeroSize < Size)
609  EmitIntValue(0, Size - NonZeroSize);
610  }
611 }
612 
614  getAssembler().addFileName(Filename);
615 }
616 
618  // If we are generating dwarf for assembly source files dump out the sections.
619  if (getContext().getGenDwarfForAssembly())
620  MCGenDwarfInfo::Emit(this);
621 
622  // Dump out the dwarf file & directory tables and line tables.
623  MCDwarfLineTable::Emit(this, getAssembler().getDWARFLinetableParams());
624 
625  flushPendingLabels(nullptr);
626  getAssembler().Finish();
627 }
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:203
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:292
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:64
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:138
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:149
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:83
static void Make(MCObjectStreamer *MCOS)
Definition: MCCodeView.cpp:682
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta)
Definition: MCDwarf.cpp:1660
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:489
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:950
void handleCodePaddingInstructionEnd(const MCInst &Inst)
Handles all target related code padding after writing an instruction to an object file...
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:506
bool isBundlingEnabled() const
Definition: MCAssembler.h:306
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:932
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:878
void EmitCVStringTableDirective() override
This implements the CodeView &#39;.cv_stringtable&#39; assembler directive.
virtual void EmitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:331
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:246
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:225
Definition: BitVector.h:920
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:277
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:508
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:261
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:835
Context object for machine code objects.
Definition: MCContext.h:60
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:110
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:159
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:181
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:215
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:282
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:573
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:280
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:553
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:886
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:275
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:286
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:420
bool getRelaxAll() const
Definition: MCAssembler.h:303
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:328
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:943
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:197
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:252
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
MCSubtargetInfo - 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:563
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:337
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:313
Subtraction.
Definition: MCExpr.h:431
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1600
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:132
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 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