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 /// DebugInfoRequireFrameMoveInfo - Does debugging info require frame move
419 bool DebugInfoRequireFrameMoveInfo; // Defaults to "true"
421 //===--- CBE Asm Translation Table -----------------------------------===//
423 const char *const *AsmTransCBE; // Defaults to empty
427 virtual ~TargetAsmInfo();
429 /// Measure the specified inline asm to determine an approximation of its
431 virtual unsigned getInlineAsmLength(const char *Str) const;
433 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
434 /// call to be explicit llvm code if it wants to. This is useful for
435 /// turning simple inline asms into LLVM intrinsics, which gives the
436 /// compiler more information about the behavior of the code.
437 virtual bool ExpandInlineAsm(CallInst *CI) const {
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,
448 /// SectionKindForGlobal - This hook allows the target to select proper
449 /// section kind used for global emission.
450 SectionKind::Kind SectionKindForGlobal(const GlobalValue *GV) const;
454 const char *getTextSection() const {
457 const char *getDataSection() const {
460 const char *getBSSSection() const {
463 const char *getTLSDataSection() const {
464 return TLSDataSection;
466 const char *getTLSBSSSection() const {
467 return TLSBSSSection;
469 const char *getZeroFillDirective() const {
470 return ZeroFillDirective;
472 const char *getNonexecutableStackDirective() const {
473 return NonexecutableStackDirective;
475 bool needsSet() const {
478 const char *getPCSymbol() const {
481 char getSeparatorChar() const {
482 return SeparatorChar;
484 const char *getCommentString() const {
485 return CommentString;
487 const char *getGlobalPrefix() const {
490 const char *getPrivateGlobalPrefix() const {
491 return PrivateGlobalPrefix;
493 const char *getJumpTableSpecialLabelPrefix() const {
494 return JumpTableSpecialLabelPrefix;
496 const char *getGlobalVarAddrPrefix() const {
497 return GlobalVarAddrPrefix;
499 const char *getGlobalVarAddrSuffix() const {
500 return GlobalVarAddrSuffix;
502 const char *getFunctionAddrPrefix() const {
503 return FunctionAddrPrefix;
505 const char *getFunctionAddrSuffix() const {
506 return FunctionAddrSuffix;
508 const char *getPersonalityPrefix() const {
509 return PersonalityPrefix;
511 const char *getPersonalitySuffix() const {
512 return PersonalitySuffix;
514 bool getNeedsIndirectEncoding() const {
515 return NeedsIndirectEncoding;
517 const char *getInlineAsmStart() const {
518 return InlineAsmStart;
520 const char *getInlineAsmEnd() const {
523 unsigned getAssemblerDialect() const {
524 return AssemblerDialect;
526 const char *getStringConstantPrefix() const {
527 return StringConstantPrefix;
529 const char *getZeroDirective() const {
530 return ZeroDirective;
532 const char *getZeroDirectiveSuffix() const {
533 return ZeroDirectiveSuffix;
535 const char *getAsciiDirective() const {
536 return AsciiDirective;
538 const char *getAscizDirective() const {
539 return AscizDirective;
541 const char *getData8bitsDirective() const {
542 return Data8bitsDirective;
544 const char *getData16bitsDirective() const {
545 return Data16bitsDirective;
547 const char *getData32bitsDirective() const {
548 return Data32bitsDirective;
550 const char *getData64bitsDirective() const {
551 return Data64bitsDirective;
553 const char *getJumpTableDirective() const {
554 return JumpTableDirective;
556 const char *getAlignDirective() const {
557 return AlignDirective;
559 bool getAlignmentIsInBytes() const {
560 return AlignmentIsInBytes;
562 unsigned getTextAlignFillValue() const {
563 return TextAlignFillValue;
565 const char *getSwitchToSectionDirective() const {
566 return SwitchToSectionDirective;
568 const char *getTextSectionStartSuffix() const {
569 return TextSectionStartSuffix;
571 const char *getDataSectionStartSuffix() const {
572 return DataSectionStartSuffix;
574 const char *getSectionEndDirectiveSuffix() const {
575 return SectionEndDirectiveSuffix;
577 const char *getConstantPoolSection() const {
578 return ConstantPoolSection;
580 const char *getJumpTableDataSection() const {
581 return JumpTableDataSection;
583 const char *getCStringSection() const {
584 return CStringSection;
586 const char *getStaticCtorsSection() const {
587 return StaticCtorsSection;
589 const char *getStaticDtorsSection() const {
590 return StaticDtorsSection;
592 const char *getFourByteConstantSection() const {
593 return FourByteConstantSection;
595 const char *getEightByteConstantSection() const {
596 return EightByteConstantSection;
598 const char *getSixteenByteConstantSection() const {
599 return SixteenByteConstantSection;
601 const char *getReadOnlySection() const {
602 return ReadOnlySection;
604 const char *getGlobalDirective() const {
605 return GlobalDirective;
607 const char *getSetDirective() const {
610 const char *getLCOMMDirective() const {
611 return LCOMMDirective;
613 const char *getCOMMDirective() const {
614 return COMMDirective;
616 bool getCOMMDirectiveTakesAlignment() const {
617 return COMMDirectiveTakesAlignment;
619 bool hasDotTypeDotSizeDirective() const {
620 return HasDotTypeDotSizeDirective;
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 const char *getGlobalEHDirective() const {
659 return GlobalEHDirective;
661 bool getSupportsWeakOmittedEHFrame() const {
662 return SupportsWeakOmittedEHFrame;
664 const char *getDwarfSectionOffsetDirective() const {
665 return DwarfSectionOffsetDirective;
667 const char *getDwarfAbbrevSection() const {
668 return DwarfAbbrevSection;
670 const char *getDwarfInfoSection() const {
671 return DwarfInfoSection;
673 const char *getDwarfLineSection() const {
674 return DwarfLineSection;
676 const char *getDwarfFrameSection() const {
677 return DwarfFrameSection;
679 const char *getDwarfPubNamesSection() const {
680 return DwarfPubNamesSection;
682 const char *getDwarfPubTypesSection() const {
683 return DwarfPubTypesSection;
685 const char *getDwarfStrSection() const {
686 return DwarfStrSection;
688 const char *getDwarfLocSection() const {
689 return DwarfLocSection;
691 const char *getDwarfARangesSection() const {
692 return DwarfARangesSection;
694 const char *getDwarfRangesSection() const {
695 return DwarfRangesSection;
697 const char *getDwarfMacInfoSection() const {
698 return DwarfMacInfoSection;
700 const char *getDwarfEHFrameSection() const {
701 return DwarfEHFrameSection;
703 const char *getDwarfExceptionSection() const {
704 return DwarfExceptionSection;
706 bool doesDebugInfoRequireFrameMoveInfo() const {
707 return DebugInfoRequireFrameMoveInfo;
709 const char *const *getAsmCBE() const {