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 Text, ///< Text section
34 Data, ///< Data section
36 ROData, ///< Readonly data section
37 RODataMergeStr, ///< Readonly data section (mergeable strings)
38 RODataMergeConst, ///< Readonly data section (mergeable constants)
39 ThreadData, ///< Initialized TLS data objects
40 ThreadBSS ///< Uninitialized TLS data objects
48 /// TargetAsmInfo - This class is intended to be used as a base class for asm
49 /// properties and features specific to the target.
52 //===------------------------------------------------------------------===//
53 // Properties to be set by the target writer, used to configure asm printer.
56 /// TextSection - Section directive for standard text.
58 const char *TextSection; // Defaults to ".text".
60 /// DataSection - Section directive for standard data.
62 const char *DataSection; // Defaults to ".data".
64 /// BSSSection - Section directive for uninitialized data. Null if this
65 /// target doesn't support a BSS section.
67 const char *BSSSection; // Default to ".bss".
69 /// TLSDataSection - Section directive for Thread Local data.
71 const char *TLSDataSection;// Defaults to ".section .tdata,"awT",@progbits".
73 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
74 /// Null if this target doesn't support a BSS section.
76 const char *TLSBSSSection;// Default to ".section .tbss,"awT",@nobits".
78 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
79 /// section on this target. Null if this target doesn't support zerofill.
80 const char *ZeroFillDirective; // Default is null.
82 /// NonexecutableStackDirective - Directive for declaring to the
83 /// linker and beyond that the emitted code does not require stack
84 /// memory to be executable.
85 const char *NonexecutableStackDirective; // Default is null.
87 /// NeedsSet - True if target asm treats expressions in data directives
88 /// as linktime-relocatable. For assembly-time computation, we need to
92 /// is computed at assembly time, while
94 /// is relocated if the relative locations of x and y change at linktime.
95 /// We want both these things in different places.
96 bool NeedsSet; // Defaults to false.
98 /// MaxInstLength - This is the maximum possible length of an instruction,
99 /// which is needed to compute the size of an inline asm.
100 unsigned MaxInstLength; // Defaults to 4.
102 /// PCSymbol - The symbol used to represent the current PC. Used in PC
103 /// relative expressions.
104 const char *PCSymbol; // Defaults to "$".
106 /// SeparatorChar - This character, if specified, is used to separate
107 /// instructions from each other when on the same line. This is used to
108 /// measure inline asm instructions.
109 char SeparatorChar; // Defaults to ';'
111 /// CommentString - This indicates the comment character used by the
113 const char *CommentString; // Defaults to "#"
115 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
116 /// onto all global symbols. This is often used for "_" or ".".
117 const char *GlobalPrefix; // Defaults to ""
119 /// PrivateGlobalPrefix - This prefix is used for globals like constant
120 /// pool entries that are completely private to the .o file and should not
121 /// have names in the .o file. This is often "." or "L".
122 const char *PrivateGlobalPrefix; // Defaults to "."
124 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
125 /// emitted before jump tables with the specified prefix.
126 const char *JumpTableSpecialLabelPrefix; // Default to null.
128 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
129 /// will enclose any GlobalVariable (that isn't a function)
131 const char *GlobalVarAddrPrefix; // Defaults to ""
132 const char *GlobalVarAddrSuffix; // Defaults to ""
134 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
135 /// will enclose any GlobalVariable that points to a function.
136 /// For example, this is used by the IA64 backend to materialize
137 /// function descriptors, by decorating the ".data8" object with the
138 /// @verbatim @fptr( ) @endverbatim
139 /// link-relocation operator.
141 const char *FunctionAddrPrefix; // Defaults to ""
142 const char *FunctionAddrSuffix; // Defaults to ""
144 /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
145 /// enclose any personality function in the common frame section.
147 const char *PersonalityPrefix; // Defaults to ""
148 const char *PersonalitySuffix; // Defaults to ""
150 /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
153 bool NeedsIndirectEncoding; // Defaults to false
155 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
156 /// emit before and after an inline assembly statement.
157 const char *InlineAsmStart; // Defaults to "#APP\n"
158 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
160 /// AssemblerDialect - Which dialect of an assembler variant to use.
161 unsigned AssemblerDialect; // Defaults to 0
163 /// StringConstantPrefix - Prefix for FEs to use when generating unnamed
164 /// constant strings. These names get run through the Mangler later; if
165 /// you want the Mangler not to add the GlobalPrefix as well,
166 /// use '\1' as the first character.
167 const char *StringConstantPrefix; // Defaults to ".str"
169 //===--- Data Emission Directives -------------------------------------===//
171 /// ZeroDirective - this should be set to the directive used to get some
172 /// number of zero bytes emitted to the current section. Common cases are
173 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
174 /// Data*bitsDirective's will be used to emit zero bytes.
175 const char *ZeroDirective; // Defaults to "\t.zero\t"
176 const char *ZeroDirectiveSuffix; // Defaults to ""
178 /// AsciiDirective - This directive allows emission of an ascii string with
179 /// the standard C escape characters embedded into it.
180 const char *AsciiDirective; // Defaults to "\t.ascii\t"
182 /// AscizDirective - If not null, this allows for special handling of
183 /// zero terminated strings on this target. This is commonly supported as
184 /// ".asciz". If a target doesn't support this, it can be set to null.
185 const char *AscizDirective; // Defaults to "\t.asciz\t"
187 /// DataDirectives - These directives are used to output some unit of
188 /// integer data to the current section. If a data directive is set to
189 /// null, smaller data directives will be used to emit the large sizes.
190 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
191 const char *Data16bitsDirective; // Defaults to "\t.short\t"
192 const char *Data32bitsDirective; // Defaults to "\t.long\t"
193 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
195 //===--- Alignment Information ----------------------------------------===//
197 /// AlignDirective - The directive used to emit round up to an alignment
200 const char *AlignDirective; // Defaults to "\t.align\t"
202 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
203 /// emits ".align N" directives, where N is the number of bytes to align to.
204 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
206 bool AlignmentIsInBytes; // Defaults to true
208 /// TextAlignFillValue - If non-zero, this is used to fill the executable
209 /// space created as the result of a alignment directive.
210 unsigned TextAlignFillValue;
212 //===--- Section Switching Directives ---------------------------------===//
214 /// SwitchToSectionDirective - This is the directive used when we want to
215 /// emit a global to an arbitrary section. The section name is emited after
217 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
219 /// TextSectionStartSuffix - This is printed after each start of section
220 /// directive for text sections.
221 const char *TextSectionStartSuffix; // Defaults to "".
223 /// DataSectionStartSuffix - This is printed after each start of section
224 /// directive for data sections.
225 const char *DataSectionStartSuffix; // Defaults to "".
227 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
228 /// section with the section name and this suffix printed.
229 const char *SectionEndDirectiveSuffix;// Defaults to null.
231 /// ConstantPoolSection - This is the section that we SwitchToSection right
232 /// before emitting the constant pool for a function.
233 const char *ConstantPoolSection; // Defaults to "\t.section .rodata"
235 /// JumpTableDataSection - This is the section that we SwitchToSection right
236 /// before emitting the jump tables for a function when the relocation model
238 const char *JumpTableDataSection; // Defaults to "\t.section .rodata"
240 /// JumpTableDirective - if non-null, the directive to emit before a jump
242 const char *JumpTableDirective;
244 /// CStringSection - If not null, this allows for special handling of
245 /// cstring constants (null terminated string that does not contain any
246 /// other null bytes) on this target. This is commonly supported as
248 const char *CStringSection; // Defaults to NULL
250 /// StaticCtorsSection - This is the directive that is emitted to switch to
251 /// a section to emit the static constructor list.
252 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
253 const char *StaticCtorsSection;
255 /// StaticDtorsSection - This is the directive that is emitted to switch to
256 /// a section to emit the static destructor list.
257 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
258 const char *StaticDtorsSection;
260 /// FourByteConstantSection, EightByteConstantSection,
261 /// SixteenByteConstantSection - These are special sections where we place
262 /// 4-, 8-, and 16- byte constant literals.
263 const char *FourByteConstantSection;
264 const char *EightByteConstantSection;
265 const char *SixteenByteConstantSection;
267 /// ReadOnlySection - This is the directive that is emitted to switch to a
268 /// read-only section for constant data (e.g. data declared const,
270 const char *ReadOnlySection; // Defaults to NULL
272 //===--- Global Variable Emission Directives --------------------------===//
274 /// GlobalDirective - This is the directive used to declare a global entity.
276 const char *GlobalDirective; // Defaults to NULL.
278 /// SetDirective - This is the name of a directive that can be used to tell
279 /// the assembler to set the value of a variable to some expression.
280 const char *SetDirective; // Defaults to null.
282 /// LCOMMDirective - This is the name of a directive (if supported) that can
283 /// be used to efficiently declare a local (internal) block of zero
284 /// initialized data in the .bss/.data section. The syntax expected is:
285 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
287 const char *LCOMMDirective; // Defaults to null.
289 const char *COMMDirective; // Defaults to "\t.comm\t".
291 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
292 /// argument that specifies the alignment of the declaration.
293 bool COMMDirectiveTakesAlignment; // Defaults to true.
295 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
296 /// directives, this is true for most ELF targets.
297 bool HasDotTypeDotSizeDirective; // Defaults to true.
299 /// UsedDirective - This directive, if non-null, is used to declare a global
300 /// as being used somehow that the assembler can't see. This prevents dead
301 /// code elimination on some targets.
302 const char *UsedDirective; // Defaults to null.
304 /// WeakRefDirective - This directive, if non-null, is used to declare a
305 /// global as being a weak undefined symbol.
306 const char *WeakRefDirective; // Defaults to null.
308 /// WeakDefDirective - This directive, if non-null, is used to declare a
309 /// global as being a weak defined symbol.
310 const char *WeakDefDirective; // Defaults to null.
312 /// HiddenDirective - This directive, if non-null, is used to declare a
313 /// global or function as having hidden visibility.
314 const char *HiddenDirective; // Defaults to "\t.hidden\t".
316 /// ProtectedDirective - This directive, if non-null, is used to declare a
317 /// global or function as having protected visibility.
318 const char *ProtectedDirective; // Defaults to "\t.protected\t".
320 //===--- Dwarf Emission Directives -----------------------------------===//
322 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
323 /// offsets for debug information. Defaults to false.
324 bool AbsoluteDebugSectionOffsets;
326 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
327 /// offsets for EH information. Defaults to false.
328 bool AbsoluteEHSectionOffsets;
330 /// HasLEB128 - True if target asm supports leb128 directives.
332 bool HasLEB128; // Defaults to false.
334 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
335 /// directives for emitting debugging information.
337 bool HasDotLocAndDotFile; // Defaults to false.
339 /// SupportsDebugInformation - True if target supports emission of debugging
341 bool SupportsDebugInformation;
343 /// SupportsExceptionHandling - True if target supports
344 /// exception handling.
346 bool SupportsExceptionHandling; // Defaults to false.
348 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
350 bool DwarfRequiresFrameSection; // Defaults to true.
352 /// GlobalEHDirective - This is the directive used to make exception frame
353 /// tables globally visible.
355 const char *GlobalEHDirective; // Defaults to NULL.
357 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
358 /// handle a weak_definition of constant 0 for an omitted EH frame.
359 bool SupportsWeakOmittedEHFrame; // Defaults to true.
361 /// DwarfSectionOffsetDirective - Special section offset directive.
362 const char* DwarfSectionOffsetDirective; // Defaults to NULL
364 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
366 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
368 /// DwarfInfoSection - Section directive for Dwarf info.
370 const char *DwarfInfoSection; // Defaults to ".debug_info".
372 /// DwarfLineSection - Section directive for Dwarf info.
374 const char *DwarfLineSection; // Defaults to ".debug_line".
376 /// DwarfFrameSection - Section directive for Dwarf info.
378 const char *DwarfFrameSection; // Defaults to ".debug_frame".
380 /// DwarfPubNamesSection - Section directive for Dwarf info.
382 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
384 /// DwarfPubTypesSection - Section directive for Dwarf info.
386 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
388 /// DwarfStrSection - Section directive for Dwarf info.
390 const char *DwarfStrSection; // Defaults to ".debug_str".
392 /// DwarfLocSection - Section directive for Dwarf info.
394 const char *DwarfLocSection; // Defaults to ".debug_loc".
396 /// DwarfARangesSection - Section directive for Dwarf info.
398 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
400 /// DwarfRangesSection - Section directive for Dwarf info.
402 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
404 /// DwarfMacInfoSection - Section directive for Dwarf info.
406 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
408 /// DwarfEHFrameSection - Section directive for Exception frames.
410 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
412 /// DwarfExceptionSection - Section directive for Exception table.
414 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
416 //===--- CBE Asm Translation Table -----------------------------------===//
418 const char *const *AsmTransCBE; // Defaults to empty
422 virtual ~TargetAsmInfo();
424 /// Measure the specified inline asm to determine an approximation of its
426 virtual unsigned getInlineAsmLength(const char *Str) const;
428 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
429 /// call to be explicit llvm code if it wants to. This is useful for
430 /// turning simple inline asms into LLVM intrinsics, which gives the
431 /// compiler more information about the behavior of the code.
432 virtual bool ExpandInlineAsm(CallInst *CI) const {
436 /// PreferredEHDataFormat - This hook allows the target to select data
437 /// format used for encoding pointers in exception handling data. Reason is
438 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
439 /// if the symbol can be relocated.
440 virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
443 /// SectionKindForGlobal - This hook allows the target to select proper
444 /// section kind used for global emission.
445 SectionKind::Kind SectionKindForGlobal(const GlobalValue *GV) const;
449 const char *getTextSection() const {
452 const char *getDataSection() const {
455 const char *getBSSSection() const {
458 const char *getTLSDataSection() const {
459 return TLSDataSection;
461 const char *getTLSBSSSection() const {
462 return TLSBSSSection;
464 const char *getZeroFillDirective() const {
465 return ZeroFillDirective;
467 const char *getNonexecutableStackDirective() const {
468 return NonexecutableStackDirective;
470 bool needsSet() const {
473 const char *getPCSymbol() const {
476 char getSeparatorChar() const {
477 return SeparatorChar;
479 const char *getCommentString() const {
480 return CommentString;
482 const char *getGlobalPrefix() const {
485 const char *getPrivateGlobalPrefix() const {
486 return PrivateGlobalPrefix;
488 const char *getJumpTableSpecialLabelPrefix() const {
489 return JumpTableSpecialLabelPrefix;
491 const char *getGlobalVarAddrPrefix() const {
492 return GlobalVarAddrPrefix;
494 const char *getGlobalVarAddrSuffix() const {
495 return GlobalVarAddrSuffix;
497 const char *getFunctionAddrPrefix() const {
498 return FunctionAddrPrefix;
500 const char *getFunctionAddrSuffix() const {
501 return FunctionAddrSuffix;
503 const char *getPersonalityPrefix() const {
504 return PersonalityPrefix;
506 const char *getPersonalitySuffix() const {
507 return PersonalitySuffix;
509 bool getNeedsIndirectEncoding() const {
510 return NeedsIndirectEncoding;
512 const char *getInlineAsmStart() const {
513 return InlineAsmStart;
515 const char *getInlineAsmEnd() const {
518 unsigned getAssemblerDialect() const {
519 return AssemblerDialect;
521 const char *getStringConstantPrefix() const {
522 return StringConstantPrefix;
524 const char *getZeroDirective() const {
525 return ZeroDirective;
527 const char *getZeroDirectiveSuffix() const {
528 return ZeroDirectiveSuffix;
530 const char *getAsciiDirective() const {
531 return AsciiDirective;
533 const char *getAscizDirective() const {
534 return AscizDirective;
536 const char *getData8bitsDirective() const {
537 return Data8bitsDirective;
539 const char *getData16bitsDirective() const {
540 return Data16bitsDirective;
542 const char *getData32bitsDirective() const {
543 return Data32bitsDirective;
545 const char *getData64bitsDirective() const {
546 return Data64bitsDirective;
548 const char *getJumpTableDirective() const {
549 return JumpTableDirective;
551 const char *getAlignDirective() const {
552 return AlignDirective;
554 bool getAlignmentIsInBytes() const {
555 return AlignmentIsInBytes;
557 unsigned getTextAlignFillValue() const {
558 return TextAlignFillValue;
560 const char *getSwitchToSectionDirective() const {
561 return SwitchToSectionDirective;
563 const char *getTextSectionStartSuffix() const {
564 return TextSectionStartSuffix;
566 const char *getDataSectionStartSuffix() const {
567 return DataSectionStartSuffix;
569 const char *getSectionEndDirectiveSuffix() const {
570 return SectionEndDirectiveSuffix;
572 const char *getConstantPoolSection() const {
573 return ConstantPoolSection;
575 const char *getJumpTableDataSection() const {
576 return JumpTableDataSection;
578 const char *getCStringSection() const {
579 return CStringSection;
581 const char *getStaticCtorsSection() const {
582 return StaticCtorsSection;
584 const char *getStaticDtorsSection() const {
585 return StaticDtorsSection;
587 const char *getFourByteConstantSection() const {
588 return FourByteConstantSection;
590 const char *getEightByteConstantSection() const {
591 return EightByteConstantSection;
593 const char *getSixteenByteConstantSection() const {
594 return SixteenByteConstantSection;
596 const char *getReadOnlySection() const {
597 return ReadOnlySection;
599 const char *getGlobalDirective() const {
600 return GlobalDirective;
602 const char *getSetDirective() const {
605 const char *getLCOMMDirective() const {
606 return LCOMMDirective;
608 const char *getCOMMDirective() const {
609 return COMMDirective;
611 bool getCOMMDirectiveTakesAlignment() const {
612 return COMMDirectiveTakesAlignment;
614 bool hasDotTypeDotSizeDirective() const {
615 return HasDotTypeDotSizeDirective;
617 const char *getUsedDirective() const {
618 return UsedDirective;
620 const char *getWeakRefDirective() const {
621 return WeakRefDirective;
623 const char *getWeakDefDirective() const {
624 return WeakDefDirective;
626 const char *getHiddenDirective() const {
627 return HiddenDirective;
629 const char *getProtectedDirective() const {
630 return ProtectedDirective;
632 bool isAbsoluteDebugSectionOffsets() const {
633 return AbsoluteDebugSectionOffsets;
635 bool isAbsoluteEHSectionOffsets() const {
636 return AbsoluteEHSectionOffsets;
638 bool hasLEB128() const {
641 bool hasDotLocAndDotFile() const {
642 return HasDotLocAndDotFile;
644 bool doesSupportDebugInformation() const {
645 return SupportsDebugInformation;
647 bool doesSupportExceptionHandling() const {
648 return SupportsExceptionHandling;
650 bool doesDwarfRequireFrameSection() const {
651 return DwarfRequiresFrameSection;
653 const char *getGlobalEHDirective() const {
654 return GlobalEHDirective;
656 bool getSupportsWeakOmittedEHFrame() const {
657 return SupportsWeakOmittedEHFrame;
659 const char *getDwarfSectionOffsetDirective() const {
660 return DwarfSectionOffsetDirective;
662 const char *getDwarfAbbrevSection() const {
663 return DwarfAbbrevSection;
665 const char *getDwarfInfoSection() const {
666 return DwarfInfoSection;
668 const char *getDwarfLineSection() const {
669 return DwarfLineSection;
671 const char *getDwarfFrameSection() const {
672 return DwarfFrameSection;
674 const char *getDwarfPubNamesSection() const {
675 return DwarfPubNamesSection;
677 const char *getDwarfPubTypesSection() const {
678 return DwarfPubTypesSection;
680 const char *getDwarfStrSection() const {
681 return DwarfStrSection;
683 const char *getDwarfLocSection() const {
684 return DwarfLocSection;
686 const char *getDwarfARangesSection() const {
687 return DwarfARangesSection;
689 const char *getDwarfRangesSection() const {
690 return DwarfRangesSection;
692 const char *getDwarfMacInfoSection() const {
693 return DwarfMacInfoSection;
695 const char *getDwarfEHFrameSection() const {
696 return DwarfEHFrameSection;
698 const char *getDwarfExceptionSection() const {
699 return DwarfExceptionSection;
701 const char *const *getAsmCBE() const {