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 {
35 /// TargetAsmInfo - This class is intended to be used as a base class for asm
36 /// properties and features specific to the target.
39 //===------------------------------------------------------------------===//
40 // Properties to be set by the target writer, used to configure asm printer.
43 /// TextSection - Section directive for standard text.
45 const char *TextSection; // Defaults to ".text".
47 /// DataSection - Section directive for standard data.
49 const char *DataSection; // Defaults to ".data".
51 /// BSSSection - Section directive for uninitialized data. Null if this
52 /// target doesn't support a BSS section.
54 const char *BSSSection; // Default to ".bss".
56 /// TLSDataSection - Section directive for Thread Local data.
58 const char *TLSDataSection;// Defaults to ".section .tdata,"awT",@progbits".
60 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
61 /// Null if this target doesn't support a BSS section.
63 const char *TLSBSSSection;// Default to ".section .tbss,"awT",@nobits".
65 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
66 /// section on this target. Null if this target doesn't support zerofill.
67 const char *ZeroFillDirective; // Default is null.
69 /// NonexecutableStackDirective - Directive for declaring to the
70 /// linker and beyond that the emitted code does not require stack
71 /// memory to be executable.
72 const char *NonexecutableStackDirective; // Default is null.
74 /// NeedsSet - True if target asm treats expressions in data directives
75 /// as linktime-relocatable. For assembly-time computation, we need to
79 /// is computed at assembly time, while
81 /// is relocated if the relative locations of x and y change at linktime.
82 /// We want both these things in different places.
83 bool NeedsSet; // Defaults to false.
85 /// MaxInstLength - This is the maximum possible length of an instruction,
86 /// which is needed to compute the size of an inline asm.
87 unsigned MaxInstLength; // Defaults to 4.
89 /// PCSymbol - The symbol used to represent the current PC. Used in PC
90 /// relative expressions.
91 const char *PCSymbol; // Defaults to "$".
93 /// SeparatorChar - This character, if specified, is used to separate
94 /// instructions from each other when on the same line. This is used to
95 /// measure inline asm instructions.
96 char SeparatorChar; // Defaults to ';'
98 /// CommentString - This indicates the comment character used by the
100 const char *CommentString; // Defaults to "#"
102 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
103 /// onto all global symbols. This is often used for "_" or ".".
104 const char *GlobalPrefix; // Defaults to ""
106 /// PrivateGlobalPrefix - This prefix is used for globals like constant
107 /// pool entries that are completely private to the .o file and should not
108 /// have names in the .o file. This is often "." or "L".
109 const char *PrivateGlobalPrefix; // Defaults to "."
111 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
112 /// emitted before jump tables with the specified prefix.
113 const char *JumpTableSpecialLabelPrefix; // Default to null.
115 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
116 /// will enclose any GlobalVariable (that isn't a function)
118 const char *GlobalVarAddrPrefix; // Defaults to ""
119 const char *GlobalVarAddrSuffix; // Defaults to ""
121 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
122 /// will enclose any GlobalVariable that points to a function.
123 /// For example, this is used by the IA64 backend to materialize
124 /// function descriptors, by decorating the ".data8" object with the
125 /// @verbatim @fptr( ) @endverbatim
126 /// link-relocation operator.
128 const char *FunctionAddrPrefix; // Defaults to ""
129 const char *FunctionAddrSuffix; // Defaults to ""
131 /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
132 /// enclose any personality function in the common frame section.
134 const char *PersonalityPrefix; // Defaults to ""
135 const char *PersonalitySuffix; // Defaults to ""
137 /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
140 bool NeedsIndirectEncoding; // Defaults to false
142 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
143 /// emit before and after an inline assembly statement.
144 const char *InlineAsmStart; // Defaults to "#APP\n"
145 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
147 /// AssemblerDialect - Which dialect of an assembler variant to use.
148 unsigned AssemblerDialect; // Defaults to 0
150 /// StringConstantPrefix - Prefix for FEs to use when generating unnamed
151 /// constant strings. These names get run through the Mangler later; if
152 /// you want the Mangler not to add the GlobalPrefix as well,
153 /// use '\1' as the first character.
154 const char *StringConstantPrefix; // Defaults to ".str"
156 //===--- Data Emission Directives -------------------------------------===//
158 /// ZeroDirective - this should be set to the directive used to get some
159 /// number of zero bytes emitted to the current section. Common cases are
160 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
161 /// Data*bitsDirective's will be used to emit zero bytes.
162 const char *ZeroDirective; // Defaults to "\t.zero\t"
163 const char *ZeroDirectiveSuffix; // Defaults to ""
165 /// AsciiDirective - This directive allows emission of an ascii string with
166 /// the standard C escape characters embedded into it.
167 const char *AsciiDirective; // Defaults to "\t.ascii\t"
169 /// AscizDirective - If not null, this allows for special handling of
170 /// zero terminated strings on this target. This is commonly supported as
171 /// ".asciz". If a target doesn't support this, it can be set to null.
172 const char *AscizDirective; // Defaults to "\t.asciz\t"
174 /// DataDirectives - These directives are used to output some unit of
175 /// integer data to the current section. If a data directive is set to
176 /// null, smaller data directives will be used to emit the large sizes.
177 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
178 const char *Data16bitsDirective; // Defaults to "\t.short\t"
179 const char *Data32bitsDirective; // Defaults to "\t.long\t"
180 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
182 //===--- Alignment Information ----------------------------------------===//
184 /// AlignDirective - The directive used to emit round up to an alignment
187 const char *AlignDirective; // Defaults to "\t.align\t"
189 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
190 /// emits ".align N" directives, where N is the number of bytes to align to.
191 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
193 bool AlignmentIsInBytes; // Defaults to true
195 /// TextAlignFillValue - If non-zero, this is used to fill the executable
196 /// space created as the result of a alignment directive.
197 unsigned TextAlignFillValue;
199 //===--- Section Switching Directives ---------------------------------===//
201 /// SwitchToSectionDirective - This is the directive used when we want to
202 /// emit a global to an arbitrary section. The section name is emited after
204 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
206 /// TextSectionStartSuffix - This is printed after each start of section
207 /// directive for text sections.
208 const char *TextSectionStartSuffix; // Defaults to "".
210 /// DataSectionStartSuffix - This is printed after each start of section
211 /// directive for data sections.
212 const char *DataSectionStartSuffix; // Defaults to "".
214 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
215 /// section with the section name and this suffix printed.
216 const char *SectionEndDirectiveSuffix;// Defaults to null.
218 /// ConstantPoolSection - This is the section that we SwitchToSection right
219 /// before emitting the constant pool for a function.
220 const char *ConstantPoolSection; // Defaults to "\t.section .rodata"
222 /// JumpTableDataSection - This is the section that we SwitchToSection right
223 /// before emitting the jump tables for a function when the relocation model
225 const char *JumpTableDataSection; // Defaults to "\t.section .rodata"
227 /// JumpTableDirective - if non-null, the directive to emit before a jump
229 const char *JumpTableDirective;
231 /// CStringSection - If not null, this allows for special handling of
232 /// cstring constants (null terminated string that does not contain any
233 /// other null bytes) on this target. This is commonly supported as
235 const char *CStringSection; // Defaults to NULL
237 /// StaticCtorsSection - This is the directive that is emitted to switch to
238 /// a section to emit the static constructor list.
239 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
240 const char *StaticCtorsSection;
242 /// StaticDtorsSection - This is the directive that is emitted to switch to
243 /// a section to emit the static destructor list.
244 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
245 const char *StaticDtorsSection;
247 /// FourByteConstantSection, EightByteConstantSection,
248 /// SixteenByteConstantSection - These are special sections where we place
249 /// 4-, 8-, and 16- byte constant literals.
250 const char *FourByteConstantSection;
251 const char *EightByteConstantSection;
252 const char *SixteenByteConstantSection;
254 /// ReadOnlySection - This is the directive that is emitted to switch to a
255 /// read-only section for constant data (e.g. data declared const,
257 const char *ReadOnlySection; // Defaults to NULL
259 //===--- Global Variable Emission Directives --------------------------===//
261 /// GlobalDirective - This is the directive used to declare a global entity.
263 const char *GlobalDirective; // Defaults to NULL.
265 /// SetDirective - This is the name of a directive that can be used to tell
266 /// the assembler to set the value of a variable to some expression.
267 const char *SetDirective; // Defaults to null.
269 /// LCOMMDirective - This is the name of a directive (if supported) that can
270 /// be used to efficiently declare a local (internal) block of zero
271 /// initialized data in the .bss/.data section. The syntax expected is:
272 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
274 const char *LCOMMDirective; // Defaults to null.
276 const char *COMMDirective; // Defaults to "\t.comm\t".
278 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
279 /// argument that specifies the alignment of the declaration.
280 bool COMMDirectiveTakesAlignment; // Defaults to true.
282 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
283 /// directives, this is true for most ELF targets.
284 bool HasDotTypeDotSizeDirective; // Defaults to true.
286 /// UsedDirective - This directive, if non-null, is used to declare a global
287 /// as being used somehow that the assembler can't see. This prevents dead
288 /// code elimination on some targets.
289 const char *UsedDirective; // Defaults to null.
291 /// WeakRefDirective - This directive, if non-null, is used to declare a
292 /// global as being a weak undefined symbol.
293 const char *WeakRefDirective; // Defaults to null.
295 /// WeakDefDirective - This directive, if non-null, is used to declare a
296 /// global as being a weak defined symbol.
297 const char *WeakDefDirective; // Defaults to null.
299 /// HiddenDirective - This directive, if non-null, is used to declare a
300 /// global or function as having hidden visibility.
301 const char *HiddenDirective; // Defaults to "\t.hidden\t".
303 /// ProtectedDirective - This directive, if non-null, is used to declare a
304 /// global or function as having protected visibility.
305 const char *ProtectedDirective; // Defaults to "\t.protected\t".
307 //===--- Dwarf Emission Directives -----------------------------------===//
309 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
310 /// offsets for debug information. Defaults to false.
311 bool AbsoluteDebugSectionOffsets;
313 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
314 /// offsets for EH information. Defaults to false.
315 bool AbsoluteEHSectionOffsets;
317 /// HasLEB128 - True if target asm supports leb128 directives.
319 bool HasLEB128; // Defaults to false.
321 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
322 /// directives for emitting debugging information.
324 bool HasDotLocAndDotFile; // Defaults to false.
326 /// SupportsDebugInformation - True if target supports emission of debugging
328 bool SupportsDebugInformation;
330 /// SupportsExceptionHandling - True if target supports
331 /// exception handling.
333 bool SupportsExceptionHandling; // Defaults to false.
335 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
337 bool DwarfRequiresFrameSection; // Defaults to true.
339 /// GlobalEHDirective - This is the directive used to make exception frame
340 /// tables globally visible.
342 const char *GlobalEHDirective; // Defaults to NULL.
344 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
345 /// handle a weak_definition of constant 0 for an omitted EH frame.
346 bool SupportsWeakOmittedEHFrame; // Defaults to true.
348 /// DwarfSectionOffsetDirective - Special section offset directive.
349 const char* DwarfSectionOffsetDirective; // Defaults to NULL
351 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
353 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
355 /// DwarfInfoSection - Section directive for Dwarf info.
357 const char *DwarfInfoSection; // Defaults to ".debug_info".
359 /// DwarfLineSection - Section directive for Dwarf info.
361 const char *DwarfLineSection; // Defaults to ".debug_line".
363 /// DwarfFrameSection - Section directive for Dwarf info.
365 const char *DwarfFrameSection; // Defaults to ".debug_frame".
367 /// DwarfPubNamesSection - Section directive for Dwarf info.
369 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
371 /// DwarfPubTypesSection - Section directive for Dwarf info.
373 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
375 /// DwarfStrSection - Section directive for Dwarf info.
377 const char *DwarfStrSection; // Defaults to ".debug_str".
379 /// DwarfLocSection - Section directive for Dwarf info.
381 const char *DwarfLocSection; // Defaults to ".debug_loc".
383 /// DwarfARangesSection - Section directive for Dwarf info.
385 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
387 /// DwarfRangesSection - Section directive for Dwarf info.
389 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
391 /// DwarfMacInfoSection - Section directive for Dwarf info.
393 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
395 /// DwarfEHFrameSection - Section directive for Exception frames.
397 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
399 /// DwarfExceptionSection - Section directive for Exception table.
401 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
404 //===--- CBE Asm Translation Table -----------------------------------===//
406 const char *const *AsmTransCBE; // Defaults to empty
410 virtual ~TargetAsmInfo();
412 /// Measure the specified inline asm to determine an approximation of its
414 virtual unsigned getInlineAsmLength(const char *Str) const;
416 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
417 /// call to be explicit llvm code if it wants to. This is useful for
418 /// turning simple inline asms into LLVM intrinsics, which gives the
419 /// compiler more information about the behavior of the code.
420 virtual bool ExpandInlineAsm(CallInst *CI) const {
424 /// PreferredEHDataFormat - This hook allows the target to select data
425 /// format used for encoding pointers in exception handling data. Reason is
426 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
427 /// if the symbol can be relocated.
428 virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
433 const char *getTextSection() const {
436 const char *getDataSection() const {
439 const char *getBSSSection() const {
442 const char *getTLSDataSection() const {
443 return TLSDataSection;
445 const char *getTLSBSSSection() const {
446 return TLSBSSSection;
448 const char *getZeroFillDirective() const {
449 return ZeroFillDirective;
451 const char *getNonexecutableStackDirective() const {
452 return NonexecutableStackDirective;
454 bool needsSet() const {
457 const char *getPCSymbol() const {
460 char getSeparatorChar() const {
461 return SeparatorChar;
463 const char *getCommentString() const {
464 return CommentString;
466 const char *getGlobalPrefix() const {
469 const char *getPrivateGlobalPrefix() const {
470 return PrivateGlobalPrefix;
472 const char *getJumpTableSpecialLabelPrefix() const {
473 return JumpTableSpecialLabelPrefix;
475 const char *getGlobalVarAddrPrefix() const {
476 return GlobalVarAddrPrefix;
478 const char *getGlobalVarAddrSuffix() const {
479 return GlobalVarAddrSuffix;
481 const char *getFunctionAddrPrefix() const {
482 return FunctionAddrPrefix;
484 const char *getFunctionAddrSuffix() const {
485 return FunctionAddrSuffix;
487 const char *getPersonalityPrefix() const {
488 return PersonalityPrefix;
490 const char *getPersonalitySuffix() const {
491 return PersonalitySuffix;
493 bool getNeedsIndirectEncoding() const {
494 return NeedsIndirectEncoding;
496 const char *getInlineAsmStart() const {
497 return InlineAsmStart;
499 const char *getInlineAsmEnd() const {
502 unsigned getAssemblerDialect() const {
503 return AssemblerDialect;
505 const char *getStringConstantPrefix() const {
506 return StringConstantPrefix;
508 const char *getZeroDirective() const {
509 return ZeroDirective;
511 const char *getZeroDirectiveSuffix() const {
512 return ZeroDirectiveSuffix;
514 const char *getAsciiDirective() const {
515 return AsciiDirective;
517 const char *getAscizDirective() const {
518 return AscizDirective;
520 const char *getData8bitsDirective() const {
521 return Data8bitsDirective;
523 const char *getData16bitsDirective() const {
524 return Data16bitsDirective;
526 const char *getData32bitsDirective() const {
527 return Data32bitsDirective;
529 const char *getData64bitsDirective() const {
530 return Data64bitsDirective;
532 const char *getJumpTableDirective() const {
533 return JumpTableDirective;
535 const char *getAlignDirective() const {
536 return AlignDirective;
538 bool getAlignmentIsInBytes() const {
539 return AlignmentIsInBytes;
541 unsigned getTextAlignFillValue() const {
542 return TextAlignFillValue;
544 const char *getSwitchToSectionDirective() const {
545 return SwitchToSectionDirective;
547 const char *getTextSectionStartSuffix() const {
548 return TextSectionStartSuffix;
550 const char *getDataSectionStartSuffix() const {
551 return DataSectionStartSuffix;
553 const char *getSectionEndDirectiveSuffix() const {
554 return SectionEndDirectiveSuffix;
556 const char *getConstantPoolSection() const {
557 return ConstantPoolSection;
559 const char *getJumpTableDataSection() const {
560 return JumpTableDataSection;
562 const char *getCStringSection() const {
563 return CStringSection;
565 const char *getStaticCtorsSection() const {
566 return StaticCtorsSection;
568 const char *getStaticDtorsSection() const {
569 return StaticDtorsSection;
571 const char *getFourByteConstantSection() const {
572 return FourByteConstantSection;
574 const char *getEightByteConstantSection() const {
575 return EightByteConstantSection;
577 const char *getSixteenByteConstantSection() const {
578 return SixteenByteConstantSection;
580 const char *getReadOnlySection() const {
581 return ReadOnlySection;
583 const char *getGlobalDirective() const {
584 return GlobalDirective;
586 const char *getSetDirective() const {
589 const char *getLCOMMDirective() const {
590 return LCOMMDirective;
592 const char *getCOMMDirective() const {
593 return COMMDirective;
595 bool getCOMMDirectiveTakesAlignment() const {
596 return COMMDirectiveTakesAlignment;
598 bool hasDotTypeDotSizeDirective() const {
599 return HasDotTypeDotSizeDirective;
601 const char *getUsedDirective() const {
602 return UsedDirective;
604 const char *getWeakRefDirective() const {
605 return WeakRefDirective;
607 const char *getWeakDefDirective() const {
608 return WeakDefDirective;
610 const char *getHiddenDirective() const {
611 return HiddenDirective;
613 const char *getProtectedDirective() const {
614 return ProtectedDirective;
616 bool isAbsoluteDebugSectionOffsets() const {
617 return AbsoluteDebugSectionOffsets;
619 bool isAbsoluteEHSectionOffsets() const {
620 return AbsoluteEHSectionOffsets;
622 bool hasLEB128() const {
625 bool hasDotLocAndDotFile() const {
626 return HasDotLocAndDotFile;
628 bool doesSupportDebugInformation() const {
629 return SupportsDebugInformation;
631 bool doesSupportExceptionHandling() const {
632 return SupportsExceptionHandling;
634 bool doesDwarfRequireFrameSection() const {
635 return DwarfRequiresFrameSection;
637 const char *getGlobalEHDirective() const {
638 return GlobalEHDirective;
640 bool getSupportsWeakOmittedEHFrame() const {
641 return SupportsWeakOmittedEHFrame;
643 const char *getDwarfSectionOffsetDirective() const {
644 return DwarfSectionOffsetDirective;
646 const char *getDwarfAbbrevSection() const {
647 return DwarfAbbrevSection;
649 const char *getDwarfInfoSection() const {
650 return DwarfInfoSection;
652 const char *getDwarfLineSection() const {
653 return DwarfLineSection;
655 const char *getDwarfFrameSection() const {
656 return DwarfFrameSection;
658 const char *getDwarfPubNamesSection() const {
659 return DwarfPubNamesSection;
661 const char *getDwarfPubTypesSection() const {
662 return DwarfPubTypesSection;
664 const char *getDwarfStrSection() const {
665 return DwarfStrSection;
667 const char *getDwarfLocSection() const {
668 return DwarfLocSection;
670 const char *getDwarfARangesSection() const {
671 return DwarfARangesSection;
673 const char *getDwarfRangesSection() const {
674 return DwarfRangesSection;
676 const char *getDwarfMacInfoSection() const {
677 return DwarfMacInfoSection;
679 const char *getDwarfEHFrameSection() const {
680 return DwarfEHFrameSection;
682 const char *getDwarfExceptionSection() const {
683 return DwarfExceptionSection;
685 const char *const *getAsmCBE() const {