LLVM  7.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) {
275  MCCVFunctionInfo *FI = CVC.getCVFunctionInfo(FunctionId);
276  if (!FI)
277  return getContext().reportError(
278  Loc, "function id not introduced by .cv_func_id or .cv_inline_site_id");
279 
280  // Track the section
281  if (FI->Section == nullptr)
283  else if (FI->Section != getCurrentSectionOnly())
284  return getContext().reportError(
285  Loc,
286  "all .cv_loc directives for a function must be in the same section");
287 
288  CVC.setCurrentCVLoc(FunctionId, FileNo, Line, Column, PrologueEnd, IsStmt);
289 }
290 
291 void MCStreamer::EmitCVLinetableDirective(unsigned FunctionId,
292  const MCSymbol *Begin,
293  const MCSymbol *End) {}
294 
295 void MCStreamer::EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
296  unsigned SourceFileId,
297  unsigned SourceLineNum,
298  const MCSymbol *FnStartSym,
299  const MCSymbol *FnEndSym) {}
300 
302  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
303  StringRef FixedSizePortion) {}
304 
306  MCSymbol *EHSymbol) {
307 }
308 
309 void MCStreamer::InitSections(bool NoExecStack) {
310  SwitchSection(getContext().getObjectFileInfo()->getTextSection());
311 }
312 
314  assert(Fragment);
315  Symbol->setFragment(Fragment);
316 
317  // As we emit symbols into a section, track the order so that they can
318  // be sorted upon later. Zero is reserved to mean 'unemitted'.
319  SymbolOrdering[Symbol] = 1 + SymbolOrdering.size();
320 }
321 
323  Symbol->redefineIfPossible();
324 
325  if (!Symbol->isUndefined() || Symbol->isVariable())
326  return getContext().reportError(Loc, "invalid symbol redefinition");
327 
328  assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
329  assert(getCurrentSectionOnly() && "Cannot emit before setting section!");
330  assert(!Symbol->getFragment() && "Unexpected fragment on symbol data!");
331  assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
332 
333  Symbol->setFragment(&getCurrentSectionOnly()->getDummyFragment());
334 
336  if (TS)
337  TS->emitLabel(Symbol);
338 }
339 
340 void MCStreamer::EmitCFISections(bool EH, bool Debug) {
341  assert(EH || Debug);
342 }
343 
344 void MCStreamer::EmitCFIStartProc(bool IsSimple) {
347  SMLoc(), "starting new .cfi frame before finishing the previous one");
348 
349  MCDwarfFrameInfo Frame;
350  Frame.IsSimple = IsSimple;
351  EmitCFIStartProcImpl(Frame);
352 
353  const MCAsmInfo* MAI = Context.getAsmInfo();
354  if (MAI) {
355  for (const MCCFIInstruction& Inst : MAI->getInitialFrameState()) {
356  if (Inst.getOperation() == MCCFIInstruction::OpDefCfa ||
357  Inst.getOperation() == MCCFIInstruction::OpDefCfaRegister) {
358  Frame.CurrentCfaRegister = Inst.getRegister();
359  }
360  }
361  }
362 
363  DwarfFrameInfos.push_back(Frame);
364 }
365 
367 }
368 
370  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
371  if (!CurFrame)
372  return;
373  EmitCFIEndProcImpl(*CurFrame);
374 }
375 
377  // Put a dummy non-null value in Frame.End to mark that this frame has been
378  // closed.
379  Frame.End = (MCSymbol *)1;
380 }
381 
383  // Return a dummy non-null value so that label fields appear filled in when
384  // generating textual assembly.
385  return (MCSymbol *)1;
386 }
387 
388 void MCStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
389  MCSymbol *Label = EmitCFILabel();
391  MCCFIInstruction::createDefCfa(Label, Register, Offset);
392  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
393  if (!CurFrame)
394  return;
395  CurFrame->Instructions.push_back(Instruction);
396  CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register);
397 }
398 
400  MCSymbol *Label = EmitCFILabel();
403  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
404  if (!CurFrame)
405  return;
406  CurFrame->Instructions.push_back(Instruction);
407 }
408 
409 void MCStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
410  MCSymbol *Label = EmitCFILabel();
412  MCCFIInstruction::createAdjustCfaOffset(Label, Adjustment);
413  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
414  if (!CurFrame)
415  return;
416  CurFrame->Instructions.push_back(Instruction);
417 }
418 
420  MCSymbol *Label = EmitCFILabel();
423  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
424  if (!CurFrame)
425  return;
426  CurFrame->Instructions.push_back(Instruction);
427  CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register);
428 }
429 
430 void MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
431  MCSymbol *Label = EmitCFILabel();
433  MCCFIInstruction::createOffset(Label, Register, Offset);
434  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
435  if (!CurFrame)
436  return;
437  CurFrame->Instructions.push_back(Instruction);
438 }
439 
441  MCSymbol *Label = EmitCFILabel();
443  MCCFIInstruction::createRelOffset(Label, Register, Offset);
444  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
445  if (!CurFrame)
446  return;
447  CurFrame->Instructions.push_back(Instruction);
448 }
449 
451  unsigned Encoding) {
452  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
453  if (!CurFrame)
454  return;
455  CurFrame->Personality = Sym;
456  CurFrame->PersonalityEncoding = Encoding;
457 }
458 
459 void MCStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
460  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
461  if (!CurFrame)
462  return;
463  CurFrame->Lsda = Sym;
464  CurFrame->LsdaEncoding = Encoding;
465 }
466 
468  MCSymbol *Label = EmitCFILabel();
470  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
471  if (!CurFrame)
472  return;
473  CurFrame->Instructions.push_back(Instruction);
474 }
475 
477  // FIXME: Error if there is no matching cfi_remember_state.
478  MCSymbol *Label = EmitCFILabel();
480  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
481  if (!CurFrame)
482  return;
483  CurFrame->Instructions.push_back(Instruction);
484 }
485 
487  MCSymbol *Label = EmitCFILabel();
489  MCCFIInstruction::createSameValue(Label, Register);
490  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
491  if (!CurFrame)
492  return;
493  CurFrame->Instructions.push_back(Instruction);
494 }
495 
497  MCSymbol *Label = EmitCFILabel();
499  MCCFIInstruction::createRestore(Label, Register);
500  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
501  if (!CurFrame)
502  return;
503  CurFrame->Instructions.push_back(Instruction);
504 }
505 
507  MCSymbol *Label = EmitCFILabel();
509  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
510  if (!CurFrame)
511  return;
512  CurFrame->Instructions.push_back(Instruction);
513 }
514 
516  MCSymbol *Label = EmitCFILabel();
519  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
520  if (!CurFrame)
521  return;
522  CurFrame->Instructions.push_back(Instruction);
523 }
524 
526  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
527  if (!CurFrame)
528  return;
529  CurFrame->IsSignalFrame = true;
530 }
531 
533  MCSymbol *Label = EmitCFILabel();
535  MCCFIInstruction::createUndefined(Label, Register);
536  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
537  if (!CurFrame)
538  return;
539  CurFrame->Instructions.push_back(Instruction);
540 }
541 
542 void MCStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) {
543  MCSymbol *Label = EmitCFILabel();
545  MCCFIInstruction::createRegister(Label, Register1, Register2);
546  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
547  if (!CurFrame)
548  return;
549  CurFrame->Instructions.push_back(Instruction);
550 }
551 
553  MCSymbol *Label = EmitCFILabel();
556  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
557  if (!CurFrame)
558  return;
559  CurFrame->Instructions.push_back(Instruction);
560 }
561 
563  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
564  if (!CurFrame)
565  return;
566  CurFrame->RAReg = Register;
567 }
568 
569 WinEH::FrameInfo *MCStreamer::EnsureValidWinFrameInfo(SMLoc Loc) {
570  const MCAsmInfo *MAI = Context.getAsmInfo();
571  if (!MAI->usesWindowsCFI()) {
573  Loc, ".seh_* directives are not supported on this target");
574  return nullptr;
575  }
576  if (!CurrentWinFrameInfo || CurrentWinFrameInfo->End) {
578  Loc, ".seh_ directive must appear within an active frame");
579  return nullptr;
580  }
581  return CurrentWinFrameInfo;
582 }
583 
585  const MCAsmInfo *MAI = Context.getAsmInfo();
586  if (!MAI->usesWindowsCFI())
587  return getContext().reportError(
588  Loc, ".seh_* directives are not supported on this target");
589  if (CurrentWinFrameInfo && !CurrentWinFrameInfo->End)
591  Loc, "Starting a function before ending the previous one!");
592 
593  MCSymbol *StartProc = EmitCFILabel();
594 
595  WinFrameInfos.emplace_back(
596  llvm::make_unique<WinEH::FrameInfo>(Symbol, StartProc));
597  CurrentWinFrameInfo = WinFrameInfos.back().get();
598  CurrentWinFrameInfo->TextSection = getCurrentSectionOnly();
599 }
600 
602  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
603  if (!CurFrame)
604  return;
605  if (CurFrame->ChainedParent)
606  getContext().reportError(Loc, "Not all chained regions terminated!");
607 
608  MCSymbol *Label = EmitCFILabel();
609  CurFrame->End = Label;
610 }
611 
613  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
614  if (!CurFrame)
615  return;
616 
617  MCSymbol *StartProc = EmitCFILabel();
618 
619  WinFrameInfos.emplace_back(llvm::make_unique<WinEH::FrameInfo>(
620  CurFrame->Function, StartProc, CurFrame));
621  CurrentWinFrameInfo = WinFrameInfos.back().get();
622  CurrentWinFrameInfo->TextSection = getCurrentSectionOnly();
623 }
624 
626  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
627  if (!CurFrame)
628  return;
629  if (!CurFrame->ChainedParent)
630  return getContext().reportError(
631  Loc, "End of a chained region outside a chained region!");
632 
633  MCSymbol *Label = EmitCFILabel();
634 
635  CurFrame->End = Label;
636  CurrentWinFrameInfo = const_cast<WinEH::FrameInfo *>(CurFrame->ChainedParent);
637 }
638 
639 void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
640  SMLoc Loc) {
641  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
642  if (!CurFrame)
643  return;
644  if (CurFrame->ChainedParent)
645  return getContext().reportError(
646  Loc, "Chained unwind areas can't have handlers!");
647  CurFrame->ExceptionHandler = Sym;
648  if (!Except && !Unwind)
649  getContext().reportError(Loc, "Don't know what kind of handler this is!");
650  if (Unwind)
651  CurFrame->HandlesUnwind = true;
652  if (Except)
653  CurFrame->HandlesExceptions = true;
654 }
655 
657  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
658  if (!CurFrame)
659  return;
660  if (CurFrame->ChainedParent)
661  getContext().reportError(Loc, "Chained unwind areas can't have handlers!");
662 }
663 
665  const MCSymbolRefExpr *To, uint64_t Count) {
666 }
667 
668 static MCSection *getWinCFISection(MCContext &Context, unsigned *NextWinCFIID,
669  MCSection *MainCFISec,
670  const MCSection *TextSec) {
671  // If this is the main .text section, use the main unwind info section.
672  if (TextSec == Context.getObjectFileInfo()->getTextSection())
673  return MainCFISec;
674 
675  const auto *TextSecCOFF = cast<MCSectionCOFF>(TextSec);
676  auto *MainCFISecCOFF = cast<MCSectionCOFF>(MainCFISec);
677  unsigned UniqueID = TextSecCOFF->getOrAssignWinCFISectionID(NextWinCFIID);
678 
679  // If this section is COMDAT, this unwind section should be COMDAT associative
680  // with its group.
681  const MCSymbol *KeySym = nullptr;
682  if (TextSecCOFF->getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) {
683  KeySym = TextSecCOFF->getCOMDATSymbol();
684 
685  // In a GNU environment, we can't use associative comdats. Instead, do what
686  // GCC does, which is to make plain comdat selectany section named like
687  // ".[px]data$_Z3foov".
688  if (!Context.getAsmInfo()->hasCOFFAssociativeComdats()) {
689  std::string SectionName =
690  (MainCFISecCOFF->getSectionName() + "$" +
691  TextSecCOFF->getSectionName().split('$').second)
692  .str();
693  return Context.getCOFFSection(
694  SectionName,
695  MainCFISecCOFF->getCharacteristics() | COFF::IMAGE_SCN_LNK_COMDAT,
696  MainCFISecCOFF->getKind(), "", COFF::IMAGE_COMDAT_SELECT_ANY);
697  }
698  }
699 
700  return Context.getAssociativeCOFFSection(MainCFISecCOFF, KeySym, UniqueID);
701 }
702 
704  return getWinCFISection(getContext(), &NextWinCFIID,
705  getContext().getObjectFileInfo()->getPDataSection(),
706  TextSec);
707 }
708 
710  return getWinCFISection(getContext(), &NextWinCFIID,
711  getContext().getObjectFileInfo()->getXDataSection(),
712  TextSec);
713 }
714 
716 
718  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
719  if (!CurFrame)
720  return;
721 
722  MCSymbol *Label = EmitCFILabel();
723 
725  CurFrame->Instructions.push_back(Inst);
726 }
727 
729  SMLoc Loc) {
730  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
731  if (!CurFrame)
732  return;
733  if (CurFrame->LastFrameInst >= 0)
734  return getContext().reportError(
735  Loc, "frame register and offset can be set at most once");
736  if (Offset & 0x0F)
737  return getContext().reportError(Loc, "offset is not a multiple of 16");
738  if (Offset > 240)
739  return getContext().reportError(
740  Loc, "frame offset must be less than or equal to 240");
741 
742  MCSymbol *Label = EmitCFILabel();
743 
744  WinEH::Instruction Inst =
745  Win64EH::Instruction::SetFPReg(Label, Register, Offset);
746  CurFrame->LastFrameInst = CurFrame->Instructions.size();
747  CurFrame->Instructions.push_back(Inst);
748 }
749 
751  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
752  if (!CurFrame)
753  return;
754  if (Size == 0)
755  return getContext().reportError(Loc,
756  "stack allocation size must be non-zero");
757  if (Size & 7)
758  return getContext().reportError(
759  Loc, "stack allocation size is not a multiple of 8");
760 
761  MCSymbol *Label = EmitCFILabel();
762 
764  CurFrame->Instructions.push_back(Inst);
765 }
766 
768  SMLoc Loc) {
769  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
770  if (!CurFrame)
771  return;
772 
773  if (Offset & 7)
774  return getContext().reportError(
775  Loc, "register save offset is not 8 byte aligned");
776 
777  MCSymbol *Label = EmitCFILabel();
778 
779  WinEH::Instruction Inst =
780  Win64EH::Instruction::SaveNonVol(Label, Register, Offset);
781  CurFrame->Instructions.push_back(Inst);
782 }
783 
785  SMLoc Loc) {
786  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
787  if (!CurFrame)
788  return;
789  if (Offset & 0x0F)
790  return getContext().reportError(Loc, "offset is not a multiple of 16");
791 
792  MCSymbol *Label = EmitCFILabel();
793 
794  WinEH::Instruction Inst =
795  Win64EH::Instruction::SaveXMM(Label, Register, Offset);
796  CurFrame->Instructions.push_back(Inst);
797 }
798 
800  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
801  if (!CurFrame)
802  return;
803  if (!CurFrame->Instructions.empty())
804  return getContext().reportError(
805  Loc, "If present, PushMachFrame must be the first UOP");
806 
807  MCSymbol *Label = EmitCFILabel();
808 
810  CurFrame->Instructions.push_back(Inst);
811 }
812 
814  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
815  if (!CurFrame)
816  return;
817 
818  MCSymbol *Label = EmitCFILabel();
819 
820  CurFrame->PrologEnd = Label;
821 }
822 
824 }
825 
827 
829 }
830 
832 
833 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
834 /// the specified string in the output .s file. This capability is
835 /// indicated by the hasRawTextSupport() predicate.
837  errs() << "EmitRawText called on an MCStreamer that doesn't support it, "
838  " something must not be fully mc'ized\n";
839  abort();
840 }
841 
843  SmallString<128> Str;
845 }
846 
848 }
849 
851  if ((!DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End) ||
852  (!WinFrameInfos.empty() && !WinFrameInfos.back()->End)) {
853  getContext().reportError(SMLoc(), "Unfinished frame!");
854  return;
855  }
856 
858  if (TS)
859  TS->finish();
860 
861  FinishImpl();
862 }
863 
865  visitUsedExpr(*Value);
866  Symbol->setVariableValue(Value);
867 
869  if (TS)
870  TS->emitAssignment(Symbol, Value);
871 }
872 
874  const MCInst &Inst, const MCSubtargetInfo &STI) {
875  InstPrinter.printInst(&Inst, OS, "", STI);
876 }
877 
879 }
880 
882  switch (Expr.getKind()) {
883  case MCExpr::Target:
884  cast<MCTargetExpr>(Expr).visitUsedExpr(*this);
885  break;
886 
887  case MCExpr::Constant:
888  break;
889 
890  case MCExpr::Binary: {
891  const MCBinaryExpr &BE = cast<MCBinaryExpr>(Expr);
892  visitUsedExpr(*BE.getLHS());
893  visitUsedExpr(*BE.getRHS());
894  break;
895  }
896 
897  case MCExpr::SymbolRef:
898  visitUsedSymbol(cast<MCSymbolRefExpr>(Expr).getSymbol());
899  break;
900 
901  case MCExpr::Unary:
902  visitUsedExpr(*cast<MCUnaryExpr>(Expr).getSubExpr());
903  break;
904  }
905 }
906 
908  bool) {
909  // Scan for values.
910  for (unsigned i = Inst.getNumOperands(); i--;)
911  if (Inst.getOperand(i).isExpr())
912  visitUsedExpr(*Inst.getOperand(i).getExpr());
913 }
914 
916  unsigned Size) {
917  // Get the Hi-Lo expression.
918  const MCExpr *Diff =
920  MCSymbolRefExpr::create(Lo, Context), Context);
921 
922  const MCAsmInfo *MAI = Context.getAsmInfo();
923  if (!MAI->doesSetDirectiveSuppressReloc()) {
924  EmitValue(Diff, Size);
925  return;
926  }
927 
928  // Otherwise, emit with .set (aka assignment).
929  MCSymbol *SetLabel = Context.createTempSymbol("set", true);
930  EmitAssignment(SetLabel, Diff);
931  EmitSymbolValue(SetLabel, Size);
932 }
933 
935  const MCSymbol *Lo) {
936  // Get the Hi-Lo expression.
937  const MCExpr *Diff =
939  MCSymbolRefExpr::create(Lo, Context), Context);
940 
941  EmitULEB128Value(Diff);
942 }
943 
946 void MCStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
948  llvm_unreachable("this directive only supported on COFF targets");
949 }
951  llvm_unreachable("this directive only supported on COFF targets");
952 }
955  llvm_unreachable("this directive only supported on COFF targets");
956 }
958  llvm_unreachable("this directive only supported on COFF targets");
959 }
962  const MCSymbol *Aliasee) {}
964  unsigned ByteAlignment) {}
966  uint64_t Size, unsigned ByteAlignment) {}
971 void MCStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) {
972  visitUsedExpr(*Value);
973 }
976 void MCStreamer::emitFill(const MCExpr &NumBytes, uint64_t Value, SMLoc Loc) {}
977 void MCStreamer::emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
978  SMLoc Loc) {}
980  unsigned ValueSize,
981  unsigned MaxBytesToEmit) {}
983  unsigned MaxBytesToEmit) {}
985  SMLoc Loc) {}
986 void MCStreamer::EmitBundleAlignMode(unsigned AlignPow2) {}
987 void MCStreamer::EmitBundleLock(bool AlignToEnd) {}
990 
992  assert(Section && "Cannot switch to a null section!");
993  MCSectionSubPair curSection = SectionStack.back().first;
994  SectionStack.back().second = curSection;
995  if (MCSectionSubPair(Section, Subsection) != curSection) {
996  ChangeSection(Section, Subsection);
997  SectionStack.back().first = MCSectionSubPair(Section, Subsection);
998  assert(!Section->hasEnded() && "Section already ended");
999  MCSymbol *Sym = Section->getBeginSymbol();
1000  if (Sym && !Sym->isInSection())
1001  EmitLabel(Sym);
1002  }
1003 }
1004 
1006  // TODO: keep track of the last subsection so that this symbol appears in the
1007  // correct place.
1008  MCSymbol *Sym = Section->getEndSymbol(Context);
1009  if (Sym->isInSection())
1010  return Sym;
1011 
1012  SwitchSection(Section);
1013  EmitLabel(Sym);
1014  return Sym;
1015 }
1016 
1018  if (!Target.isOSBinFormatMachO() || !Target.isOSDarwin())
1019  return;
1020  // Do we even know the version?
1021  if (Target.getOSMajorVersion() == 0)
1022  return;
1023 
1024  unsigned Major;
1025  unsigned Minor;
1026  unsigned Update;
1027  MCVersionMinType VersionType;
1028  if (Target.isWatchOS()) {
1029  VersionType = MCVM_WatchOSVersionMin;
1030  Target.getWatchOSVersion(Major, Minor, Update);
1031  } else if (Target.isTvOS()) {
1032  VersionType = MCVM_TvOSVersionMin;
1033  Target.getiOSVersion(Major, Minor, Update);
1034  } else if (Target.isMacOSX()) {
1035  VersionType = MCVM_OSXVersionMin;
1036  if (!Target.getMacOSXVersion(Major, Minor, Update))
1037  Major = 0;
1038  } else {
1039  VersionType = MCVM_IOSVersionMin;
1040  Target.getiOSVersion(Major, Minor, Update);
1041  }
1042  if (Major != 0)
1043  EmitVersionMin(VersionType, Major, Minor, Update);
1044 }
virtual void EmitBundleUnlock()
Ends a bundle-locked group.
Definition: MCStreamer.cpp:989
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag)
Note in the output the specified Flag.
Definition: MCStreamer.cpp:944
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:986
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
Definition: Triple.h:470
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:213
bool doesSetDirectiveSuppressReloc() const
Definition: MCAsmInfo.h:519
void getiOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getiOSVersion - Parse the version number as with getOSVersion.
Definition: Triple.cpp:1067
MCStreamer(MCContext &Ctx)
Definition: MCStreamer.cpp:77
bool usesWindowsCFI() const
Definition: MCAsmInfo.h:579
virtual void EmitCFISameValue(int64_t Register)
Definition: MCStreamer.cpp:486
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:301
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:450
virtual void EmitWinCFIPushReg(unsigned Register, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:717
virtual void EmitSLEB128Value(const MCExpr *Value)
Definition: MCStreamer.cpp:975
virtual void EmitCFIGnuArgsSize(int64_t Size)
Definition: MCStreamer.cpp:515
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:842
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:321
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:115
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:442
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:984
virtual void emitELFSymverDirective(StringRef AliasName, const MCSymbol *Aliasee)
Emit an ELF .symver directive.
Definition: MCStreamer.cpp:961
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:965
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:584
virtual void EndCOFFSymbolDef()
Marks the end of the symbol definition.
Definition: MCStreamer.cpp:950
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:132
const MCSymbol * End
Definition: MCWinEH.h:33
.watchos_version_min
Definition: MCDirectives.h:68
virtual void EmitULEB128Value(const MCExpr *Value)
Definition: MCStreamer.cpp:974
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:525
virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol)
Emit an weak reference from Alias to Symbol.
Definition: MCStreamer.cpp:968
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:784
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:969
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:480
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:582
virtual void EmitWindowsUnwindTables()
Definition: MCStreamer.cpp:847
void EmitCFIStartProc(bool IsSimple)
Definition: MCStreamer.cpp:344
virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol)
Start emitting COFF symbol definition.
Definition: MCStreamer.cpp:947
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:461
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:562
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:504
virtual void EmitCFIRegister(int64_t Register1, int64_t Register2)
Definition: MCStreamer.cpp:542
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:934
virtual void EmitCFIDefCfaOffset(int64_t Offset)
Definition: MCStreamer.cpp:399
virtual MCSymbol * getDwarfLineTableSymbol(unsigned CUID)
Definition: MCStreamer.cpp:221
StringRef getPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:486
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition: MCDwarf.h:467
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:354
virtual void EmitCOFFSymbolStorageClass(int StorageClass)
Emit the storage class of the symbol.
Definition: MCStreamer.cpp:954
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:971
unsigned LsdaEncoding
Definition: MCDwarf.h:584
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:474
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:907
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:340
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:581
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:514
virtual void EmitCFIRememberState()
Definition: MCStreamer.cpp:467
MCContext & getContext() const
Definition: MCStreamer.h:250
virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding)
Definition: MCStreamer.cpp:459
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:313
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:601
virtual void EmitCFIEscape(StringRef Values)
Definition: MCStreamer.cpp:506
virtual void EmitCOFFSymbolType(int Type)
Emit the type of the symbol.
Definition: MCStreamer.cpp:957
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:639
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
const MCSymbol * Lsda
Definition: MCDwarf.h:580
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:366
virtual ~MCStreamer()
Definition: MCStreamer.cpp:83
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:528
MCSymbol * getEndSymbol(MCContext &Ctx)
Definition: MCSection.cpp:28
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:864
virtual void EmitWinCFIStartChained(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:612
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
void setCurrentCVLoc(unsigned FunctionId, unsigned FileNo, unsigned Line, unsigned Column, bool PrologueEnd, bool IsStmt)
Saves the information from the currently parsed .cv_loc directive and sets CVLocSeen.
Definition: MCCodeView.h:186
static WinEH::Instruction PushNonVol(MCSymbol *L, unsigned Reg)
Definition: MCWin64EH.h:27
bool hasEnded() const
Definition: MCSection.cpp:34
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:544
virtual void finish()
Definition: MCStreamer.cpp:51
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:565
virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame)
Definition: MCStreamer.cpp:376
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:970
const MCExpr * getExpr() const
Definition: MCInst.h:96
virtual void EmitCFIRestoreState()
Definition: MCStreamer.cpp:476
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:330
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:496
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:987
virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment)
Emit a local common (.lcomm) symbol.
Definition: MCStreamer.cpp:963
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:520
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:257
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:453
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:291
.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:460
static MCCFIInstruction createWindowSave(MCSymbol *L)
.cfi_window_save SPARC register window is saved.
Definition: MCDwarf.h:501
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:991
static MCCFIInstruction createGnuArgsSize(MCSymbol *L, int Size)
A special wrapper for .cfi_escape that indicates GNU_ARGS_SIZE.
Definition: MCDwarf.h:541
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:703
virtual void EmitSyntaxDirective()
Definition: MCStreamer.cpp:715
virtual void EmitCFIDefCfaRegister(int64_t Register)
Definition: MCStreamer.cpp:419
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:979
void getWatchOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getWatchOSVersion - Parse the version number as with getOSVersion.
Definition: Triple.cpp:1093
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:297
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:617
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:488
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:508
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:836
virtual void EmitWinEHHandlerData(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:656
unsigned getNumOperands() const
Definition: MCInst.h:184
unsigned size() const
Definition: DenseMap.h:96
virtual void EmitCFIUndefined(int64_t Register)
Definition: MCStreamer.cpp:532
unsigned PersonalityEncoding
Definition: MCDwarf.h:583
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:598
static WinEH::Instruction SetFPReg(MCSymbol *L, unsigned Reg, unsigned Off)
Definition: MCWin64EH.h:49
void Finish()
Finish emission of machine code.
Definition: MCStreamer.cpp:850
virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol)
Definition: MCStreamer.cpp:305
virtual void EmitWinCFIEndChained(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:625
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:530
Binary assembler expressions.
Definition: MCExpr.h:415
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:327
virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol)
Definition: MCStreamer.cpp:823
virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:728
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:668
virtual void EmitWinCFIPushFrame(bool Code, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:799
const std::vector< MCCFIInstruction > & getInitialFrameState() const
Definition: MCAsmInfo.h:600
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:309
virtual void EmitCFIReturnColumn(int64_t Register)
Definition: MCStreamer.cpp:562
std::pair< MCSection *, const MCExpr * > MCSectionSubPair
Definition: MCStreamer.h:56
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:1026
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
Definition: MCStreamer.cpp:915
virtual void EmitCOFFSymbolIndex(MCSymbol const *Symbol)
Emits the symbol table index of a Symbol into the current section.
Definition: MCStreamer.cpp:826
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:430
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:813
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:982
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:182
virtual void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:750
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:295
MCSymbol * getBeginSymbol()
Definition: MCSection.h:106
const Triple & getTargetTriple() const
virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS, const MCInst &Inst, const MCSubtargetInfo &STI)
Definition: MCStreamer.cpp:873
StringRef str()
Return a StringRef for the vector contents.
Definition: raw_ostream.h:529
virtual void ChangeSection(MCSection *, const MCExpr *)
Update streamer for a new active section.
Definition: MCStreamer.cpp:967
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:337
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:881
MCTargetStreamer(MCStreamer &S)
Definition: MCStreamer.cpp:42
virtual MCSymbol * EmitCFILabel()
When emitting an object file, create and emit a real label.
Definition: MCStreamer.cpp:382
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:945
virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:767
virtual void EmitCFISignalFrame()
Definition: MCStreamer.cpp:525
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:440
const MCSymbol * Personality
Definition: MCDwarf.h:579
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:471
virtual void EmitFileDirective(StringRef Filename)
Switch to a new logical file.
Definition: MCStreamer.cpp:953
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:960
void EmitVersionForTarget(const Triple &Target)
References to labels and assigned expressions.
Definition: MCExpr.h:41
bool isLittleEndian() const
True if the target is little endian.
Definition: MCAsmInfo.h:401
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:561
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:388
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:577
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:831
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual void FinishImpl()
Streamer specific finalization.
Definition: MCStreamer.cpp:988
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:456
MCVersionMinType
Definition: MCDirectives.h:64
LLVM Value Representation.
Definition: Value.h:73
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:42
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))
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:322
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:664
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:446
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:112
virtual void visitUsedSymbol(const MCSymbol &Sym)
Definition: MCStreamer.cpp:878
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:536
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:242
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:828
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:164
virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment)
Definition: MCStreamer.cpp:409
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:495
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue)
Set the DescValue for the Symbol.
Definition: MCStreamer.cpp:946
virtual void EmitCFIWindowSave()
Definition: MCStreamer.cpp:552
MCSection * getAssociatedXDataSection(const MCSection *TextSec)
Get the .xdata section used for the given section.
Definition: MCStreamer.cpp:709
Holds state from .cv_file and .cv_loc directives for later emission.
Definition: MCCodeView.h:158