LLVM  6.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/MCAsmInfo.h"
14 #include "llvm/MC/MCAssembler.h"
15 #include "llvm/MC/MCCodeEmitter.h"
16 #include "llvm/MC/MCCodeView.h"
17 #include "llvm/MC/MCContext.h"
18 #include "llvm/MC/MCDwarf.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/MC/MCObjectWriter.h"
21 #include "llvm/MC/MCSection.h"
22 #include "llvm/MC/MCSymbol.h"
24 #include "llvm/Support/SourceMgr.h"
26 using namespace llvm;
27 
30  MCCodeEmitter *Emitter_)
31  : MCStreamer(Context),
32  Assembler(new MCAssembler(Context, TAB, *Emitter_,
33  *TAB.createObjectWriter(OS))),
34  EmitEHFrame(true), EmitDebugFrame(false) {}
35 
37  delete &Assembler->getBackend();
38  delete &Assembler->getEmitter();
39  delete &Assembler->getWriter();
40  delete Assembler;
41 }
42 
44  if (PendingLabels.empty())
45  return;
46  if (!F) {
47  F = new MCDataFragment();
48  MCSection *CurSection = getCurrentSectionOnly();
49  CurSection->getFragmentList().insert(CurInsertionPoint, F);
50  F->setParent(CurSection);
51  }
52  for (MCSymbol *Sym : PendingLabels) {
53  Sym->setFragment(F);
54  Sym->setOffset(FOffset);
55  }
56  PendingLabels.clear();
57 }
58 
60  const MCSymbol *Lo,
61  unsigned Size) {
62  // If not assigned to the same (valid) fragment, fallback.
63  if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
64  Hi->isVariable() || Lo->isVariable()) {
66  return;
67  }
68 
69  EmitIntValue(Hi->getOffset() - Lo->getOffset(), Size);
70 }
71 
73  if (Assembler)
74  Assembler->reset();
75  CurInsertionPoint = MCSection::iterator();
76  EmitEHFrame = true;
77  EmitDebugFrame = false;
78  PendingLabels.clear();
80 }
81 
83  if (!getNumFrameInfos())
84  return;
85 
86  if (EmitEHFrame)
87  MCDwarfFrameEmitter::Emit(*this, MAB, true);
88 
89  if (EmitDebugFrame)
90  MCDwarfFrameEmitter::Emit(*this, MAB, false);
91 }
92 
94  assert(getCurrentSectionOnly() && "No current section!");
95 
96  if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
97  return &*std::prev(CurInsertionPoint);
98 
99  return nullptr;
100 }
101 
103  MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
104  // When bundling is enabled, we don't want to add data to a fragment that
105  // already has instructions (see MCELFStreamer::EmitInstToData for details)
106  if (!F || (Assembler->isBundlingEnabled() && !Assembler->getRelaxAll() &&
107  F->hasInstructions())) {
108  F = new MCDataFragment();
109  insert(F);
110  }
111  return F;
112 }
113 
115  Assembler->registerSymbol(Sym);
116 }
117 
119  MCStreamer::EmitCFISections(EH, Debug);
120  EmitEHFrame = EH;
121  EmitDebugFrame = Debug;
122 }
123 
125  SMLoc Loc) {
126  MCStreamer::EmitValueImpl(Value, Size, Loc);
128  flushPendingLabels(DF, DF->getContents().size());
129 
130  MCCVLineEntry::Make(this);
132 
133  // Avoid fixups when possible.
134  int64_t AbsValue;
135  if (Value->evaluateAsAbsolute(AbsValue, getAssembler())) {
136  if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
138  Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
139  return;
140  }
141  EmitIntValue(AbsValue, Size);
142  return;
143  }
144  DF->getFixups().push_back(
145  MCFixup::create(DF->getContents().size(), Value,
146  MCFixup::getKindForSize(Size, false), Loc));
147  DF->getContents().resize(DF->getContents().size() + Size, 0);
148 }
149 
150 void MCObjectStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
151  // We need to create a local symbol to avoid relocations.
152  Frame.Begin = getContext().createTempSymbol();
153  EmitLabel(Frame.Begin);
154 }
155 
156 void MCObjectStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
157  Frame.End = getContext().createTempSymbol();
158  EmitLabel(Frame.End);
159 }
160 
162  MCStreamer::EmitLabel(Symbol, Loc);
163 
164  getAssembler().registerSymbol(*Symbol);
165 
166  // If there is a current fragment, mark the symbol as pointing into it.
167  // Otherwise queue the label and set its fragment pointer when we emit the
168  // next fragment.
169  auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
170  if (F && !(getAssembler().isBundlingEnabled() &&
171  getAssembler().getRelaxAll())) {
172  Symbol->setFragment(F);
173  Symbol->setOffset(F->getContents().size());
174  } else {
175  PendingLabels.push_back(Symbol);
176  }
177 }
178 
180  MCStreamer::EmitLabel(Symbol, Loc);
181  getAssembler().registerSymbol(*Symbol);
182  auto *DF = dyn_cast_or_null<MCDataFragment>(F);
183  if (DF)
184  Symbol->setFragment(F);
185  else
186  PendingLabels.push_back(Symbol);
187 }
188 
190  int64_t IntValue;
191  if (Value->evaluateAsAbsolute(IntValue, getAssembler())) {
192  EmitULEB128IntValue(IntValue);
193  return;
194  }
195  insert(new MCLEBFragment(*Value, false));
196 }
197 
199  int64_t IntValue;
200  if (Value->evaluateAsAbsolute(IntValue, getAssembler())) {
201  EmitSLEB128IntValue(IntValue);
202  return;
203  }
204  insert(new MCLEBFragment(*Value, true));
205 }
206 
208  const MCSymbol *Symbol) {
209  report_fatal_error("This file format doesn't support weak aliases.");
210 }
211 
213  const MCExpr *Subsection) {
214  changeSectionImpl(Section, Subsection);
215 }
216 
218  const MCExpr *Subsection) {
219  assert(Section && "Cannot switch to a null section!");
220  flushPendingLabels(nullptr);
222 
223  bool Created = getAssembler().registerSection(*Section);
224 
225  int64_t IntSubsection = 0;
226  if (Subsection &&
227  !Subsection->evaluateAsAbsolute(IntSubsection, getAssembler()))
228  report_fatal_error("Cannot evaluate subsection number");
229  if (IntSubsection < 0 || IntSubsection > 8192)
230  report_fatal_error("Subsection number out of range");
231  CurInsertionPoint =
232  Section->getSubsectionInsertionPoint(unsigned(IntSubsection));
233  return Created;
234 }
235 
237  getAssembler().registerSymbol(*Symbol);
238  MCStreamer::EmitAssignment(Symbol, Value);
239 }
240 
242  return Sec.hasInstructions();
243 }
244 
246  const MCSubtargetInfo &STI, bool) {
247  MCStreamer::EmitInstruction(Inst, STI);
248 
250  Sec->setHasInstructions(true);
251 
252  // Now that a machine instruction has been assembled into this section, make
253  // a line entry for any .loc directive that has been seen.
254  MCCVLineEntry::Make(this);
256 
257  // If this instruction doesn't need relaxation, just emit it as data.
258  MCAssembler &Assembler = getAssembler();
259  if (!Assembler.getBackend().mayNeedRelaxation(Inst)) {
260  EmitInstToData(Inst, STI);
261  return;
262  }
263 
264  // Otherwise, relax and emit it as data if either:
265  // - The RelaxAll flag was passed
266  // - Bundling is enabled and this instruction is inside a bundle-locked
267  // group. We want to emit all such instructions into the same data
268  // fragment.
269  if (Assembler.getRelaxAll() ||
270  (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
271  MCInst Relaxed;
272  getAssembler().getBackend().relaxInstruction(Inst, STI, Relaxed);
273  while (getAssembler().getBackend().mayNeedRelaxation(Relaxed))
274  getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed);
275  EmitInstToData(Relaxed, STI);
276  return;
277  }
278 
279  // Otherwise emit to a separate fragment.
280  EmitInstToFragment(Inst, STI);
281 }
282 
284  const MCSubtargetInfo &STI) {
285  if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
286  llvm_unreachable("All instructions should have already been relaxed");
287 
288  // Always create a new, separate fragment here, because its size can change
289  // during relaxation.
290  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
291  insert(IF);
292 
293  SmallString<128> Code;
294  raw_svector_ostream VecOS(Code);
295  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
296  STI);
297  IF->getContents().append(Code.begin(), Code.end());
298 }
299 
300 #ifndef NDEBUG
301 static const char *const BundlingNotImplementedMsg =
302  "Aligned bundling is not implemented for this object format";
303 #endif
304 
305 void MCObjectStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
306  llvm_unreachable(BundlingNotImplementedMsg);
307 }
308 
309 void MCObjectStreamer::EmitBundleLock(bool AlignToEnd) {
310  llvm_unreachable(BundlingNotImplementedMsg);
311 }
312 
314  llvm_unreachable(BundlingNotImplementedMsg);
315 }
316 
317 void MCObjectStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
318  unsigned Column, unsigned Flags,
319  unsigned Isa,
320  unsigned Discriminator,
321  StringRef FileName) {
322  // In case we see two .loc directives in a row, make sure the
323  // first one gets a line entry.
325 
326  this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
327  Isa, Discriminator, FileName);
328 }
329 
331  const MCSymbol *B) {
332  MCContext &Context = OS.getContext();
334  const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
335  const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
336  const MCExpr *AddrDelta =
337  MCBinaryExpr::create(MCBinaryExpr::Sub, ARef, BRef, Context);
338  return AddrDelta;
339 }
340 
342  MCDwarfLineTableParams Params,
343  int64_t LineDelta, const MCSymbol *Label,
344  int PointerSize) {
345  // emit the sequence to set the address
346  OS.EmitIntValue(dwarf::DW_LNS_extended_op, 1);
347  OS.EmitULEB128IntValue(PointerSize + 1);
348  OS.EmitIntValue(dwarf::DW_LNE_set_address, 1);
349  OS.EmitSymbolValue(Label, PointerSize);
350 
351  // emit the sequence for the LineDelta (from 1) and a zero address delta.
352  MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
353 }
354 
356  const MCSymbol *LastLabel,
357  const MCSymbol *Label,
358  unsigned PointerSize) {
359  if (!LastLabel) {
360  emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
361  Label, PointerSize);
362  return;
363  }
364  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
365  int64_t Res;
366  if (AddrDelta->evaluateAsAbsolute(Res, getAssembler())) {
367  MCDwarfLineAddr::Emit(this, Assembler->getDWARFLinetableParams(), LineDelta,
368  Res);
369  return;
370  }
371  insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
372 }
373 
375  const MCSymbol *Label) {
376  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
377  int64_t Res;
378  if (AddrDelta->evaluateAsAbsolute(Res, getAssembler())) {
380  return;
381  }
382  insert(new MCDwarfCallFrameFragment(*AddrDelta));
383 }
384 
385 void MCObjectStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
386  unsigned Line, unsigned Column,
387  bool PrologueEnd, bool IsStmt,
388  StringRef FileName, SMLoc Loc) {
389  // In case we see two .cv_loc directives in a row, make sure the
390  // first one gets a line entry.
391  MCCVLineEntry::Make(this);
392 
393  this->MCStreamer::EmitCVLocDirective(FunctionId, FileNo, Line, Column,
394  PrologueEnd, IsStmt, FileName, Loc);
395 }
396 
398  const MCSymbol *Begin,
399  const MCSymbol *End) {
400  getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
401  End);
402  this->MCStreamer::EmitCVLinetableDirective(FunctionId, Begin, End);
403 }
404 
406  unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
407  const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
409  *this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
410  FnEndSym);
412  PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
413 }
414 
416  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
417  StringRef FixedSizePortion) {
418  getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
419  this->MCStreamer::EmitCVDefRangeDirective(Ranges, FixedSizePortion);
420 }
421 
424 }
427 }
428 
429 
431  MCCVLineEntry::Make(this);
434  flushPendingLabels(DF, DF->getContents().size());
435  DF->getContents().append(Data.begin(), Data.end());
436 }
437 
439  int64_t Value,
440  unsigned ValueSize,
441  unsigned MaxBytesToEmit) {
442  if (MaxBytesToEmit == 0)
443  MaxBytesToEmit = ByteAlignment;
444  insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
445 
446  // Update the maximum alignment on the current section if necessary.
447  MCSection *CurSec = getCurrentSectionOnly();
448  if (ByteAlignment > CurSec->getAlignment())
449  CurSec->setAlignment(ByteAlignment);
450 }
451 
453  unsigned MaxBytesToEmit) {
454  EmitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
455  cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true);
456 }
457 
459  unsigned char Value,
460  SMLoc Loc) {
461  insert(new MCOrgFragment(*Offset, Value, Loc));
462 }
463 
464 // Associate DTPRel32 fixup with data and resize data area
467  flushPendingLabels(DF, DF->getContents().size());
468 
469  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
470  Value, FK_DTPRel_4));
471  DF->getContents().resize(DF->getContents().size() + 4, 0);
472 }
473 
474 // Associate DTPRel64 fixup with data and resize data area
477  flushPendingLabels(DF, DF->getContents().size());
478 
479  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
480  Value, FK_DTPRel_8));
481  DF->getContents().resize(DF->getContents().size() + 8, 0);
482 }
483 
484 // Associate TPRel32 fixup with data and resize data area
487  flushPendingLabels(DF, DF->getContents().size());
488 
489  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
490  Value, FK_TPRel_4));
491  DF->getContents().resize(DF->getContents().size() + 4, 0);
492 }
493 
494 // Associate TPRel64 fixup with data and resize data area
497  flushPendingLabels(DF, DF->getContents().size());
498 
499  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
500  Value, FK_TPRel_8));
501  DF->getContents().resize(DF->getContents().size() + 8, 0);
502 }
503 
504 // Associate GPRel32 fixup with data and resize data area
507  flushPendingLabels(DF, DF->getContents().size());
508 
509  DF->getFixups().push_back(
510  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
511  DF->getContents().resize(DF->getContents().size() + 4, 0);
512 }
513 
514 // Associate GPRel64 fixup with data and resize data area
517  flushPendingLabels(DF, DF->getContents().size());
518 
519  DF->getFixups().push_back(
520  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
521  DF->getContents().resize(DF->getContents().size() + 8, 0);
522 }
523 
525  const MCExpr *Expr, SMLoc Loc) {
526  int64_t OffsetValue;
527  if (!Offset.evaluateAsAbsolute(OffsetValue))
528  llvm_unreachable("Offset is not absolute");
529 
530  if (OffsetValue < 0)
531  llvm_unreachable("Offset is negative");
532 
534  flushPendingLabels(DF, DF->getContents().size());
535 
536  Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
537  if (!MaybeKind.hasValue())
538  return true;
539 
540  MCFixupKind Kind = *MaybeKind;
541 
542  if (Expr == nullptr)
543  Expr =
544  MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
545  DF->getFixups().push_back(MCFixup::create(OffsetValue, Expr, Kind, Loc));
546  return false;
547 }
548 
549 void MCObjectStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) {
550  assert(getCurrentSectionOnly() && "need a section");
551  insert(new MCFillFragment(FillValue, NumBytes));
552 }
553 
554 void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
555  SMLoc Loc) {
557  flushPendingLabels(DF, DF->getContents().size());
558 
559  int64_t IntNumBytes;
560  if (!NumBytes.evaluateAsAbsolute(IntNumBytes, getAssembler())) {
561  getContext().reportError(Loc, "expected absolute expression");
562  return;
563  }
564 
565  if (IntNumBytes <= 0) {
566  getContext().reportError(Loc, "invalid number of bytes");
567  return;
568  }
569 
570  emitFill(IntNumBytes, FillValue);
571 }
572 
573 void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
574  int64_t Expr, SMLoc Loc) {
575  int64_t IntNumValues;
576  if (!NumValues.evaluateAsAbsolute(IntNumValues, getAssembler())) {
577  getContext().reportError(Loc, "expected absolute expression");
578  return;
579  }
580 
581  if (IntNumValues < 0) {
584  "'.fill' directive with negative repeat count has no effect");
585  return;
586  }
587 
588  MCStreamer::emitFill(IntNumValues, Size, Expr);
589 }
590 
592  getAssembler().addFileName(Filename);
593 }
594 
596  // If we are generating dwarf for assembly source files dump out the sections.
597  if (getContext().getGenDwarfForAssembly())
598  MCGenDwarfInfo::Emit(this);
599 
600  // Dump out the dwarf file & directory tables and line tables.
601  MCDwarfLineTable::Emit(this, getAssembler().getDWARFLinetableParams());
602 
603  flushPendingLabels(nullptr);
604  getAssembler().Finish();
605 }
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:191
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:280
void EmitBytes(StringRef Data) override
Emit the bytes in Data into the output.
bool changeSectionImpl(MCSection *Section, const MCExpr *Subsection)
void emitLineTableForFunction(MCObjectStreamer &OS, unsigned FuncId, const MCSymbol *FuncBegin, const MCSymbol *FuncEnd)
Emits a line table substream.
Definition: MCCodeView.cpp:192
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:234
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:305
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:117
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:103
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:128
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:295
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
virtual void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &)
Emit an instruction to a special fragment, because this instruction can change its size during relaxa...
void setAlignment(unsigned Value)
Definition: MCSection.h:118
virtual void reset()
State management.
Definition: MCStreamer.cpp:64
static void Make(MCObjectStreamer *MCOS)
Definition: MCCodeView.cpp:551
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta)
Definition: MCDwarf.cpp:1574
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:490
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
void EmitCVDefRangeDirective(ArrayRef< std::pair< const MCSymbol *, const MCSymbol *>> Ranges, StringRef FixedSizePortion) override
This implements the CodeView &#39;.cv_def_range&#39; assembler directive.
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:421
bool isBundlingEnabled() const
Definition: MCAssembler.h:290
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:834
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:780
void EmitCVStringTableDirective() override
This implements the CodeView &#39;.cv_stringtable&#39; assembler directive.
virtual void EmitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:319
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:284
MCContext & getContext() const
Definition: MCStreamer.h:226
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
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
MCDwarfLineTableParams getDWARFLinetableParams() const
Definition: MCAssembler.h:265
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:261
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:501
MCObjectWriter & getWriter() const
Definition: MCAssembler.h:263
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:274
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:249
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:737
Context object for machine code objects.
Definition: MCContext.h:59
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:297
A four-byte gp relative fixup.
Definition: MCFixup.h:34
#define F(x, y, z)
Definition: MD5.cpp:55
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:181
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:93
const char * Name
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:255
A four-byte dtp relative fixup.
Definition: MCFixup.h:36
void EmitULEB128Value(const MCExpr *Value) override
Streaming machine code generation interface.
Definition: MCStreamer.h:167
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:215
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:270
void EmitSLEB128Value(const MCExpr *Value) override
void insert(MCFragment *F)
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()
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:22
#define A
Definition: LargeTest.cpp:12
MCFixupKind
Extensible enumeration to represent the type of a fixup.
Definition: MCFixup.h:23
SmallVectorImpl< MCFixup > & getFixups()
Definition: MCFragment.h:206
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:608
uint64_t getOffset() const
Definition: MCSymbol.h:320
A eight-byte tp relative fixup.
Definition: MCFixup.h:39
void EmitFrames(MCAsmBackend *MAB)
const SourceMgr * getSourceManager() const
Definition: MCContext.h:279
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:390
void setOffset(uint64_t Value)
Definition: MCSymbol.h:326
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:577
void emitFill(uint64_t NumBytes, uint8_t FillValue) override
Emit NumBytes bytes worth of the value specified by FillValue.
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.
static const MCExpr * buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A, const MCSymbol *B)
void EmitCFISections(bool EH, bool Debug) override
void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel, const MCSymbol *Label)
#define B
Definition: LargeTest.cpp:24
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:788
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:259
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:383
virtual Optional< MCFixupKind > getFixupKind(StringRef Name) const
Map a relocation name used in .reloc to a fixup kind.
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:274
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:404
bool getRelaxAll() const
Definition: MCAssembler.h:287
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:308
bool hasInstructions() const
Does this fragment have instructions emitted into it? By default this is false, but specific fragment...
Definition: MCFragment.h:113
static void Emit(MCStreamer *MCOS)
Definition: MCDwarf.cpp:858
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:398
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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
static std::vector< std::string > Flags
Definition: FlagsTest.cpp:8
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:232
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:143
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.
virtual void emitFill(uint64_t NumBytes, uint8_t FillValue)
Emit NumBytes bytes worth of the value specified by FillValue.
Definition: MCStreamer.cpp:165
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.
void EmitULEB128IntValue(uint64_t Value, unsigned Padding=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:108
MCFragment * getCurrentFragment() const
CodeViewContext & getCVContext()
Definition: MCContext.cpp:598
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:333
const unsigned Kind
void reset()
Reuse an assembler instance.
Definition: MCAssembler.cpp:92
Fragment for data and encoded instructions.
Definition: MCFragment.h:224
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:35
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:301
Subtraction.
Definition: MCExpr.h:423
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1511
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
FragmentListType::iterator iterator
Definition: MCSection.h:53
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:165
void setParent(MCSection *Value)
Definition: MCFragment.h:103
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...
MCObjectStreamer(MCContext &Context, MCAsmBackend &TAB, raw_pwrite_stream &OS, MCCodeEmitter *Emitter)
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:355