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  SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
80 }
81 
83 
85  DwarfFrameInfos.clear();
86  CurrentWinFrameInfo = nullptr;
87  WinFrameInfos.clear();
88  SymbolOrdering.clear();
89  SectionStack.clear();
90  SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
91 }
92 
94  // By default, discard comments.
95  return nulls();
96 }
97 
98 void MCStreamer::emitRawComment(const Twine &T, bool TabPrefix) {}
99 
102 
104  for (auto &FI : DwarfFrameInfos)
105  FI.CompactUnwindEncoding =
106  (MAB ? MAB->generateCompactUnwindEncoding(FI.Instructions) : 0);
107 }
108 
109 /// EmitIntValue - Special case of EmitValue that avoids the client having to
110 /// pass in a MCExpr for constant integers.
111 void MCStreamer::EmitIntValue(uint64_t Value, unsigned Size) {
112  assert(1 <= Size && Size <= 8 && "Invalid size");
113  assert((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) &&
114  "Invalid size");
115  char buf[8];
116  const bool isLittleEndian = Context.getAsmInfo()->isLittleEndian();
117  for (unsigned i = 0; i != Size; ++i) {
118  unsigned index = isLittleEndian ? i : (Size - i - 1);
119  buf[i] = uint8_t(Value >> (index * 8));
120  }
121  EmitBytes(StringRef(buf, Size));
122 }
123 
124 /// EmitULEB128IntValue - Special case of EmitULEB128Value that avoids the
125 /// client having to pass in a MCExpr for constant integers.
127  SmallString<128> Tmp;
128  raw_svector_ostream OSE(Tmp);
129  encodeULEB128(Value, OSE);
130  EmitBytes(OSE.str());
131 }
132 
133 /// EmitSLEB128IntValue - Special case of EmitSLEB128Value that avoids the
134 /// client having to pass in a MCExpr for constant integers.
136  SmallString<128> Tmp;
137  raw_svector_ostream OSE(Tmp);
138  encodeSLEB128(Value, OSE);
139  EmitBytes(OSE.str());
140 }
141 
142 void MCStreamer::EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc) {
143  EmitValueImpl(Value, Size, Loc);
144 }
145 
146 void MCStreamer::EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
147  bool IsSectionRelative) {
148  assert((!IsSectionRelative || Size == 4) &&
149  "SectionRelative value requires 4-bytes");
150 
151  if (!IsSectionRelative)
153  else
154  EmitCOFFSecRel32(Sym, /*Offset=*/0);
155 }
156 
158  report_fatal_error("unsupported directive in streamer");
159 }
160 
162  report_fatal_error("unsupported directive in streamer");
163 }
164 
166  report_fatal_error("unsupported directive in streamer");
167 }
168 
170  report_fatal_error("unsupported directive in streamer");
171 }
172 
174  report_fatal_error("unsupported directive in streamer");
175 }
176 
178  report_fatal_error("unsupported directive in streamer");
179 }
180 
181 /// Emit NumBytes bytes worth of the value specified by FillValue.
182 /// This implements directives such as '.space'.
183 void MCStreamer::emitFill(uint64_t NumBytes, uint8_t FillValue) {
184  emitFill(*MCConstantExpr::create(NumBytes, getContext()), FillValue);
185 }
186 
187 /// The implementation in this class just redirects to emitFill.
188 void MCStreamer::EmitZeros(uint64_t NumBytes) {
189  emitFill(NumBytes, 0);
190 }
191 
194  StringRef Filename,
195  MD5::MD5Result *Checksum,
197  unsigned CUID) {
198  return getContext().getDwarfFile(Directory, Filename, FileNo, Checksum,
199  Source, CUID);
200 }
201 
203  StringRef Filename,
204  MD5::MD5Result *Checksum,
206  unsigned CUID) {
207  getContext().setMCLineTableRootFile(CUID, Directory, Filename, Checksum,
208  Source);
209 }
210 
211 void MCStreamer::EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
212  unsigned Column, unsigned Flags,
213  unsigned Isa,
214  unsigned Discriminator,
215  StringRef FileName) {
216  getContext().setCurrentDwarfLoc(FileNo, Line, Column, Flags, Isa,
217  Discriminator);
218 }
219 
222  if (!Table.getLabel()) {
224  Table.setLabel(
225  Context.getOrCreateSymbol(Prefix + "line_table_start" + Twine(CUID)));
226  }
227  return Table.getLabel();
228 }
229 
231  return !DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End;
232 }
233 
234 MCDwarfFrameInfo *MCStreamer::getCurrentDwarfFrameInfo() {
236  getContext().reportError(SMLoc(), "this directive must appear between "
237  ".cfi_startproc and .cfi_endproc "
238  "directives");
239  return nullptr;
240  }
241  return &DwarfFrameInfos.back();
242 }
243 
244 bool MCStreamer::EmitCVFileDirective(unsigned FileNo, StringRef Filename,
245  ArrayRef<uint8_t> Checksum,
246  unsigned ChecksumKind) {
247  return getContext().getCVContext().addFile(*this, FileNo, Filename, Checksum,
248  ChecksumKind);
249 }
250 
251 bool MCStreamer::EmitCVFuncIdDirective(unsigned FunctionId) {
252  return getContext().getCVContext().recordFunctionId(FunctionId);
253 }
254 
256  unsigned IAFunc, unsigned IAFile,
257  unsigned IALine, unsigned IACol,
258  SMLoc Loc) {
259  if (getContext().getCVContext().getCVFunctionInfo(IAFunc) == nullptr) {
260  getContext().reportError(Loc, "parent function id not introduced by "
261  ".cv_func_id or .cv_inline_site_id");
262  return true;
263  }
264 
266  FunctionId, IAFunc, IAFile, IALine, IACol);
267 }
268 
269 void MCStreamer::EmitCVLocDirective(unsigned FunctionId, unsigned FileNo,
270  unsigned Line, unsigned Column,
271  bool PrologueEnd, bool IsStmt,
272  StringRef FileName, SMLoc Loc) {
274  MCCVFunctionInfo *FI = CVC.getCVFunctionInfo(FunctionId);
275  if (!FI)
276  return getContext().reportError(
277  Loc, "function id not introduced by .cv_func_id or .cv_inline_site_id");
278 
279  // Track the section
280  if (FI->Section == nullptr)
282  else if (FI->Section != getCurrentSectionOnly())
283  return getContext().reportError(
284  Loc,
285  "all .cv_loc directives for a function must be in the same section");
286 
287  CVC.setCurrentCVLoc(FunctionId, FileNo, Line, Column, PrologueEnd, IsStmt);
288 }
289 
290 void MCStreamer::EmitCVLinetableDirective(unsigned FunctionId,
291  const MCSymbol *Begin,
292  const MCSymbol *End) {}
293 
294 void MCStreamer::EmitCVInlineLinetableDirective(unsigned PrimaryFunctionId,
295  unsigned SourceFileId,
296  unsigned SourceLineNum,
297  const MCSymbol *FnStartSym,
298  const MCSymbol *FnEndSym) {}
299 
301  ArrayRef<std::pair<const MCSymbol *, const MCSymbol *>> Ranges,
302  StringRef FixedSizePortion) {}
303 
305  MCSymbol *EHSymbol) {
306 }
307 
308 void MCStreamer::InitSections(bool NoExecStack) {
309  SwitchSection(getContext().getObjectFileInfo()->getTextSection());
310 }
311 
313  assert(Fragment);
314  Symbol->setFragment(Fragment);
315 
316  // As we emit symbols into a section, track the order so that they can
317  // be sorted upon later. Zero is reserved to mean 'unemitted'.
318  SymbolOrdering[Symbol] = 1 + SymbolOrdering.size();
319 }
320 
322  Symbol->redefineIfPossible();
323 
324  if (!Symbol->isUndefined() || Symbol->isVariable())
325  return getContext().reportError(Loc, "invalid symbol redefinition");
326 
327  assert(!Symbol->isVariable() && "Cannot emit a variable symbol!");
328  assert(getCurrentSectionOnly() && "Cannot emit before setting section!");
329  assert(!Symbol->getFragment() && "Unexpected fragment on symbol data!");
330  assert(Symbol->isUndefined() && "Cannot define a symbol twice!");
331 
332  Symbol->setFragment(&getCurrentSectionOnly()->getDummyFragment());
333 
335  if (TS)
336  TS->emitLabel(Symbol);
337 }
338 
339 void MCStreamer::EmitCFISections(bool EH, bool Debug) {
340  assert(EH || Debug);
341 }
342 
343 void MCStreamer::EmitCFIStartProc(bool IsSimple) {
346  SMLoc(), "starting new .cfi frame before finishing the previous one");
347 
348  MCDwarfFrameInfo Frame;
349  Frame.IsSimple = IsSimple;
350  EmitCFIStartProcImpl(Frame);
351 
352  const MCAsmInfo* MAI = Context.getAsmInfo();
353  if (MAI) {
354  for (const MCCFIInstruction& Inst : MAI->getInitialFrameState()) {
355  if (Inst.getOperation() == MCCFIInstruction::OpDefCfa ||
356  Inst.getOperation() == MCCFIInstruction::OpDefCfaRegister) {
357  Frame.CurrentCfaRegister = Inst.getRegister();
358  }
359  }
360  }
361 
362  DwarfFrameInfos.push_back(Frame);
363 }
364 
366 }
367 
369  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
370  if (!CurFrame)
371  return;
372  EmitCFIEndProcImpl(*CurFrame);
373 }
374 
376  // Put a dummy non-null value in Frame.End to mark that this frame has been
377  // closed.
378  Frame.End = (MCSymbol *)1;
379 }
380 
382  // Return a dummy non-null value so that label fields appear filled in when
383  // generating textual assembly.
384  return (MCSymbol *)1;
385 }
386 
387 void MCStreamer::EmitCFIDefCfa(int64_t Register, int64_t Offset) {
388  MCSymbol *Label = EmitCFILabel();
390  MCCFIInstruction::createDefCfa(Label, Register, Offset);
391  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
392  if (!CurFrame)
393  return;
394  CurFrame->Instructions.push_back(Instruction);
395  CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register);
396 }
397 
399  MCSymbol *Label = EmitCFILabel();
402  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
403  if (!CurFrame)
404  return;
405  CurFrame->Instructions.push_back(Instruction);
406 }
407 
408 void MCStreamer::EmitCFIAdjustCfaOffset(int64_t Adjustment) {
409  MCSymbol *Label = EmitCFILabel();
411  MCCFIInstruction::createAdjustCfaOffset(Label, Adjustment);
412  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
413  if (!CurFrame)
414  return;
415  CurFrame->Instructions.push_back(Instruction);
416 }
417 
419  MCSymbol *Label = EmitCFILabel();
422  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
423  if (!CurFrame)
424  return;
425  CurFrame->Instructions.push_back(Instruction);
426  CurFrame->CurrentCfaRegister = static_cast<unsigned>(Register);
427 }
428 
429 void MCStreamer::EmitCFIOffset(int64_t Register, int64_t Offset) {
430  MCSymbol *Label = EmitCFILabel();
432  MCCFIInstruction::createOffset(Label, Register, Offset);
433  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
434  if (!CurFrame)
435  return;
436  CurFrame->Instructions.push_back(Instruction);
437 }
438 
440  MCSymbol *Label = EmitCFILabel();
442  MCCFIInstruction::createRelOffset(Label, Register, Offset);
443  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
444  if (!CurFrame)
445  return;
446  CurFrame->Instructions.push_back(Instruction);
447 }
448 
450  unsigned Encoding) {
451  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
452  if (!CurFrame)
453  return;
454  CurFrame->Personality = Sym;
455  CurFrame->PersonalityEncoding = Encoding;
456 }
457 
458 void MCStreamer::EmitCFILsda(const MCSymbol *Sym, unsigned Encoding) {
459  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
460  if (!CurFrame)
461  return;
462  CurFrame->Lsda = Sym;
463  CurFrame->LsdaEncoding = Encoding;
464 }
465 
467  MCSymbol *Label = EmitCFILabel();
469  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
470  if (!CurFrame)
471  return;
472  CurFrame->Instructions.push_back(Instruction);
473 }
474 
476  // FIXME: Error if there is no matching cfi_remember_state.
477  MCSymbol *Label = EmitCFILabel();
479  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
480  if (!CurFrame)
481  return;
482  CurFrame->Instructions.push_back(Instruction);
483 }
484 
486  MCSymbol *Label = EmitCFILabel();
488  MCCFIInstruction::createSameValue(Label, Register);
489  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
490  if (!CurFrame)
491  return;
492  CurFrame->Instructions.push_back(Instruction);
493 }
494 
496  MCSymbol *Label = EmitCFILabel();
498  MCCFIInstruction::createRestore(Label, Register);
499  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
500  if (!CurFrame)
501  return;
502  CurFrame->Instructions.push_back(Instruction);
503 }
504 
506  MCSymbol *Label = EmitCFILabel();
508  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
509  if (!CurFrame)
510  return;
511  CurFrame->Instructions.push_back(Instruction);
512 }
513 
515  MCSymbol *Label = EmitCFILabel();
518  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
519  if (!CurFrame)
520  return;
521  CurFrame->Instructions.push_back(Instruction);
522 }
523 
525  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
526  if (!CurFrame)
527  return;
528  CurFrame->IsSignalFrame = true;
529 }
530 
532  MCSymbol *Label = EmitCFILabel();
534  MCCFIInstruction::createUndefined(Label, Register);
535  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
536  if (!CurFrame)
537  return;
538  CurFrame->Instructions.push_back(Instruction);
539 }
540 
541 void MCStreamer::EmitCFIRegister(int64_t Register1, int64_t Register2) {
542  MCSymbol *Label = EmitCFILabel();
544  MCCFIInstruction::createRegister(Label, Register1, Register2);
545  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
546  if (!CurFrame)
547  return;
548  CurFrame->Instructions.push_back(Instruction);
549 }
550 
552  MCSymbol *Label = EmitCFILabel();
555  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
556  if (!CurFrame)
557  return;
558  CurFrame->Instructions.push_back(Instruction);
559 }
560 
562  MCDwarfFrameInfo *CurFrame = getCurrentDwarfFrameInfo();
563  if (!CurFrame)
564  return;
565  CurFrame->RAReg = Register;
566 }
567 
568 WinEH::FrameInfo *MCStreamer::EnsureValidWinFrameInfo(SMLoc Loc) {
569  const MCAsmInfo *MAI = Context.getAsmInfo();
570  if (!MAI->usesWindowsCFI()) {
572  Loc, ".seh_* directives are not supported on this target");
573  return nullptr;
574  }
575  if (!CurrentWinFrameInfo || CurrentWinFrameInfo->End) {
577  Loc, ".seh_ directive must appear within an active frame");
578  return nullptr;
579  }
580  return CurrentWinFrameInfo;
581 }
582 
584  const MCAsmInfo *MAI = Context.getAsmInfo();
585  if (!MAI->usesWindowsCFI())
586  return getContext().reportError(
587  Loc, ".seh_* directives are not supported on this target");
588  if (CurrentWinFrameInfo && !CurrentWinFrameInfo->End)
590  Loc, "Starting a function before ending the previous one!");
591 
592  MCSymbol *StartProc = EmitCFILabel();
593 
594  WinFrameInfos.emplace_back(
595  llvm::make_unique<WinEH::FrameInfo>(Symbol, StartProc));
596  CurrentWinFrameInfo = WinFrameInfos.back().get();
597  CurrentWinFrameInfo->TextSection = getCurrentSectionOnly();
598 }
599 
601  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
602  if (!CurFrame)
603  return;
604  if (CurFrame->ChainedParent)
605  getContext().reportError(Loc, "Not all chained regions terminated!");
606 
607  MCSymbol *Label = EmitCFILabel();
608  CurFrame->End = Label;
609 }
610 
612  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
613  if (!CurFrame)
614  return;
615 
616  MCSymbol *StartProc = EmitCFILabel();
617 
618  WinFrameInfos.emplace_back(llvm::make_unique<WinEH::FrameInfo>(
619  CurFrame->Function, StartProc, CurFrame));
620  CurrentWinFrameInfo = WinFrameInfos.back().get();
621  CurrentWinFrameInfo->TextSection = getCurrentSectionOnly();
622 }
623 
625  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
626  if (!CurFrame)
627  return;
628  if (!CurFrame->ChainedParent)
629  return getContext().reportError(
630  Loc, "End of a chained region outside a chained region!");
631 
632  MCSymbol *Label = EmitCFILabel();
633 
634  CurFrame->End = Label;
635  CurrentWinFrameInfo = const_cast<WinEH::FrameInfo *>(CurFrame->ChainedParent);
636 }
637 
638 void MCStreamer::EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except,
639  SMLoc Loc) {
640  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
641  if (!CurFrame)
642  return;
643  if (CurFrame->ChainedParent)
644  return getContext().reportError(
645  Loc, "Chained unwind areas can't have handlers!");
646  CurFrame->ExceptionHandler = Sym;
647  if (!Except && !Unwind)
648  getContext().reportError(Loc, "Don't know what kind of handler this is!");
649  if (Unwind)
650  CurFrame->HandlesUnwind = true;
651  if (Except)
652  CurFrame->HandlesExceptions = true;
653 }
654 
656  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
657  if (!CurFrame)
658  return;
659  if (CurFrame->ChainedParent)
660  getContext().reportError(Loc, "Chained unwind areas can't have handlers!");
661 }
662 
663 static MCSection *getWinCFISection(MCContext &Context, unsigned *NextWinCFIID,
664  MCSection *MainCFISec,
665  const MCSection *TextSec) {
666  // If this is the main .text section, use the main unwind info section.
667  if (TextSec == Context.getObjectFileInfo()->getTextSection())
668  return MainCFISec;
669 
670  const auto *TextSecCOFF = cast<MCSectionCOFF>(TextSec);
671  unsigned UniqueID = TextSecCOFF->getOrAssignWinCFISectionID(NextWinCFIID);
672 
673  // If this section is COMDAT, this unwind section should be COMDAT associative
674  // with its group.
675  const MCSymbol *KeySym = nullptr;
676  if (TextSecCOFF->getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT)
677  KeySym = TextSecCOFF->getCOMDATSymbol();
678 
679  return Context.getAssociativeCOFFSection(cast<MCSectionCOFF>(MainCFISec),
680  KeySym, UniqueID);
681 }
682 
684  return getWinCFISection(getContext(), &NextWinCFIID,
685  getContext().getObjectFileInfo()->getPDataSection(),
686  TextSec);
687 }
688 
690  return getWinCFISection(getContext(), &NextWinCFIID,
691  getContext().getObjectFileInfo()->getXDataSection(),
692  TextSec);
693 }
694 
696 
698  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
699  if (!CurFrame)
700  return;
701 
702  MCSymbol *Label = EmitCFILabel();
703 
705  CurFrame->Instructions.push_back(Inst);
706 }
707 
709  SMLoc Loc) {
710  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
711  if (!CurFrame)
712  return;
713  if (CurFrame->LastFrameInst >= 0)
714  return getContext().reportError(
715  Loc, "frame register and offset can be set at most once");
716  if (Offset & 0x0F)
717  return getContext().reportError(Loc, "offset is not a multiple of 16");
718  if (Offset > 240)
719  return getContext().reportError(
720  Loc, "frame offset must be less than or equal to 240");
721 
722  MCSymbol *Label = EmitCFILabel();
723 
724  WinEH::Instruction Inst =
725  Win64EH::Instruction::SetFPReg(Label, Register, Offset);
726  CurFrame->LastFrameInst = CurFrame->Instructions.size();
727  CurFrame->Instructions.push_back(Inst);
728 }
729 
731  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
732  if (!CurFrame)
733  return;
734  if (Size == 0)
735  return getContext().reportError(Loc,
736  "stack allocation size must be non-zero");
737  if (Size & 7)
738  return getContext().reportError(
739  Loc, "stack allocation size is not a multiple of 8");
740 
741  MCSymbol *Label = EmitCFILabel();
742 
744  CurFrame->Instructions.push_back(Inst);
745 }
746 
748  SMLoc Loc) {
749  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
750  if (!CurFrame)
751  return;
752 
753  if (Offset & 7)
754  return getContext().reportError(
755  Loc, "register save offset is not 8 byte aligned");
756 
757  MCSymbol *Label = EmitCFILabel();
758 
759  WinEH::Instruction Inst =
760  Win64EH::Instruction::SaveNonVol(Label, Register, Offset);
761  CurFrame->Instructions.push_back(Inst);
762 }
763 
765  SMLoc Loc) {
766  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
767  if (!CurFrame)
768  return;
769  if (Offset & 0x0F)
770  return getContext().reportError(Loc, "offset is not a multiple of 16");
771 
772  MCSymbol *Label = EmitCFILabel();
773 
774  WinEH::Instruction Inst =
775  Win64EH::Instruction::SaveXMM(Label, Register, Offset);
776  CurFrame->Instructions.push_back(Inst);
777 }
778 
780  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
781  if (!CurFrame)
782  return;
783  if (!CurFrame->Instructions.empty())
784  return getContext().reportError(
785  Loc, "If present, PushMachFrame must be the first UOP");
786 
787  MCSymbol *Label = EmitCFILabel();
788 
790  CurFrame->Instructions.push_back(Inst);
791 }
792 
794  WinEH::FrameInfo *CurFrame = EnsureValidWinFrameInfo(Loc);
795  if (!CurFrame)
796  return;
797 
798  MCSymbol *Label = EmitCFILabel();
799 
800  CurFrame->PrologEnd = Label;
801 }
802 
804 }
805 
807 
809 }
810 
812 
813 /// EmitRawText - If this file is backed by an assembly streamer, this dumps
814 /// the specified string in the output .s file. This capability is
815 /// indicated by the hasRawTextSupport() predicate.
817  errs() << "EmitRawText called on an MCStreamer that doesn't support it, "
818  " something must not be fully mc'ized\n";
819  abort();
820 }
821 
823  SmallString<128> Str;
825 }
826 
828 }
829 
831  if ((!DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End) ||
832  (!WinFrameInfos.empty() && !WinFrameInfos.back()->End)) {
833  getContext().reportError(SMLoc(), "Unfinished frame!");
834  return;
835  }
836 
838  if (TS)
839  TS->finish();
840 
841  FinishImpl();
842 }
843 
845  visitUsedExpr(*Value);
846  Symbol->setVariableValue(Value);
847 
849  if (TS)
850  TS->emitAssignment(Symbol, Value);
851 }
852 
854  const MCInst &Inst, const MCSubtargetInfo &STI) {
855  InstPrinter.printInst(&Inst, OS, "", STI);
856 }
857 
859 }
860 
862  switch (Expr.getKind()) {
863  case MCExpr::Target:
864  cast<MCTargetExpr>(Expr).visitUsedExpr(*this);
865  break;
866 
867  case MCExpr::Constant:
868  break;
869 
870  case MCExpr::Binary: {
871  const MCBinaryExpr &BE = cast<MCBinaryExpr>(Expr);
872  visitUsedExpr(*BE.getLHS());
873  visitUsedExpr(*BE.getRHS());
874  break;
875  }
876 
877  case MCExpr::SymbolRef:
878  visitUsedSymbol(cast<MCSymbolRefExpr>(Expr).getSymbol());
879  break;
880 
881  case MCExpr::Unary:
882  visitUsedExpr(*cast<MCUnaryExpr>(Expr).getSubExpr());
883  break;
884  }
885 }
886 
888  bool) {
889  // Scan for values.
890  for (unsigned i = Inst.getNumOperands(); i--;)
891  if (Inst.getOperand(i).isExpr())
892  visitUsedExpr(*Inst.getOperand(i).getExpr());
893 }
894 
896  unsigned Size) {
897  // Get the Hi-Lo expression.
898  const MCExpr *Diff =
900  MCSymbolRefExpr::create(Lo, Context), Context);
901 
902  const MCAsmInfo *MAI = Context.getAsmInfo();
903  if (!MAI->doesSetDirectiveSuppressReloc()) {
904  EmitValue(Diff, Size);
905  return;
906  }
907 
908  // Otherwise, emit with .set (aka assignment).
909  MCSymbol *SetLabel = Context.createTempSymbol("set", true);
910  EmitAssignment(SetLabel, Diff);
911  EmitSymbolValue(SetLabel, Size);
912 }
913 
915  const MCSymbol *Lo) {
916  // Get the Hi-Lo expression.
917  const MCExpr *Diff =
919  MCSymbolRefExpr::create(Lo, Context), Context);
920 
921  EmitULEB128Value(Diff);
922 }
923 
926 void MCStreamer::EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) {}
928  llvm_unreachable("this directive only supported on COFF targets");
929 }
931  llvm_unreachable("this directive only supported on COFF targets");
932 }
935  llvm_unreachable("this directive only supported on COFF targets");
936 }
938  llvm_unreachable("this directive only supported on COFF targets");
939 }
942  const MCSymbol *Aliasee) {}
944  unsigned ByteAlignment) {}
946  uint64_t Size, unsigned ByteAlignment) {}
951 void MCStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) {
952  visitUsedExpr(*Value);
953 }
956 void MCStreamer::emitFill(const MCExpr &NumBytes, uint64_t Value, SMLoc Loc) {}
957 void MCStreamer::emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr,
958  SMLoc Loc) {}
960  unsigned ValueSize,
961  unsigned MaxBytesToEmit) {}
963  unsigned MaxBytesToEmit) {}
965  SMLoc Loc) {}
966 void MCStreamer::EmitBundleAlignMode(unsigned AlignPow2) {}
967 void MCStreamer::EmitBundleLock(bool AlignToEnd) {}
970 
972  assert(Section && "Cannot switch to a null section!");
973  MCSectionSubPair curSection = SectionStack.back().first;
974  SectionStack.back().second = curSection;
975  if (MCSectionSubPair(Section, Subsection) != curSection) {
976  ChangeSection(Section, Subsection);
977  SectionStack.back().first = MCSectionSubPair(Section, Subsection);
978  assert(!Section->hasEnded() && "Section already ended");
979  MCSymbol *Sym = Section->getBeginSymbol();
980  if (Sym && !Sym->isInSection())
981  EmitLabel(Sym);
982  }
983 }
984 
986  // TODO: keep track of the last subsection so that this symbol appears in the
987  // correct place.
988  MCSymbol *Sym = Section->getEndSymbol(Context);
989  if (Sym->isInSection())
990  return Sym;
991 
992  SwitchSection(Section);
993  EmitLabel(Sym);
994  return Sym;
995 }
996 
998  if (!Target.isOSBinFormatMachO() || !Target.isOSDarwin())
999  return;
1000  // Do we even know the version?
1001  if (Target.getOSMajorVersion() == 0)
1002  return;
1003 
1004  unsigned Major;
1005  unsigned Minor;
1006  unsigned Update;
1007  MCVersionMinType VersionType;
1008  if (Target.isWatchOS()) {
1009  VersionType = MCVM_WatchOSVersionMin;
1010  Target.getWatchOSVersion(Major, Minor, Update);
1011  } else if (Target.isTvOS()) {
1012  VersionType = MCVM_TvOSVersionMin;
1013  Target.getiOSVersion(Major, Minor, Update);
1014  } else if (Target.isMacOSX()) {
1015  VersionType = MCVM_OSXVersionMin;
1016  if (!Target.getMacOSXVersion(Major, Minor, Update))
1017  Major = 0;
1018  } else {
1019  VersionType = MCVM_IOSVersionMin;
1020  Target.getiOSVersion(Major, Minor, Update);
1021  }
1022  if (Major != 0)
1023  EmitVersionMin(VersionType, Major, Minor, Update);
1024 }
virtual void EmitBundleUnlock()
Ends a bundle-locked group.
Definition: MCStreamer.cpp:969
virtual void EmitAssemblerFlag(MCAssemblerFlag Flag)
Note in the output the specified Flag.
Definition: MCStreamer.cpp:924
const MCAsmInfo * getAsmInfo() const
Definition: MCContext.h:290
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:211
virtual void EmitBundleAlignMode(unsigned AlignPow2)
Set the bundle alignment mode from now on in the section.
Definition: MCStreamer.cpp:966
bool isOSDarwin() const
isOSDarwin - Is this a "Darwin" OS (OS X, iOS, or watchOS).
Definition: Triple.h:468
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:212
bool doesSetDirectiveSuppressReloc() const
Definition: MCAsmInfo.h:513
void getiOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getiOSVersion - Parse the version number as with getOSVersion.
Definition: Triple.cpp:1063
MCStreamer(MCContext &Ctx)
Definition: MCStreamer.cpp:77
bool usesWindowsCFI() const
Definition: MCAsmInfo.h:573
virtual void EmitCFISameValue(int64_t Register)
Definition: MCStreamer.cpp:485
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:300
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:449
virtual void EmitWinCFIPushReg(unsigned Register, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:697
virtual void EmitSLEB128Value(const MCExpr *Value)
Definition: MCStreamer.cpp:955
virtual void EmitCFIGnuArgsSize(int64_t Size)
Definition: MCStreamer.cpp:514
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:822
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:313
void EmitSLEB128IntValue(int64_t Value)
Special case of EmitSLEB128Value that avoids the client having to pass in a MCExpr for constant integ...
Definition: MCStreamer.cpp:135
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:146
bool isMacOSX() const
isMacOSX - Is this a Mac OS X triple.
Definition: Triple.h:440
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:964
virtual void emitELFSymverDirective(StringRef AliasName, const MCSymbol *Aliasee)
Emit an ELF .symver directive.
Definition: MCStreamer.cpp:941
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:945
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:583
virtual void EndCOFFSymbolDef()
Marks the end of the symbol definition.
Definition: MCStreamer.cpp:930
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:954
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:202
static MCCFIInstruction createRememberState(MCSymbol *L)
.cfi_remember_state Save all current rules for all registers.
Definition: MCDwarf.h:499
virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol)
Emit an weak reference from Alias to Symbol.
Definition: MCStreamer.cpp:948
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:764
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:949
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:454
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:84
unsigned CurrentCfaRegister
Definition: MCDwarf.h:556
virtual void EmitWindowsUnwindTables()
Definition: MCStreamer.cpp:827
void EmitCFIStartProc(bool IsSimple)
Definition: MCStreamer.cpp:343
virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol)
Start emitting COFF symbol definition.
Definition: MCStreamer.cpp:927
virtual void EmitDTPRel64Value(const MCExpr *Value)
Emit the expression Value into the output as a dtprel (64-bit DTP relative) value.
Definition: MCStreamer.cpp:157
bool isWatchOS() const
Is this an Apple watchOS triple.
Definition: Triple.h:459
const MCExpr * getLHS() const
Get the left-hand side expression of the binary operator.
Definition: MCExpr.h:554
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:494
virtual void EmitCFIRegister(int64_t Register1, int64_t Register2)
Definition: MCStreamer.cpp:541
virtual void emitExplicitComments()
Emit added explicit comments.
Definition: MCStreamer.cpp:101
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:914
virtual void EmitCFIDefCfaOffset(int64_t Offset)
Definition: MCStreamer.cpp:398
virtual MCSymbol * getDwarfLineTableSymbol(unsigned CUID)
Definition: MCStreamer.cpp:220
StringRef getPrivateGlobalPrefix() const
Definition: MCAsmInfo.h:480
static MCCFIInstruction createDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
Definition: MCDwarf.h:441
COFF::SymbolStorageClass StorageClass
Definition: COFFYAML.cpp:354
virtual void EmitCOFFSymbolStorageClass(int StorageClass)
Emit the storage class of the symbol.
Definition: MCStreamer.cpp:934
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:951
unsigned LsdaEncoding
Definition: MCDwarf.h:558
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:448
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:887
virtual void addExplicitComment(const Twine &T)
Add explicit comment T.
Definition: MCStreamer.cpp:100
virtual void EmitCFISections(bool EH, bool Debug)
Definition: MCStreamer.cpp:339
virtual void EmitGPRel32Value(const MCExpr *Value)
Emit the expression Value into the output as a gprel32 (32-bit GP relative) value.
Definition: MCStreamer.cpp:177
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:469
std::vector< MCCFIInstruction > Instructions
Definition: MCDwarf.h:555
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:488
virtual void EmitCFIRememberState()
Definition: MCStreamer.cpp:466
MCContext & getContext() const
Definition: MCStreamer.h:248
virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding)
Definition: MCStreamer.cpp:458
virtual void EmitGPRel64Value(const MCExpr *Value)
Emit the expression Value into the output as a gprel64 (64-bit GP relative) value.
Definition: MCStreamer.cpp:173
void AssignFragment(MCSymbol *Symbol, MCFragment *Fragment)
Sets the symbol&#39;s section.
Definition: MCStreamer.cpp:312
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:600
virtual void EmitCFIEscape(StringRef Values)
Definition: MCStreamer.cpp:505
virtual void EmitCOFFSymbolType(int Type)
Emit the type of the symbol.
Definition: MCStreamer.cpp:937
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:193
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:638
const MCSymbol * Lsda
Definition: MCDwarf.h:554
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:141
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:365
virtual ~MCStreamer()
Definition: MCStreamer.cpp:82
MCDwarfLineTable & getMCDwarfLineTable(unsigned CUID)
Definition: MCContext.h:509
MCSymbol * getEndSymbol(MCContext &Ctx)
Definition: MCSection.cpp:27
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:269
virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value)
Emit an assignment of Value to Symbol.
Definition: MCStreamer.cpp:844
virtual void EmitWinCFIStartChained(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:611
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:244
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:33
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:536
virtual void finish()
Definition: MCStreamer.cpp:51
const MCExpr * getRHS() const
Get the right-hand side expression of the binary operator.
Definition: MCExpr.h:557
virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame)
Definition: MCStreamer.cpp:375
virtual void EmitTPRel64Value(const MCExpr *Value)
Emit the expression Value into the output as a tprel (64-bit TP relative) value.
Definition: MCStreamer.cpp:165
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:98
virtual void EmitBinaryData(StringRef Data)
Functionally identical to EmitBytes.
Definition: MCStreamer.cpp:950
const MCExpr * getExpr() const
Definition: MCInst.h:96
virtual void EmitCFIRestoreState()
Definition: MCStreamer.cpp:475
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:111
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
Definition: ELF.h:319
void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:142
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:495
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:121
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:967
virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment)
Emit a local common (.lcomm) symbol.
Definition: MCStreamer.cpp:943
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:494
virtual raw_ostream & GetCommentOS()
Return a raw_ostream that comments can be written to.
Definition: MCStreamer.cpp:93
void EmitZeros(uint64_t NumBytes)
Emit NumBytes worth of zeros.
Definition: MCStreamer.cpp:188
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:216
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:40
const FrameInfo * ChainedParent
Definition: MCWinEH.h:44
MCTargetStreamer * getTargetStreamer()
Definition: MCStreamer.h:250
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:427
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:290
.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:434
static MCCFIInstruction createWindowSave(MCSymbol *L)
.cfi_window_save SPARC register window is saved.
Definition: MCDwarf.h:475
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:971
static MCCFIInstruction createGnuArgsSize(MCSymbol *L, int Size)
A special wrapper for .cfi_escape that indicates GNU_ARGS_SIZE.
Definition: MCDwarf.h:515
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:683
virtual void EmitSyntaxDirective()
Definition: MCStreamer.cpp:695
virtual void EmitCFIDefCfaRegister(int64_t Register)
Definition: MCStreamer.cpp:418
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:959
void getWatchOSVersion(unsigned &Major, unsigned &Minor, unsigned &Micro) const
getWatchOSVersion - Parse the version number as with getOSVersion.
Definition: Triple.cpp:1089
static const unsigned End
const MCObjectFileInfo * getObjectFileInfo() const
Definition: MCContext.h:294
void reportError(SMLoc L, const Twine &Msg)
Definition: MCContext.cpp:577
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:462
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:482
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:816
virtual void EmitWinEHHandlerData(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:655
unsigned getNumOperands() const
Definition: MCInst.h:184
unsigned size() const
Definition: DenseMap.h:96
virtual void EmitCFIUndefined(int64_t Register)
Definition: MCStreamer.cpp:531
unsigned PersonalityEncoding
Definition: MCDwarf.h:557
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:596
static WinEH::Instruction SetFPReg(MCSymbol *L, unsigned Reg, unsigned Off)
Definition: MCWin64EH.h:49
void Finish()
Finish emission of machine code.
Definition: MCStreamer.cpp:830
virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol)
Definition: MCStreamer.cpp:304
virtual void EmitWinCFIEndChained(SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:624
bool isIntN(unsigned N, int64_t x)
Checks if an signed integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:390
static MCCFIInstruction createRestoreState(MCSymbol *L)
.cfi_restore_state Restore the previously saved state.
Definition: MCDwarf.h:504
Binary assembler expressions.
Definition: MCExpr.h:407
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:325
virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol)
Definition: MCStreamer.cpp:803
virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:708
void generateCompactUnwindEncodings(MCAsmBackend *MAB)
Definition: MCStreamer.cpp:103
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:663
virtual void EmitWinCFIPushFrame(bool Code, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:779
const std::vector< MCCFIInstruction > & getInitialFrameState() const
Definition: MCAsmInfo.h:594
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:169
const MCSymbol * PrologEnd
Definition: MCWinEH.h:36
virtual void InitSections(bool NoExecStack)
Create the default sections and set the initial one.
Definition: MCStreamer.cpp:308
virtual void EmitCFIReturnColumn(int64_t Register)
Definition: MCStreamer.cpp:561
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:1022
virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo, unsigned Size)
Emit the absolute difference between two symbols.
Definition: MCStreamer.cpp:895
virtual void EmitCOFFSymbolIndex(MCSymbol const *Symbol)
Emits the symbol table index of a Symbol into the current section.
Definition: MCStreamer.cpp:806
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:429
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:382
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:793
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:962
const MCOperand & getOperand(unsigned i) const
Definition: MCInst.h:182
virtual void EmitWinCFIAllocStack(unsigned Size, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:730
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:294
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:853
StringRef str()
Return a StringRef for the vector contents.
Definition: raw_ostream.h:519
virtual void ChangeSection(MCSection *, const MCExpr *)
Update streamer for a new active section.
Definition: MCStreamer.cpp:947
void setVariableValue(const MCExpr *Value)
Definition: MCSymbol.cpp:48
bool hasUnfinishedDwarfFrameInfo()
Definition: MCStreamer.cpp:230
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:330
void visitUsedExpr(const MCExpr &Expr)
Definition: MCStreamer.cpp:861
MCTargetStreamer(MCStreamer &S)
Definition: MCStreamer.cpp:42
virtual MCSymbol * EmitCFILabel()
When emitting an object file, create and emit a real label.
Definition: MCStreamer.cpp:381
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:41
virtual void EmitThumbFunc(MCSymbol *Func)
Note in the output that the specified Func is a Thumb mode function (ARM target only).
Definition: MCStreamer.cpp:925
virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset, SMLoc Loc=SMLoc())
Definition: MCStreamer.cpp:747
virtual void EmitCFISignalFrame()
Definition: MCStreamer.cpp:524
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:122
virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:439
const MCSymbol * Personality
Definition: MCDwarf.h:553
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
virtual void EmitFileDirective(StringRef Filename)
Switch to a new logical file.
Definition: MCStreamer.cpp:933
virtual void EmitDTPRel32Value(const MCExpr *Value)
Emit the expression Value into the output as a dtprel (32-bit DTP relative) value.
Definition: MCStreamer.cpp:161
Generic base class for all target subtargets.
virtual void emitELFSize(MCSymbol *Symbol, const MCExpr *Value)
Emit an ELF .size directive.
Definition: MCStreamer.cpp:940
void EmitVersionForTarget(const Triple &Target)
Definition: MCStreamer.cpp:997
References to labels and assigned expressions.
Definition: MCExpr.h:41
bool isLittleEndian() const
True if the target is little endian.
Definition: MCAsmInfo.h:396
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:542
void emitFill(uint64_t NumBytes, uint8_t FillValue)
Emit NumBytes bytes worth of the value specified by FillValue.
Definition: MCStreamer.cpp:183
virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset)
Definition: MCStreamer.cpp:387
MCSymbol * endSection(MCSection *Section)
Definition: MCStreamer.cpp:985
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:553
CodeViewContext & getCVContext()
Definition: MCContext.cpp:567
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:540
MCSymbol * getLabel() const
Definition: MCDwarf.h:301
MCSection * getTextSection() const
virtual void EmitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset)
Emits a COFF section relative relocation.
Definition: MCStreamer.cpp:811
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
virtual void FinishImpl()
Streamer specific finalization.
Definition: MCStreamer.cpp:968
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:255
bool isTvOS() const
Is this an Apple tvOS triple.
Definition: Triple.h:454
MCVersionMinType
Definition: MCDirectives.h:64
LLVM Value Representation.
Definition: Value.h:73
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:40
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static cl::opt< bool, true > Debug("debug", cl::desc("Enable debug output"), cl::Hidden, cl::location(DebugFlag))
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:251
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:321
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
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:439
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:126
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:858
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:510
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
Definition: MathExtras.h:385
const MCSymbol * ExceptionHandler
Definition: MCWinEH.h:34
void setTargetStreamer(MCTargetStreamer *TS)
Definition: MCStreamer.h:240
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:808
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx)
Definition: MCExpr.cpp:159
virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment)
Definition: MCStreamer.cpp:408
void setLabel(MCSymbol *Label)
Definition: MCDwarf.h:305
static MCCFIInstruction createRegister(MCSymbol *L, unsigned Register1, unsigned Register2)
.cfi_register Previous value of Register1 is saved in register Register2.
Definition: MCDwarf.h:469
virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue)
Set the DescValue for the Symbol.
Definition: MCStreamer.cpp:926
virtual void EmitCFIWindowSave()
Definition: MCStreamer.cpp:551
MCSection * getAssociatedXDataSection(const MCSection *TextSec)
Get the .xdata section used for the given section.
Definition: MCStreamer.cpp:689
Holds state from .cv_file and .cv_loc directives for later emission.
Definition: MCCodeView.h:158