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/Support/DataTypes.h"
22 // DWARF encoding query type
23 namespace DwarfEncoding {
31 namespace SectionKind {
33 Unknown = 0, ///< Custom section
34 Text, ///< Text section
35 Data, ///< Data section
37 ROData, ///< Readonly data section
38 RODataMergeStr, ///< Readonly data section (mergeable strings)
39 RODataMergeConst, ///< Readonly data section (mergeable constants)
40 ThreadData, ///< Initialized TLS data objects
41 ThreadBSS ///< Uninitialized TLS data objects
45 namespace SectionFlags {
48 Code = 1 << 0, ///< Section contains code
49 Writeable = 1 << 1, ///< Section is writeable
50 BSS = 1 << 2, ///< Section contains only zeroes
51 Mergeable = 1 << 3, ///< Section contains mergeable data
52 Strings = 1 << 4, ///< Section contains null-terminated strings
53 TLS = 1 << 5, ///< Section contains thread-local data
54 Debug = 1 << 6, ///< Section contains debug data
55 Linkonce = 1 << 7 ///< Section is linkonce
60 SectionKind::Kind kind;
61 SectionFlags::Flags flags;
68 /// TargetAsmInfo - This class is intended to be used as a base class for asm
69 /// properties and features specific to the target.
72 //===------------------------------------------------------------------===//
73 // Properties to be set by the target writer, used to configure asm printer.
76 /// TextSection - Section directive for standard text.
78 const char *TextSection; // Defaults to ".text".
80 /// DataSection - Section directive for standard data.
82 const char *DataSection; // Defaults to ".data".
84 /// BSSSection - Section directive for uninitialized data. Null if this
85 /// target doesn't support a BSS section.
87 const char *BSSSection; // Default to ".bss".
89 /// TLSDataSection - Section directive for Thread Local data.
91 const char *TLSDataSection;// Defaults to ".section .tdata,"awT",@progbits".
93 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
94 /// Null if this target doesn't support a BSS section.
96 const char *TLSBSSSection;// Default to ".section .tbss,"awT",@nobits".
98 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
99 /// section on this target. Null if this target doesn't support zerofill.
100 const char *ZeroFillDirective; // Default is null.
102 /// NonexecutableStackDirective - Directive for declaring to the
103 /// linker and beyond that the emitted code does not require stack
104 /// memory to be executable.
105 const char *NonexecutableStackDirective; // Default is null.
107 /// NeedsSet - True if target asm treats expressions in data directives
108 /// as linktime-relocatable. For assembly-time computation, we need to
109 /// use a .set. Thus:
112 /// is computed at assembly time, while
114 /// is relocated if the relative locations of x and y change at linktime.
115 /// We want both these things in different places.
116 bool NeedsSet; // Defaults to false.
118 /// MaxInstLength - This is the maximum possible length of an instruction,
119 /// which is needed to compute the size of an inline asm.
120 unsigned MaxInstLength; // Defaults to 4.
122 /// PCSymbol - The symbol used to represent the current PC. Used in PC
123 /// relative expressions.
124 const char *PCSymbol; // Defaults to "$".
126 /// SeparatorChar - This character, if specified, is used to separate
127 /// instructions from each other when on the same line. This is used to
128 /// measure inline asm instructions.
129 char SeparatorChar; // Defaults to ';'
131 /// CommentString - This indicates the comment character used by the
133 const char *CommentString; // Defaults to "#"
135 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
136 /// onto all global symbols. This is often used for "_" or ".".
137 const char *GlobalPrefix; // Defaults to ""
139 /// PrivateGlobalPrefix - This prefix is used for globals like constant
140 /// pool entries that are completely private to the .o file and should not
141 /// have names in the .o file. This is often "." or "L".
142 const char *PrivateGlobalPrefix; // Defaults to "."
144 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
145 /// emitted before jump tables with the specified prefix.
146 const char *JumpTableSpecialLabelPrefix; // Default to null.
148 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
149 /// will enclose any GlobalVariable (that isn't a function)
151 const char *GlobalVarAddrPrefix; // Defaults to ""
152 const char *GlobalVarAddrSuffix; // Defaults to ""
154 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
155 /// will enclose any GlobalVariable that points to a function.
156 /// For example, this is used by the IA64 backend to materialize
157 /// function descriptors, by decorating the ".data8" object with the
158 /// @verbatim @fptr( ) @endverbatim
159 /// link-relocation operator.
161 const char *FunctionAddrPrefix; // Defaults to ""
162 const char *FunctionAddrSuffix; // Defaults to ""
164 /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
165 /// enclose any personality function in the common frame section.
167 const char *PersonalityPrefix; // Defaults to ""
168 const char *PersonalitySuffix; // Defaults to ""
170 /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
173 bool NeedsIndirectEncoding; // Defaults to false
175 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
176 /// emit before and after an inline assembly statement.
177 const char *InlineAsmStart; // Defaults to "#APP\n"
178 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
180 /// AssemblerDialect - Which dialect of an assembler variant to use.
181 unsigned AssemblerDialect; // Defaults to 0
183 /// StringConstantPrefix - Prefix for FEs to use when generating unnamed
184 /// constant strings. These names get run through the Mangler later; if
185 /// you want the Mangler not to add the GlobalPrefix as well,
186 /// use '\1' as the first character.
187 const char *StringConstantPrefix; // Defaults to ".str"
189 //===--- Data Emission Directives -------------------------------------===//
191 /// ZeroDirective - this should be set to the directive used to get some
192 /// number of zero bytes emitted to the current section. Common cases are
193 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
194 /// Data*bitsDirective's will be used to emit zero bytes.
195 const char *ZeroDirective; // Defaults to "\t.zero\t"
196 const char *ZeroDirectiveSuffix; // Defaults to ""
198 /// AsciiDirective - This directive allows emission of an ascii string with
199 /// the standard C escape characters embedded into it.
200 const char *AsciiDirective; // Defaults to "\t.ascii\t"
202 /// AscizDirective - If not null, this allows for special handling of
203 /// zero terminated strings on this target. This is commonly supported as
204 /// ".asciz". If a target doesn't support this, it can be set to null.
205 const char *AscizDirective; // Defaults to "\t.asciz\t"
207 /// DataDirectives - These directives are used to output some unit of
208 /// integer data to the current section. If a data directive is set to
209 /// null, smaller data directives will be used to emit the large sizes.
210 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
211 const char *Data16bitsDirective; // Defaults to "\t.short\t"
212 const char *Data32bitsDirective; // Defaults to "\t.long\t"
213 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
215 //===--- Alignment Information ----------------------------------------===//
217 /// AlignDirective - The directive used to emit round up to an alignment
220 const char *AlignDirective; // Defaults to "\t.align\t"
222 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
223 /// emits ".align N" directives, where N is the number of bytes to align to.
224 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
226 bool AlignmentIsInBytes; // Defaults to true
228 /// TextAlignFillValue - If non-zero, this is used to fill the executable
229 /// space created as the result of a alignment directive.
230 unsigned TextAlignFillValue;
232 //===--- Section Switching Directives ---------------------------------===//
234 /// SwitchToSectionDirective - This is the directive used when we want to
235 /// emit a global to an arbitrary section. The section name is emited after
237 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
239 /// TextSectionStartSuffix - This is printed after each start of section
240 /// directive for text sections.
241 const char *TextSectionStartSuffix; // Defaults to "".
243 /// DataSectionStartSuffix - This is printed after each start of section
244 /// directive for data sections.
245 const char *DataSectionStartSuffix; // Defaults to "".
247 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
248 /// section with the section name and this suffix printed.
249 const char *SectionEndDirectiveSuffix;// Defaults to null.
251 /// ConstantPoolSection - This is the section that we SwitchToSection right
252 /// before emitting the constant pool for a function.
253 const char *ConstantPoolSection; // Defaults to "\t.section .rodata"
255 /// JumpTableDataSection - This is the section that we SwitchToSection right
256 /// before emitting the jump tables for a function when the relocation model
258 const char *JumpTableDataSection; // Defaults to "\t.section .rodata"
260 /// JumpTableDirective - if non-null, the directive to emit before a jump
262 const char *JumpTableDirective;
264 /// CStringSection - If not null, this allows for special handling of
265 /// cstring constants (null terminated string that does not contain any
266 /// other null bytes) on this target. This is commonly supported as
268 const char *CStringSection; // Defaults to NULL
270 /// StaticCtorsSection - This is the directive that is emitted to switch to
271 /// a section to emit the static constructor list.
272 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
273 const char *StaticCtorsSection;
275 /// StaticDtorsSection - This is the directive that is emitted to switch to
276 /// a section to emit the static destructor list.
277 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
278 const char *StaticDtorsSection;
280 /// FourByteConstantSection, EightByteConstantSection,
281 /// SixteenByteConstantSection - These are special sections where we place
282 /// 4-, 8-, and 16- byte constant literals.
283 const char *FourByteConstantSection;
284 const char *EightByteConstantSection;
285 const char *SixteenByteConstantSection;
287 /// ReadOnlySection - This is the directive that is emitted to switch to a
288 /// read-only section for constant data (e.g. data declared const,
290 const char *ReadOnlySection; // Defaults to NULL
292 //===--- Global Variable Emission Directives --------------------------===//
294 /// GlobalDirective - This is the directive used to declare a global entity.
296 const char *GlobalDirective; // Defaults to NULL.
298 /// SetDirective - This is the name of a directive that can be used to tell
299 /// the assembler to set the value of a variable to some expression.
300 const char *SetDirective; // Defaults to null.
302 /// LCOMMDirective - This is the name of a directive (if supported) that can
303 /// be used to efficiently declare a local (internal) block of zero
304 /// initialized data in the .bss/.data section. The syntax expected is:
305 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
307 const char *LCOMMDirective; // Defaults to null.
309 const char *COMMDirective; // Defaults to "\t.comm\t".
311 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
312 /// argument that specifies the alignment of the declaration.
313 bool COMMDirectiveTakesAlignment; // Defaults to true.
315 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
316 /// directives, this is true for most ELF targets.
317 bool HasDotTypeDotSizeDirective; // Defaults to true.
319 /// UsedDirective - This directive, if non-null, is used to declare a global
320 /// as being used somehow that the assembler can't see. This prevents dead
321 /// code elimination on some targets.
322 const char *UsedDirective; // Defaults to null.
324 /// WeakRefDirective - This directive, if non-null, is used to declare a
325 /// global as being a weak undefined symbol.
326 const char *WeakRefDirective; // Defaults to null.
328 /// WeakDefDirective - This directive, if non-null, is used to declare a
329 /// global as being a weak defined symbol.
330 const char *WeakDefDirective; // Defaults to null.
332 /// HiddenDirective - This directive, if non-null, is used to declare a
333 /// global or function as having hidden visibility.
334 const char *HiddenDirective; // Defaults to "\t.hidden\t".
336 /// ProtectedDirective - This directive, if non-null, is used to declare a
337 /// global or function as having protected visibility.
338 const char *ProtectedDirective; // Defaults to "\t.protected\t".
340 //===--- Dwarf Emission Directives -----------------------------------===//
342 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
343 /// offsets for debug information. Defaults to false.
344 bool AbsoluteDebugSectionOffsets;
346 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
347 /// offsets for EH information. Defaults to false.
348 bool AbsoluteEHSectionOffsets;
350 /// HasLEB128 - True if target asm supports leb128 directives.
352 bool HasLEB128; // Defaults to false.
354 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
355 /// directives for emitting debugging information.
357 bool HasDotLocAndDotFile; // Defaults to false.
359 /// SupportsDebugInformation - True if target supports emission of debugging
361 bool SupportsDebugInformation;
363 /// SupportsExceptionHandling - True if target supports
364 /// exception handling.
366 bool SupportsExceptionHandling; // Defaults to false.
368 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
370 bool DwarfRequiresFrameSection; // Defaults to true.
372 /// GlobalEHDirective - This is the directive used to make exception frame
373 /// tables globally visible.
375 const char *GlobalEHDirective; // Defaults to NULL.
377 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
378 /// handle a weak_definition of constant 0 for an omitted EH frame.
379 bool SupportsWeakOmittedEHFrame; // Defaults to true.
381 /// DwarfSectionOffsetDirective - Special section offset directive.
382 const char* DwarfSectionOffsetDirective; // Defaults to NULL
384 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
386 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
388 /// DwarfInfoSection - Section directive for Dwarf info.
390 const char *DwarfInfoSection; // Defaults to ".debug_info".
392 /// DwarfLineSection - Section directive for Dwarf info.
394 const char *DwarfLineSection; // Defaults to ".debug_line".
396 /// DwarfFrameSection - Section directive for Dwarf info.
398 const char *DwarfFrameSection; // Defaults to ".debug_frame".
400 /// DwarfPubNamesSection - Section directive for Dwarf info.
402 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
404 /// DwarfPubTypesSection - Section directive for Dwarf info.
406 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
408 /// DwarfStrSection - Section directive for Dwarf info.
410 const char *DwarfStrSection; // Defaults to ".debug_str".
412 /// DwarfLocSection - Section directive for Dwarf info.
414 const char *DwarfLocSection; // Defaults to ".debug_loc".
416 /// DwarfARangesSection - Section directive for Dwarf info.
418 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
420 /// DwarfRangesSection - Section directive for Dwarf info.
422 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
424 /// DwarfMacInfoSection - Section directive for Dwarf info.
426 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
428 /// DwarfEHFrameSection - Section directive for Exception frames.
430 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
432 /// DwarfExceptionSection - Section directive for Exception table.
434 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
436 //===--- CBE Asm Translation Table -----------------------------------===//
438 const char *const *AsmTransCBE; // Defaults to empty
442 virtual ~TargetAsmInfo();
444 /// Measure the specified inline asm to determine an approximation of its
446 virtual unsigned getInlineAsmLength(const char *Str) const;
448 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
449 /// call to be explicit llvm code if it wants to. This is useful for
450 /// turning simple inline asms into LLVM intrinsics, which gives the
451 /// compiler more information about the behavior of the code.
452 virtual bool ExpandInlineAsm(CallInst *CI) const {
456 /// PreferredEHDataFormat - This hook allows the target to select data
457 /// format used for encoding pointers in exception handling data. Reason is
458 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
459 /// if the symbol can be relocated.
460 virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
463 /// SectionKindForGlobal - This hook allows the target to select proper
464 /// section kind used for global emission.
465 virtual SectionKind::Kind
466 SectionKindForGlobal(const GlobalValue *GV) const;
469 /// SectionFlagsForGlobal - This hook allows the target to select proper
470 /// section flags either for given global or for section.
472 SectionFlagsForGlobal(const GlobalValue *GV = NULL,
473 const char* name = NULL) const;
475 /// SectionForGlobal - This hooks returns proper section name for given
476 /// global with all necessary flags and marks.
477 virtual std::string SectionForGlobal(const GlobalValue *GV) const;
481 const char *getTextSection() const {
484 const char *getDataSection() const {
487 const char *getBSSSection() const {
490 const char *getTLSDataSection() const {
491 return TLSDataSection;
493 const char *getTLSBSSSection() const {
494 return TLSBSSSection;
496 const char *getZeroFillDirective() const {
497 return ZeroFillDirective;
499 const char *getNonexecutableStackDirective() const {
500 return NonexecutableStackDirective;
502 bool needsSet() const {
505 const char *getPCSymbol() const {
508 char getSeparatorChar() const {
509 return SeparatorChar;
511 const char *getCommentString() const {
512 return CommentString;
514 const char *getGlobalPrefix() const {
517 const char *getPrivateGlobalPrefix() const {
518 return PrivateGlobalPrefix;
520 const char *getJumpTableSpecialLabelPrefix() const {
521 return JumpTableSpecialLabelPrefix;
523 const char *getGlobalVarAddrPrefix() const {
524 return GlobalVarAddrPrefix;
526 const char *getGlobalVarAddrSuffix() const {
527 return GlobalVarAddrSuffix;
529 const char *getFunctionAddrPrefix() const {
530 return FunctionAddrPrefix;
532 const char *getFunctionAddrSuffix() const {
533 return FunctionAddrSuffix;
535 const char *getPersonalityPrefix() const {
536 return PersonalityPrefix;
538 const char *getPersonalitySuffix() const {
539 return PersonalitySuffix;
541 bool getNeedsIndirectEncoding() const {
542 return NeedsIndirectEncoding;
544 const char *getInlineAsmStart() const {
545 return InlineAsmStart;
547 const char *getInlineAsmEnd() const {
550 unsigned getAssemblerDialect() const {
551 return AssemblerDialect;
553 const char *getStringConstantPrefix() const {
554 return StringConstantPrefix;
556 const char *getZeroDirective() const {
557 return ZeroDirective;
559 const char *getZeroDirectiveSuffix() const {
560 return ZeroDirectiveSuffix;
562 const char *getAsciiDirective() const {
563 return AsciiDirective;
565 const char *getAscizDirective() const {
566 return AscizDirective;
568 const char *getData8bitsDirective() const {
569 return Data8bitsDirective;
571 const char *getData16bitsDirective() const {
572 return Data16bitsDirective;
574 const char *getData32bitsDirective() const {
575 return Data32bitsDirective;
577 const char *getData64bitsDirective() const {
578 return Data64bitsDirective;
580 const char *getJumpTableDirective() const {
581 return JumpTableDirective;
583 const char *getAlignDirective() const {
584 return AlignDirective;
586 bool getAlignmentIsInBytes() const {
587 return AlignmentIsInBytes;
589 unsigned getTextAlignFillValue() const {
590 return TextAlignFillValue;
592 const char *getSwitchToSectionDirective() const {
593 return SwitchToSectionDirective;
595 const char *getTextSectionStartSuffix() const {
596 return TextSectionStartSuffix;
598 const char *getDataSectionStartSuffix() const {
599 return DataSectionStartSuffix;
601 const char *getSectionEndDirectiveSuffix() const {
602 return SectionEndDirectiveSuffix;
604 const char *getConstantPoolSection() const {
605 return ConstantPoolSection;
607 const char *getJumpTableDataSection() const {
608 return JumpTableDataSection;
610 const char *getCStringSection() const {
611 return CStringSection;
613 const char *getStaticCtorsSection() const {
614 return StaticCtorsSection;
616 const char *getStaticDtorsSection() const {
617 return StaticDtorsSection;
619 const char *getFourByteConstantSection() const {
620 return FourByteConstantSection;
622 const char *getEightByteConstantSection() const {
623 return EightByteConstantSection;
625 const char *getSixteenByteConstantSection() const {
626 return SixteenByteConstantSection;
628 const char *getReadOnlySection() const {
629 return ReadOnlySection;
631 const char *getGlobalDirective() const {
632 return GlobalDirective;
634 const char *getSetDirective() const {
637 const char *getLCOMMDirective() const {
638 return LCOMMDirective;
640 const char *getCOMMDirective() const {
641 return COMMDirective;
643 bool getCOMMDirectiveTakesAlignment() const {
644 return COMMDirectiveTakesAlignment;
646 bool hasDotTypeDotSizeDirective() const {
647 return HasDotTypeDotSizeDirective;
649 const char *getUsedDirective() const {
650 return UsedDirective;
652 const char *getWeakRefDirective() const {
653 return WeakRefDirective;
655 const char *getWeakDefDirective() const {
656 return WeakDefDirective;
658 const char *getHiddenDirective() const {
659 return HiddenDirective;
661 const char *getProtectedDirective() const {
662 return ProtectedDirective;
664 bool isAbsoluteDebugSectionOffsets() const {
665 return AbsoluteDebugSectionOffsets;
667 bool isAbsoluteEHSectionOffsets() const {
668 return AbsoluteEHSectionOffsets;
670 bool hasLEB128() const {
673 bool hasDotLocAndDotFile() const {
674 return HasDotLocAndDotFile;
676 bool doesSupportDebugInformation() const {
677 return SupportsDebugInformation;
679 bool doesSupportExceptionHandling() const {
680 return SupportsExceptionHandling;
682 bool doesDwarfRequireFrameSection() const {
683 return DwarfRequiresFrameSection;
685 const char *getGlobalEHDirective() const {
686 return GlobalEHDirective;
688 bool getSupportsWeakOmittedEHFrame() const {
689 return SupportsWeakOmittedEHFrame;
691 const char *getDwarfSectionOffsetDirective() const {
692 return DwarfSectionOffsetDirective;
694 const char *getDwarfAbbrevSection() const {
695 return DwarfAbbrevSection;
697 const char *getDwarfInfoSection() const {
698 return DwarfInfoSection;
700 const char *getDwarfLineSection() const {
701 return DwarfLineSection;
703 const char *getDwarfFrameSection() const {
704 return DwarfFrameSection;
706 const char *getDwarfPubNamesSection() const {
707 return DwarfPubNamesSection;
709 const char *getDwarfPubTypesSection() const {
710 return DwarfPubTypesSection;
712 const char *getDwarfStrSection() const {
713 return DwarfStrSection;
715 const char *getDwarfLocSection() const {
716 return DwarfLocSection;
718 const char *getDwarfARangesSection() const {
719 return DwarfARangesSection;
721 const char *getDwarfRangesSection() const {
722 return DwarfRangesSection;
724 const char *getDwarfMacInfoSection() const {
725 return DwarfMacInfoSection;
727 const char *getDwarfEHFrameSection() const {
728 return DwarfEHFrameSection;
730 const char *getDwarfExceptionSection() const {
731 return DwarfExceptionSection;
733 const char *const *getAsmCBE() const {