LLVM  8.0.0svn
MCStreamer.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCStreamer.cpp - Streaming Machine Code Output --------------===//
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 
10 #include "llvm/MC/MCStreamer.h"
11 #include "llvm/ADT/Optional.h"
12 #include "llvm/ADT/SmallString.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/Twine.h"
15 #include "llvm/BinaryFormat/COFF.h"
16 #include "llvm/MC/MCAsmBackend.h"
17 #include "llvm/MC/MCAsmInfo.h"
18 #include "llvm/MC/MCCodeView.h"
19 #include "llvm/MC/MCContext.h"
20 #include "llvm/MC/MCDwarf.h"
21 #include "llvm/MC/MCExpr.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/MC/MCInstPrinter.h"
25 #include "llvm/MC/MCSection.h"
26 #include "llvm/MC/MCSectionCOFF.h"
27 #include "llvm/MC/MCSymbol.h"
28 #include "llvm/MC/MCWin64EH.h"
29 #include "llvm/MC/MCWinEH.h"
30 #include "llvm/Support/Casting.h"
32 #include "llvm/Support/LEB128.h"
35 #include <cassert>
36 #include <cstdint>
37 #include <cstdlib>
38 #include <utility>
39 
40 using namespace llvm;
41 
43  S.setTargetStreamer(this);
44 }
45 
46 // Pin the vtables to this file.
48 
50 
52 
55  const MCExpr *Subsection,
56  raw_ostream &OS) {
57  Section->PrintSwitchToSection(
60  Subsection);
61 }
62 
64  Streamer.EmitRawText(Directive);
65 }
66 
68  SmallString<128> Str;
69  raw_svector_ostream OS(Str);
70 
71  Value->print(OS, Streamer.getContext().getAsmInfo());
72  Streamer.EmitRawText(OS.str());
73 }
74 
76 
78  : Context(Ctx), CurrentWinFrameInfo(nullptr),
79  UseAssemblerInfoForParsing(false) {
80  SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
81 }
82 
84 
86  DwarfFrameInfos.clear();
87  CurrentWinFrameInfo = nullptr;
88  WinFrameInfos.clear();
89  SymbolOrdering.clear();
90  SectionStack.clear();
91  SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
92 }
93 
95  // By default, discard comments.
96  return nulls();
97 }
98 
99 void MCStreamer::emitRawComment(const Twine &T, bool TabPrefix) {}
100 
103 
105  for (auto &FI : DwarfFrameInfos)
106  FI.CompactUnwindEncoding =
107  (MAB ? MAB->generateCompactUnwindEncoding(FI.Instructions) : 0);
108 }
109 
110 /// EmitIntValue - Special case of EmitValue that avoids the client having to
111 /// pass in a MCExpr for constant integers.
112 void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
113  assert(1 <= Size && Size <= 8 && "Invalid size");
114  assert((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) &&
115  "Invalid size");
116  char buf[8];
117  const bool isLittleEndian = Context.getAsmInfo()->isLittleEndian();
118  for (unsigned i = 0; i != Size; ++i) {
119  unsigned index = isLittleEndian ? i : (Size - i - 1);
120  buf[i] = uint8_t(Value >> (index * 8));
121  }
122  EmitBytes(StringRef(buf, Size));
123 }
124 
125 /// EmitULEB128IntValue - Special case of EmitULEB128Value that avoids the
126 /// client having to pass in a MCExpr for constant integers.
128  SmallString<128> Tmp;
129  raw_svector_ostream OSE(Tmp);
130  encodeULEB128(Value, OSE);
131  EmitBytes(OSE.str());
132 }
133 
134 /// EmitSLEB128IntValue - Special case of EmitSLEB128Value that avoids the
135 /// client having to pass in a MCExpr for constant integers.
137  SmallString<128> Tmp;
138  raw_svector_ostream OSE(Tmp);
139  encodeSLEB128(Value, OSE);
140  EmitBytes(OSE.str());
141 }
142 
143 void MCStreamer::EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc) {
144  EmitValueImpl(Value, Size, Loc);
145 }
146 
147 void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
148  bool IsSectionRelative) {
149  assert((!IsSectionRelative || Size == 4) &&
150  "SectionRelative value requires 4-bytes");
151 
152  if (!IsSectionRelative)
154  else
155  EmitCOFFSecRel32(Sym, /*Offset=*/0);
156 }
157 
159  report_fatal_error("unsupported directive in streamer");
160 }
161 
163  report_fatal_error("unsupported directive in streamer");
164 }
165 
167  report_fatal_error("unsupported directive in streamer");
168 }
169 
171  report_fatal_error("unsupported directive in streamer");
172 }
173 
175  report_fatal_error("unsupported directive in streamer");
176 }
177 
179  report_fatal_error("unsupported directive in streamer");
180 }
181 
182 /// Emit NumBytes bytes worth of the value specified by FillValue.
183 /// This implements directives such as '.space'.
184 void MCStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) {
185  emitFill(*MCConstantExpr::create(NumBytes, getContext()), FillValue);
186 }
187 
188 /// The implementation in this class just redirects to emitFill.
189 void MCStreamer::EmitZeros(uint64_t NumBytes) {
190  emitFill(NumBytes, 0);
191 }
192 
195  StringRef Filename,
196  MD5::MD5Result *Checksum,
198  unsigned CUID) {
199  return getContext().getDwarfFile(Directory, Filename, FileNo, Checksum,
200  Source, CUID);
201 }
202 
204  StringRef Filename,
205  MD5::MD5Result *Checksum,
207  unsigned CUID) {
208  getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum,
209  Source);
210 }
211 
212 void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
213  unsigned Column, unsigned Flags,
214  unsigned Isa,
215  unsigned Discriminator,
216  StringRef FileName) {
217  getContext().setCurrentDwarfLoc(FileNo, Line, Column, Flags, Isa,
218  Discriminator);
219 }
220 
223  if (!Table.getLabel()) {
225  Table.setLabel(
226  Context.getOrCreateSymbol(Prefix + "line_table_start" + Twine(CUID)));
227  }
228  return Table.getLabel();
229 }
230 
232  return !DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End;
233 }
234 
235 MCDwarfFrameInfo *MCStreamer::getCurrentDwarfFrameInfo() {
237  getContext().reportError(SMLoc(), "this directive must appear between "
238  ".cfi_startproc and .cfi_endproc "
239  "directives");
240  return nullptr;
241  }
242  return &DwarfFrameInfos.back();
243 }
244 
245 bool MCStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename,
246  ArrayRef<uint8_t> Checksum,
247  unsigned ChecksumKind) {
248  return getContext().getCVContext().addFile(*this, FileNo, Filename, Checksum,
249  ChecksumKind);
250 }
251 
252 bool MCStreamer::EmitCVFuncIdDirective(unsigned FunctionId) {
253  return getContext().getCVContext().recordFunctionId(FunctionId);
254 }
255 
257  unsigned IAFunc, unsigned IAFile,
258  unsigned IALine, unsigned IACol,
259  SMLoc Loc) {
260  if (getContext().getCVContext().getCVFunctionInfo(IAFunc) == nullptr) {
261  getContext().reportError(Loc, "parent function id not introduced by "
262  ".cv_func_id or .cv_inline_site_id");
263  return true;
264  }
265 
267  FunctionId, IAFunc, IAFile, IALine, IACol);
268 }
269 
270 void MCStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
271  unsigned Line, unsigned Column,
272  bool PrologueEnd, bool IsStmt,
273  StringRef FileName, SMLoc Loc) {}
274 
275 bool MCStreamer::checkCVLocSection(unsigned FuncId, unsigned FileNo,
276  SMLoc Loc) {
278  MCCVFunctionInfo *FI = CVC.getCVFunctionInfo(FuncId);
279  if (!FI) {
281  Loc, "function id not introduced by .cv_func_id or .cv_inline_site_id");
282  return false;
283  }
284 
285  // Track the section
286  if (FI->Section == nullptr)
288  else if (FI->Section != getCurrentSectionOnly()) {
290  Loc,
291  "all .cv_loc directives for a function must be in the same section");
292  return false;
293  }
294  return true;
295 }
296 
297 void MCStreamer::EmitCVLinetableDirective(unsigned FunctionId,
298  const MCSymbol *Begin,
299  const MCSymbol *End) {}
300 
301 void MCStreamer::EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
302  unsigned SourceFileId,
303  unsigned SourceLineNum,
304  const MCSymbol *FnStartSym,
305  const MCSymbol *FnEndSym) {}
306 
308  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
309  StringRef FixedSizePortion) {}
310 
312  MCSymbol *EHSymbol) {
313 }
314 
315 void MCStreamer::InitSections(bool NoExecStack) {
316  SwitchSection(getContext().getObjectFileInfo()->getTextSection());
317 }
318 
320  assert(Fragment);
321  Symbol->setFragment(Fragment);
322 
323  // As we emit symbols into a section, track the order so that they can
324  // be sorted upon later. Zero is reserved to mean 'unemitted'.
325  SymbolOrdering[Symbol] = 1 + SymbolOrdering.size();
326 }
327 
329  Symbol->redefineIfPossible();
330 
331  if (!Symbol->isUndefined() || Symbol->isVariable())
332  return getContext().reportError(Loc, "invalid symbol redefinition");
333 
334  assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
335  assert(getCurrentSectionOnly() && "Cannot emit before setting section!");
336  assert(!Symbol->getFragment() && "Unexpected fragment on symbol data!");
337  assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
338 
339  Symbol->setFragment(&getCurrentSectionOnly()->getDummyFragment());
340 
342  if (TS)
343  TS->emitLabel(Symbol);
344 }
345 
346 void MCStreamer::EmitCFISections(bool EH, bool Debug) {
347  assert(EH || Debug);
348 }
349 
350 void MCStreamer::EmitCFIStartProc(bool IsSimple) {
353  SMLoc(), "starting new .cfi frame before finishing the previous one");
354 
355  MCDwarfFrameInfo Frame;
356  Frame.IsSimple = IsSimple;
357  EmitCFIStartProcImpl(Frame);
358 
359  const MCAsmInfo* MAI = Context.getAsmInfo();
360  if (MAI) {
361  for (const MCCFIInstruction& Inst : MAI->getInitialFrameState()) {
362  if (Inst.getOperation() == MCCFIInstruction::OpDefCfa ||
363  Inst.getOperation() == MCCFIInstruction::OpDefCfaRegister) {
364  Frame.CurrentCfaRegister = Inst.getRegister();
365  }
366  }
367  }
368 
369  DwarfFrameInfos.push_back(Frame);
370 }
371 
373 }
374 
376  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
377  if (!CurFrame)
378  return;
379  EmitCFIEndProcImpl(*CurFrame);
380 }
381 
383  // Put a dummy non-null value in Frame.End to mark that this frame has been
384  // closed.
385  Frame.End = (MCSymbol *)1;
386 }
387 
389  // Return a dummy non-null value so that label fields appear filled in when
390  // generating textual assembly.
391  return (MCSymbol *)1;
392 }
393 
394 void MCStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
395  MCSymbol *Label = EmitCFILabel();
397  MCCFIInstruction::createDefCfa(Label, Register, Offset);
398  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
399  if (!CurFrame)
400  return;
401  CurFrame->Instructions.push_back(Instruction);
402  CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register);
403 }
404 
406  MCSymbol *Label = EmitCFILabel();
409  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
410  if (!CurFrame)
411  return;
412  CurFrame->Instructions.push_back(Instruction);
413 }
414 
415 void MCStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
416  MCSymbol *Label = EmitCFILabel();
418  MCCFIInstruction::createAdjustCfaOffset(Label, Adjustment);
419  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
420  if (!CurFrame)
421  return;
422  CurFrame->Instructions.push_back(Instruction);
423 }
424 
426  MCSymbol *Label = EmitCFILabel();
429  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
430  if (!CurFrame)
431  return;
432  CurFrame->Instructions.push_back(Instruction);
433  CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register);
434 }
435 
436 void MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
437  MCSymbol *Label = EmitCFILabel();
439  MCCFIInstruction::createOffset(Label, Register, Offset);
440  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
441  if (!CurFrame)
442  return;
443  CurFrame->Instructions.push_back(Instruction);
444 }
445 
447  MCSymbol *Label = EmitCFILabel();
449  MCCFIInstruction::createRelOffset(Label, Register, Offset);
450  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
451  if (!CurFrame)
452  return;
453  CurFrame->Instructions.push_back(Instruction);
454 }
455 
457  unsigned Encoding) {
458  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
459  if (!CurFrame)
460  return;
461  CurFrame->Personality = Sym;
462  CurFrame->PersonalityEncoding = Encoding;
463 }
464 
465 void MCStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
466  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
467  if (!CurFrame)
468  return;
469  CurFrame->Lsda = Sym;
470  CurFrame->LsdaEncoding = Encoding;
471 }
472 
474  MCSymbol *Label = EmitCFILabel();
476  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
477  if (!CurFrame)
478  return;
479  CurFrame->Instructions.push_back(Instruction);
480 }
481 
483  // FIXME: Error if there is no matching cfi_remember_state.
484  MCSymbol *Label = EmitCFILabel();
486  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
487  if (!CurFrame)
488  return;
489  CurFrame->Instructions.push_back(Instruction);
490 }
491 
493  MCSymbol *Label = EmitCFILabel();
495  MCCFIInstruction::createSameValue(Label, Register);
496  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
497  if (!CurFrame)
498  return;
499  CurFrame->Instructions.push_back(Instruction);
500 }
501 
503  MCSymbol *Label = EmitCFILabel();
505  MCCFIInstruction::createRestore(Label, Register);
506  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
507  if (!CurFrame)
508  return;
509  CurFrame->Instructions.push_back(Instruction);
510 }
511 
513  MCSymbol *Label = EmitCFILabel();
515  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
516  if (!CurFrame)
517  return;
518  CurFrame->Instructions.push_back(Instruction);
519 }
520 
522  MCSymbol *Label = EmitCFILabel();
525  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
526  if (!CurFrame)
527  return;
528  CurFrame->Instructions.push_back(Instruction);
529 }
530 
532  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
533  if (!CurFrame)
534  return;
535  CurFrame->IsSignalFrame = true;
536 }
537 
539  MCSymbol *Label = EmitCFILabel();
541  MCCFIInstruction::createUndefined(Label, Register);
542  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
543  if (!CurFrame)
544  return;
545  CurFrame->Instructions.push_back(Instruction);
546 }
547 
548 void MCStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) {
549  MCSymbol *Label = EmitCFILabel();
551  MCCFIInstruction::createRegister(Label, Register1, Register2);
552  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
553  if (!CurFrame)
554  return;
555  CurFrame->Instructions.push_back(Instruction);
556 }
557 
559  MCSymbol *Label = EmitCFILabel();
562  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
563  if (!CurFrame)
564  return;
565  CurFrame->Instructions.push_back(Instruction);
566 }
567 
569  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
570  if (!CurFrame)
571  return;
572  CurFrame->RAReg = Register;
573 }
574 
575 WinEH::FrameInfo *MCStreamer::EnsureValidWinFrameInfo(SMLoc Loc) {
576  const MCAsmInfo *MAI = Context.getAsmInfo();
577  if (!MAI->usesWindowsCFI()) {
579  Loc, ".seh_* directives are not supported on this target");
580  return nullptr;
581  }
582  if (!CurrentWinFrameInfo || CurrentWinFrameInfo->End) {
584  Loc, ".seh_ directive must appear within an active frame");
585  return nullptr;
586  }
587  return CurrentWinFrameInfo;
588 }
589 
591  const MCAsmInfo *MAI = Context.getAsmInfo();
592  if (!MAI->usesWindowsCFI())
593  return getContext().reportError(
594  Loc, ".seh_* directives are not supported on this target");
595  if (CurrentWinFrameInfo && !CurrentWinFrameInfo->End)
597  Loc, "Starting a function before ending the previous one!");
598 
599  MCSymbol *StartProc = EmitCFILabel();
600 
601  WinFrameInfos.emplace_back(
602  llvm::make_unique<WinEH::FrameInfo>(Symbol, StartProc));
603  CurrentWinFrameInfo = WinFrameInfos.back().get();
604  CurrentWinFrameInfo->TextSection = getCurrentSectionOnly();
605 }
606 
608  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
609  if (!CurFrame)
610  return;
611  if (CurFrame->ChainedParent)
612  getContext().reportError(Loc, "Not all chained regions terminated!");
613 
614  MCSymbol *Label = EmitCFILabel();
615  CurFrame->End = Label;
616 }
617 
619  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
620  if (!CurFrame)
621  return;
622 
623  MCSymbol *StartProc = EmitCFILabel();
624 
625  WinFrameInfos.emplace_back(llvm::make_unique<WinEH::FrameInfo>(
626  CurFrame->Function, StartProc, CurFrame));
627  CurrentWinFrameInfo = WinFrameInfos.back().get();
628  CurrentWinFrameInfo->TextSection = getCurrentSectionOnly();
629 }
630 
632  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
633  if (!CurFrame)
634  return;
635  if (!CurFrame->ChainedParent)
636  return getContext().reportError(
637  Loc, "End of a chained region outside a chained region!");
638 
639  MCSymbol *Label = EmitCFILabel();
640 
641  CurFrame->End = Label;
642  CurrentWinFrameInfo = const_cast<WinEH::FrameInfo *>(CurFrame->ChainedParent);
643 }
644 
645 void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
646  SMLoc Loc) {
647  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
648  if (!CurFrame)
649  return;
650  if (CurFrame->ChainedParent)
651  return getContext().reportError(
652  Loc, "Chained unwind areas can't have handlers!");
653  CurFrame->ExceptionHandler = Sym;
654  if (!Except && !Unwind)
655  getContext().reportError(Loc, "Don't know what kind of handler this is!");
656  if (Unwind)
657  CurFrame->HandlesUnwind = true;
658  if (Except)
659  CurFrame->HandlesExceptions = true;
660 }
661 
663  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
664  if (!CurFrame)
665  return;
666  if (CurFrame->ChainedParent)
667  getContext().reportError(Loc, "Chained unwind areas can't have handlers!");
668 }
669 
671  const MCSymbolRefExpr *To, uint64_t Count) {
672 }
673 
674 static MCSection *getWinCFISection(MCContext &Context, unsigned *NextWinCFIID,
675  MCSection *MainCFISec,
676  const MCSection *TextSec) {
677  // If this is the main .text section, use the main unwind info section.
678  if (TextSec == Context.getObjectFileInfo()->getTextSection())
679  return MainCFISec;
680 
681  const auto *TextSecCOFF = cast<MCSectionCOFF>(TextSec);
682  auto *MainCFISecCOFF = cast<MCSectionCOFF>(MainCFISec);
683  unsigned UniqueID = TextSecCOFF->getOrAssignWinCFISectionID(NextWinCFIID);
684 
685  // If this section is COMDAT, this unwind section should be COMDAT associative
686  // with its group.
687  const MCSymbol *KeySym = nullptr;
688  if (TextSecCOFF->getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
689  KeySym = TextSecCOFF->getCOMDATSymbol();
690 
691  // In a GNU environment, we can't use associative comdats. Instead, do what
692  // GCC does, which is to make plain comdat selectany section named like
693  // ".[px]data$_Z3foov".
694  if (!Context.getAsmInfo()->hasCOFFAssociativeComdats()) {
695  std::string SectionName =
696  (MainCFISecCOFF->getSectionName() + "$" +
697  TextSecCOFF->getSectionName().split('$').second)
698  .str();
699  return Context.getCOFFSection(
700  SectionName,
701  MainCFISecCOFF->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT,
702  MainCFISecCOFF->getKind(), "", COFF::IMAGE_COMDAT_SELECT_ANY);
703  }
704  }
705 
706  return Context.getAssociativeCOFFSection(MainCFISecCOFF, KeySym, UniqueID);
707 }
708 
710  return getWinCFISection(getContext(), &NextWinCFIID,
711  getContext().getObjectFileInfo()->getPDataSection(),
712  TextSec);
713 }
714 
716  return getWinCFISection(getContext(), &NextWinCFIID,
717  getContext().getObjectFileInfo()->getXDataSection(),
718  TextSec);
719 }
720 
722 
724  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
725  if (!CurFrame)
726  return;
727 
728  MCSymbol *Label = EmitCFILabel();
729 
731  CurFrame->Instructions.push_back(Inst);
732 }
733 
735  SMLoc Loc) {
736  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
737  if (!CurFrame)
738  return;
739  if (CurFrame->LastFrameInst >= 0)
740  return getContext().reportError(
741  Loc, "frame register and offset can be set at most once");
742  if (Offset & 0x0F)
743  return getContext().reportError(Loc, "offset is not a multiple of 16");
744  if (Offset > 240)
745  return getContext().reportError(
746  Loc, "frame offset must be less than or equal to 240");
747 
748  MCSymbol *Label = EmitCFILabel();
749 
750  WinEH::Instruction Inst =
751  Win64EH::Instruction::SetFPReg(Label, Register, Offset);
752  CurFrame->LastFrameInst = CurFrame->Instructions.size();
753  CurFrame->Instructions.push_back(Inst);
754 }
755 
757  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
758  if (!CurFrame)
759  return;
760  if (Size == 0)
761  return getContext().reportError(Loc,
762  "stack allocation size must be non-zero");
763  if (Size & 7)
764  return getContext().reportError(
765  Loc, "stack allocation size is not a multiple of 8");
766 
767  MCSymbol *Label = EmitCFILabel();
768 
770  CurFrame->Instructions.push_back(Inst);
771 }
772 
774  SMLoc Loc) {
775  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
776  if (!CurFrame)
777  return;
778 
779  if (Offset & 7)
780  return getContext().reportError(
781  Loc, "register save offset is not 8 byte aligned");
782 
783  MCSymbol *Label = EmitCFILabel();
784 
785  WinEH::Instruction Inst =
786  Win64EH::Instruction::SaveNonVol(Label, Register, Offset);
787  CurFrame->Instructions.push_back(Inst);
788 }
789 
791  SMLoc Loc) {
792  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
793  if (!CurFrame)
794  return;
795  if (Offset & 0x0F)
796  return getContext().reportError(Loc, "offset is not a multiple of 16");
797 
798  MCSymbol *Label = EmitCFILabel();
799 
800  WinEH::Instruction Inst =
801  Win64EH::Instruction::SaveXMM(Label, Register, Offset);
802  CurFrame->Instructions.push_back(Inst);
803 }
804 
806  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
807  if (!CurFrame)
808  return;
809  if (!CurFrame->Instructions.empty())
810  return getContext().reportError(
811  Loc, "If present, PushMachFrame must be the first UOP");
812 
813  MCSymbol *Label = EmitCFILabel();
814 
816  CurFrame->Instructions.push_back(Inst);
817 }
818 
820  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
821  if (!CurFrame)
822  return;
823 
824  MCSymbol *Label = EmitCFILabel();
825 
826  CurFrame->PrologEnd = Label;
827 }
828 
830 }
831 
833 
835 }
836 
838 
840 
841 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
842 /// the specified string in the output .s file. This capability is
843 /// indicated by the hasRawTextSupport() predicate.
845  errs() << "EmitRawText called on an MCStreamer that doesn't support it, "
846  " something must not be fully mc'ized\n";
847  abort();
848 }
849 
851  SmallString<128> Str;
853 }
854 
856 }
857 
859  if ((!DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End) ||
860  (!WinFrameInfos.empty() && !WinFrameInfos.back()->End)) {
861  getContext().reportError(SMLoc(), "Unfinished frame!");
862  return;
863  }
864 
866  if (TS)
867  TS->finish();
868 
869  FinishImpl();
870 }
871 
873  visitUsedExpr(*Value);
874  Symbol->setVariableValue(Value);
875 
877  if (TS)
878  TS->emitAssignment(Symbol, Value);
879 }
880 
882  const MCInst &Inst, const MCSubtargetInfo &STI) {
883  InstPrinter.printInst(&Inst, OS, "", STI);
884 }
885 
887 }
888 
890  switch (Expr.getKind()) {
891  case MCExpr::Target:
892  cast<MCTargetExpr>(Expr).visitUsedExpr(*this);
893  break;
894 
895  case MCExpr::Constant:
896  break;
897 
898  case MCExpr::Binary: {
899  const MCBinaryExpr &BE = cast<MCBinaryExpr>(Expr);
900  visitUsedExpr(*BE.getLHS());
901  visitUsedExpr(*BE.getRHS());
902  break;
903  }
904 
905  case MCExpr::SymbolRef:
906  visitUsedSymbol(cast<MCSymbolRefExpr>(Expr).getSymbol());
907  break;
908 
909  case MCExpr::Unary:
910  visitUsedExpr(*cast<MCUnaryExpr>(Expr).getSubExpr());
911  break;
912  }
913 }
914 
916  bool) {
917  // Scan for values.
918  for (unsigned i = Inst.getNumOperands(); i--;)
919  if (Inst.getOperand(i).isExpr())
920  visitUsedExpr(*Inst.getOperand(i).getExpr());
921 }
922 
924  unsigned Size) {
925  // Get the Hi-Lo expression.
926  const MCExpr *Diff =
928  MCSymbolRefExpr::create(Lo, Context), Context);
929 
930  const MCAsmInfo *MAI = Context.getAsmInfo();
931  if (!MAI->doesSetDirectiveSuppressReloc()) {
932  EmitValue(Diff, Size);
933  return;
934  }
935 
936  // Otherwise, emit with .set (aka assignment).
937  MCSymbol *SetLabel = Context.createTempSymbol("set", true);
938  EmitAssignment(SetLabel, Diff);
939  EmitSymbolValue(SetLabel, Size);
940 }
941 
943  const MCSymbol *Lo) {
944  // Get the Hi-Lo expression.
945  const MCExpr *Diff =
947  MCSymbolRefExpr::create(Lo, Context), Context);
948 
949  EmitULEB128Value(Diff);
950 }
951 
954 void MCStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
956  llvm_unreachable("this directive only supported on COFF targets");
957 }
959  llvm_unreachable("this directive only supported on COFF targets");
960 }
963  llvm_unreachable("this directive only supported on COFF targets");
964 }
966  llvm_unreachable("this directive only supported on COFF targets");
967 }
970  const MCSymbol *Aliasee) {}
972  unsigned ByteAlignment) {}
974  uint64_t Size, unsigned ByteAlignment) {}
979 void MCStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) {
980  visitUsedExpr(*Value);
981 }
984 void MCStreamer::emitFill(const MCExpr &NumBytes, uint64_t Value, SMLoc Loc) {}
985 void MCStreamer::emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
986  SMLoc Loc) {}
988  unsigned ValueSize,
989  unsigned MaxBytesToEmit) {}
991  unsigned MaxBytesToEmit) {}
993  SMLoc Loc) {}
994 void MCStreamer::EmitBundleAlignMode(unsigned AlignPow2) {}
995 void MCStreamer::EmitBundleLock(bool AlignToEnd) {}
998 
1000  assert(Section && "Cannot switch to a null section!");
1001  MCSectionSubPair curSection = SectionStack.back().first;
1002  SectionStack.back().second = curSection;
1003  if (MCSectionSubPair(Section, Subsection) != curSection) {
1004  ChangeSection(Section, Subsection);
1005  SectionStack.back().first = MCSectionSubPair(Section, Subsection);
1006  assert(!Section->hasEnded() && "Section already ended");
1007  MCSymbol *Sym = Section->getBeginSymbol();
1008  if (Sym && !Sym->isInSection())
1009  EmitLabel(Sym);
1010  }
1011 }
1012 
1014  // TODO: keep track of the last subsection so that this symbol appears in the
1015  // correct place.
1016  MCSymbol *Sym = Section->getEndSymbol(Context);
1017  if (Sym->isInSection())
1018  return Sym;
1019 
1020  SwitchSection(Section);
1021  EmitLabel(Sym);
1022  return Sym;
1023 }
1024 
1026  if (!Target.isOSBinFormatMachO() || !Target.isOSDarwin())
1027  return;
1028  // Do we even know the version?
1029  if (Target.getOSMajorVersion() == 0)
1030  return;
1031 
1032  unsigned Major;
1033  unsigned Minor;
1034  unsigned Update;
1035  MCVersionMinType VersionType;
1036  if (Target.isWatchOS()) {
1037  VersionType = MCVM_WatchOSVersionMin;
1038  Target.getWatchOSVersion(Major, Minor, Update);
1039  } else if (Target.isTvOS()) {
1040  VersionType = MCVM_TvOSVersionMin;
1041  Target.getiOSVersion(Major, Minor, Update);
1042  } else if (Target.isMacOSX()) {
1043  VersionType = MCVM_OSXVersionMin;
1044  if (!Target.getMacOSXVersion(Major, Minor, Update))
1045  Major = 0;
1046  } else {
1047  VersionType = MCVM_IOSVersionMin;
1048  Target.getiOSVersion(Major, Minor, Update);
1049  }
1050  if (Major != 0)
1051  EmitVersionMin(VersionType, Major, Minor, Update);
1052 }
virtual void EmitBundleUnlock()
Ends a bundle-locked group.
Definition: MCStreamer.cpp:997
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag)
Note in the output the specified Flag.
Definition: MCStreamer.cpp:952
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:293
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:212
virtual void EmitBundleAlignMode(unsigned AlignPow2)
Set the bundle alignment mode from now on in the section.
Definition: MCStreamer.cpp:994
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
Definition: Triple.h:471
Profile::FuncID FuncId
Definition: Profile.cpp:321
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
void push_back(const T &Elt)
Definition: SmallVector.h:218
bool doesSetDirectiveSuppressReloc() const
Definition: MCAsmInfo.h:524
void getiOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getiOSVersion - Parse the version number as with getOSVersion.
Definition: Triple.cpp:1083
MCStreamer(MCContext &Ctx)
Definition: MCStreamer.cpp:77
bool usesWindowsCFI() const
Definition: MCAsmInfo.h:584
virtual void EmitCFISameValue(int64_t Register)
Definition: MCStreamer.cpp:492
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:307
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding)
Definition: MCStreamer.cpp:456
virtual void EmitWinCFIPushReg(unsigned Register, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:723
virtual void EmitSLEB128Value(const MCExpr *Value)
Definition: MCStreamer.cpp:983
virtual void EmitCFIGnuArgsSize(int64_t Size)
Definition: MCStreamer.cpp:521
LLVMContext & Context
void EmitRawText(const Twine &String)
If this file is backed by a assembly streamer, this dumps the specified string in the output ...
Definition: MCStreamer.cpp:850
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:322
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:136
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:139
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
bool isVariable() const
isVariable - Check if this is a variable symbol.
Definition: MCSymbol.h:294
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:147
bool isMacOSX() const
isMacOSX - Is this a Mac OS X triple.
Definition: Triple.h:443
virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value, SMLoc Loc)
Emit some number of copies of Value until the byte offset Offset is reached.
Definition: MCStreamer.cpp:992
virtual void emitELFSymverDirective(StringRef AliasName, const MCSymbol *Aliasee)
Emit an ELF .symver directive.
Definition: MCStreamer.cpp:969
virtual void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot, const MCSubtargetInfo &STI)=0
Print the specified MCInst to the specified raw_ostream.
virtual void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment=0)
Emit a thread local bss (.tbss) symbol.
Definition: MCStreamer.cpp:973
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
void redefineIfPossible()
Prepare this symbol to be redefined.
Definition: MCSymbol.h:230
virtual void EmitWinCFIStartProc(const MCSymbol *Symbol, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:590
virtual void EndCOFFSymbolDef()
Marks the end of the symbol definition.
Definition: MCStreamer.cpp:958
MCSection * Section
The section of the first .cv_loc directive used for this function, or null if none has been seen yet...
Definition: MCCodeView.h:112
const MCSymbol * End
Definition: MCWinEH.h:33
.watchos_version_min
Definition: MCDirectives.h:68
virtual void EmitULEB128Value(const MCExpr *Value)
Definition: MCStreamer.cpp:982
virtual void emitDwarfFile0Directive(StringRef Directory, StringRef Filename, MD5::MD5Result *Checksum, Optional< StringRef > Source, unsigned CUID=0)
Specify the "root" file of the compilation, using the ".file 0" extension.
Definition: MCStreamer.cpp:203
static MCCFIInstruction createRememberState(MCSymbol *L)
.cfi_remember_state Save all current rules for all registers.
Definition: MCDwarf.h:532
virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol)
Emit an weak reference from Alias to Symbol.
Definition: MCStreamer.cpp:976
static WinEH::Instruction SaveNonVol(MCSymbol *L, unsigned Reg, unsigned Offset)
Definition: MCWin64EH.h:37
virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:790
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:977
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
Definition: MCDwarf.h:487
Target specific streamer interface.
Definition: MCStreamer.h:83
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Definition: Twine.h:453
.ios_version_min
Definition: MCDirectives.h:65
virtual void reset()
State management.
Definition: MCStreamer.cpp:85
unsigned CurrentCfaRegister
Definition: MCDwarf.h:589
virtual void EmitWindowsUnwindTables()
Definition: MCStreamer.cpp:855
void EmitCFIStartProc(bool IsSimple)
Definition: MCStreamer.cpp:350
virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol)
Start emitting COFF symbol definition.
Definition: MCStreamer.cpp:955
virtual void EmitDTPRel64Value(const MCExpr *Value)
Emit the expression Value into the output as a dtprel (64-bit DTP relative) value.
Definition: MCStreamer.cpp:158
bool isWatchOS() const
Is this an Apple watchOS triple.
Definition: Triple.h:462
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:563
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:510
virtual void EmitCFIRegister(int64_t Register1, int64_t Register2)
Definition: MCStreamer.cpp:548
virtual void emitExplicitComments()
Emit added explicit comments.
Definition: MCStreamer.cpp:102
virtual void emitValue(const MCExpr *Value)
Definition: MCStreamer.cpp:67
.macosx_version_min
Definition: MCDirectives.h:66
virtual void emitAbsoluteSymbolDiffAsULEB128(const MCSymbol *Hi, const MCSymbol *Lo)
Emit the absolute difference between two symbols encoded with ULEB128.
Definition: MCStreamer.cpp:942
virtual void EmitCFIDefCfaOffset(int64_t Offset)
Definition: MCStreamer.cpp:405
virtual MCSymbol * getDwarfLineTableSymbol(unsigned CUID)
Definition: MCStreamer.cpp:221
StringRef getPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:491
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition: MCDwarf.h:474
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:354
virtual void EmitCOFFSymbolStorageClass(int StorageClass)
Emit the storage class of the symbol.
Definition: MCStreamer.cpp:962
std::vector< Instruction > Instructions
Definition: MCWinEH.h:45
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:979
unsigned LsdaEncoding
Definition: MCDwarf.h:591
virtual void EmitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset)
Emits a COFF image relative relocation.
Definition: MCStreamer.cpp:839
static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int Adjustment)
.cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but Offset is a relative value that is added/subt...
Definition: MCDwarf.h:481
bool addFile(MCStreamer &OS, unsigned FileNumber, StringRef Filename, ArrayRef< uint8_t > ChecksumBytes, uint8_t ChecksumKind)
Definition: MCCodeView.cpp:47
virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, bool PrintSchedInfo=false)
Emit the given Instruction into the current section.
Definition: MCStreamer.cpp:915
MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, SectionKind Kind, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID, const char *BeginSymName=nullptr)
Definition: MCContext.cpp:422
virtual void addExplicitComment(const Twine &T)
Add explicit comment T.
Definition: MCStreamer.cpp:101
virtual void EmitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:346
virtual void EmitGPRel32Value(const MCExpr *Value)
Emit the expression Value into the output as a gprel32 (32-bit GP relative) value.
Definition: MCStreamer.cpp:178
MCSectionCOFF * getAssociativeCOFFSection(MCSectionCOFF *Sec, const MCSymbol *KeySym, unsigned UniqueID=GenericSectionID)
Gets or creates a section equivalent to Sec that is associated with the section containing KeySym...
Definition: MCContext.cpp:470
std::vector< MCCFIInstruction > Instructions
Definition: MCDwarf.h:588
static MCCFIInstruction createUndefined(MCSymbol *L, unsigned Register)
.cfi_undefined From now on the previous value of Register can&#39;t be restored anymore.
Definition: MCDwarf.h:521
virtual void EmitCFIRememberState()
Definition: MCStreamer.cpp:473
MCContext & getContext() const
Definition: MCStreamer.h:253
virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding)
Definition: MCStreamer.cpp:465
virtual void EmitGPRel64Value(const MCExpr *Value)
Emit the expression Value into the output as a gprel64 (64-bit GP relative) value.
Definition: MCStreamer.cpp:174
void AssignFragment(MCSymbol *Symbol, MCFragment *Fragment)
Sets the symbol&#39;s section.
Definition: MCStreamer.cpp:319
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
virtual void EmitWinCFIEndProc(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:607
virtual void EmitCFIEscape(StringRef Values)
Definition: MCStreamer.cpp:512
virtual void EmitCOFFSymbolType(int Type)
Emit the type of the symbol.
Definition: MCStreamer.cpp:965
virtual Expected< unsigned > tryEmitDwarfFileDirective(unsigned FileNo, StringRef Directory, StringRef Filename, MD5::MD5Result *Checksum=nullptr, Optional< StringRef > Source=None, unsigned CUID=0)
Associate a filename with a specified logical file number.
Definition: MCStreamer.cpp:194
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
Definition: MCSymbol.h:252
virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:645
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
const MCSymbol * Lsda
Definition: MCDwarf.h:587
void setFragment(MCFragment *F) const
Mark the symbol as defined in the fragment F.
Definition: MCSymbol.h:273
virtual uint32_t generateCompactUnwindEncoding(ArrayRef< MCCFIInstruction >) const
Generate the compact unwind encoding for the CFI instructions.
Definition: MCAsmBackend.h:164
Tagged union holding either a T or a Error.
Definition: CachePruning.h:23
virtual void emitLabel(MCSymbol *Symbol)
Definition: MCStreamer.cpp:49
virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame)
Definition: MCStreamer.cpp:372
virtual ~MCStreamer()
Definition: MCStreamer.cpp:83
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:524
MCSymbol * getEndSymbol(MCContext &Ctx)
Definition: MCSection.cpp:29
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:270
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:872
virtual void EmitWinCFIStartChained(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:618
Context object for machine code objects.
Definition: MCContext.h:63
virtual bool EmitCVFileDirective(unsigned FileNo, StringRef Filename, ArrayRef< uint8_t > Checksum, unsigned ChecksumKind)
Associate a filename with a specified logical file number, and also specify that file&#39;s checksum info...
Definition: MCStreamer.cpp:245
static WinEH::Instruction PushNonVol(MCSymbol *L, unsigned Reg)
Definition: MCWin64EH.h:27
bool hasEnded() const
Definition: MCSection.cpp:35
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:545
virtual void finish()
Definition: MCStreamer.cpp:51
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:566
virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame)
Definition: MCStreamer.cpp:382
virtual void EmitTPRel64Value(const MCExpr *Value)
Emit the expression Value into the output as a tprel (64-bit TP relative) value.
Definition: MCStreamer.cpp:166
virtual void emitRawComment(const Twine &T, bool TabPrefix=true)
Print T and prefix it with the comment string (normally #) and optionally a tab.
Definition: MCStreamer.cpp:99
virtual void EmitBinaryData(StringRef Data)
Functionally identical to EmitBytes.
Definition: MCStreamer.cpp:978
const MCExpr * getExpr() const
Definition: MCInst.h:96
virtual void EmitCFIRestoreState()
Definition: MCStreamer.cpp:482
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:112
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
Definition: ELF.h:337
void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:143
Unary expressions.
Definition: MCExpr.h:42
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:161
virtual void EmitCFIRestore(int64_t Register)
Definition: MCStreamer.cpp:502
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:118
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
virtual void EmitBundleLock(bool AlignToEnd)
The following instructions are a bundle-locked group.
Definition: MCStreamer.cpp:995
virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment)
Emit a local common (.lcomm) symbol.
Definition: MCStreamer.cpp:971
static MCCFIInstruction createSameValue(MCSymbol *L, unsigned Register)
.cfi_same_value Current value of Register is the same as in the previous frame.
Definition: MCDwarf.h:527
virtual raw_ostream & GetCommentOS()
Return a raw_ostream that comments can be written to.
Definition: MCStreamer.cpp:94
void EmitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
Definition: MCStreamer.cpp:189
Streaming machine code generation interface.
Definition: MCStreamer.h:183
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:217
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:42
const FrameInfo * ChainedParent
Definition: MCWinEH.h:44
MCTargetStreamer * getTargetStreamer()
Definition: MCStreamer.h:260
static MCCFIInstruction createDefCfa(MCSymbol *L, unsigned Register, int Offset)
.cfi_def_cfa defines a rule for computing CFA as: take address from Register and add Offset to it...
Definition: MCDwarf.h:460
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
virtual void EmitCVLinetableDirective(unsigned FunctionId, const MCSymbol *FnStart, const MCSymbol *FnEnd)
This implements the CodeView &#39;.cv_linetable&#39; assembler directive.
Definition: MCStreamer.cpp:297
.tvos_version_min
Definition: MCDirectives.h:67
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register)
.cfi_def_cfa_register modifies a rule for computing CFA.
Definition: MCDwarf.h:467
static MCCFIInstruction createWindowSave(MCSymbol *L)
.cfi_window_save SPARC register window is saved.
Definition: MCDwarf.h:508
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:999
static MCCFIInstruction createGnuArgsSize(MCSymbol *L, int Size)
A special wrapper for .cfi_escape that indicates GNU_ARGS_SIZE.
Definition: MCDwarf.h:548
static WinEH::Instruction PushMachFrame(MCSymbol *L, bool Code)
Definition: MCWin64EH.h:34
MCSection * getAssociatedPDataSection(const MCSection *TextSec)
Get the .pdata section used for the given section.
Definition: MCStreamer.cpp:709
virtual void EmitSyntaxDirective()
Definition: MCStreamer.cpp:721
virtual void EmitCFIDefCfaRegister(int64_t Register)
Definition: MCStreamer.cpp:425
virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value=0, unsigned ValueSize=1, unsigned MaxBytesToEmit=0)
Emit some number of copies of Value until the byte alignment ByteAlignment is reached.
Definition: MCStreamer.cpp:987
void getWatchOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getWatchOSVersion - Parse the version number as with getOSVersion.
Definition: Triple.cpp:1109
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:297
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:612
static MCCFIInstruction createRelOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_rel_offset Previous value of Register is saved at offset Offset from the current CFA register...
Definition: MCDwarf.h:495
bool isExpr() const
Definition: MCInst.h:61
static MCCFIInstruction createRestore(MCSymbol *L, unsigned Register)
.cfi_restore says that the rule for Register is now the same as it was at the beginning of the functi...
Definition: MCDwarf.h:515
virtual void EmitRawTextImpl(StringRef String)
EmitRawText - If this file is backed by an assembly streamer, this dumps the specified string in the ...
Definition: MCStreamer.cpp:844
virtual void EmitWinEHHandlerData(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:662
unsigned getNumOperands() const
Definition: MCInst.h:184
unsigned size() const
Definition: DenseMap.h:96
virtual void EmitCFIUndefined(int64_t Register)
Definition: MCStreamer.cpp:538
unsigned PersonalityEncoding
Definition: MCDwarf.h:590
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:599
static WinEH::Instruction SetFPReg(MCSymbol *L, unsigned Reg, unsigned Off)
Definition: MCWin64EH.h:49
void Finish()
Finish emission of machine code.
Definition: MCStreamer.cpp:858
virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol)
Definition: MCStreamer.cpp:311
virtual void EmitWinCFIEndChained(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:631
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:398
static MCCFIInstruction createRestoreState(MCSymbol *L)
.cfi_restore_state Restore the previously saved state.
Definition: MCDwarf.h:537
Binary assembler expressions.
Definition: MCExpr.h:416
virtual void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const =0
unsigned getOSMajorVersion() const
getOSMajorVersion - Return just the major version number, this is specialized because it is a common ...
Definition: Triple.h:328
virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol)
Definition: MCStreamer.cpp:829
virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:734
void generateCompactUnwindEncodings(MCAsmBackend *MAB)
Definition: MCStreamer.cpp:104
MCCVFunctionInfo * getCVFunctionInfo(unsigned FuncId)
Retreive the function info if this is a valid function id, or nullptr.
Definition: MCCodeView.cpp:79
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
static MCSection * getWinCFISection(MCContext &Context, unsigned *NextWinCFIID, MCSection *MainCFISec, const MCSection *TextSec)
Definition: MCStreamer.cpp:674
virtual void EmitWinCFIPushFrame(bool Code, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:805
const std::vector< MCCFIInstruction > & getInitialFrameState() const
Definition: MCAsmInfo.h:605
static WinEH::Instruction SaveXMM(MCSymbol *L, unsigned Reg, unsigned Offset)
Definition: MCWin64EH.h:43
virtual void EmitTPRel32Value(const MCExpr *Value)
Emit the expression Value into the output as a tprel (32-bit TP relative) value.
Definition: MCStreamer.cpp:170
const MCSymbol * PrologEnd
Definition: MCWinEH.h:36
virtual void InitSections(bool NoExecStack)
Create the default sections and set the initial one.
Definition: MCStreamer.cpp:315
virtual void EmitCFIReturnColumn(int64_t Register)
Definition: MCStreamer.cpp:568
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
Definition: MCStreamer.h:56
BlockVerifier::State From
bool getMacOSXVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getMacOSXVersion - Parse the version number as with getOSVersion and then translate generic "darwin" ...
Definition: Triple.cpp:1042
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
Definition: MCStreamer.cpp:923
virtual void EmitCOFFSymbolIndex(MCSymbol const *Symbol)
Emits the symbol table index of a Symbol into the current section.
Definition: MCStreamer.cpp:832
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:81
ExprKind getKind() const
Definition: MCExpr.h:73
virtual void EmitCFIOffset(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:436
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:257
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:384
unsigned encodeSLEB128(int64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a SLEB128 value to an output stream.
Definition: LEB128.h:24
const MCSection * TextSection
Definition: MCWinEH.h:38
virtual void EmitWinCFIEndProlog(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:819
static WinEH::Instruction Alloc(MCSymbol *L, unsigned Size)
Definition: MCWin64EH.h:30
virtual void EmitCodeAlignment(unsigned ByteAlignment, unsigned MaxBytesToEmit=0)
Emit nops until the byte alignment ByteAlignment is reached.
Definition: MCStreamer.cpp:990
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:182
virtual void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:756
MCStreamer & Streamer
Definition: MCStreamer.h:85
Promote Memory to Register
Definition: Mem2Reg.cpp:110
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:301
MCSymbol * getBeginSymbol()
Definition: MCSection.h:110
const Triple & getTargetTriple() const
virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS, const MCInst &Inst, const MCSubtargetInfo &STI)
Definition: MCStreamer.cpp:881
StringRef str()
Return a StringRef for the vector contents.
Definition: raw_ostream.h:535
virtual void ChangeSection(MCSection *, const MCExpr *)
Update streamer for a new active section.
Definition: MCStreamer.cpp:975
void setVariableValue(const MCExpr *Value)
Definition: MCSymbol.cpp:49
bool hasUnfinishedDwarfFrameInfo()
Definition: MCStreamer.cpp:231
virtual void changeSection(const MCSection *CurSection, MCSection *Section, const MCExpr *SubSection, raw_ostream &OS)
Update streamer for a new active section.
Definition: MCStreamer.cpp:53
const MCSymbol * Function
Definition: MCWinEH.h:35
Target - Wrapper for Target specific information.
MCSection * getCurrentSectionOnly() const
Definition: MCStreamer.h:340
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:889
bool checkCVLocSection(unsigned FuncId, unsigned FileNo, SMLoc Loc)
Returns true if the the .cv_loc directive is in the right section.
Definition: MCStreamer.cpp:275
MCTargetStreamer(MCStreamer &S)
Definition: MCStreamer.cpp:42
virtual MCSymbol * EmitCFILabel()
When emitting an object file, create and emit a real label.
Definition: MCStreamer.cpp:388
bool recordFunctionId(unsigned FuncId)
Records the function id of a normal function.
Definition: MCCodeView.cpp:87
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:40
virtual void EmitThumbFunc(MCSymbol *Func)
Note in the output that the specified Func is a Thumb mode function (ARM target only).
Definition: MCStreamer.cpp:953
virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:773
virtual void EmitCFISignalFrame()
Definition: MCStreamer.cpp:531
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:123
virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:446
const MCSymbol * Personality
Definition: MCDwarf.h:586
MCAssemblerFlag
Definition: MCDirectives.h:48
bool recordInlinedCallSiteId(unsigned FuncId, unsigned IAFunc, unsigned IAFile, unsigned IALine, unsigned IACol)
Records the function id of an inlined call site.
Definition: MCCodeView.cpp:100
bool hasCOFFAssociativeComdats() const
Definition: MCAsmInfo.h:475
virtual void EmitFileDirective(StringRef Filename)
Switch to a new logical file.
Definition: MCStreamer.cpp:961
virtual void EmitDTPRel32Value(const MCExpr *Value)
Emit the expression Value into the output as a dtprel (32-bit DTP relative) value.
Definition: MCStreamer.cpp:162
Generic base class for all target subtargets.
virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value)
Emit an ELF .size directive.
Definition: MCStreamer.cpp:968
void EmitVersionForTarget(const Triple &Target)
References to labels and assigned expressions.
Definition: MCExpr.h:41
uint32_t Size
Definition: Profile.cpp:47
bool isLittleEndian() const
True if the target is little endian.
Definition: MCAsmInfo.h:405
void setMCLineTableRootFile(unsigned CUID, StringRef CompilationDir, StringRef Filename, MD5::MD5Result *Checksum, Optional< StringRef > Source)
Specifies the "root" file and directory of the compilation unit.
Definition: MCContext.h:557
void emitFill(uint64_t NumBytes, uint8_t FillValue)
Emit NumBytes bytes worth of the value specified by FillValue.
Definition: MCStreamer.cpp:184
virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:394
MCSymbol * endSection(MCSection *Section)
void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column, unsigned Flags, unsigned Isa, unsigned Discriminator)
Saves the information from the currently parsed dwarf .loc directive and sets DwarfLocSeen.
Definition: MCContext.h:573
CodeViewContext & getCVContext()
Definition: MCContext.cpp:602
Expected< unsigned > getDwarfFile(StringRef Directory, StringRef FileName, unsigned FileNumber, MD5::MD5Result *Checksum, Optional< StringRef > Source, unsigned CUID)
Creates an entry in the dwarf file and directory tables.
Definition: MCContext.cpp:573
MCSymbol * getLabel() const
Definition: MCDwarf.h:327
MCSection * getTextSection() const
virtual void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset)
Emits a COFF section relative relocation.
Definition: MCStreamer.cpp:837
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual void FinishImpl()
Streamer specific finalization.
Definition: MCStreamer.cpp:996
virtual bool EmitCVInlineSiteIdDirective(unsigned FunctionId, unsigned IAFunc, unsigned IAFile, unsigned IALine, unsigned IACol, SMLoc Loc)
Introduces an inline call site id for use with .cv_loc.
Definition: MCStreamer.cpp:256
bool isTvOS() const
Is this an Apple tvOS triple.
Definition: Triple.h:457
MCVersionMinType
Definition: MCDirectives.h:64
LLVM Value Representation.
Definition: Value.h:73
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:42
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
Constant expressions.
Definition: MCExpr.h:40
Binary expressions.
Definition: MCExpr.h:39
virtual bool EmitCVFuncIdDirective(unsigned FunctionId)
Introduces a function id for use with .cv_loc.
Definition: MCStreamer.cpp:252
raw_ostream & nulls()
This returns a reference to a raw_ostream which simply discards output.
virtual void EmitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:328
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
virtual void emitCGProfileEntry(const MCSymbolRefExpr *From, const MCSymbolRefExpr *To, uint64_t Count)
Definition: MCStreamer.cpp:670
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
virtual void EmitVersionMin(MCVersionMinType Type, unsigned Major, unsigned Minor, unsigned Update)
Specify the Mach-O minimum deployment target version.
Definition: MCStreamer.h:449
Target specific expression.
Definition: MCExpr.h:43
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:127
Information describing a function or inlined call site introduced by .cv_func_id or ...
Definition: MCCodeView.h:92
virtual void visitUsedSymbol(const MCSymbol &Sym)
Definition: MCStreamer.cpp:886
virtual void emitDwarfFileDirective(StringRef Directive)
Definition: MCStreamer.cpp:63
Represents a location in source code.
Definition: SMLoc.h:24
static MCCFIInstruction createEscape(MCSymbol *L, StringRef Vals)
.cfi_escape Allows the user to add arbitrary bytes to the unwind info.
Definition: MCDwarf.h:543
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:393
const MCSymbol * ExceptionHandler
Definition: MCWinEH.h:34
void setTargetStreamer(MCTargetStreamer *TS)
Definition: MCStreamer.h:245
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Definition: MCStreamer.cpp:75
virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol)
Emits a COFF section index.
Definition: MCStreamer.cpp:834
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:164
virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment)
Definition: MCStreamer.cpp:415
void setLabel(MCSymbol *Label)
Definition: MCDwarf.h:331
static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1, unsigned Register2)
.cfi_register Previous value of Register1 is saved in register Register2.
Definition: MCDwarf.h:502
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue)
Set the DescValue for the Symbol.
Definition: MCStreamer.cpp:954
virtual void EmitCFIWindowSave()
Definition: MCStreamer.cpp:558
MCSection * getAssociatedXDataSection(const MCSection *TextSec)
Get the .xdata section used for the given section.
Definition: MCStreamer.cpp:715
Holds state from .cv_file and .cv_loc directives for later emission.
Definition: MCCodeView.h:138