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/CodeGen/MachineFunctionPass.h"
20 #include "llvm/Support/DataTypes.h"
23 // DWARF encoding query type
24 namespace DwarfEncoding {
32 namespace SectionKind {
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
49 /// TargetAsmInfo - This class is intended to be used as a base class for asm
50 /// properties and features specific to the target.
53 //===------------------------------------------------------------------===//
54 // Properties to be set by the target writer, used to configure asm printer.
57 /// TextSection - Section directive for standard text.
59 const char *TextSection; // Defaults to ".text".
61 /// DataSection - Section directive for standard data.
63 const char *DataSection; // Defaults to ".data".
65 /// BSSSection - Section directive for uninitialized data. Null if this
66 /// target doesn't support a BSS section.
68 const char *BSSSection; // Default to ".bss".
70 /// TLSDataSection - Section directive for Thread Local data.
72 const char *TLSDataSection;// Defaults to ".section .tdata,"awT",@progbits".
74 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
75 /// Null if this target doesn't support a BSS section.
77 const char *TLSBSSSection;// Default to ".section .tbss,"awT",@nobits".
79 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
80 /// section on this target. Null if this target doesn't support zerofill.
81 const char *ZeroFillDirective; // Default is null.
83 /// NonexecutableStackDirective - Directive for declaring to the
84 /// linker and beyond that the emitted code does not require stack
85 /// memory to be executable.
86 const char *NonexecutableStackDirective; // Default is null.
88 /// NeedsSet - True if target asm treats expressions in data directives
89 /// as linktime-relocatable. For assembly-time computation, we need to
93 /// is computed at assembly time, while
95 /// is relocated if the relative locations of x and y change at linktime.
96 /// We want both these things in different places.
97 bool NeedsSet; // Defaults to false.
99 /// MaxInstLength - This is the maximum possible length of an instruction,
100 /// which is needed to compute the size of an inline asm.
101 unsigned MaxInstLength; // Defaults to 4.
103 /// PCSymbol - The symbol used to represent the current PC. Used in PC
104 /// relative expressions.
105 const char *PCSymbol; // Defaults to "$".
107 /// SeparatorChar - This character, if specified, is used to separate
108 /// instructions from each other when on the same line. This is used to
109 /// measure inline asm instructions.
110 char SeparatorChar; // Defaults to ';'
112 /// CommentString - This indicates the comment character used by the
114 const char *CommentString; // Defaults to "#"
116 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
117 /// onto all global symbols. This is often used for "_" or ".".
118 const char *GlobalPrefix; // Defaults to ""
120 /// PrivateGlobalPrefix - This prefix is used for globals like constant
121 /// pool entries that are completely private to the .o file and should not
122 /// have names in the .o file. This is often "." or "L".
123 const char *PrivateGlobalPrefix; // Defaults to "."
125 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
126 /// emitted before jump tables with the specified prefix.
127 const char *JumpTableSpecialLabelPrefix; // Default to null.
129 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
130 /// will enclose any GlobalVariable (that isn't a function)
132 const char *GlobalVarAddrPrefix; // Defaults to ""
133 const char *GlobalVarAddrSuffix; // Defaults to ""
135 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
136 /// will enclose any GlobalVariable that points to a function.
137 /// For example, this is used by the IA64 backend to materialize
138 /// function descriptors, by decorating the ".data8" object with the
139 /// @verbatim @fptr( ) @endverbatim
140 /// link-relocation operator.
142 const char *FunctionAddrPrefix; // Defaults to ""
143 const char *FunctionAddrSuffix; // Defaults to ""
145 /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
146 /// enclose any personality function in the common frame section.
148 const char *PersonalityPrefix; // Defaults to ""
149 const char *PersonalitySuffix; // Defaults to ""
151 /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
154 bool NeedsIndirectEncoding; // Defaults to false
156 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
157 /// emit before and after an inline assembly statement.
158 const char *InlineAsmStart; // Defaults to "#APP\n"
159 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
161 /// AssemblerDialect - Which dialect of an assembler variant to use.
162 unsigned AssemblerDialect; // Defaults to 0
164 /// StringConstantPrefix - Prefix for FEs to use when generating unnamed
165 /// constant strings. These names get run through the Mangler later; if
166 /// you want the Mangler not to add the GlobalPrefix as well,
167 /// use '\1' as the first character.
168 const char *StringConstantPrefix; // Defaults to ".str"
170 //===--- Data Emission Directives -------------------------------------===//
172 /// ZeroDirective - this should be set to the directive used to get some
173 /// number of zero bytes emitted to the current section. Common cases are
174 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
175 /// Data*bitsDirective's will be used to emit zero bytes.
176 const char *ZeroDirective; // Defaults to "\t.zero\t"
177 const char *ZeroDirectiveSuffix; // Defaults to ""
179 /// AsciiDirective - This directive allows emission of an ascii string with
180 /// the standard C escape characters embedded into it.
181 const char *AsciiDirective; // Defaults to "\t.ascii\t"
183 /// AscizDirective - If not null, this allows for special handling of
184 /// zero terminated strings on this target. This is commonly supported as
185 /// ".asciz". If a target doesn't support this, it can be set to null.
186 const char *AscizDirective; // Defaults to "\t.asciz\t"
188 /// DataDirectives - These directives are used to output some unit of
189 /// integer data to the current section. If a data directive is set to
190 /// null, smaller data directives will be used to emit the large sizes.
191 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
192 const char *Data16bitsDirective; // Defaults to "\t.short\t"
193 const char *Data32bitsDirective; // Defaults to "\t.long\t"
194 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
196 //===--- Alignment Information ----------------------------------------===//
198 /// AlignDirective - The directive used to emit round up to an alignment
201 const char *AlignDirective; // Defaults to "\t.align\t"
203 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
204 /// emits ".align N" directives, where N is the number of bytes to align to.
205 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
207 bool AlignmentIsInBytes; // Defaults to true
209 /// TextAlignFillValue - If non-zero, this is used to fill the executable
210 /// space created as the result of a alignment directive.
211 unsigned TextAlignFillValue;
213 //===--- Section Switching Directives ---------------------------------===//
215 /// SwitchToSectionDirective - This is the directive used when we want to
216 /// emit a global to an arbitrary section. The section name is emited after
218 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
220 /// TextSectionStartSuffix - This is printed after each start of section
221 /// directive for text sections.
222 const char *TextSectionStartSuffix; // Defaults to "".
224 /// DataSectionStartSuffix - This is printed after each start of section
225 /// directive for data sections.
226 const char *DataSectionStartSuffix; // Defaults to "".
228 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
229 /// section with the section name and this suffix printed.
230 const char *SectionEndDirectiveSuffix;// Defaults to null.
232 /// ConstantPoolSection - This is the section that we SwitchToSection right
233 /// before emitting the constant pool for a function.
234 const char *ConstantPoolSection; // Defaults to "\t.section .rodata"
236 /// JumpTableDataSection - This is the section that we SwitchToSection right
237 /// before emitting the jump tables for a function when the relocation model
239 const char *JumpTableDataSection; // Defaults to "\t.section .rodata"
241 /// JumpTableDirective - if non-null, the directive to emit before a jump
243 const char *JumpTableDirective;
245 /// CStringSection - If not null, this allows for special handling of
246 /// cstring constants (null terminated string that does not contain any
247 /// other null bytes) on this target. This is commonly supported as
249 const char *CStringSection; // Defaults to NULL
251 /// StaticCtorsSection - This is the directive that is emitted to switch to
252 /// a section to emit the static constructor list.
253 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
254 const char *StaticCtorsSection;
256 /// StaticDtorsSection - This is the directive that is emitted to switch to
257 /// a section to emit the static destructor list.
258 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
259 const char *StaticDtorsSection;
261 /// FourByteConstantSection, EightByteConstantSection,
262 /// SixteenByteConstantSection - These are special sections where we place
263 /// 4-, 8-, and 16- byte constant literals.
264 const char *FourByteConstantSection;
265 const char *EightByteConstantSection;
266 const char *SixteenByteConstantSection;
268 /// ReadOnlySection - This is the directive that is emitted to switch to a
269 /// read-only section for constant data (e.g. data declared const,
271 const char *ReadOnlySection; // Defaults to NULL
273 //===--- Global Variable Emission Directives --------------------------===//
275 /// GlobalDirective - This is the directive used to declare a global entity.
277 const char *GlobalDirective; // Defaults to NULL.
279 /// SetDirective - This is the name of a directive that can be used to tell
280 /// the assembler to set the value of a variable to some expression.
281 const char *SetDirective; // Defaults to null.
283 /// LCOMMDirective - This is the name of a directive (if supported) that can
284 /// be used to efficiently declare a local (internal) block of zero
285 /// initialized data in the .bss/.data section. The syntax expected is:
286 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
288 const char *LCOMMDirective; // Defaults to null.
290 const char *COMMDirective; // Defaults to "\t.comm\t".
292 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
293 /// argument that specifies the alignment of the declaration.
294 bool COMMDirectiveTakesAlignment; // Defaults to true.
296 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
297 /// directives, this is true for most ELF targets.
298 bool HasDotTypeDotSizeDirective; // Defaults to true.
300 /// UsedDirective - This directive, if non-null, is used to declare a global
301 /// as being used somehow that the assembler can't see. This prevents dead
302 /// code elimination on some targets.
303 const char *UsedDirective; // Defaults to null.
305 /// WeakRefDirective - This directive, if non-null, is used to declare a
306 /// global as being a weak undefined symbol.
307 const char *WeakRefDirective; // Defaults to null.
309 /// WeakDefDirective - This directive, if non-null, is used to declare a
310 /// global as being a weak defined symbol.
311 const char *WeakDefDirective; // Defaults to null.
313 /// HiddenDirective - This directive, if non-null, is used to declare a
314 /// global or function as having hidden visibility.
315 const char *HiddenDirective; // Defaults to "\t.hidden\t".
317 /// ProtectedDirective - This directive, if non-null, is used to declare a
318 /// global or function as having protected visibility.
319 const char *ProtectedDirective; // Defaults to "\t.protected\t".
321 //===--- Dwarf Emission Directives -----------------------------------===//
323 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
324 /// offsets for debug information. Defaults to false.
325 bool AbsoluteDebugSectionOffsets;
327 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
328 /// offsets for EH information. Defaults to false.
329 bool AbsoluteEHSectionOffsets;
331 /// HasLEB128 - True if target asm supports leb128 directives.
333 bool HasLEB128; // Defaults to false.
335 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
336 /// directives for emitting debugging information.
338 bool HasDotLocAndDotFile; // Defaults to false.
340 /// SupportsDebugInformation - True if target supports emission of debugging
342 bool SupportsDebugInformation;
344 /// SupportsExceptionHandling - True if target supports
345 /// exception handling.
347 bool SupportsExceptionHandling; // Defaults to false.
349 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
351 bool DwarfRequiresFrameSection; // Defaults to true.
353 /// GlobalEHDirective - This is the directive used to make exception frame
354 /// tables globally visible.
356 const char *GlobalEHDirective; // Defaults to NULL.
358 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
359 /// handle a weak_definition of constant 0 for an omitted EH frame.
360 bool SupportsWeakOmittedEHFrame; // Defaults to true.
362 /// DwarfSectionOffsetDirective - Special section offset directive.
363 const char* DwarfSectionOffsetDirective; // Defaults to NULL
365 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
367 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
369 /// DwarfInfoSection - Section directive for Dwarf info.
371 const char *DwarfInfoSection; // Defaults to ".debug_info".
373 /// DwarfLineSection - Section directive for Dwarf info.
375 const char *DwarfLineSection; // Defaults to ".debug_line".
377 /// DwarfFrameSection - Section directive for Dwarf info.
379 const char *DwarfFrameSection; // Defaults to ".debug_frame".
381 /// DwarfPubNamesSection - Section directive for Dwarf info.
383 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
385 /// DwarfPubTypesSection - Section directive for Dwarf info.
387 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
389 /// DwarfStrSection - Section directive for Dwarf info.
391 const char *DwarfStrSection; // Defaults to ".debug_str".
393 /// DwarfLocSection - Section directive for Dwarf info.
395 const char *DwarfLocSection; // Defaults to ".debug_loc".
397 /// DwarfARangesSection - Section directive for Dwarf info.
399 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
401 /// DwarfRangesSection - Section directive for Dwarf info.
403 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
405 /// DwarfMacInfoSection - Section directive for Dwarf info.
407 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
409 /// DwarfEHFrameSection - Section directive for Exception frames.
411 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
413 /// DwarfExceptionSection - Section directive for Exception table.
415 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
418 //===--- CBE Asm Translation Table -----------------------------------===//
420 const char *const *AsmTransCBE; // Defaults to empty
424 virtual ~TargetAsmInfo();
426 /// Measure the specified inline asm to determine an approximation of its
428 virtual unsigned getInlineAsmLength(const char *Str) const;
430 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
431 /// call to be explicit llvm code if it wants to. This is useful for
432 /// turning simple inline asms into LLVM intrinsics, which gives the
433 /// compiler more information about the behavior of the code.
434 virtual bool ExpandInlineAsm(CallInst *CI) const {
438 /// PreferredEHDataFormat - This hook allows the target to select data
439 /// format used for encoding pointers in exception handling data. Reason is
440 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
441 /// if the symbol can be relocated.
442 virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
445 /// SectionKindForGlobal - This hook allows the target to select proper
446 /// section kind used for global emission.
447 SectionKind::Kind SectionKindForGlobal(const GlobalValue *GV) const;
451 const char *getTextSection() const {
454 const char *getDataSection() const {
457 const char *getBSSSection() const {
460 const char *getTLSDataSection() const {
461 return TLSDataSection;
463 const char *getTLSBSSSection() const {
464 return TLSBSSSection;
466 const char *getZeroFillDirective() const {
467 return ZeroFillDirective;
469 const char *getNonexecutableStackDirective() const {
470 return NonexecutableStackDirective;
472 bool needsSet() const {
475 const char *getPCSymbol() const {
478 char getSeparatorChar() const {
479 return SeparatorChar;
481 const char *getCommentString() const {
482 return CommentString;
484 const char *getGlobalPrefix() const {
487 const char *getPrivateGlobalPrefix() const {
488 return PrivateGlobalPrefix;
490 const char *getJumpTableSpecialLabelPrefix() const {
491 return JumpTableSpecialLabelPrefix;
493 const char *getGlobalVarAddrPrefix() const {
494 return GlobalVarAddrPrefix;
496 const char *getGlobalVarAddrSuffix() const {
497 return GlobalVarAddrSuffix;
499 const char *getFunctionAddrPrefix() const {
500 return FunctionAddrPrefix;
502 const char *getFunctionAddrSuffix() const {
503 return FunctionAddrSuffix;
505 const char *getPersonalityPrefix() const {
506 return PersonalityPrefix;
508 const char *getPersonalitySuffix() const {
509 return PersonalitySuffix;
511 bool getNeedsIndirectEncoding() const {
512 return NeedsIndirectEncoding;
514 const char *getInlineAsmStart() const {
515 return InlineAsmStart;
517 const char *getInlineAsmEnd() const {
520 unsigned getAssemblerDialect() const {
521 return AssemblerDialect;
523 const char *getStringConstantPrefix() const {
524 return StringConstantPrefix;
526 const char *getZeroDirective() const {
527 return ZeroDirective;
529 const char *getZeroDirectiveSuffix() const {
530 return ZeroDirectiveSuffix;
532 const char *getAsciiDirective() const {
533 return AsciiDirective;
535 const char *getAscizDirective() const {
536 return AscizDirective;
538 const char *getData8bitsDirective() const {
539 return Data8bitsDirective;
541 const char *getData16bitsDirective() const {
542 return Data16bitsDirective;
544 const char *getData32bitsDirective() const {
545 return Data32bitsDirective;
547 const char *getData64bitsDirective() const {
548 return Data64bitsDirective;
550 const char *getJumpTableDirective() const {
551 return JumpTableDirective;
553 const char *getAlignDirective() const {
554 return AlignDirective;
556 bool getAlignmentIsInBytes() const {
557 return AlignmentIsInBytes;
559 unsigned getTextAlignFillValue() const {
560 return TextAlignFillValue;
562 const char *getSwitchToSectionDirective() const {
563 return SwitchToSectionDirective;
565 const char *getTextSectionStartSuffix() const {
566 return TextSectionStartSuffix;
568 const char *getDataSectionStartSuffix() const {
569 return DataSectionStartSuffix;
571 const char *getSectionEndDirectiveSuffix() const {
572 return SectionEndDirectiveSuffix;
574 const char *getConstantPoolSection() const {
575 return ConstantPoolSection;
577 const char *getJumpTableDataSection() const {
578 return JumpTableDataSection;
580 const char *getCStringSection() const {
581 return CStringSection;
583 const char *getStaticCtorsSection() const {
584 return StaticCtorsSection;
586 const char *getStaticDtorsSection() const {
587 return StaticDtorsSection;
589 const char *getFourByteConstantSection() const {
590 return FourByteConstantSection;
592 const char *getEightByteConstantSection() const {
593 return EightByteConstantSection;
595 const char *getSixteenByteConstantSection() const {
596 return SixteenByteConstantSection;
598 const char *getReadOnlySection() const {
599 return ReadOnlySection;
601 const char *getGlobalDirective() const {
602 return GlobalDirective;
604 const char *getSetDirective() const {
607 const char *getLCOMMDirective() const {
608 return LCOMMDirective;
610 const char *getCOMMDirective() const {
611 return COMMDirective;
613 bool getCOMMDirectiveTakesAlignment() const {
614 return COMMDirectiveTakesAlignment;
616 bool hasDotTypeDotSizeDirective() const {
617 return HasDotTypeDotSizeDirective;
619 const char *getUsedDirective() const {
620 return UsedDirective;
622 const char *getWeakRefDirective() const {
623 return WeakRefDirective;
625 const char *getWeakDefDirective() const {
626 return WeakDefDirective;
628 const char *getHiddenDirective() const {
629 return HiddenDirective;
631 const char *getProtectedDirective() const {
632 return ProtectedDirective;
634 bool isAbsoluteDebugSectionOffsets() const {
635 return AbsoluteDebugSectionOffsets;
637 bool isAbsoluteEHSectionOffsets() const {
638 return AbsoluteEHSectionOffsets;
640 bool hasLEB128() const {
643 bool hasDotLocAndDotFile() const {
644 return HasDotLocAndDotFile;
646 bool doesSupportDebugInformation() const {
647 return SupportsDebugInformation;
649 bool doesSupportExceptionHandling() const {
650 return SupportsExceptionHandling;
652 bool doesDwarfRequireFrameSection() const {
653 return DwarfRequiresFrameSection;
655 const char *getGlobalEHDirective() const {
656 return GlobalEHDirective;
658 bool getSupportsWeakOmittedEHFrame() const {
659 return SupportsWeakOmittedEHFrame;
661 const char *getDwarfSectionOffsetDirective() const {
662 return DwarfSectionOffsetDirective;
664 const char *getDwarfAbbrevSection() const {
665 return DwarfAbbrevSection;
667 const char *getDwarfInfoSection() const {
668 return DwarfInfoSection;
670 const char *getDwarfLineSection() const {
671 return DwarfLineSection;
673 const char *getDwarfFrameSection() const {
674 return DwarfFrameSection;
676 const char *getDwarfPubNamesSection() const {
677 return DwarfPubNamesSection;
679 const char *getDwarfPubTypesSection() const {
680 return DwarfPubTypesSection;
682 const char *getDwarfStrSection() const {
683 return DwarfStrSection;
685 const char *getDwarfLocSection() const {
686 return DwarfLocSection;
688 const char *getDwarfARangesSection() const {
689 return DwarfARangesSection;
691 const char *getDwarfRangesSection() const {
692 return DwarfRangesSection;
694 const char *getDwarfMacInfoSection() const {
695 return DwarfMacInfoSection;
697 const char *getDwarfEHFrameSection() const {
698 return DwarfEHFrameSection;
700 const char *getDwarfExceptionSection() const {
701 return DwarfExceptionSection;
703 const char *const *getAsmCBE() const {