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".
64 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
65 /// section on this target. Null if this target doesn't support zerofill.
66 const char *ZeroFillDirective; // Default is null.
68 /// NeedsSet - True if target asm can't compute addresses on data
70 bool NeedsSet; // Defaults to false.
72 /// MaxInstLength - This is the maximum possible length of an instruction,
73 /// which is needed to compute the size of an inline asm.
74 unsigned MaxInstLength; // Defaults to 4.
76 /// PCSymbol - The symbol used to represent the current PC. Used in PC
77 /// relative expressions.
78 const char *PCSymbol; // Defaults to "$".
80 /// SeparatorChar - This character, if specified, is used to separate
81 /// instructions from each other when on the same line. This is used to
82 /// measure inline asm instructions.
83 char SeparatorChar; // Defaults to ';'
85 /// CommentString - This indicates the comment character used by the
87 const char *CommentString; // Defaults to "#"
89 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
90 /// onto all global symbols. This is often used for "_" or ".".
91 const char *GlobalPrefix; // Defaults to ""
93 /// PrivateGlobalPrefix - This prefix is used for globals like constant
94 /// pool entries that are completely private to the .o file and should not
95 /// have names in the .o file. This is often "." or "L".
96 const char *PrivateGlobalPrefix; // Defaults to "."
98 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
99 /// emitted before jump tables with the specified prefix.
100 const char *JumpTableSpecialLabelPrefix; // Default to null.
102 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
103 /// will enclose any GlobalVariable (that isn't a function)
105 const char *GlobalVarAddrPrefix; // Defaults to ""
106 const char *GlobalVarAddrSuffix; // Defaults to ""
108 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
109 /// will enclose any GlobalVariable that points to a function.
110 /// For example, this is used by the IA64 backend to materialize
111 /// function descriptors, by decorating the ".data8" object with the
112 /// @verbatim @fptr( ) @endverbatim
113 /// link-relocation operator.
115 const char *FunctionAddrPrefix; // Defaults to ""
116 const char *FunctionAddrSuffix; // Defaults to ""
118 /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
119 /// enclose any personality function in the common frame section.
121 const char *PersonalityPrefix; // Defaults to ""
122 const char *PersonalitySuffix; // Defaults to ""
124 /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
127 bool NeedsIndirectEncoding; // Defaults to false
129 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
130 /// emit before and after an inline assembly statement.
131 const char *InlineAsmStart; // Defaults to "#APP\n"
132 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
134 /// AssemblerDialect - Which dialect of an assembler variant to use.
135 unsigned AssemblerDialect; // Defaults to 0
137 //===--- Data Emission Directives -------------------------------------===//
139 /// ZeroDirective - this should be set to the directive used to get some
140 /// number of zero bytes emitted to the current section. Common cases are
141 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
142 /// Data*bitsDirective's will be used to emit zero bytes.
143 const char *ZeroDirective; // Defaults to "\t.zero\t"
144 const char *ZeroDirectiveSuffix; // Defaults to ""
146 /// AsciiDirective - This directive allows emission of an ascii string with
147 /// the standard C escape characters embedded into it.
148 const char *AsciiDirective; // Defaults to "\t.ascii\t"
150 /// AscizDirective - If not null, this allows for special handling of
151 /// zero terminated strings on this target. This is commonly supported as
152 /// ".asciz". If a target doesn't support this, it can be set to null.
153 const char *AscizDirective; // Defaults to "\t.asciz\t"
155 /// DataDirectives - These directives are used to output some unit of
156 /// integer data to the current section. If a data directive is set to
157 /// null, smaller data directives will be used to emit the large sizes.
158 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
159 const char *Data16bitsDirective; // Defaults to "\t.short\t"
160 const char *Data32bitsDirective; // Defaults to "\t.long\t"
161 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
163 //===--- Alignment Information ----------------------------------------===//
165 /// AlignDirective - The directive used to emit round up to an alignment
168 const char *AlignDirective; // Defaults to "\t.align\t"
170 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
171 /// emits ".align N" directives, where N is the number of bytes to align to.
172 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
174 bool AlignmentIsInBytes; // Defaults to true
176 /// TextAlignFillValue - If non-zero, this is used to fill the executable
177 /// space created as the result of a alignment directive.
178 unsigned TextAlignFillValue;
180 //===--- Section Switching Directives ---------------------------------===//
182 /// SwitchToSectionDirective - This is the directive used when we want to
183 /// emit a global to an arbitrary section. The section name is emited after
185 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
187 /// TextSectionStartSuffix - This is printed after each start of section
188 /// directive for text sections.
189 const char *TextSectionStartSuffix; // Defaults to "".
191 /// DataSectionStartSuffix - This is printed after each start of section
192 /// directive for data sections.
193 const char *DataSectionStartSuffix; // Defaults to "".
195 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
196 /// section with the section name and this suffix printed.
197 const char *SectionEndDirectiveSuffix;// Defaults to null.
199 /// ConstantPoolSection - This is the section that we SwitchToSection right
200 /// before emitting the constant pool for a function.
201 const char *ConstantPoolSection; // Defaults to "\t.section .rodata"
203 /// JumpTableDataSection - This is the section that we SwitchToSection right
204 /// before emitting the jump tables for a function when the relocation model
206 const char *JumpTableDataSection; // Defaults to "\t.section .rodata"
208 /// JumpTableDirective - if non-null, the directive to emit before a jump
210 const char *JumpTableDirective;
212 /// CStringSection - If not null, this allows for special handling of
213 /// cstring constants (null terminated string that does not contain any
214 /// other null bytes) on this target. This is commonly supported as
216 const char *CStringSection; // Defaults to NULL
218 /// StaticCtorsSection - This is the directive that is emitted to switch to
219 /// a section to emit the static constructor list.
220 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
221 const char *StaticCtorsSection;
223 /// StaticDtorsSection - This is the directive that is emitted to switch to
224 /// a section to emit the static destructor list.
225 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
226 const char *StaticDtorsSection;
228 /// FourByteConstantSection, EightByteConstantSection,
229 /// SixteenByteConstantSection - These are special sections where we place
230 /// 4-, 8-, and 16- byte constant literals.
231 const char *FourByteConstantSection;
232 const char *EightByteConstantSection;
233 const char *SixteenByteConstantSection;
235 /// ReadOnlySection - This is the directive that is emitted to switch to a
236 /// read-only section for constant data (e.g. data declared const,
238 const char *ReadOnlySection; // Defaults to NULL
240 //===--- Global Variable Emission Directives --------------------------===//
242 /// GlobalDirective - This is the directive used to declare a global entity.
244 const char *GlobalDirective; // Defaults to NULL.
246 /// SetDirective - This is the name of a directive that can be used to tell
247 /// the assembler to set the value of a variable to some expression.
248 const char *SetDirective; // Defaults to null.
250 /// LCOMMDirective - This is the name of a directive (if supported) that can
251 /// be used to efficiently declare a local (internal) block of zero
252 /// initialized data in the .bss/.data section. The syntax expected is:
253 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
255 const char *LCOMMDirective; // Defaults to null.
257 const char *COMMDirective; // Defaults to "\t.comm\t".
259 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
260 /// argument that specifies the alignment of the declaration.
261 bool COMMDirectiveTakesAlignment; // Defaults to true.
263 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
264 /// directives, this is true for most ELF targets.
265 bool HasDotTypeDotSizeDirective; // Defaults to true.
267 /// UsedDirective - This directive, if non-null, is used to declare a global
268 /// as being used somehow that the assembler can't see. This prevents dead
269 /// code elimination on some targets.
270 const char *UsedDirective; // Defaults to null.
272 /// WeakRefDirective - This directive, if non-null, is used to declare a
273 /// global as being a weak undefined symbol.
274 const char *WeakRefDirective; // Defaults to null.
276 /// WeakDefDirective - This directive, if non-null, is used to declare a
277 /// global as being a weak defined symbol.
278 const char *WeakDefDirective; // Defaults to null.
280 /// HiddenDirective - This directive, if non-null, is used to declare a
281 /// global or function as having hidden visibility.
282 const char *HiddenDirective; // Defaults to "\t.hidden\t".
284 /// ProtectedDirective - This directive, if non-null, is used to declare a
285 /// global or function as having protected visibility.
286 const char *ProtectedDirective; // Defaults to "\t.protected\t".
288 //===--- Dwarf Emission Directives -----------------------------------===//
290 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
291 /// offsets for debug information. Defaults to false.
292 bool AbsoluteDebugSectionOffsets;
294 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
295 /// offsets for EH information. Defaults to false.
296 bool AbsoluteEHSectionOffsets;
298 /// HasLEB128 - True if target asm supports leb128 directives.
300 bool HasLEB128; // Defaults to false.
302 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
303 /// directives for emitting debugging information.
305 bool HasDotLocAndDotFile; // Defaults to false.
307 /// SupportsDebugInformation - True if target supports emission of debugging
309 bool SupportsDebugInformation;
311 /// SupportsExceptionHandling - True if target supports
312 /// exception handling.
314 bool SupportsExceptionHandling; // Defaults to false.
316 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
318 bool DwarfRequiresFrameSection; // Defaults to true.
320 /// GlobalEHDirective - This is the directive used to make exception frame
321 /// tables globally visible.
323 const char *GlobalEHDirective; // Defaults to NULL.
325 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
326 /// handle a weak_definition of constant 0 for an omitted EH frame.
327 bool SupportsWeakOmittedEHFrame; // Defaults to true.
329 /// ShortenEHDataON64Bit - True if target exception table format requires
330 /// 32-bit data in certain places even when targeting 64-bits.
331 bool ShortenEHDataOn64Bit; // Defaults to false.
333 /// DwarfSectionOffsetDirective - Special section offset directive.
334 const char* DwarfSectionOffsetDirective; // Defaults to NULL
336 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
338 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
340 /// DwarfInfoSection - Section directive for Dwarf info.
342 const char *DwarfInfoSection; // Defaults to ".debug_info".
344 /// DwarfLineSection - Section directive for Dwarf info.
346 const char *DwarfLineSection; // Defaults to ".debug_line".
348 /// DwarfFrameSection - Section directive for Dwarf info.
350 const char *DwarfFrameSection; // Defaults to ".debug_frame".
352 /// DwarfPubNamesSection - Section directive for Dwarf info.
354 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
356 /// DwarfPubTypesSection - Section directive for Dwarf info.
358 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
360 /// DwarfStrSection - Section directive for Dwarf info.
362 const char *DwarfStrSection; // Defaults to ".debug_str".
364 /// DwarfLocSection - Section directive for Dwarf info.
366 const char *DwarfLocSection; // Defaults to ".debug_loc".
368 /// DwarfARangesSection - Section directive for Dwarf info.
370 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
372 /// DwarfRangesSection - Section directive for Dwarf info.
374 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
376 /// DwarfMacInfoSection - Section directive for Dwarf info.
378 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
380 /// DwarfEHFrameSection - Section directive for Exception frames.
382 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
384 /// DwarfExceptionSection - Section directive for Exception table.
386 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
389 //===--- CBE Asm Translation Table -----------------------------------===//
391 const char** AsmTransCBE; // Defaults to empty
395 virtual ~TargetAsmInfo();
397 /// Measure the specified inline asm to determine an approximation of its
399 virtual unsigned getInlineAsmLength(const char *Str) const;
401 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
402 /// call to be explicit llvm code if it wants to. This is useful for
403 /// turning simple inline asms into LLVM intrinsics, which gives the
404 /// compiler more information about the behavior of the code.
405 virtual bool ExpandInlineAsm(CallInst *CI) const {
409 /// PreferredEHDataFormat - This hook allows the target to select data
410 /// format used for encoding pointers in exception handling data. Reason is
411 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
412 /// if the symbol can be relocated.
413 virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
418 const char *getTextSection() const {
421 const char *getDataSection() const {
424 const char *getBSSSection() const {
427 const char *getTLSDataSection() const {
428 return TLSDataSection;
430 const char *getTLSBSSSection() const {
431 return TLSBSSSection;
433 const char *getZeroFillDirective() const {
434 return ZeroFillDirective;
436 bool needsSet() const {
439 const char *getPCSymbol() const {
442 char getSeparatorChar() const {
443 return SeparatorChar;
445 const char *getCommentString() const {
446 return CommentString;
448 const char *getGlobalPrefix() const {
451 const char *getPrivateGlobalPrefix() const {
452 return PrivateGlobalPrefix;
454 const char *getJumpTableSpecialLabelPrefix() const {
455 return JumpTableSpecialLabelPrefix;
457 const char *getGlobalVarAddrPrefix() const {
458 return GlobalVarAddrPrefix;
460 const char *getGlobalVarAddrSuffix() const {
461 return GlobalVarAddrSuffix;
463 const char *getFunctionAddrPrefix() const {
464 return FunctionAddrPrefix;
466 const char *getFunctionAddrSuffix() const {
467 return FunctionAddrSuffix;
469 const char *getPersonalityPrefix() const {
470 return PersonalityPrefix;
472 const char *getPersonalitySuffix() const {
473 return PersonalitySuffix;
475 bool getNeedsIndirectEncoding() const {
476 return NeedsIndirectEncoding;
478 const char *getInlineAsmStart() const {
479 return InlineAsmStart;
481 const char *getInlineAsmEnd() const {
484 unsigned getAssemblerDialect() const {
485 return AssemblerDialect;
487 const char *getZeroDirective() const {
488 return ZeroDirective;
490 const char *getZeroDirectiveSuffix() const {
491 return ZeroDirectiveSuffix;
493 const char *getAsciiDirective() const {
494 return AsciiDirective;
496 const char *getAscizDirective() const {
497 return AscizDirective;
499 const char *getData8bitsDirective() const {
500 return Data8bitsDirective;
502 const char *getData16bitsDirective() const {
503 return Data16bitsDirective;
505 const char *getData32bitsDirective() const {
506 return Data32bitsDirective;
508 const char *getData64bitsDirective() const {
509 return Data64bitsDirective;
511 const char *getJumpTableDirective() const {
512 return JumpTableDirective;
514 const char *getAlignDirective() const {
515 return AlignDirective;
517 bool getAlignmentIsInBytes() const {
518 return AlignmentIsInBytes;
520 unsigned getTextAlignFillValue() const {
521 return TextAlignFillValue;
523 const char *getSwitchToSectionDirective() const {
524 return SwitchToSectionDirective;
526 const char *getTextSectionStartSuffix() const {
527 return TextSectionStartSuffix;
529 const char *getDataSectionStartSuffix() const {
530 return DataSectionStartSuffix;
532 const char *getSectionEndDirectiveSuffix() const {
533 return SectionEndDirectiveSuffix;
535 const char *getConstantPoolSection() const {
536 return ConstantPoolSection;
538 const char *getJumpTableDataSection() const {
539 return JumpTableDataSection;
541 const char *getCStringSection() const {
542 return CStringSection;
544 const char *getStaticCtorsSection() const {
545 return StaticCtorsSection;
547 const char *getStaticDtorsSection() const {
548 return StaticDtorsSection;
550 const char *getFourByteConstantSection() const {
551 return FourByteConstantSection;
553 const char *getEightByteConstantSection() const {
554 return EightByteConstantSection;
556 const char *getSixteenByteConstantSection() const {
557 return SixteenByteConstantSection;
559 const char *getReadOnlySection() const {
560 return ReadOnlySection;
562 const char *getGlobalDirective() const {
563 return GlobalDirective;
565 const char *getSetDirective() const {
568 const char *getLCOMMDirective() const {
569 return LCOMMDirective;
571 const char *getCOMMDirective() const {
572 return COMMDirective;
574 bool getCOMMDirectiveTakesAlignment() const {
575 return COMMDirectiveTakesAlignment;
577 bool hasDotTypeDotSizeDirective() const {
578 return HasDotTypeDotSizeDirective;
580 const char *getUsedDirective() const {
581 return UsedDirective;
583 const char *getWeakRefDirective() const {
584 return WeakRefDirective;
586 const char *getWeakDefDirective() const {
587 return WeakDefDirective;
589 const char *getHiddenDirective() const {
590 return HiddenDirective;
592 const char *getProtectedDirective() const {
593 return ProtectedDirective;
595 bool isAbsoluteDebugSectionOffsets() const {
596 return AbsoluteDebugSectionOffsets;
598 bool isAbsoluteEHSectionOffsets() const {
599 return AbsoluteEHSectionOffsets;
601 bool hasLEB128() const {
604 bool hasDotLocAndDotFile() const {
605 return HasDotLocAndDotFile;
607 bool doesSupportDebugInformation() const {
608 return SupportsDebugInformation;
610 bool doesSupportExceptionHandling() const {
611 return SupportsExceptionHandling;
613 bool doesDwarfRequireFrameSection() const {
614 return DwarfRequiresFrameSection;
616 const char *getGlobalEHDirective() const {
617 return GlobalEHDirective;
619 bool getSupportsWeakOmittedEHFrame() const {
620 return SupportsWeakOmittedEHFrame;
622 bool getShortenEHDataOn64Bit() const {
623 return ShortenEHDataOn64Bit;
625 const char *getDwarfSectionOffsetDirective() const {
626 return DwarfSectionOffsetDirective;
628 const char *getDwarfAbbrevSection() const {
629 return DwarfAbbrevSection;
631 const char *getDwarfInfoSection() const {
632 return DwarfInfoSection;
634 const char *getDwarfLineSection() const {
635 return DwarfLineSection;
637 const char *getDwarfFrameSection() const {
638 return DwarfFrameSection;
640 const char *getDwarfPubNamesSection() const {
641 return DwarfPubNamesSection;
643 const char *getDwarfPubTypesSection() const {
644 return DwarfPubTypesSection;
646 const char *getDwarfStrSection() const {
647 return DwarfStrSection;
649 const char *getDwarfLocSection() const {
650 return DwarfLocSection;
652 const char *getDwarfARangesSection() const {
653 return DwarfARangesSection;
655 const char *getDwarfRangesSection() const {
656 return DwarfRangesSection;
658 const char *getDwarfMacInfoSection() const {
659 return DwarfMacInfoSection;
661 const char *getDwarfEHFrameSection() const {
662 return DwarfEHFrameSection;
664 const char *getDwarfExceptionSection() const {
665 return DwarfExceptionSection;
667 const char** getAsmCBE() const {