Taints the non-acquire RMW's store address with the load part
[oota-llvm.git] / include / llvm / MC / MCStreamer.h
1 //===- MCStreamer.h - High-level Streaming Machine Code Output --*- C++ -*-===//
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 // This file declares the MCStreamer class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_MC_MCSTREAMER_H
15 #define LLVM_MC_MCSTREAMER_H
16
17 #include "llvm/ADT/ArrayRef.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/MC/MCDirectives.h"
20 #include "llvm/MC/MCDwarf.h"
21 #include "llvm/MC/MCLinkerOptimizationHint.h"
22 #include "llvm/MC/MCSymbol.h"
23 #include "llvm/MC/MCWinEH.h"
24 #include "llvm/Support/DataTypes.h"
25 #include "llvm/Support/SMLoc.h"
26 #include <string>
27
28 namespace llvm {
29 class MCAsmBackend;
30 class MCCodeEmitter;
31 class MCContext;
32 class MCExpr;
33 class MCInst;
34 class MCInstPrinter;
35 class MCSection;
36 class MCStreamer;
37 class MCSymbolELF;
38 class MCSymbolRefExpr;
39 class MCSubtargetInfo;
40 class StringRef;
41 class Twine;
42 class raw_ostream;
43 class formatted_raw_ostream;
44 class AssemblerConstantPools;
45
46 typedef std::pair<MCSection *, const MCExpr *> MCSectionSubPair;
47
48 /// Target specific streamer interface. This is used so that targets can
49 /// implement support for target specific assembly directives.
50 ///
51 /// If target foo wants to use this, it should implement 3 classes:
52 /// * FooTargetStreamer : public MCTargetStreamer
53 /// * FooTargetAsmStreamer : public FooTargetStreamer
54 /// * FooTargetELFStreamer : public FooTargetStreamer
55 ///
56 /// FooTargetStreamer should have a pure virtual method for each directive. For
57 /// example, for a ".bar symbol_name" directive, it should have
58 /// virtual emitBar(const MCSymbol &Symbol) = 0;
59 ///
60 /// The FooTargetAsmStreamer and FooTargetELFStreamer classes implement the
61 /// method. The assembly streamer just prints ".bar symbol_name". The object
62 /// streamer does whatever is needed to implement .bar in the object file.
63 ///
64 /// In the assembly printer and parser the target streamer can be used by
65 /// calling getTargetStreamer and casting it to FooTargetStreamer:
66 ///
67 /// MCTargetStreamer &TS = OutStreamer.getTargetStreamer();
68 /// FooTargetStreamer &ATS = static_cast<FooTargetStreamer &>(TS);
69 ///
70 /// The base classes FooTargetAsmStreamer and FooTargetELFStreamer should
71 /// *never* be treated differently. Callers should always talk to a
72 /// FooTargetStreamer.
73 class MCTargetStreamer {
74 protected:
75   MCStreamer &Streamer;
76
77 public:
78   MCTargetStreamer(MCStreamer &S);
79   virtual ~MCTargetStreamer();
80
81   MCStreamer &getStreamer() { return Streamer; }
82
83   // Allow a target to add behavior to the EmitLabel of MCStreamer.
84   virtual void emitLabel(MCSymbol *Symbol);
85   // Allow a target to add behavior to the emitAssignment of MCStreamer.
86   virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
87
88   virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, raw_ostream &OS,
89                               const MCInst &Inst, const MCSubtargetInfo &STI);
90
91   virtual void finish();
92 };
93
94 // FIXME: declared here because it is used from
95 // lib/CodeGen/AsmPrinter/ARMException.cpp.
96 class ARMTargetStreamer : public MCTargetStreamer {
97 public:
98   ARMTargetStreamer(MCStreamer &S);
99   ~ARMTargetStreamer() override;
100
101   virtual void emitFnStart();
102   virtual void emitFnEnd();
103   virtual void emitCantUnwind();
104   virtual void emitPersonality(const MCSymbol *Personality);
105   virtual void emitPersonalityIndex(unsigned Index);
106   virtual void emitHandlerData();
107   virtual void emitSetFP(unsigned FpReg, unsigned SpReg,
108                          int64_t Offset = 0);
109   virtual void emitMovSP(unsigned Reg, int64_t Offset = 0);
110   virtual void emitPad(int64_t Offset);
111   virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
112                            bool isVector);
113   virtual void emitUnwindRaw(int64_t StackOffset,
114                              const SmallVectorImpl<uint8_t> &Opcodes);
115
116   virtual void switchVendor(StringRef Vendor);
117   virtual void emitAttribute(unsigned Attribute, unsigned Value);
118   virtual void emitTextAttribute(unsigned Attribute, StringRef String);
119   virtual void emitIntTextAttribute(unsigned Attribute, unsigned IntValue,
120                                     StringRef StringValue = "");
121   virtual void emitFPU(unsigned FPU);
122   virtual void emitArch(unsigned Arch);
123   virtual void emitArchExtension(unsigned ArchExt);
124   virtual void emitObjectArch(unsigned Arch);
125   virtual void finishAttributeSection();
126   virtual void emitInst(uint32_t Inst, char Suffix = '\0');
127
128   virtual void AnnotateTLSDescriptorSequence(const MCSymbolRefExpr *SRE);
129
130   virtual void emitThumbSet(MCSymbol *Symbol, const MCExpr *Value);
131
132   void finish() override;
133
134   /// Reset any state between object emissions, i.e. the equivalent of
135   /// MCStreamer's reset method.
136   virtual void reset();
137
138   /// Callback used to implement the ldr= pseudo.
139   /// Add a new entry to the constant pool for the current section and return an
140   /// MCExpr that can be used to refer to the constant pool location.
141   const MCExpr *addConstantPoolEntry(const MCExpr *, SMLoc Loc);
142
143   /// Callback used to implemnt the .ltorg directive.
144   /// Emit contents of constant pool for the current section.
145   void emitCurrentConstantPool();
146
147 private:
148   std::unique_ptr<AssemblerConstantPools> ConstantPools;
149 };
150
151 /// \brief Streaming machine code generation interface.
152 ///
153 /// This interface is intended to provide a programatic interface that is very
154 /// similar to the level that an assembler .s file provides.  It has callbacks
155 /// to emit bytes, handle directives, etc.  The implementation of this interface
156 /// retains state to know what the current section is etc.
157 ///
158 /// There are multiple implementations of this interface: one for writing out
159 /// a .s file, and implementations that write out .o files of various formats.
160 ///
161 class MCStreamer {
162   MCContext &Context;
163   std::unique_ptr<MCTargetStreamer> TargetStreamer;
164
165   MCStreamer(const MCStreamer &) = delete;
166   MCStreamer &operator=(const MCStreamer &) = delete;
167
168   std::vector<MCDwarfFrameInfo> DwarfFrameInfos;
169   MCDwarfFrameInfo *getCurrentDwarfFrameInfo();
170   void EnsureValidDwarfFrame();
171
172   MCSymbol *EmitCFICommon();
173
174   std::vector<WinEH::FrameInfo *> WinFrameInfos;
175   WinEH::FrameInfo *CurrentWinFrameInfo;
176   void EnsureValidWinFrameInfo();
177
178   /// \brief Tracks an index to represent the order a symbol was emitted in.
179   /// Zero means we did not emit that symbol.
180   DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
181
182   /// \brief This is stack of current and previous section values saved by
183   /// PushSection.
184   SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
185
186 protected:
187   MCStreamer(MCContext &Ctx);
188
189   virtual void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame);
190   virtual void EmitCFIEndProcImpl(MCDwarfFrameInfo &CurFrame);
191
192   WinEH::FrameInfo *getCurrentWinFrameInfo() {
193     return CurrentWinFrameInfo;
194   }
195
196   virtual void EmitWindowsUnwindTables();
197
198   virtual void EmitRawTextImpl(StringRef String);
199
200 public:
201   virtual ~MCStreamer();
202
203   void visitUsedExpr(const MCExpr &Expr);
204   virtual void visitUsedSymbol(const MCSymbol &Sym);
205
206   void setTargetStreamer(MCTargetStreamer *TS) {
207     TargetStreamer.reset(TS);
208   }
209
210   /// State management
211   ///
212   virtual void reset();
213
214   MCContext &getContext() const { return Context; }
215
216   MCTargetStreamer *getTargetStreamer() {
217     return TargetStreamer.get();
218   }
219
220   unsigned getNumFrameInfos() { return DwarfFrameInfos.size(); }
221   ArrayRef<MCDwarfFrameInfo> getDwarfFrameInfos() const {
222     return DwarfFrameInfos;
223   }
224
225   unsigned getNumWinFrameInfos() { return WinFrameInfos.size(); }
226   ArrayRef<WinEH::FrameInfo *> getWinFrameInfos() const {
227     return WinFrameInfos;
228   }
229
230   void generateCompactUnwindEncodings(MCAsmBackend *MAB);
231
232   /// \name Assembly File Formatting.
233   /// @{
234
235   /// \brief Return true if this streamer supports verbose assembly and if it is
236   /// enabled.
237   virtual bool isVerboseAsm() const { return false; }
238
239   /// \brief Return true if this asm streamer supports emitting unformatted text
240   /// to the .s file with EmitRawText.
241   virtual bool hasRawTextSupport() const { return false; }
242
243   /// \brief Is the integrated assembler required for this streamer to function
244   /// correctly?
245   virtual bool isIntegratedAssemblerRequired() const { return false; }
246
247   /// \brief Add a textual command.
248   ///
249   /// Typically for comments that can be emitted to the generated .s
250   /// file if applicable as a QoI issue to make the output of the compiler
251   /// more readable.  This only affects the MCAsmStreamer, and only when
252   /// verbose assembly output is enabled.
253   ///
254   /// If the comment includes embedded \n's, they will each get the comment
255   /// prefix as appropriate.  The added comment should not end with a \n.
256   virtual void AddComment(const Twine &T) {}
257
258   /// \brief Return a raw_ostream that comments can be written to. Unlike
259   /// AddComment, you are required to terminate comments with \n if you use this
260   /// method.
261   virtual raw_ostream &GetCommentOS();
262
263   /// \brief Print T and prefix it with the comment string (normally #) and
264   /// optionally a tab. This prints the comment immediately, not at the end of
265   /// the current line. It is basically a safe version of EmitRawText: since it
266   /// only prints comments, the object streamer ignores it instead of asserting.
267   virtual void emitRawComment(const Twine &T, bool TabPrefix = true);
268
269   /// AddBlankLine - Emit a blank line to a .s file to pretty it up.
270   virtual void AddBlankLine() {}
271
272   /// @}
273
274   /// \name Symbol & Section Management
275   /// @{
276
277   /// \brief Return the current section that the streamer is emitting code to.
278   MCSectionSubPair getCurrentSection() const {
279     if (!SectionStack.empty())
280       return SectionStack.back().first;
281     return MCSectionSubPair();
282   }
283   MCSection *getCurrentSectionOnly() const { return getCurrentSection().first; }
284
285   /// \brief Return the previous section that the streamer is emitting code to.
286   MCSectionSubPair getPreviousSection() const {
287     if (!SectionStack.empty())
288       return SectionStack.back().second;
289     return MCSectionSubPair();
290   }
291
292   /// \brief Returns an index to represent the order a symbol was emitted in.
293   /// (zero if we did not emit that symbol)
294   unsigned GetSymbolOrder(const MCSymbol *Sym) const {
295     return SymbolOrdering.lookup(Sym);
296   }
297
298   /// \brief Update streamer for a new active section.
299   ///
300   /// This is called by PopSection and SwitchSection, if the current
301   /// section changes.
302   virtual void ChangeSection(MCSection *, const MCExpr *);
303
304   /// \brief Save the current and previous section on the section stack.
305   void PushSection() {
306     SectionStack.push_back(
307         std::make_pair(getCurrentSection(), getPreviousSection()));
308   }
309
310   /// \brief Restore the current and previous section from the section stack.
311   /// Calls ChangeSection as needed.
312   ///
313   /// Returns false if the stack was empty.
314   bool PopSection() {
315     if (SectionStack.size() <= 1)
316       return false;
317     auto I = SectionStack.end();
318     --I;
319     MCSectionSubPair OldSection = I->first;
320     --I;
321     MCSectionSubPair NewSection = I->first;
322
323     if (OldSection != NewSection)
324       ChangeSection(NewSection.first, NewSection.second);
325     SectionStack.pop_back();
326     return true;
327   }
328
329   bool SubSection(const MCExpr *Subsection) {
330     if (SectionStack.empty())
331       return false;
332
333     SwitchSection(SectionStack.back().first.first, Subsection);
334     return true;
335   }
336
337   /// Set the current section where code is being emitted to \p Section.  This
338   /// is required to update CurSection.
339   ///
340   /// This corresponds to assembler directives like .section, .text, etc.
341   virtual void SwitchSection(MCSection *Section,
342                              const MCExpr *Subsection = nullptr);
343
344   /// \brief Set the current section where code is being emitted to \p Section.
345   /// This is required to update CurSection. This version does not call
346   /// ChangeSection.
347   void SwitchSectionNoChange(MCSection *Section,
348                              const MCExpr *Subsection = nullptr) {
349     assert(Section && "Cannot switch to a null section!");
350     MCSectionSubPair curSection = SectionStack.back().first;
351     SectionStack.back().second = curSection;
352     if (MCSectionSubPair(Section, Subsection) != curSection)
353       SectionStack.back().first = MCSectionSubPair(Section, Subsection);
354   }
355
356   /// \brief Create the default sections and set the initial one.
357   virtual void InitSections(bool NoExecStack);
358
359   MCSymbol *endSection(MCSection *Section);
360
361   /// \brief Sets the symbol's section.
362   ///
363   /// Each emitted symbol will be tracked in the ordering table,
364   /// so we can sort on them later.
365   void AssignFragment(MCSymbol *Symbol, MCFragment *Fragment);
366
367   /// \brief Emit a label for \p Symbol into the current section.
368   ///
369   /// This corresponds to an assembler statement such as:
370   ///   foo:
371   ///
372   /// \param Symbol - The symbol to emit. A given symbol should only be
373   /// emitted as a label once, and symbols emitted as a label should never be
374   /// used in an assignment.
375   // FIXME: These emission are non-const because we mutate the symbol to
376   // add the section we're emitting it to later.
377   virtual void EmitLabel(MCSymbol *Symbol);
378
379   virtual void EmitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol);
380
381   /// \brief Note in the output the specified \p Flag.
382   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
383
384   /// \brief Emit the given list \p Options of strings as linker
385   /// options into the output.
386   virtual void EmitLinkerOptions(ArrayRef<std::string> Kind) {}
387
388   /// \brief Note in the output the specified region \p Kind.
389   virtual void EmitDataRegion(MCDataRegionType Kind) {}
390
391   /// \brief Specify the MachO minimum deployment target version.
392   virtual void EmitVersionMin(MCVersionMinType, unsigned Major, unsigned Minor,
393                               unsigned Update) {}
394
395   /// \brief Note in the output that the specified \p Func is a Thumb mode
396   /// function (ARM target only).
397   virtual void EmitThumbFunc(MCSymbol *Func);
398
399   /// \brief Emit an assignment of \p Value to \p Symbol.
400   ///
401   /// This corresponds to an assembler statement such as:
402   ///  symbol = value
403   ///
404   /// The assignment generates no code, but has the side effect of binding the
405   /// value in the current context. For the assembly streamer, this prints the
406   /// binding into the .s file.
407   ///
408   /// \param Symbol - The symbol being assigned to.
409   /// \param Value - The value for the symbol.
410   virtual void EmitAssignment(MCSymbol *Symbol, const MCExpr *Value);
411
412   /// \brief Emit an weak reference from \p Alias to \p Symbol.
413   ///
414   /// This corresponds to an assembler statement such as:
415   ///  .weakref alias, symbol
416   ///
417   /// \param Alias - The alias that is being created.
418   /// \param Symbol - The symbol being aliased.
419   virtual void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol);
420
421   /// \brief Add the given \p Attribute to \p Symbol.
422   virtual bool EmitSymbolAttribute(MCSymbol *Symbol,
423                                    MCSymbolAttr Attribute) = 0;
424
425   /// \brief Set the \p DescValue for the \p Symbol.
426   ///
427   /// \param Symbol - The symbol to have its n_desc field set.
428   /// \param DescValue - The value to set into the n_desc field.
429   virtual void EmitSymbolDesc(MCSymbol *Symbol, unsigned DescValue);
430
431   /// \brief Start emitting COFF symbol definition
432   ///
433   /// \param Symbol - The symbol to have its External & Type fields set.
434   virtual void BeginCOFFSymbolDef(const MCSymbol *Symbol);
435
436   /// \brief Emit the storage class of the symbol.
437   ///
438   /// \param StorageClass - The storage class the symbol should have.
439   virtual void EmitCOFFSymbolStorageClass(int StorageClass);
440
441   /// \brief Emit the type of the symbol.
442   ///
443   /// \param Type - A COFF type identifier (see COFF::SymbolType in X86COFF.h)
444   virtual void EmitCOFFSymbolType(int Type);
445
446   /// \brief Marks the end of the symbol definition.
447   virtual void EndCOFFSymbolDef();
448
449   virtual void EmitCOFFSafeSEH(MCSymbol const *Symbol);
450
451   /// \brief Emits a COFF section index.
452   ///
453   /// \param Symbol - Symbol the section number relocation should point to.
454   virtual void EmitCOFFSectionIndex(MCSymbol const *Symbol);
455
456   /// \brief Emits a COFF section relative relocation.
457   ///
458   /// \param Symbol - Symbol the section relative relocation should point to.
459   virtual void EmitCOFFSecRel32(MCSymbol const *Symbol);
460
461   /// \brief Emit an ELF .size directive.
462   ///
463   /// This corresponds to an assembler statement such as:
464   ///  .size symbol, expression
465   virtual void emitELFSize(MCSymbolELF *Symbol, const MCExpr *Value);
466
467   /// \brief Emit a Linker Optimization Hint (LOH) directive.
468   /// \param Args - Arguments of the LOH.
469   virtual void EmitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) {}
470
471   /// \brief Emit a common symbol.
472   ///
473   /// \param Symbol - The common symbol to emit.
474   /// \param Size - The size of the common symbol.
475   /// \param ByteAlignment - The alignment of the symbol if
476   /// non-zero. This must be a power of 2.
477   virtual void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
478                                 unsigned ByteAlignment) = 0;
479
480   /// \brief Emit a local common (.lcomm) symbol.
481   ///
482   /// \param Symbol - The common symbol to emit.
483   /// \param Size - The size of the common symbol.
484   /// \param ByteAlignment - The alignment of the common symbol in bytes.
485   virtual void EmitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size,
486                                      unsigned ByteAlignment);
487
488   /// \brief Emit the zerofill section and an optional symbol.
489   ///
490   /// \param Section - The zerofill section to create and or to put the symbol
491   /// \param Symbol - The zerofill symbol to emit, if non-NULL.
492   /// \param Size - The size of the zerofill symbol.
493   /// \param ByteAlignment - The alignment of the zerofill symbol if
494   /// non-zero. This must be a power of 2 on some targets.
495   virtual void EmitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr,
496                             uint64_t Size = 0, unsigned ByteAlignment = 0) = 0;
497
498   /// \brief Emit a thread local bss (.tbss) symbol.
499   ///
500   /// \param Section - The thread local common section.
501   /// \param Symbol - The thread local common symbol to emit.
502   /// \param Size - The size of the symbol.
503   /// \param ByteAlignment - The alignment of the thread local common symbol
504   /// if non-zero.  This must be a power of 2 on some targets.
505   virtual void EmitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
506                               uint64_t Size, unsigned ByteAlignment = 0);
507
508   /// @}
509   /// \name Generating Data
510   /// @{
511
512   /// \brief Emit the bytes in \p Data into the output.
513   ///
514   /// This is used to implement assembler directives such as .byte, .ascii,
515   /// etc.
516   virtual void EmitBytes(StringRef Data);
517
518   /// \brief Emit the expression \p Value into the output as a native
519   /// integer of the given \p Size bytes.
520   ///
521   /// This is used to implement assembler directives such as .word, .quad,
522   /// etc.
523   ///
524   /// \param Value - The value to emit.
525   /// \param Size - The size of the integer (in bytes) to emit. This must
526   /// match a native machine width.
527   /// \param Loc - The location of the expression for error reporting.
528   virtual void EmitValueImpl(const MCExpr *Value, unsigned Size,
529                              SMLoc Loc = SMLoc());
530
531   void EmitValue(const MCExpr *Value, unsigned Size, SMLoc Loc = SMLoc());
532
533   /// \brief Special case of EmitValue that avoids the client having
534   /// to pass in a MCExpr for constant integers.
535   virtual void EmitIntValue(uint64_t Value, unsigned Size);
536
537   virtual void EmitULEB128Value(const MCExpr *Value);
538
539   virtual void EmitSLEB128Value(const MCExpr *Value);
540
541   /// \brief Special case of EmitULEB128Value that avoids the client having to
542   /// pass in a MCExpr for constant integers.
543   void EmitULEB128IntValue(uint64_t Value, unsigned Padding = 0);
544
545   /// \brief Special case of EmitSLEB128Value that avoids the client having to
546   /// pass in a MCExpr for constant integers.
547   void EmitSLEB128IntValue(int64_t Value);
548
549   /// \brief Special case of EmitValue that avoids the client having to pass in
550   /// a MCExpr for MCSymbols.
551   void EmitSymbolValue(const MCSymbol *Sym, unsigned Size,
552                        bool IsSectionRelative = false);
553
554   /// \brief Emit the expression \p Value into the output as a gprel64 (64-bit
555   /// GP relative) value.
556   ///
557   /// This is used to implement assembler directives such as .gpdword on
558   /// targets that support them.
559   virtual void EmitGPRel64Value(const MCExpr *Value);
560
561   /// \brief Emit the expression \p Value into the output as a gprel32 (32-bit
562   /// GP relative) value.
563   ///
564   /// This is used to implement assembler directives such as .gprel32 on
565   /// targets that support them.
566   virtual void EmitGPRel32Value(const MCExpr *Value);
567
568   /// \brief Emit NumBytes bytes worth of the value specified by FillValue.
569   /// This implements directives such as '.space'.
570   virtual void EmitFill(uint64_t NumBytes, uint8_t FillValue);
571
572   /// \brief Emit NumBytes worth of zeros.
573   /// This function properly handles data in virtual sections.
574   void EmitZeros(uint64_t NumBytes);
575
576   /// \brief Emit some number of copies of \p Value until the byte alignment \p
577   /// ByteAlignment is reached.
578   ///
579   /// If the number of bytes need to emit for the alignment is not a multiple
580   /// of \p ValueSize, then the contents of the emitted fill bytes is
581   /// undefined.
582   ///
583   /// This used to implement the .align assembler directive.
584   ///
585   /// \param ByteAlignment - The alignment to reach. This must be a power of
586   /// two on some targets.
587   /// \param Value - The value to use when filling bytes.
588   /// \param ValueSize - The size of the integer (in bytes) to emit for
589   /// \p Value. This must match a native machine width.
590   /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
591   /// the alignment cannot be reached in this many bytes, no bytes are
592   /// emitted.
593   virtual void EmitValueToAlignment(unsigned ByteAlignment, int64_t Value = 0,
594                                     unsigned ValueSize = 1,
595                                     unsigned MaxBytesToEmit = 0);
596
597   /// \brief Emit nops until the byte alignment \p ByteAlignment is reached.
598   ///
599   /// This used to align code where the alignment bytes may be executed.  This
600   /// can emit different bytes for different sizes to optimize execution.
601   ///
602   /// \param ByteAlignment - The alignment to reach. This must be a power of
603   /// two on some targets.
604   /// \param MaxBytesToEmit - The maximum numbers of bytes to emit, or 0. If
605   /// the alignment cannot be reached in this many bytes, no bytes are
606   /// emitted.
607   virtual void EmitCodeAlignment(unsigned ByteAlignment,
608                                  unsigned MaxBytesToEmit = 0);
609
610   /// \brief Emit some number of copies of \p Value until the byte offset \p
611   /// Offset is reached.
612   ///
613   /// This is used to implement assembler directives such as .org.
614   ///
615   /// \param Offset - The offset to reach. This may be an expression, but the
616   /// expression must be associated with the current section.
617   /// \param Value - The value to use when filling bytes.
618   virtual void emitValueToOffset(const MCExpr *Offset, unsigned char Value = 0);
619
620   /// @}
621
622   /// \brief Switch to a new logical file.  This is used to implement the '.file
623   /// "foo.c"' assembler directive.
624   virtual void EmitFileDirective(StringRef Filename);
625
626   /// \brief Emit the "identifiers" directive.  This implements the
627   /// '.ident "version foo"' assembler directive.
628   virtual void EmitIdent(StringRef IdentString) {}
629
630   /// \brief Associate a filename with a specified logical file number.  This
631   /// implements the DWARF2 '.file 4 "foo.c"' assembler directive.
632   virtual unsigned EmitDwarfFileDirective(unsigned FileNo, StringRef Directory,
633                                           StringRef Filename,
634                                           unsigned CUID = 0);
635
636   /// \brief This implements the DWARF2 '.loc fileno lineno ...' assembler
637   /// directive.
638   virtual void EmitDwarfLocDirective(unsigned FileNo, unsigned Line,
639                                      unsigned Column, unsigned Flags,
640                                      unsigned Isa, unsigned Discriminator,
641                                      StringRef FileName);
642
643   /// Emit the absolute difference between two symbols.
644   ///
645   /// \pre Offset of \c Hi is greater than the offset \c Lo.
646   virtual void emitAbsoluteSymbolDiff(const MCSymbol *Hi, const MCSymbol *Lo,
647                                       unsigned Size);
648
649   virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
650   virtual void EmitCFISections(bool EH, bool Debug);
651   void EmitCFIStartProc(bool IsSimple);
652   void EmitCFIEndProc();
653   virtual void EmitCFIDefCfa(int64_t Register, int64_t Offset);
654   virtual void EmitCFIDefCfaOffset(int64_t Offset);
655   virtual void EmitCFIDefCfaRegister(int64_t Register);
656   virtual void EmitCFIOffset(int64_t Register, int64_t Offset);
657   virtual void EmitCFIPersonality(const MCSymbol *Sym, unsigned Encoding);
658   virtual void EmitCFILsda(const MCSymbol *Sym, unsigned Encoding);
659   virtual void EmitCFIRememberState();
660   virtual void EmitCFIRestoreState();
661   virtual void EmitCFISameValue(int64_t Register);
662   virtual void EmitCFIRestore(int64_t Register);
663   virtual void EmitCFIRelOffset(int64_t Register, int64_t Offset);
664   virtual void EmitCFIAdjustCfaOffset(int64_t Adjustment);
665   virtual void EmitCFIEscape(StringRef Values);
666   virtual void EmitCFIGnuArgsSize(int64_t Size);
667   virtual void EmitCFISignalFrame();
668   virtual void EmitCFIUndefined(int64_t Register);
669   virtual void EmitCFIRegister(int64_t Register1, int64_t Register2);
670   virtual void EmitCFIWindowSave();
671
672   virtual void EmitWinCFIStartProc(const MCSymbol *Symbol);
673   virtual void EmitWinCFIEndProc();
674   virtual void EmitWinCFIStartChained();
675   virtual void EmitWinCFIEndChained();
676   virtual void EmitWinCFIPushReg(unsigned Register);
677   virtual void EmitWinCFISetFrame(unsigned Register, unsigned Offset);
678   virtual void EmitWinCFIAllocStack(unsigned Size);
679   virtual void EmitWinCFISaveReg(unsigned Register, unsigned Offset);
680   virtual void EmitWinCFISaveXMM(unsigned Register, unsigned Offset);
681   virtual void EmitWinCFIPushFrame(bool Code);
682   virtual void EmitWinCFIEndProlog();
683
684   virtual void EmitWinEHHandler(const MCSymbol *Sym, bool Unwind, bool Except);
685   virtual void EmitWinEHHandlerData();
686
687   virtual void EmitSyntaxDirective();
688
689   /// \brief Emit a .reloc directive.
690   /// Returns true if the relocation could not be emitted because Name is not
691   /// known.
692   virtual bool EmitRelocDirective(const MCExpr &Offset, StringRef Name,
693                                   const MCExpr *Expr, SMLoc Loc) {
694     return true;
695   }
696
697   /// \brief Emit the given \p Instruction into the current section.
698   virtual void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
699
700   /// \brief Set the bundle alignment mode from now on in the section.
701   /// The argument is the power of 2 to which the alignment is set. The
702   /// value 0 means turn the bundle alignment off.
703   virtual void EmitBundleAlignMode(unsigned AlignPow2);
704
705   /// \brief The following instructions are a bundle-locked group.
706   ///
707   /// \param AlignToEnd - If true, the bundle-locked group will be aligned to
708   ///                     the end of a bundle.
709   virtual void EmitBundleLock(bool AlignToEnd);
710
711   /// \brief Ends a bundle-locked group.
712   virtual void EmitBundleUnlock();
713
714   /// \brief If this file is backed by a assembly streamer, this dumps the
715   /// specified string in the output .s file.  This capability is indicated by
716   /// the hasRawTextSupport() predicate.  By default this aborts.
717   void EmitRawText(const Twine &String);
718
719   /// \brief Streamer specific finalization.
720   virtual void FinishImpl();
721   /// \brief Finish emission of machine code.
722   void Finish();
723
724   virtual bool mayHaveInstructions(MCSection &Sec) const { return true; }
725 };
726
727 /// Create a dummy machine code streamer, which does nothing. This is useful for
728 /// timing the assembler front end.
729 MCStreamer *createNullStreamer(MCContext &Ctx);
730
731 /// Create a machine code streamer which will print out assembly for the native
732 /// target, suitable for compiling with a native assembler.
733 ///
734 /// \param InstPrint - If given, the instruction printer to use. If not given
735 /// the MCInst representation will be printed.  This method takes ownership of
736 /// InstPrint.
737 ///
738 /// \param CE - If given, a code emitter to use to show the instruction
739 /// encoding inline with the assembly. This method takes ownership of \p CE.
740 ///
741 /// \param TAB - If given, a target asm backend to use to show the fixup
742 /// information in conjunction with encoding information. This method takes
743 /// ownership of \p TAB.
744 ///
745 /// \param ShowInst - Whether to show the MCInst representation inline with
746 /// the assembly.
747 MCStreamer *createAsmStreamer(MCContext &Ctx,
748                               std::unique_ptr<formatted_raw_ostream> OS,
749                               bool isVerboseAsm, bool useDwarfDirectory,
750                               MCInstPrinter *InstPrint, MCCodeEmitter *CE,
751                               MCAsmBackend *TAB, bool ShowInst);
752 } // end namespace llvm
753
754 #endif