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
63 /// TargetAsmInfo - This class is intended to be used as a base class for asm
64 /// properties and features specific to the target.
67 //===------------------------------------------------------------------===//
68 // Properties to be set by the target writer, used to configure asm printer.
71 /// TextSection - Section directive for standard text.
73 const char *TextSection; // Defaults to ".text".
75 /// DataSection - Section directive for standard data.
77 const char *DataSection; // Defaults to ".data".
79 /// BSSSection - Section directive for uninitialized data. Null if this
80 /// target doesn't support a BSS section.
82 const char *BSSSection; // Default to ".bss".
84 /// TLSDataSection - Section directive for Thread Local data.
86 const char *TLSDataSection;// Defaults to ".section .tdata,"awT",@progbits".
88 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
89 /// Null if this target doesn't support a BSS section.
91 const char *TLSBSSSection;// Default to ".section .tbss,"awT",@nobits".
93 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
94 /// section on this target. Null if this target doesn't support zerofill.
95 const char *ZeroFillDirective; // Default is null.
97 /// NonexecutableStackDirective - Directive for declaring to the
98 /// linker and beyond that the emitted code does not require stack
99 /// memory to be executable.
100 const char *NonexecutableStackDirective; // Default is null.
102 /// NeedsSet - True if target asm treats expressions in data directives
103 /// as linktime-relocatable. For assembly-time computation, we need to
104 /// use a .set. Thus:
107 /// is computed at assembly time, while
109 /// is relocated if the relative locations of x and y change at linktime.
110 /// We want both these things in different places.
111 bool NeedsSet; // Defaults to false.
113 /// MaxInstLength - This is the maximum possible length of an instruction,
114 /// which is needed to compute the size of an inline asm.
115 unsigned MaxInstLength; // Defaults to 4.
117 /// PCSymbol - The symbol used to represent the current PC. Used in PC
118 /// relative expressions.
119 const char *PCSymbol; // Defaults to "$".
121 /// SeparatorChar - This character, if specified, is used to separate
122 /// instructions from each other when on the same line. This is used to
123 /// measure inline asm instructions.
124 char SeparatorChar; // Defaults to ';'
126 /// CommentString - This indicates the comment character used by the
128 const char *CommentString; // Defaults to "#"
130 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
131 /// onto all global symbols. This is often used for "_" or ".".
132 const char *GlobalPrefix; // Defaults to ""
134 /// PrivateGlobalPrefix - This prefix is used for globals like constant
135 /// pool entries that are completely private to the .o file and should not
136 /// have names in the .o file. This is often "." or "L".
137 const char *PrivateGlobalPrefix; // Defaults to "."
139 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
140 /// emitted before jump tables with the specified prefix.
141 const char *JumpTableSpecialLabelPrefix; // Default to null.
143 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
144 /// will enclose any GlobalVariable (that isn't a function)
146 const char *GlobalVarAddrPrefix; // Defaults to ""
147 const char *GlobalVarAddrSuffix; // Defaults to ""
149 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
150 /// will enclose any GlobalVariable that points to a function.
151 /// For example, this is used by the IA64 backend to materialize
152 /// function descriptors, by decorating the ".data8" object with the
153 /// @verbatim @fptr( ) @endverbatim
154 /// link-relocation operator.
156 const char *FunctionAddrPrefix; // Defaults to ""
157 const char *FunctionAddrSuffix; // Defaults to ""
159 /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
160 /// enclose any personality function in the common frame section.
162 const char *PersonalityPrefix; // Defaults to ""
163 const char *PersonalitySuffix; // Defaults to ""
165 /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
168 bool NeedsIndirectEncoding; // Defaults to false
170 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
171 /// emit before and after an inline assembly statement.
172 const char *InlineAsmStart; // Defaults to "#APP\n"
173 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
175 /// AssemblerDialect - Which dialect of an assembler variant to use.
176 unsigned AssemblerDialect; // Defaults to 0
178 /// StringConstantPrefix - Prefix for FEs to use when generating unnamed
179 /// constant strings. These names get run through the Mangler later; if
180 /// you want the Mangler not to add the GlobalPrefix as well,
181 /// use '\1' as the first character.
182 const char *StringConstantPrefix; // Defaults to ".str"
184 //===--- Data Emission Directives -------------------------------------===//
186 /// ZeroDirective - this should be set to the directive used to get some
187 /// number of zero bytes emitted to the current section. Common cases are
188 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
189 /// Data*bitsDirective's will be used to emit zero bytes.
190 const char *ZeroDirective; // Defaults to "\t.zero\t"
191 const char *ZeroDirectiveSuffix; // Defaults to ""
193 /// AsciiDirective - This directive allows emission of an ascii string with
194 /// the standard C escape characters embedded into it.
195 const char *AsciiDirective; // Defaults to "\t.ascii\t"
197 /// AscizDirective - If not null, this allows for special handling of
198 /// zero terminated strings on this target. This is commonly supported as
199 /// ".asciz". If a target doesn't support this, it can be set to null.
200 const char *AscizDirective; // Defaults to "\t.asciz\t"
202 /// DataDirectives - These directives are used to output some unit of
203 /// integer data to the current section. If a data directive is set to
204 /// null, smaller data directives will be used to emit the large sizes.
205 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
206 const char *Data16bitsDirective; // Defaults to "\t.short\t"
207 const char *Data32bitsDirective; // Defaults to "\t.long\t"
208 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
210 //===--- Alignment Information ----------------------------------------===//
212 /// AlignDirective - The directive used to emit round up to an alignment
215 const char *AlignDirective; // Defaults to "\t.align\t"
217 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
218 /// emits ".align N" directives, where N is the number of bytes to align to.
219 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
221 bool AlignmentIsInBytes; // Defaults to true
223 /// TextAlignFillValue - If non-zero, this is used to fill the executable
224 /// space created as the result of a alignment directive.
225 unsigned TextAlignFillValue;
227 //===--- Section Switching Directives ---------------------------------===//
229 /// SwitchToSectionDirective - This is the directive used when we want to
230 /// emit a global to an arbitrary section. The section name is emited after
232 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
234 /// TextSectionStartSuffix - This is printed after each start of section
235 /// directive for text sections.
236 const char *TextSectionStartSuffix; // Defaults to "".
238 /// DataSectionStartSuffix - This is printed after each start of section
239 /// directive for data sections.
240 const char *DataSectionStartSuffix; // Defaults to "".
242 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
243 /// section with the section name and this suffix printed.
244 const char *SectionEndDirectiveSuffix;// Defaults to null.
246 /// ConstantPoolSection - This is the section that we SwitchToSection right
247 /// before emitting the constant pool for a function.
248 const char *ConstantPoolSection; // Defaults to "\t.section .rodata"
250 /// JumpTableDataSection - This is the section that we SwitchToSection right
251 /// before emitting the jump tables for a function when the relocation model
253 const char *JumpTableDataSection; // Defaults to "\t.section .rodata"
255 /// JumpTableDirective - if non-null, the directive to emit before a jump
257 const char *JumpTableDirective;
259 /// CStringSection - If not null, this allows for special handling of
260 /// cstring constants (null terminated string that does not contain any
261 /// other null bytes) on this target. This is commonly supported as
263 const char *CStringSection; // Defaults to NULL
265 /// StaticCtorsSection - This is the directive that is emitted to switch to
266 /// a section to emit the static constructor list.
267 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
268 const char *StaticCtorsSection;
270 /// StaticDtorsSection - This is the directive that is emitted to switch to
271 /// a section to emit the static destructor list.
272 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
273 const char *StaticDtorsSection;
275 /// FourByteConstantSection, EightByteConstantSection,
276 /// SixteenByteConstantSection - These are special sections where we place
277 /// 4-, 8-, and 16- byte constant literals.
278 const char *FourByteConstantSection;
279 const char *EightByteConstantSection;
280 const char *SixteenByteConstantSection;
282 /// ReadOnlySection - This is the directive that is emitted to switch to a
283 /// read-only section for constant data (e.g. data declared const,
285 const char *ReadOnlySection; // Defaults to NULL
287 //===--- Global Variable Emission Directives --------------------------===//
289 /// GlobalDirective - This is the directive used to declare a global entity.
291 const char *GlobalDirective; // Defaults to NULL.
293 /// SetDirective - This is the name of a directive that can be used to tell
294 /// the assembler to set the value of a variable to some expression.
295 const char *SetDirective; // Defaults to null.
297 /// LCOMMDirective - This is the name of a directive (if supported) that can
298 /// be used to efficiently declare a local (internal) block of zero
299 /// initialized data in the .bss/.data section. The syntax expected is:
300 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
302 const char *LCOMMDirective; // Defaults to null.
304 const char *COMMDirective; // Defaults to "\t.comm\t".
306 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
307 /// argument that specifies the alignment of the declaration.
308 bool COMMDirectiveTakesAlignment; // Defaults to true.
310 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
311 /// directives, this is true for most ELF targets.
312 bool HasDotTypeDotSizeDirective; // Defaults to true.
314 /// UsedDirective - This directive, if non-null, is used to declare a global
315 /// as being used somehow that the assembler can't see. This prevents dead
316 /// code elimination on some targets.
317 const char *UsedDirective; // Defaults to null.
319 /// WeakRefDirective - This directive, if non-null, is used to declare a
320 /// global as being a weak undefined symbol.
321 const char *WeakRefDirective; // Defaults to null.
323 /// WeakDefDirective - This directive, if non-null, is used to declare a
324 /// global as being a weak defined symbol.
325 const char *WeakDefDirective; // Defaults to null.
327 /// HiddenDirective - This directive, if non-null, is used to declare a
328 /// global or function as having hidden visibility.
329 const char *HiddenDirective; // Defaults to "\t.hidden\t".
331 /// ProtectedDirective - This directive, if non-null, is used to declare a
332 /// global or function as having protected visibility.
333 const char *ProtectedDirective; // Defaults to "\t.protected\t".
335 //===--- Dwarf Emission Directives -----------------------------------===//
337 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
338 /// offsets for debug information. Defaults to false.
339 bool AbsoluteDebugSectionOffsets;
341 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
342 /// offsets for EH information. Defaults to false.
343 bool AbsoluteEHSectionOffsets;
345 /// HasLEB128 - True if target asm supports leb128 directives.
347 bool HasLEB128; // Defaults to false.
349 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
350 /// directives for emitting debugging information.
352 bool HasDotLocAndDotFile; // Defaults to false.
354 /// SupportsDebugInformation - True if target supports emission of debugging
356 bool SupportsDebugInformation;
358 /// SupportsExceptionHandling - True if target supports
359 /// exception handling.
361 bool SupportsExceptionHandling; // Defaults to false.
363 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
365 bool DwarfRequiresFrameSection; // Defaults to true.
367 /// GlobalEHDirective - This is the directive used to make exception frame
368 /// tables globally visible.
370 const char *GlobalEHDirective; // Defaults to NULL.
372 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
373 /// handle a weak_definition of constant 0 for an omitted EH frame.
374 bool SupportsWeakOmittedEHFrame; // Defaults to true.
376 /// DwarfSectionOffsetDirective - Special section offset directive.
377 const char* DwarfSectionOffsetDirective; // Defaults to NULL
379 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
381 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
383 /// DwarfInfoSection - Section directive for Dwarf info.
385 const char *DwarfInfoSection; // Defaults to ".debug_info".
387 /// DwarfLineSection - Section directive for Dwarf info.
389 const char *DwarfLineSection; // Defaults to ".debug_line".
391 /// DwarfFrameSection - Section directive for Dwarf info.
393 const char *DwarfFrameSection; // Defaults to ".debug_frame".
395 /// DwarfPubNamesSection - Section directive for Dwarf info.
397 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
399 /// DwarfPubTypesSection - Section directive for Dwarf info.
401 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
403 /// DwarfStrSection - Section directive for Dwarf info.
405 const char *DwarfStrSection; // Defaults to ".debug_str".
407 /// DwarfLocSection - Section directive for Dwarf info.
409 const char *DwarfLocSection; // Defaults to ".debug_loc".
411 /// DwarfARangesSection - Section directive for Dwarf info.
413 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
415 /// DwarfRangesSection - Section directive for Dwarf info.
417 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
419 /// DwarfMacInfoSection - Section directive for Dwarf info.
421 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
423 /// DwarfEHFrameSection - Section directive for Exception frames.
425 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
427 /// DwarfExceptionSection - Section directive for Exception table.
429 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
431 //===--- CBE Asm Translation Table -----------------------------------===//
433 const char *const *AsmTransCBE; // Defaults to empty
437 virtual ~TargetAsmInfo();
439 /// Measure the specified inline asm to determine an approximation of its
441 virtual unsigned getInlineAsmLength(const char *Str) const;
443 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
444 /// call to be explicit llvm code if it wants to. This is useful for
445 /// turning simple inline asms into LLVM intrinsics, which gives the
446 /// compiler more information about the behavior of the code.
447 virtual bool ExpandInlineAsm(CallInst *CI) const {
451 /// PreferredEHDataFormat - This hook allows the target to select data
452 /// format used for encoding pointers in exception handling data. Reason is
453 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
454 /// if the symbol can be relocated.
455 virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
458 /// SectionKindForGlobal - This hook allows the target to select proper
459 /// section kind used for global emission.
460 virtual SectionKind::Kind
461 SectionKindForGlobal(const GlobalValue *GV) const;
464 /// SectionFlagsForGlobal - This hook allows the target to select proper
465 /// section flags either for given global or for section.
467 SectionFlagsForGlobal(const GlobalValue *GV = NULL,
468 const char* name = NULL) const;
470 /// SectionForGlobal - This hooks returns proper section name for given
471 /// global with all necessary flags and marks.
472 virtual std::string SectionForGlobal(const GlobalValue *GV) const;
474 virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
475 SectionKind::Kind kind) const;
479 const char *getTextSection() const {
482 const char *getDataSection() const {
485 const char *getBSSSection() const {
488 const char *getTLSDataSection() const {
489 return TLSDataSection;
491 const char *getTLSBSSSection() const {
492 return TLSBSSSection;
494 const char *getZeroFillDirective() const {
495 return ZeroFillDirective;
497 const char *getNonexecutableStackDirective() const {
498 return NonexecutableStackDirective;
500 bool needsSet() const {
503 const char *getPCSymbol() const {
506 char getSeparatorChar() const {
507 return SeparatorChar;
509 const char *getCommentString() const {
510 return CommentString;
512 const char *getGlobalPrefix() const {
515 const char *getPrivateGlobalPrefix() const {
516 return PrivateGlobalPrefix;
518 const char *getJumpTableSpecialLabelPrefix() const {
519 return JumpTableSpecialLabelPrefix;
521 const char *getGlobalVarAddrPrefix() const {
522 return GlobalVarAddrPrefix;
524 const char *getGlobalVarAddrSuffix() const {
525 return GlobalVarAddrSuffix;
527 const char *getFunctionAddrPrefix() const {
528 return FunctionAddrPrefix;
530 const char *getFunctionAddrSuffix() const {
531 return FunctionAddrSuffix;
533 const char *getPersonalityPrefix() const {
534 return PersonalityPrefix;
536 const char *getPersonalitySuffix() const {
537 return PersonalitySuffix;
539 bool getNeedsIndirectEncoding() const {
540 return NeedsIndirectEncoding;
542 const char *getInlineAsmStart() const {
543 return InlineAsmStart;
545 const char *getInlineAsmEnd() const {
548 unsigned getAssemblerDialect() const {
549 return AssemblerDialect;
551 const char *getStringConstantPrefix() const {
552 return StringConstantPrefix;
554 const char *getZeroDirective() const {
555 return ZeroDirective;
557 const char *getZeroDirectiveSuffix() const {
558 return ZeroDirectiveSuffix;
560 const char *getAsciiDirective() const {
561 return AsciiDirective;
563 const char *getAscizDirective() const {
564 return AscizDirective;
566 const char *getData8bitsDirective() const {
567 return Data8bitsDirective;
569 const char *getData16bitsDirective() const {
570 return Data16bitsDirective;
572 const char *getData32bitsDirective() const {
573 return Data32bitsDirective;
575 const char *getData64bitsDirective() const {
576 return Data64bitsDirective;
578 const char *getJumpTableDirective() const {
579 return JumpTableDirective;
581 const char *getAlignDirective() const {
582 return AlignDirective;
584 bool getAlignmentIsInBytes() const {
585 return AlignmentIsInBytes;
587 unsigned getTextAlignFillValue() const {
588 return TextAlignFillValue;
590 const char *getSwitchToSectionDirective() const {
591 return SwitchToSectionDirective;
593 const char *getTextSectionStartSuffix() const {
594 return TextSectionStartSuffix;
596 const char *getDataSectionStartSuffix() const {
597 return DataSectionStartSuffix;
599 const char *getSectionEndDirectiveSuffix() const {
600 return SectionEndDirectiveSuffix;
602 const char *getConstantPoolSection() const {
603 return ConstantPoolSection;
605 const char *getJumpTableDataSection() const {
606 return JumpTableDataSection;
608 const char *getCStringSection() const {
609 return CStringSection;
611 const char *getStaticCtorsSection() const {
612 return StaticCtorsSection;
614 const char *getStaticDtorsSection() const {
615 return StaticDtorsSection;
617 const char *getFourByteConstantSection() const {
618 return FourByteConstantSection;
620 const char *getEightByteConstantSection() const {
621 return EightByteConstantSection;
623 const char *getSixteenByteConstantSection() const {
624 return SixteenByteConstantSection;
626 const char *getReadOnlySection() const {
627 return ReadOnlySection;
629 const char *getGlobalDirective() const {
630 return GlobalDirective;
632 const char *getSetDirective() const {
635 const char *getLCOMMDirective() const {
636 return LCOMMDirective;
638 const char *getCOMMDirective() const {
639 return COMMDirective;
641 bool getCOMMDirectiveTakesAlignment() const {
642 return COMMDirectiveTakesAlignment;
644 bool hasDotTypeDotSizeDirective() const {
645 return HasDotTypeDotSizeDirective;
647 const char *getUsedDirective() const {
648 return UsedDirective;
650 const char *getWeakRefDirective() const {
651 return WeakRefDirective;
653 const char *getWeakDefDirective() const {
654 return WeakDefDirective;
656 const char *getHiddenDirective() const {
657 return HiddenDirective;
659 const char *getProtectedDirective() const {
660 return ProtectedDirective;
662 bool isAbsoluteDebugSectionOffsets() const {
663 return AbsoluteDebugSectionOffsets;
665 bool isAbsoluteEHSectionOffsets() const {
666 return AbsoluteEHSectionOffsets;
668 bool hasLEB128() const {
671 bool hasDotLocAndDotFile() const {
672 return HasDotLocAndDotFile;
674 bool doesSupportDebugInformation() const {
675 return SupportsDebugInformation;
677 bool doesSupportExceptionHandling() const {
678 return SupportsExceptionHandling;
680 bool doesDwarfRequireFrameSection() const {
681 return DwarfRequiresFrameSection;
683 const char *getGlobalEHDirective() const {
684 return GlobalEHDirective;
686 bool getSupportsWeakOmittedEHFrame() const {
687 return SupportsWeakOmittedEHFrame;
689 const char *getDwarfSectionOffsetDirective() const {
690 return DwarfSectionOffsetDirective;
692 const char *getDwarfAbbrevSection() const {
693 return DwarfAbbrevSection;
695 const char *getDwarfInfoSection() const {
696 return DwarfInfoSection;
698 const char *getDwarfLineSection() const {
699 return DwarfLineSection;
701 const char *getDwarfFrameSection() const {
702 return DwarfFrameSection;
704 const char *getDwarfPubNamesSection() const {
705 return DwarfPubNamesSection;
707 const char *getDwarfPubTypesSection() const {
708 return DwarfPubTypesSection;
710 const char *getDwarfStrSection() const {
711 return DwarfStrSection;
713 const char *getDwarfLocSection() const {
714 return DwarfLocSection;
716 const char *getDwarfARangesSection() const {
717 return DwarfARangesSection;
719 const char *getDwarfRangesSection() const {
720 return DwarfRangesSection;
722 const char *getDwarfMacInfoSection() const {
723 return DwarfMacInfoSection;
725 const char *getDwarfEHFrameSection() const {
726 return DwarfEHFrameSection;
728 const char *getDwarfExceptionSection() const {
729 return DwarfExceptionSection;
731 const char *const *getAsmCBE() const {