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 
29  std::unique_ptr<MCAsmBackend> TAB,
31  std::unique_ptr<MCCodeEmitter> Emitter)
32  : MCStreamer(Context), ObjectWriter(TAB->createObjectWriter(OS)),
33  TAB(std::move(TAB)), Emitter(std::move(Emitter)),
34  Assembler(llvm::make_unique<MCAssembler>(Context, *this->TAB,
35  *this->Emitter, *ObjectWriter)),
36  EmitEHFrame(true), EmitDebugFrame(false) {}
37 
39 
41  if (PendingLabels.empty())
42  return;
43  if (!F) {
44  F = new MCDataFragment();
45  MCSection *CurSection = getCurrentSectionOnly();
46  CurSection->getFragmentList().insert(CurInsertionPoint, F);
47  F->setParent(CurSection);
48  }
49  for (MCSymbol *Sym : PendingLabels) {
50  Sym->setFragment(F);
51  Sym->setOffset(FOffset);
52  }
53  PendingLabels.clear();
54 }
55 
57  const MCSymbol *Lo,
58  unsigned Size) {
59  // If not assigned to the same (valid) fragment, fallback.
60  if (!Hi->getFragment() || Hi->getFragment() != Lo->getFragment() ||
61  Hi->isVariable() || Lo->isVariable()) {
63  return;
64  }
65 
66  EmitIntValue(Hi->getOffset() - Lo->getOffset(), Size);
67 }
68 
70  if (Assembler)
71  Assembler->reset();
72  CurInsertionPoint = MCSection::iterator();
73  EmitEHFrame = true;
74  EmitDebugFrame = false;
75  PendingLabels.clear();
77 }
78 
80  if (!getNumFrameInfos())
81  return;
82 
83  if (EmitEHFrame)
84  MCDwarfFrameEmitter::Emit(*this, MAB, true);
85 
86  if (EmitDebugFrame)
87  MCDwarfFrameEmitter::Emit(*this, MAB, false);
88 }
89 
91  assert(getCurrentSectionOnly() && "No current section!");
92 
93  if (CurInsertionPoint != getCurrentSectionOnly()->getFragmentList().begin())
94  return &*std::prev(CurInsertionPoint);
95 
96  return nullptr;
97 }
98 
100  MCDataFragment *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
101  // When bundling is enabled, we don't want to add data to a fragment that
102  // already has instructions (see MCELFStreamer::EmitInstToData for details)
103  if (!F || (Assembler->isBundlingEnabled() && !Assembler->getRelaxAll() &&
104  F->hasInstructions())) {
105  F = new MCDataFragment();
106  insert(F);
107  }
108  return F;
109 }
110 
113  dyn_cast_or_null<MCPaddingFragment>(getCurrentFragment());
114  if (!F) {
115  F = new MCPaddingFragment();
116  insert(F);
117  }
118  return F;
119 }
120 
122  Assembler->registerSymbol(Sym);
123 }
124 
126  MCStreamer::EmitCFISections(EH, Debug);
127  EmitEHFrame = EH;
128  EmitDebugFrame = Debug;
129 }
130 
132  SMLoc Loc) {
133  MCStreamer::EmitValueImpl(Value, Size, Loc);
135  flushPendingLabels(DF, DF->getContents().size());
136 
137  MCCVLineEntry::Make(this);
139 
140  // Avoid fixups when possible.
141  int64_t AbsValue;
142  if (Value->evaluateAsAbsolute(AbsValue, getAssembler())) {
143  if (!isUIntN(8 * Size, AbsValue) && !isIntN(8 * Size, AbsValue)) {
145  Loc, "value evaluated as " + Twine(AbsValue) + " is out of range.");
146  return;
147  }
148  EmitIntValue(AbsValue, Size);
149  return;
150  }
151  DF->getFixups().push_back(
152  MCFixup::create(DF->getContents().size(), Value,
153  MCFixup::getKindForSize(Size, false), Loc));
154  DF->getContents().resize(DF->getContents().size() + Size, 0);
155 }
156 
157 MCSymbol *MCObjectStreamer::EmitCFILabel() {
158  MCSymbol *Label = getContext().createTempSymbol("cfi", true);
159  EmitLabel(Label);
160  return Label;
161 }
162 
163 void MCObjectStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
164  // We need to create a local symbol to avoid relocations.
165  Frame.Begin = getContext().createTempSymbol();
166  EmitLabel(Frame.Begin);
167 }
168 
169 void MCObjectStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
170  Frame.End = getContext().createTempSymbol();
171  EmitLabel(Frame.End);
172 }
173 
175  MCStreamer::EmitLabel(Symbol, Loc);
176 
177  getAssembler().registerSymbol(*Symbol);
178 
179  // If there is a current fragment, mark the symbol as pointing into it.
180  // Otherwise queue the label and set its fragment pointer when we emit the
181  // next fragment.
182  auto *F = dyn_cast_or_null<MCDataFragment>(getCurrentFragment());
183  if (F && !(getAssembler().isBundlingEnabled() &&
184  getAssembler().getRelaxAll())) {
185  Symbol->setFragment(F);
186  Symbol->setOffset(F->getContents().size());
187  } else {
188  PendingLabels.push_back(Symbol);
189  }
190 }
191 
193  MCStreamer::EmitLabel(Symbol, Loc);
194  getAssembler().registerSymbol(*Symbol);
195  auto *DF = dyn_cast_or_null<MCDataFragment>(F);
196  if (DF)
197  Symbol->setFragment(F);
198  else
199  PendingLabels.push_back(Symbol);
200 }
201 
203  int64_t IntValue;
204  if (Value->evaluateAsAbsolute(IntValue, getAssembler())) {
205  EmitULEB128IntValue(IntValue);
206  return;
207  }
208  insert(new MCLEBFragment(*Value, false));
209 }
210 
212  int64_t IntValue;
213  if (Value->evaluateAsAbsolute(IntValue, getAssembler())) {
214  EmitSLEB128IntValue(IntValue);
215  return;
216  }
217  insert(new MCLEBFragment(*Value, true));
218 }
219 
221  const MCSymbol *Symbol) {
222  report_fatal_error("This file format doesn't support weak aliases.");
223 }
224 
226  const MCExpr *Subsection) {
227  changeSectionImpl(Section, Subsection);
228 }
229 
231  const MCExpr *Subsection) {
232  assert(Section && "Cannot switch to a null section!");
233  flushPendingLabels(nullptr);
235 
236  bool Created = getAssembler().registerSection(*Section);
237 
238  int64_t IntSubsection = 0;
239  if (Subsection &&
240  !Subsection->evaluateAsAbsolute(IntSubsection, getAssembler()))
241  report_fatal_error("Cannot evaluate subsection number");
242  if (IntSubsection < 0 || IntSubsection > 8192)
243  report_fatal_error("Subsection number out of range");
244  CurInsertionPoint =
245  Section->getSubsectionInsertionPoint(unsigned(IntSubsection));
246  return Created;
247 }
248 
250  getAssembler().registerSymbol(*Symbol);
251  MCStreamer::EmitAssignment(Symbol, Value);
252 }
253 
255  return Sec.hasInstructions();
256 }
257 
259  const MCSubtargetInfo &STI, bool) {
261  EmitInstructionImpl(Inst, STI);
263 }
264 
265 void MCObjectStreamer::EmitInstructionImpl(const MCInst &Inst,
266  const MCSubtargetInfo &STI) {
267  MCStreamer::EmitInstruction(Inst, STI);
268 
270  Sec->setHasInstructions(true);
271 
272  // Now that a machine instruction has been assembled into this section, make
273  // a line entry for any .loc directive that has been seen.
274  MCCVLineEntry::Make(this);
276 
277  // If this instruction doesn't need relaxation, just emit it as data.
278  MCAssembler &Assembler = getAssembler();
279  if (!Assembler.getBackend().mayNeedRelaxation(Inst)) {
280  EmitInstToData(Inst, STI);
281  return;
282  }
283 
284  // Otherwise, relax and emit it as data if either:
285  // - The RelaxAll flag was passed
286  // - Bundling is enabled and this instruction is inside a bundle-locked
287  // group. We want to emit all such instructions into the same data
288  // fragment.
289  if (Assembler.getRelaxAll() ||
290  (Assembler.isBundlingEnabled() && Sec->isBundleLocked())) {
291  MCInst Relaxed;
292  getAssembler().getBackend().relaxInstruction(Inst, STI, Relaxed);
293  while (getAssembler().getBackend().mayNeedRelaxation(Relaxed))
294  getAssembler().getBackend().relaxInstruction(Relaxed, STI, Relaxed);
295  EmitInstToData(Relaxed, STI);
296  return;
297  }
298 
299  // Otherwise emit to a separate fragment.
300  EmitInstToFragment(Inst, STI);
301 }
302 
304  const MCSubtargetInfo &STI) {
305  if (getAssembler().getRelaxAll() && getAssembler().isBundlingEnabled())
306  llvm_unreachable("All instructions should have already been relaxed");
307 
308  // Always create a new, separate fragment here, because its size can change
309  // during relaxation.
310  MCRelaxableFragment *IF = new MCRelaxableFragment(Inst, STI);
311  insert(IF);
312 
313  SmallString<128> Code;
314  raw_svector_ostream VecOS(Code);
315  getAssembler().getEmitter().encodeInstruction(Inst, VecOS, IF->getFixups(),
316  STI);
317  IF->getContents().append(Code.begin(), Code.end());
318 }
319 
320 #ifndef NDEBUG
321 static const char *const BundlingNotImplementedMsg =
322  "Aligned bundling is not implemented for this object format";
323 #endif
324 
325 void MCObjectStreamer::EmitBundleAlignMode(unsigned AlignPow2) {
326  llvm_unreachable(BundlingNotImplementedMsg);
327 }
328 
329 void MCObjectStreamer::EmitBundleLock(bool AlignToEnd) {
330  llvm_unreachable(BundlingNotImplementedMsg);
331 }
332 
334  llvm_unreachable(BundlingNotImplementedMsg);
335 }
336 
337 void MCObjectStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
338  unsigned Column, unsigned Flags,
339  unsigned Isa,
340  unsigned Discriminator,
341  StringRef FileName) {
342  // In case we see two .loc directives in a row, make sure the
343  // first one gets a line entry.
345 
346  this->MCStreamer::EmitDwarfLocDirective(FileNo, Line, Column, Flags,
347  Isa, Discriminator, FileName);
348 }
349 
350 static const MCExpr *buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A,
351  const MCSymbol *B) {
352  MCContext &Context = OS.getContext();
354  const MCExpr *ARef = MCSymbolRefExpr::create(A, Variant, Context);
355  const MCExpr *BRef = MCSymbolRefExpr::create(B, Variant, Context);
356  const MCExpr *AddrDelta =
357  MCBinaryExpr::create(MCBinaryExpr::Sub, ARef, BRef, Context);
358  return AddrDelta;
359 }
360 
362  MCDwarfLineTableParams Params,
363  int64_t LineDelta, const MCSymbol *Label,
364  int PointerSize) {
365  // emit the sequence to set the address
366  OS.EmitIntValue(dwarf::DW_LNS_extended_op, 1);
367  OS.EmitULEB128IntValue(PointerSize + 1);
368  OS.EmitIntValue(dwarf::DW_LNE_set_address, 1);
369  OS.EmitSymbolValue(Label, PointerSize);
370 
371  // emit the sequence for the LineDelta (from 1) and a zero address delta.
372  MCDwarfLineAddr::Emit(&OS, Params, LineDelta, 0);
373 }
374 
376  const MCSymbol *LastLabel,
377  const MCSymbol *Label,
378  unsigned PointerSize) {
379  if (!LastLabel) {
380  emitDwarfSetLineAddr(*this, Assembler->getDWARFLinetableParams(), LineDelta,
381  Label, PointerSize);
382  return;
383  }
384  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
385  int64_t Res;
386  if (AddrDelta->evaluateAsAbsolute(Res, getAssembler())) {
387  MCDwarfLineAddr::Emit(this, Assembler->getDWARFLinetableParams(), LineDelta,
388  Res);
389  return;
390  }
391  insert(new MCDwarfLineAddrFragment(LineDelta, *AddrDelta));
392 }
393 
395  const MCSymbol *Label) {
396  const MCExpr *AddrDelta = buildSymbolDiff(*this, Label, LastLabel);
397  int64_t Res;
398  if (AddrDelta->evaluateAsAbsolute(Res, getAssembler())) {
400  return;
401  }
402  insert(new MCDwarfCallFrameFragment(*AddrDelta));
403 }
404 
405 void MCObjectStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
406  unsigned Line, unsigned Column,
407  bool PrologueEnd, bool IsStmt,
408  StringRef FileName, SMLoc Loc) {
409  // In case we see two .cv_loc directives in a row, make sure the
410  // first one gets a line entry.
411  MCCVLineEntry::Make(this);
412 
413  this->MCStreamer::EmitCVLocDirective(FunctionId, FileNo, Line, Column,
414  PrologueEnd, IsStmt, FileName, Loc);
415 }
416 
418  const MCSymbol *Begin,
419  const MCSymbol *End) {
420  getContext().getCVContext().emitLineTableForFunction(*this, FunctionId, Begin,
421  End);
422  this->MCStreamer::EmitCVLinetableDirective(FunctionId, Begin, End);
423 }
424 
426  unsigned PrimaryFunctionId, unsigned SourceFileId, unsigned SourceLineNum,
427  const MCSymbol *FnStartSym, const MCSymbol *FnEndSym) {
429  *this, PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym,
430  FnEndSym);
432  PrimaryFunctionId, SourceFileId, SourceLineNum, FnStartSym, FnEndSym);
433 }
434 
436  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
437  StringRef FixedSizePortion) {
438  getContext().getCVContext().emitDefRange(*this, Ranges, FixedSizePortion);
439  this->MCStreamer::EmitCVDefRangeDirective(Ranges, FixedSizePortion);
440 }
441 
444 }
447 }
448 
451 }
452 
454  MCCVLineEntry::Make(this);
457  flushPendingLabels(DF, DF->getContents().size());
458  DF->getContents().append(Data.begin(), Data.end());
459 }
460 
462  int64_t Value,
463  unsigned ValueSize,
464  unsigned MaxBytesToEmit) {
465  if (MaxBytesToEmit == 0)
466  MaxBytesToEmit = ByteAlignment;
467  insert(new MCAlignFragment(ByteAlignment, Value, ValueSize, MaxBytesToEmit));
468 
469  // Update the maximum alignment on the current section if necessary.
470  MCSection *CurSec = getCurrentSectionOnly();
471  if (ByteAlignment > CurSec->getAlignment())
472  CurSec->setAlignment(ByteAlignment);
473 }
474 
476  unsigned MaxBytesToEmit) {
477  EmitValueToAlignment(ByteAlignment, 0, 1, MaxBytesToEmit);
478  cast<MCAlignFragment>(getCurrentFragment())->setEmitNops(true);
479 }
480 
482  unsigned char Value,
483  SMLoc Loc) {
484  insert(new MCOrgFragment(*Offset, Value, Loc));
485 }
486 
488  const MCCodePaddingContext &Context) {
490 }
491 
493  const MCCodePaddingContext &Context) {
495 }
496 
497 // Associate DTPRel32 fixup with data and resize data area
500  flushPendingLabels(DF, DF->getContents().size());
501 
502  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
503  Value, FK_DTPRel_4));
504  DF->getContents().resize(DF->getContents().size() + 4, 0);
505 }
506 
507 // Associate DTPRel64 fixup with data and resize data area
510  flushPendingLabels(DF, DF->getContents().size());
511 
512  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
513  Value, FK_DTPRel_8));
514  DF->getContents().resize(DF->getContents().size() + 8, 0);
515 }
516 
517 // Associate TPRel32 fixup with data and resize data area
520  flushPendingLabels(DF, DF->getContents().size());
521 
522  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
523  Value, FK_TPRel_4));
524  DF->getContents().resize(DF->getContents().size() + 4, 0);
525 }
526 
527 // Associate TPRel64 fixup with data and resize data area
530  flushPendingLabels(DF, DF->getContents().size());
531 
532  DF->getFixups().push_back(MCFixup::create(DF->getContents().size(),
533  Value, FK_TPRel_8));
534  DF->getContents().resize(DF->getContents().size() + 8, 0);
535 }
536 
537 // Associate GPRel32 fixup with data and resize data area
540  flushPendingLabels(DF, DF->getContents().size());
541 
542  DF->getFixups().push_back(
543  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
544  DF->getContents().resize(DF->getContents().size() + 4, 0);
545 }
546 
547 // Associate GPRel64 fixup with data and resize data area
550  flushPendingLabels(DF, DF->getContents().size());
551 
552  DF->getFixups().push_back(
553  MCFixup::create(DF->getContents().size(), Value, FK_GPRel_4));
554  DF->getContents().resize(DF->getContents().size() + 8, 0);
555 }
556 
558  const MCExpr *Expr, SMLoc Loc) {
559  int64_t OffsetValue;
560  if (!Offset.evaluateAsAbsolute(OffsetValue))
561  llvm_unreachable("Offset is not absolute");
562 
563  if (OffsetValue < 0)
564  llvm_unreachable("Offset is negative");
565 
567  flushPendingLabels(DF, DF->getContents().size());
568 
569  Optional<MCFixupKind> MaybeKind = Assembler->getBackend().getFixupKind(Name);
570  if (!MaybeKind.hasValue())
571  return true;
572 
573  MCFixupKind Kind = *MaybeKind;
574 
575  if (Expr == nullptr)
576  Expr =
577  MCSymbolRefExpr::create(getContext().createTempSymbol(), getContext());
578  DF->getFixups().push_back(MCFixup::create(OffsetValue, Expr, Kind, Loc));
579  return false;
580 }
581 
582 void MCObjectStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) {
583  assert(getCurrentSectionOnly() && "need a section");
584  insert(new MCFillFragment(FillValue, NumBytes));
585 }
586 
587 void MCObjectStreamer::emitFill(const MCExpr &NumBytes, uint64_t FillValue,
588  SMLoc Loc) {
590  flushPendingLabels(DF, DF->getContents().size());
591 
592  int64_t IntNumBytes;
593  if (!NumBytes.evaluateAsAbsolute(IntNumBytes, getAssembler())) {
594  getContext().reportError(Loc, "expected absolute expression");
595  return;
596  }
597 
598  if (IntNumBytes <= 0) {
599  getContext().reportError(Loc, "invalid number of bytes");
600  return;
601  }
602 
603  emitFill(IntNumBytes, FillValue);
604 }
605 
606 void MCObjectStreamer::emitFill(const MCExpr &NumValues, int64_t Size,
607  int64_t Expr, SMLoc Loc) {
608  int64_t IntNumValues;
609  if (!NumValues.evaluateAsAbsolute(IntNumValues, getAssembler())) {
610  getContext().reportError(Loc, "expected absolute expression");
611  return;
612  }
613 
614  if (IntNumValues < 0) {
617  "'.fill' directive with negative repeat count has no effect");
618  return;
619  }
620 
621  MCStreamer::emitFill(IntNumValues, Size, Expr);
622 }
623 
625  getAssembler().addFileName(Filename);
626 }
627 
629  // If we are generating dwarf for assembly source files dump out the sections.
630  if (getContext().getGenDwarfForAssembly())
631  MCGenDwarfInfo::Emit(this);
632 
633  // Dump out the dwarf file & directory tables and line tables.
634  MCDwarfLineTable::Emit(this, getAssembler().getDWARFLinetableParams());
635 
636  flushPendingLabels(nullptr);
637  getAssembler().Finish();
638 }
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:190
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:279
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:251
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:235
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:116
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:127
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
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:61
static void Make(MCObjectStreamer *MCOS)
Definition: MCCodeView.cpp:614
static void EmitAdvanceLoc(MCObjectStreamer &Streamer, uint64_t AddrDelta)
Definition: MCDwarf.cpp:1575
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:899
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:421
bool isBundlingEnabled() const
Definition: MCAssembler.h:292
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:917
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:863
void EmitCVStringTableDirective() override
This implements the CodeView &#39;.cv_stringtable&#39; assembler directive.
virtual void EmitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:318
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:346
MCContext & getContext() const
Definition: MCStreamer.h:234
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:263
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
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:248
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:820
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:359
A four-byte gp relative fixup.
Definition: MCFixup.h:34
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:88
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:169
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:269
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:570
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 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: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:551
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.
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:871
MCAsmBackend & getBackend() const
Definition: MCAssembler.h:261
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:383
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:273
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:406
bool getRelaxAll() const
Definition: MCAssembler.h:289
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:316
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: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
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:240
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:156
void emitFileChecksumOffset(MCObjectStreamer &OS, unsigned FileNo)
Emits the offset into the checksum table of the given file number.
Definition: MCCodeView.cpp:233
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:164
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:560
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:300
Subtraction.
Definition: MCExpr.h:423
static void Emit(MCObjectStreamer &streamer, MCAsmBackend *MAB, bool isEH)
Definition: MCDwarf.cpp:1515
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:110
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:178
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:355