1 //===-- llvm/Target/TargetAsmInfo.h - Asm info ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_TARGET_ASM_INFO_H
17 #define LLVM_TARGET_ASM_INFO_H
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/Support/DataTypes.h"
24 template <typename T> class SmallVectorImpl;
29 // DWARF encoding query type
30 namespace DwarfEncoding {
38 /// TargetAsmInfo - This class is intended to be used as a base class for asm
39 /// properties and features specific to the target.
42 /// TM - The current TargetMachine.
43 const TargetMachine &TM;
45 //===------------------------------------------------------------------===//
46 // Properties to be set by the target writer, used to configure asm printer.
49 /// BSSSection - Section directive for uninitialized data. Null if this
50 /// target doesn't support a BSS section.
53 const char *BSSSection; // Default to ".bss".
55 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
56 /// section on this target. Null if this target doesn't support zerofill.
57 const char *ZeroFillDirective; // Default is null.
59 /// NonexecutableStackDirective - Directive for declaring to the
60 /// linker and beyond that the emitted code does not require stack
61 /// memory to be executable.
62 const char *NonexecutableStackDirective; // Default is null.
64 /// NeedsSet - True if target asm treats expressions in data directives
65 /// as linktime-relocatable. For assembly-time computation, we need to
69 /// is computed at assembly time, while
71 /// is relocated if the relative locations of x and y change at linktime.
72 /// We want both these things in different places.
73 bool NeedsSet; // Defaults to false.
75 /// MaxInstLength - This is the maximum possible length of an instruction,
76 /// which is needed to compute the size of an inline asm.
77 unsigned MaxInstLength; // Defaults to 4.
79 /// PCSymbol - The symbol used to represent the current PC. Used in PC
80 /// relative expressions.
81 const char *PCSymbol; // Defaults to "$".
83 /// SeparatorChar - This character, if specified, is used to separate
84 /// instructions from each other when on the same line. This is used to
85 /// measure inline asm instructions.
86 char SeparatorChar; // Defaults to ';'
88 /// CommentColumn - This indicates the comment num (zero-based) at
89 /// which asm comments should be printed.
90 unsigned CommentColumn; // Defaults to 60
92 /// CommentString - This indicates the comment character used by the
94 const char *CommentString; // Defaults to "#"
96 /// FirstOperandColumn - The output column where the first operand
98 unsigned FirstOperandColumn; // Defaults to 0 (ignored)
100 /// MaxOperandLength - The maximum length of any printed asm
102 unsigned MaxOperandLength; // Defaults to 0 (ignored)
104 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
105 /// onto all global symbols. This is often used for "_" or ".".
106 const char *GlobalPrefix; // Defaults to ""
108 /// PrivateGlobalPrefix - This prefix is used for globals like constant
109 /// pool entries that are completely private to the .s file and should not
110 /// have names in the .o file. This is often "." or "L".
111 const char *PrivateGlobalPrefix; // Defaults to "."
113 /// LinkerPrivateGlobalPrefix - This prefix is used for symbols that should
114 /// be passed through the assembler but be removed by the linker. This
115 /// is "l" on Darwin, currently used for some ObjC metadata.
116 const char *LinkerPrivateGlobalPrefix; // Defaults to ""
118 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
119 /// emitted before jump tables with the specified prefix.
120 const char *JumpTableSpecialLabelPrefix; // Default to null.
122 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
123 /// will enclose any GlobalVariable (that isn't a function)
125 const char *GlobalVarAddrPrefix; // Defaults to ""
126 const char *GlobalVarAddrSuffix; // Defaults to ""
128 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
129 /// will enclose any GlobalVariable that points to a function.
131 const char *FunctionAddrPrefix; // Defaults to ""
132 const char *FunctionAddrSuffix; // Defaults to ""
134 /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
135 /// enclose any personality function in the common frame section.
137 const char *PersonalityPrefix; // Defaults to ""
138 const char *PersonalitySuffix; // Defaults to ""
140 /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
143 bool NeedsIndirectEncoding; // Defaults to false
145 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
146 /// emit before and after an inline assembly statement.
147 const char *InlineAsmStart; // Defaults to "#APP\n"
148 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
150 /// AssemblerDialect - Which dialect of an assembler variant to use.
151 unsigned AssemblerDialect; // Defaults to 0
153 /// AllowQuotesInName - This is true if the assembler allows for complex
154 /// symbol names to be surrounded in quotes. This defaults to false.
155 bool AllowQuotesInName;
157 //===--- Data Emission Directives -------------------------------------===//
159 /// ZeroDirective - this should be set to the directive used to get some
160 /// number of zero bytes emitted to the current section. Common cases are
161 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
162 /// Data*bitsDirective's will be used to emit zero bytes.
163 const char *ZeroDirective; // Defaults to "\t.zero\t"
164 const char *ZeroDirectiveSuffix; // Defaults to ""
166 /// AsciiDirective - This directive allows emission of an ascii string with
167 /// the standard C escape characters embedded into it.
168 const char *AsciiDirective; // Defaults to "\t.ascii\t"
170 /// AscizDirective - If not null, this allows for special handling of
171 /// zero terminated strings on this target. This is commonly supported as
172 /// ".asciz". If a target doesn't support this, it can be set to null.
173 const char *AscizDirective; // Defaults to "\t.asciz\t"
175 /// DataDirectives - These directives are used to output some unit of
176 /// integer data to the current section. If a data directive is set to
177 /// null, smaller data directives will be used to emit the large sizes.
178 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
179 const char *Data16bitsDirective; // Defaults to "\t.short\t"
180 const char *Data32bitsDirective; // Defaults to "\t.long\t"
181 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
183 /// getDataASDirective - Return the directive that should be used to emit
184 /// data of the specified size to the specified numeric address space.
185 virtual const char *getDataASDirective(unsigned Size, unsigned AS) const {
186 assert(AS != 0 && "Don't know the directives for default addr space");
190 //===--- Alignment Information ----------------------------------------===//
192 /// AlignDirective - The directive used to emit round up to an alignment
195 const char *AlignDirective; // Defaults to "\t.align\t"
197 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
198 /// emits ".align N" directives, where N is the number of bytes to align to.
199 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
201 bool AlignmentIsInBytes; // Defaults to true
203 /// TextAlignFillValue - If non-zero, this is used to fill the executable
204 /// space created as the result of a alignment directive.
205 unsigned TextAlignFillValue;
207 //===--- Section Switching Directives ---------------------------------===//
209 /// SwitchToSectionDirective - This is the directive used when we want to
210 /// emit a global to an arbitrary section. The section name is emited after
212 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
214 /// TextSectionStartSuffix - This is printed after each start of section
215 /// directive for text sections.
216 const char *TextSectionStartSuffix; // Defaults to "".
218 /// DataSectionStartSuffix - This is printed after each start of section
219 /// directive for data sections.
220 const char *DataSectionStartSuffix; // Defaults to "".
222 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
223 /// section with the section name and this suffix printed.
224 const char *SectionEndDirectiveSuffix;// Defaults to null.
226 /// ConstantPoolSection - This is the section that we SwitchToSection right
227 /// before emitting the constant pool for a function.
228 const char *ConstantPoolSection; // Defaults to "\t.section .rodata"
230 /// JumpTableDataSection - This is the section that we SwitchToSection right
231 /// before emitting the jump tables for a function when the relocation model
233 const char *JumpTableDataSection; // Defaults to "\t.section .rodata"
235 /// JumpTableDirective - if non-null, the directive to emit before a jump
237 const char *JumpTableDirective;
239 /// CStringSection - If not null, this allows for special handling of
240 /// cstring constants (null terminated string that does not contain any
241 /// other null bytes) on this target. This is commonly supported as
244 const char *CStringSection; // Defaults to NULL
246 /// StaticCtorsSection - This is the directive that is emitted to switch to
247 /// a section to emit the static constructor list.
248 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
249 const char *StaticCtorsSection;
251 /// StaticDtorsSection - This is the directive that is emitted to switch to
252 /// a section to emit the static destructor list.
253 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
254 const char *StaticDtorsSection;
256 //===--- Global Variable Emission Directives --------------------------===//
258 /// GlobalDirective - This is the directive used to declare a global entity.
260 const char *GlobalDirective; // Defaults to NULL.
262 /// ExternDirective - This is the directive used to declare external
265 const char *ExternDirective; // Defaults to NULL.
267 /// SetDirective - This is the name of a directive that can be used to tell
268 /// the assembler to set the value of a variable to some expression.
269 const char *SetDirective; // Defaults to null.
271 /// LCOMMDirective - This is the name of a directive (if supported) that can
272 /// be used to efficiently declare a local (internal) block of zero
273 /// initialized data in the .bss/.data section. The syntax expected is:
274 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
276 const char *LCOMMDirective; // Defaults to null.
278 const char *COMMDirective; // Defaults to "\t.comm\t".
280 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
281 /// argument that specifies the alignment of the declaration.
282 bool COMMDirectiveTakesAlignment; // Defaults to true.
284 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
285 /// directives, this is true for most ELF targets.
286 bool HasDotTypeDotSizeDirective; // Defaults to true.
288 /// HasSingleParameterDotFile - True if the target has a single parameter
289 /// .file directive, this is true for ELF targets.
290 bool HasSingleParameterDotFile; // Defaults to true.
292 /// UsedDirective - This directive, if non-null, is used to declare a global
293 /// as being used somehow that the assembler can't see. This prevents dead
294 /// code elimination on some targets.
295 const char *UsedDirective; // Defaults to null.
297 /// WeakRefDirective - This directive, if non-null, is used to declare a
298 /// global as being a weak undefined symbol.
299 const char *WeakRefDirective; // Defaults to null.
301 /// WeakDefDirective - This directive, if non-null, is used to declare a
302 /// global as being a weak defined symbol.
303 const char *WeakDefDirective; // Defaults to null.
305 /// HiddenDirective - This directive, if non-null, is used to declare a
306 /// global or function as having hidden visibility.
307 const char *HiddenDirective; // Defaults to "\t.hidden\t".
309 /// ProtectedDirective - This directive, if non-null, is used to declare a
310 /// global or function as having protected visibility.
311 const char *ProtectedDirective; // Defaults to "\t.protected\t".
313 //===--- Dwarf Emission Directives -----------------------------------===//
315 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
316 /// offsets for debug information. Defaults to false.
317 bool AbsoluteDebugSectionOffsets;
319 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
320 /// offsets for EH information. Defaults to false.
321 bool AbsoluteEHSectionOffsets;
323 /// HasLEB128 - True if target asm supports leb128 directives.
325 bool HasLEB128; // Defaults to false.
327 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
328 /// directives for emitting debugging information.
330 bool HasDotLocAndDotFile; // Defaults to false.
332 /// SupportsDebugInformation - True if target supports emission of debugging
334 bool SupportsDebugInformation;
336 /// SupportsExceptionHandling - True if target supports
337 /// exception handling.
339 bool SupportsExceptionHandling; // Defaults to false.
341 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
343 bool DwarfRequiresFrameSection; // Defaults to true.
345 /// DwarfUsesInlineInfoSection - True if DwarfDebugInlineSection is used to
346 /// encode inline subroutine information.
347 bool DwarfUsesInlineInfoSection; // Defaults to false.
349 /// Is_EHSymbolPrivate - If set, the "_foo.eh" is made private so that it
350 /// doesn't show up in the symbol table of the object file.
351 bool Is_EHSymbolPrivate; // Defaults to true.
353 /// GlobalEHDirective - This is the directive used to make exception frame
354 /// tables globally visible.
356 const char *GlobalEHDirective; // Defaults to NULL.
358 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
359 /// handle a weak_definition of constant 0 for an omitted EH frame.
360 bool SupportsWeakOmittedEHFrame; // Defaults to true.
362 /// DwarfSectionOffsetDirective - Special section offset directive.
363 const char* DwarfSectionOffsetDirective; // Defaults to NULL
365 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
367 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
369 /// DwarfInfoSection - Section directive for Dwarf info.
371 const char *DwarfInfoSection; // Defaults to ".debug_info".
373 /// DwarfLineSection - Section directive for Dwarf info.
375 const char *DwarfLineSection; // Defaults to ".debug_line".
377 /// DwarfFrameSection - Section directive for Dwarf info.
379 const char *DwarfFrameSection; // Defaults to ".debug_frame".
381 /// DwarfPubNamesSection - Section directive for Dwarf info.
383 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
385 /// DwarfPubTypesSection - Section directive for Dwarf info.
387 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
389 /// DwarfDebugInlineSection - Section directive for inline info.
391 const char *DwarfDebugInlineSection; // Defaults to ".debug_inlined"
393 /// DwarfStrSection - Section directive for Dwarf info.
395 const char *DwarfStrSection; // Defaults to ".debug_str".
397 /// DwarfLocSection - Section directive for Dwarf info.
399 const char *DwarfLocSection; // Defaults to ".debug_loc".
401 /// DwarfARangesSection - Section directive for Dwarf info.
403 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
405 /// DwarfRangesSection - Section directive for Dwarf info.
407 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
409 /// DwarfMacroInfoSection - Section directive for DWARF macro info.
411 const char *DwarfMacroInfoSection; // Defaults to ".debug_macinfo".
413 /// DwarfEHFrameSection - Section directive for Exception frames.
415 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
417 /// DwarfExceptionSection - Section directive for Exception table.
419 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
421 //===--- CBE Asm Translation Table -----------------------------------===//
423 const char *const *AsmTransCBE; // Defaults to empty
426 explicit TargetAsmInfo(const TargetMachine &TM);
427 virtual ~TargetAsmInfo();
429 /// Measure the specified inline asm to determine an approximation of its
431 virtual unsigned getInlineAsmLength(const char *Str) const;
433 /// emitUsedDirectiveFor - This hook allows targets to selectively decide
434 /// not to emit the UsedDirective for some symbols in llvm.used.
435 // FIXME: REMOVE this (rdar://7071300)
436 virtual bool emitUsedDirectiveFor(const GlobalValue *GV,
441 /// PreferredEHDataFormat - This hook allows the target to select data
442 /// format used for encoding pointers in exception handling data. Reason is
443 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
444 /// if the symbol can be relocated.
445 virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
449 /// getSLEB128Size - Compute the number of bytes required for a signed
451 static unsigned getSLEB128Size(int Value);
453 /// getULEB128Size - Compute the number of bytes required for an unsigned
455 static unsigned getULEB128Size(unsigned Value);
457 // Data directive accessors.
459 const char *getData8bitsDirective(unsigned AS = 0) const {
460 return AS == 0 ? Data8bitsDirective : getDataASDirective(8, AS);
462 const char *getData16bitsDirective(unsigned AS = 0) const {
463 return AS == 0 ? Data16bitsDirective : getDataASDirective(16, AS);
465 const char *getData32bitsDirective(unsigned AS = 0) const {
466 return AS == 0 ? Data32bitsDirective : getDataASDirective(32, AS);
468 const char *getData64bitsDirective(unsigned AS = 0) const {
469 return AS == 0 ? Data64bitsDirective : getDataASDirective(64, AS);
475 const char *getBSSSection() const {
478 const char *getZeroFillDirective() const {
479 return ZeroFillDirective;
481 const char *getNonexecutableStackDirective() const {
482 return NonexecutableStackDirective;
484 bool needsSet() const {
487 const char *getPCSymbol() const {
490 char getSeparatorChar() const {
491 return SeparatorChar;
493 unsigned getCommentColumn() const {
494 return CommentColumn;
496 const char *getCommentString() const {
497 return CommentString;
499 unsigned getOperandColumn(int operand) const {
500 return FirstOperandColumn + (MaxOperandLength+1)*(operand-1);
502 const char *getGlobalPrefix() const {
505 const char *getPrivateGlobalPrefix() const {
506 return PrivateGlobalPrefix;
508 const char *getLinkerPrivateGlobalPrefix() const {
509 return LinkerPrivateGlobalPrefix;
511 const char *getJumpTableSpecialLabelPrefix() const {
512 return JumpTableSpecialLabelPrefix;
514 const char *getGlobalVarAddrPrefix() const {
515 return GlobalVarAddrPrefix;
517 const char *getGlobalVarAddrSuffix() const {
518 return GlobalVarAddrSuffix;
520 const char *getFunctionAddrPrefix() const {
521 return FunctionAddrPrefix;
523 const char *getFunctionAddrSuffix() const {
524 return FunctionAddrSuffix;
526 const char *getPersonalityPrefix() const {
527 return PersonalityPrefix;
529 const char *getPersonalitySuffix() const {
530 return PersonalitySuffix;
532 bool getNeedsIndirectEncoding() const {
533 return NeedsIndirectEncoding;
535 const char *getInlineAsmStart() const {
536 return InlineAsmStart;
538 const char *getInlineAsmEnd() const {
541 unsigned getAssemblerDialect() const {
542 return AssemblerDialect;
544 bool doesAllowQuotesInName() const {
545 return AllowQuotesInName;
547 const char *getZeroDirective() const {
548 return ZeroDirective;
550 const char *getZeroDirectiveSuffix() const {
551 return ZeroDirectiveSuffix;
553 const char *getAsciiDirective() const {
554 return AsciiDirective;
556 const char *getAscizDirective() const {
557 return AscizDirective;
559 const char *getJumpTableDirective() const {
560 return JumpTableDirective;
562 const char *getAlignDirective() const {
563 return AlignDirective;
565 bool getAlignmentIsInBytes() const {
566 return AlignmentIsInBytes;
568 unsigned getTextAlignFillValue() const {
569 return TextAlignFillValue;
571 const char *getSwitchToSectionDirective() const {
572 return SwitchToSectionDirective;
574 const char *getTextSectionStartSuffix() const {
575 return TextSectionStartSuffix;
577 const char *getDataSectionStartSuffix() const {
578 return DataSectionStartSuffix;
580 const char *getSectionEndDirectiveSuffix() const {
581 return SectionEndDirectiveSuffix;
583 const char *getConstantPoolSection() const {
584 return ConstantPoolSection;
586 const char *getJumpTableDataSection() const {
587 return JumpTableDataSection;
589 const char *getCStringSection() const {
590 return CStringSection;
592 const char *getStaticCtorsSection() const {
593 return StaticCtorsSection;
595 const char *getStaticDtorsSection() const {
596 return StaticDtorsSection;
598 const char *getGlobalDirective() const {
599 return GlobalDirective;
601 const char *getExternDirective() const {
602 return ExternDirective;
604 const char *getSetDirective() const {
607 const char *getLCOMMDirective() const {
608 return LCOMMDirective;
610 const char *getCOMMDirective() const {
611 return COMMDirective;
613 bool getCOMMDirectiveTakesAlignment() const {
614 return COMMDirectiveTakesAlignment;
616 bool hasDotTypeDotSizeDirective() const {
617 return HasDotTypeDotSizeDirective;
619 bool hasSingleParameterDotFile() const {
620 return HasSingleParameterDotFile;
622 const char *getUsedDirective() const {
623 return UsedDirective;
625 const char *getWeakRefDirective() const {
626 return WeakRefDirective;
628 const char *getWeakDefDirective() const {
629 return WeakDefDirective;
631 const char *getHiddenDirective() const {
632 return HiddenDirective;
634 const char *getProtectedDirective() const {
635 return ProtectedDirective;
637 bool isAbsoluteDebugSectionOffsets() const {
638 return AbsoluteDebugSectionOffsets;
640 bool isAbsoluteEHSectionOffsets() const {
641 return AbsoluteEHSectionOffsets;
643 bool hasLEB128() const {
646 bool hasDotLocAndDotFile() const {
647 return HasDotLocAndDotFile;
649 bool doesSupportDebugInformation() const {
650 return SupportsDebugInformation;
652 bool doesSupportExceptionHandling() const {
653 return SupportsExceptionHandling;
655 bool doesDwarfRequireFrameSection() const {
656 return DwarfRequiresFrameSection;
658 bool doesDwarfUsesInlineInfoSection() const {
659 return DwarfUsesInlineInfoSection;
661 bool is_EHSymbolPrivate() const {
662 return Is_EHSymbolPrivate;
664 const char *getGlobalEHDirective() const {
665 return GlobalEHDirective;
667 bool getSupportsWeakOmittedEHFrame() const {
668 return SupportsWeakOmittedEHFrame;
670 const char *getDwarfSectionOffsetDirective() const {
671 return DwarfSectionOffsetDirective;
673 const char *getDwarfAbbrevSection() const {
674 return DwarfAbbrevSection;
676 const char *getDwarfInfoSection() const {
677 return DwarfInfoSection;
679 const char *getDwarfLineSection() const {
680 return DwarfLineSection;
682 const char *getDwarfFrameSection() const {
683 return DwarfFrameSection;
685 const char *getDwarfPubNamesSection() const {
686 return DwarfPubNamesSection;
688 const char *getDwarfPubTypesSection() const {
689 return DwarfPubTypesSection;
691 const char *getDwarfDebugInlineSection() const {
692 return DwarfDebugInlineSection;
694 const char *getDwarfStrSection() const {
695 return DwarfStrSection;
697 const char *getDwarfLocSection() const {
698 return DwarfLocSection;
700 const char *getDwarfARangesSection() const {
701 return DwarfARangesSection;
703 const char *getDwarfRangesSection() const {
704 return DwarfRangesSection;
706 const char *getDwarfMacroInfoSection() const {
707 return DwarfMacroInfoSection;
709 const char *getDwarfEHFrameSection() const {
710 return DwarfEHFrameSection;
712 const char *getDwarfExceptionSection() const {
713 return DwarfExceptionSection;
715 const char *const *getAsmCBE() const {