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