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