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