[NVPTX] Do not emit .weak symbols for NVPTX
[oota-llvm.git] / include / llvm / MC / MCAsmInfo.h
1 //===-- llvm/MC/MCAsmInfo.h - Asm info --------------------------*- 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 contains a class to be used as the basis for target specific
11 // asm writers.  This class primarily takes care of global printing constants,
12 // which are used in very similar ways across all targets.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_MC_MCASMINFO_H
17 #define LLVM_MC_MCASMINFO_H
18
19 #include "llvm/MC/MCDirectives.h"
20 #include "llvm/MC/MCDwarf.h"
21 #include "llvm/MC/MachineLocation.h"
22 #include <cassert>
23 #include <vector>
24
25 namespace llvm {
26 class MCExpr;
27 class MCSection;
28 class MCStreamer;
29 class MCSymbol;
30 class MCContext;
31
32 namespace WinEH {
33 enum class EncodingType {
34   Invalid, /// Invalid
35   Alpha,   /// Windows Alpha
36   Alpha64, /// Windows AXP64
37   ARM,     /// Windows NT (Windows on ARM)
38   CE,      /// Windows CE ARM, PowerPC, SH3, SH4
39   Itanium, /// Windows x64, Windows Itanium (IA-64)
40   MIPS = Alpha,
41 };
42 }
43
44 enum class ExceptionHandling {
45   None,         /// No exception support
46   DwarfCFI,     /// DWARF-like instruction based exceptions
47   SjLj,         /// setjmp/longjmp based exceptions
48   ARM,          /// ARM EHABI
49   ItaniumWinEH, /// Itanium EH built on Windows unwind info (.pdata and .xdata)
50 };
51
52 namespace LCOMM {
53 enum LCOMMType { NoAlignment, ByteAlignment, Log2Alignment };
54 }
55
56 /// This class is intended to be used as a base class for asm
57 /// properties and features specific to the target.
58 class MCAsmInfo {
59 protected:
60   //===------------------------------------------------------------------===//
61   // Properties to be set by the target writer, used to configure asm printer.
62   //
63
64   /// Pointer size in bytes.  Default is 4.
65   unsigned PointerSize;
66
67   /// Size of the stack slot reserved for callee-saved registers, in bytes.
68   /// Default is same as pointer size.
69   unsigned CalleeSaveStackSlotSize;
70
71   /// True if target is little endian.  Default is true.
72   bool IsLittleEndian;
73
74   /// True if target stack grow up.  Default is false.
75   bool StackGrowsUp;
76
77   /// True if this target has the MachO .subsections_via_symbols directive.
78   /// Default is false.
79   bool HasSubsectionsViaSymbols;
80
81   /// True if this is a MachO target that supports the macho-specific .zerofill
82   /// directive for emitting BSS Symbols.  Default is false.
83   bool HasMachoZeroFillDirective;
84
85   /// True if this is a MachO target that supports the macho-specific .tbss
86   /// directive for emitting thread local BSS Symbols.  Default is false.
87   bool HasMachoTBSSDirective;
88
89   /// True if the compiler should emit a ".reference .constructors_used" or
90   /// ".reference .destructors_used" directive after the static ctor/dtor
91   /// list.  This directive is only emitted in Static relocation model.  Default
92   /// is false.
93   bool HasStaticCtorDtorReferenceInStaticMode;
94
95   /// This is the maximum possible length of an instruction, which is needed to
96   /// compute the size of an inline asm.  Defaults to 4.
97   unsigned MaxInstLength;
98
99   /// Every possible instruction length is a multiple of this value.  Factored
100   /// out in .debug_frame and .debug_line.  Defaults to 1.
101   unsigned MinInstAlignment;
102
103   /// The '$' token, when not referencing an identifier or constant, refers to
104   /// the current PC.  Defaults to false.
105   bool DollarIsPC;
106
107   /// This string, if specified, is used to separate instructions from each
108   /// other when on the same line.  Defaults to ';'
109   const char *SeparatorString;
110
111   /// This indicates the comment character used by the assembler.  Defaults to
112   /// "#"
113   const char *CommentString;
114
115   /// This is appended to emitted labels.  Defaults to ":"
116   const char *LabelSuffix;
117
118   // Print the EH begin symbol with an assignment. Defaults to false.
119   bool UseAssignmentForEHBegin;
120
121   /// This prefix is used for globals like constant pool entries that are
122   /// completely private to the .s file and should not have names in the .o
123   /// file.  Defaults to "L"
124   const char *PrivateGlobalPrefix;
125
126   /// This prefix is used for symbols that should be passed through the
127   /// assembler but be removed by the linker.  This is 'l' on Darwin, currently
128   /// used for some ObjC metadata.  The default of "" meast that for this system
129   /// a plain private symbol should be used.  Defaults to "".
130   const char *LinkerPrivateGlobalPrefix;
131
132   /// If these are nonempty, they contain a directive to emit before and after
133   /// an inline assembly statement.  Defaults to "#APP\n", "#NO_APP\n"
134   const char *InlineAsmStart;
135   const char *InlineAsmEnd;
136
137   /// These are assembly directives that tells the assembler to interpret the
138   /// following instructions differently.  Defaults to ".code16", ".code32",
139   /// ".code64".
140   const char *Code16Directive;
141   const char *Code32Directive;
142   const char *Code64Directive;
143
144   /// Which dialect of an assembler variant to use.  Defaults to 0
145   unsigned AssemblerDialect;
146
147   /// This is true if the assembler allows @ characters in symbol names.
148   /// Defaults to false.
149   bool AllowAtInName;
150
151   /// This is true if data region markers should be printed as
152   /// ".data_region/.end_data_region" directives. If false, use "$d/$a" labels
153   /// instead.
154   bool UseDataRegionDirectives;
155
156   //===--- Data Emission Directives -------------------------------------===//
157
158   /// This should be set to the directive used to get some number of zero bytes
159   /// emitted to the current section.  Common cases are "\t.zero\t" and
160   /// "\t.space\t".  If this is set to null, the Data*bitsDirective's will be
161   /// used to emit zero bytes.  Defaults to "\t.zero\t"
162   const char *ZeroDirective;
163
164   /// This directive allows emission of an ascii string with the standard C
165   /// escape characters embedded into it.  Defaults to "\t.ascii\t"
166   const char *AsciiDirective;
167
168   /// If not null, this allows for special handling of zero terminated strings
169   /// on this target.  This is commonly supported as ".asciz".  If a target
170   /// doesn't support this, it can be set to null.  Defaults to "\t.asciz\t"
171   const char *AscizDirective;
172
173   /// These directives are used to output some unit of integer data to the
174   /// current section.  If a data directive is set to null, smaller data
175   /// directives will be used to emit the large sizes.  Defaults to "\t.byte\t",
176   /// "\t.short\t", "\t.long\t", "\t.quad\t"
177   const char *Data8bitsDirective;
178   const char *Data16bitsDirective;
179   const char *Data32bitsDirective;
180   const char *Data64bitsDirective;
181
182   /// If non-null, a directive that is used to emit a word which should be
183   /// relocated as a 64-bit GP-relative offset, e.g. .gpdword on Mips.  Defaults
184   /// to NULL.
185   const char *GPRel64Directive;
186
187   /// If non-null, a directive that is used to emit a word which should be
188   /// relocated as a 32-bit GP-relative offset, e.g. .gpword on Mips or .gprel32
189   /// on Alpha.  Defaults to NULL.
190   const char *GPRel32Directive;
191
192   /// This is true if this target uses "Sun Style" syntax for section switching
193   /// ("#alloc,#write" etc) instead of the normal ELF syntax (,"a,w") in
194   /// .section directives.  Defaults to false.
195   bool SunStyleELFSectionSwitchSyntax;
196
197   /// This is true if this target uses ELF '.section' directive before the
198   /// '.bss' one. It's used for PPC/Linux which doesn't support the '.bss'
199   /// directive only.  Defaults to false.
200   bool UsesELFSectionDirectiveForBSS;
201
202   bool NeedsDwarfSectionOffsetDirective;
203
204   //===--- Alignment Information ----------------------------------------===//
205
206   /// If this is true (the default) then the asmprinter emits ".align N"
207   /// directives, where N is the number of bytes to align to.  Otherwise, it
208   /// emits ".align log2(N)", e.g. 3 to align to an 8 byte boundary.  Defaults
209   /// to true.
210   bool AlignmentIsInBytes;
211
212   /// If non-zero, this is used to fill the executable space created as the
213   /// result of a alignment directive.  Defaults to 0
214   unsigned TextAlignFillValue;
215
216   //===--- Global Variable Emission Directives --------------------------===//
217
218   /// This is the directive used to declare a global entity. Defaults to
219   /// ".globl".
220   const char *GlobalDirective;
221
222   /// True if the expression
223   ///   .long f - g
224   /// uses an relocation but it can be supressed by writting
225   ///   a = f - g
226   ///   .long a
227   bool SetDirectiveSuppressesReloc;
228
229   /// False if the assembler requires that we use
230   /// \code
231   ///   Lc = a - b
232   ///   .long Lc
233   /// \endcode
234   //
235   /// instead of
236   //
237   /// \code
238   ///   .long a - b
239   /// \endcode
240   ///
241   ///  Defaults to true.
242   bool HasAggressiveSymbolFolding;
243
244   /// True is .comm's and .lcomms optional alignment is to be specified in bytes
245   /// instead of log2(n).  Defaults to true.
246   bool COMMDirectiveAlignmentIsInBytes;
247
248   /// Describes if the .lcomm directive for the target supports an alignment
249   /// argument and how it is interpreted.  Defaults to NoAlignment.
250   LCOMM::LCOMMType LCOMMDirectiveAlignmentType;
251
252   /// True if the target has .type and .size directives, this is true for most
253   /// ELF targets.  Defaults to true.
254   bool HasDotTypeDotSizeDirective;
255
256   /// True if the target has a single parameter .file directive, this is true
257   /// for ELF targets.  Defaults to true.
258   bool HasSingleParameterDotFile;
259
260   /// True if the target has a .ident directive, this is true for ELF targets.
261   /// Defaults to false.
262   bool HasIdentDirective;
263
264   /// True if this target supports the MachO .no_dead_strip directive.  Defaults
265   /// to false.
266   bool HasNoDeadStrip;
267
268   /// Used to declare a global as being a weak symbol. Defaults to ".weak".
269   const char *WeakDirective;
270
271   /// This directive, if non-null, is used to declare a global as being a weak
272   /// undefined symbol.  Defaults to NULL.
273   const char *WeakRefDirective;
274
275   /// True if we have a directive to declare a global as being a weak defined
276   /// symbol.  Defaults to false.
277   bool HasWeakDefDirective;
278
279   /// True if we have a directive to declare a global as being a weak defined
280   /// symbol that can be hidden (unexported).  Defaults to false.
281   bool HasWeakDefCanBeHiddenDirective;
282
283   /// True if we have a .linkonce directive.  This is used on cygwin/mingw.
284   /// Defaults to false.
285   bool HasLinkOnceDirective;
286
287   /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
288   /// hidden visibility.  Defaults to MCSA_Hidden.
289   MCSymbolAttr HiddenVisibilityAttr;
290
291   /// This attribute, if not MCSA_Invalid, is used to declare an undefined
292   /// symbol as having hidden visibility. Defaults to MCSA_Hidden.
293   MCSymbolAttr HiddenDeclarationVisibilityAttr;
294
295   /// This attribute, if not MCSA_Invalid, is used to declare a symbol as having
296   /// protected visibility.  Defaults to MCSA_Protected
297   MCSymbolAttr ProtectedVisibilityAttr;
298
299   //===--- Dwarf Emission Directives -----------------------------------===//
300
301   /// True if target supports emission of debugging information.  Defaults to
302   /// false.
303   bool SupportsDebugInformation;
304
305   /// Exception handling format for the target.  Defaults to None.
306   ExceptionHandling ExceptionsType;
307
308   /// Windows exception handling data (.pdata) encoding.  Defaults to Invalid.
309   WinEH::EncodingType WinEHEncodingType;
310
311   /// True if Dwarf2 output generally uses relocations for references to other
312   /// .debug_* sections.
313   bool DwarfUsesRelocationsAcrossSections;
314
315   /// True if DWARF FDE symbol reference relocations should be replaced by an
316   /// absolute difference.
317   bool DwarfFDESymbolsUseAbsDiff;
318
319   /// True if dwarf register numbers are printed instead of symbolic register
320   /// names in .cfi_* directives.  Defaults to false.
321   bool DwarfRegNumForCFI;
322
323   /// True if target uses parens to indicate the symbol variant instead of @.
324   /// For example, foo(plt) instead of foo@plt.  Defaults to false.
325   bool UseParensForSymbolVariant;
326
327   //===--- Prologue State ----------------------------------------------===//
328
329   std::vector<MCCFIInstruction> InitialFrameState;
330
331   //===--- Integrated Assembler State ----------------------------------===//
332
333   /// Should we use the integrated assembler?
334   /// The integrated assembler should be enabled by default (by the
335   /// constructors) when failing to parse a valid piece of assembly (inline
336   /// or otherwise) is considered a bug. It may then be overridden after
337   /// construction (see LLVMTargetMachine::initAsmInfo()).
338   bool UseIntegratedAssembler;
339
340   /// Compress DWARF debug sections. Defaults to false.
341   bool CompressDebugSections;
342
343 public:
344   explicit MCAsmInfo();
345   virtual ~MCAsmInfo();
346
347   /// Get the pointer size in bytes.
348   unsigned getPointerSize() const { return PointerSize; }
349
350   /// Get the callee-saved register stack slot
351   /// size in bytes.
352   unsigned getCalleeSaveStackSlotSize() const {
353     return CalleeSaveStackSlotSize;
354   }
355
356   /// True if the target is little endian.
357   bool isLittleEndian() const { return IsLittleEndian; }
358
359   /// True if target stack grow up.
360   bool isStackGrowthDirectionUp() const { return StackGrowsUp; }
361
362   bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
363
364   // Data directive accessors.
365
366   const char *getData8bitsDirective() const { return Data8bitsDirective; }
367   const char *getData16bitsDirective() const { return Data16bitsDirective; }
368   const char *getData32bitsDirective() const { return Data32bitsDirective; }
369   const char *getData64bitsDirective() const { return Data64bitsDirective; }
370   const char *getGPRel64Directive() const { return GPRel64Directive; }
371   const char *getGPRel32Directive() const { return GPRel32Directive; }
372
373   /// Targets can implement this method to specify a section to switch to if the
374   /// translation unit doesn't have any trampolines that require an executable
375   /// stack.
376   virtual const MCSection *getNonexecutableStackSection(MCContext &Ctx) const {
377     return nullptr;
378   }
379
380   virtual const MCExpr *getExprForPersonalitySymbol(const MCSymbol *Sym,
381                                                     unsigned Encoding,
382                                                     MCStreamer &Streamer) const;
383
384   virtual const MCExpr *getExprForFDESymbol(const MCSymbol *Sym,
385                                             unsigned Encoding,
386                                             MCStreamer &Streamer) const;
387
388   bool usesSunStyleELFSectionSwitchSyntax() const {
389     return SunStyleELFSectionSwitchSyntax;
390   }
391
392   bool usesELFSectionDirectiveForBSS() const {
393     return UsesELFSectionDirectiveForBSS;
394   }
395
396   bool needsDwarfSectionOffsetDirective() const {
397     return NeedsDwarfSectionOffsetDirective;
398   }
399
400   // Accessors.
401
402   bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
403   bool hasMachoTBSSDirective() const { return HasMachoTBSSDirective; }
404   bool hasStaticCtorDtorReferenceInStaticMode() const {
405     return HasStaticCtorDtorReferenceInStaticMode;
406   }
407   unsigned getMaxInstLength() const { return MaxInstLength; }
408   unsigned getMinInstAlignment() const { return MinInstAlignment; }
409   bool getDollarIsPC() const { return DollarIsPC; }
410   const char *getSeparatorString() const { return SeparatorString; }
411
412   /// This indicates the column (zero-based) at which asm comments should be
413   /// printed.
414   unsigned getCommentColumn() const { return 40; }
415
416   const char *getCommentString() const { return CommentString; }
417   const char *getLabelSuffix() const { return LabelSuffix; }
418
419   bool useAssignmentForEHBegin() const { return UseAssignmentForEHBegin; }
420   const char *getPrivateGlobalPrefix() const { return PrivateGlobalPrefix; }
421   bool hasLinkerPrivateGlobalPrefix() const {
422     return LinkerPrivateGlobalPrefix[0] != '\0';
423   }
424   const char *getLinkerPrivateGlobalPrefix() const {
425     if (hasLinkerPrivateGlobalPrefix())
426       return LinkerPrivateGlobalPrefix;
427     return getPrivateGlobalPrefix();
428   }
429   const char *getInlineAsmStart() const { return InlineAsmStart; }
430   const char *getInlineAsmEnd() const { return InlineAsmEnd; }
431   const char *getCode16Directive() const { return Code16Directive; }
432   const char *getCode32Directive() const { return Code32Directive; }
433   const char *getCode64Directive() const { return Code64Directive; }
434   unsigned getAssemblerDialect() const { return AssemblerDialect; }
435   bool doesAllowAtInName() const { return AllowAtInName; }
436   bool doesSupportDataRegionDirectives() const {
437     return UseDataRegionDirectives;
438   }
439   const char *getZeroDirective() const { return ZeroDirective; }
440   const char *getAsciiDirective() const { return AsciiDirective; }
441   const char *getAscizDirective() const { return AscizDirective; }
442   bool getAlignmentIsInBytes() const { return AlignmentIsInBytes; }
443   unsigned getTextAlignFillValue() const { return TextAlignFillValue; }
444   const char *getGlobalDirective() const { return GlobalDirective; }
445   bool doesSetDirectiveSuppressesReloc() const {
446     return SetDirectiveSuppressesReloc;
447   }
448   bool hasAggressiveSymbolFolding() const { return HasAggressiveSymbolFolding; }
449   bool getCOMMDirectiveAlignmentIsInBytes() const {
450     return COMMDirectiveAlignmentIsInBytes;
451   }
452   LCOMM::LCOMMType getLCOMMDirectiveAlignmentType() const {
453     return LCOMMDirectiveAlignmentType;
454   }
455   bool hasDotTypeDotSizeDirective() const { return HasDotTypeDotSizeDirective; }
456   bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
457   bool hasIdentDirective() const { return HasIdentDirective; }
458   bool hasNoDeadStrip() const { return HasNoDeadStrip; }
459   const char *getWeakDirective() const { return WeakDirective; }
460   const char *getWeakRefDirective() const { return WeakRefDirective; }
461   bool hasWeakDefDirective() const { return HasWeakDefDirective; }
462   bool hasWeakDefCanBeHiddenDirective() const {
463     return HasWeakDefCanBeHiddenDirective;
464   }
465   bool hasLinkOnceDirective() const { return HasLinkOnceDirective; }
466
467   MCSymbolAttr getHiddenVisibilityAttr() const { return HiddenVisibilityAttr; }
468   MCSymbolAttr getHiddenDeclarationVisibilityAttr() const {
469     return HiddenDeclarationVisibilityAttr;
470   }
471   MCSymbolAttr getProtectedVisibilityAttr() const {
472     return ProtectedVisibilityAttr;
473   }
474   bool doesSupportDebugInformation() const { return SupportsDebugInformation; }
475   bool doesSupportExceptionHandling() const {
476     return ExceptionsType != ExceptionHandling::None;
477   }
478   ExceptionHandling getExceptionHandlingType() const { return ExceptionsType; }
479   WinEH::EncodingType getWinEHEncodingType() const { return WinEHEncodingType; }
480
481   /// Return true if the exception handling type uses the language-specific data
482   /// area (LSDA) format specified by the Itanium C++ ABI.
483   bool usesItaniumLSDAForExceptions() const {
484     return (ExceptionsType == ExceptionHandling::DwarfCFI ||
485             ExceptionsType == ExceptionHandling::ARM ||
486             // This Windows EH type uses the Itanium LSDA encoding.
487             ExceptionsType == ExceptionHandling::ItaniumWinEH);
488   }
489
490   bool doesDwarfUseRelocationsAcrossSections() const {
491     return DwarfUsesRelocationsAcrossSections;
492   }
493   bool doDwarfFDESymbolsUseAbsDiff() const { return DwarfFDESymbolsUseAbsDiff; }
494   bool useDwarfRegNumForCFI() const { return DwarfRegNumForCFI; }
495   bool useParensForSymbolVariant() const { return UseParensForSymbolVariant; }
496
497   void addInitialFrameState(const MCCFIInstruction &Inst) {
498     InitialFrameState.push_back(Inst);
499   }
500
501   const std::vector<MCCFIInstruction> &getInitialFrameState() const {
502     return InitialFrameState;
503   }
504
505   /// Return true if assembly (inline or otherwise) should be parsed.
506   bool useIntegratedAssembler() const { return UseIntegratedAssembler; }
507
508   /// Set whether assembly (inline or otherwise) should be parsed.
509   virtual void setUseIntegratedAssembler(bool Value) {
510     UseIntegratedAssembler = Value;
511   }
512
513   bool compressDebugSections() const { return CompressDebugSections; }
514
515   void setCompressDebugSections(bool CompressDebugSections) {
516     this->CompressDebugSections = CompressDebugSections;
517   }
518 };
519 }
520
521 #endif