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 treats expressions in data directives
69 /// as linktime-relocatable. For assembly-time computation, we need to
73 /// is computed at assembly time, while
75 /// is relocated if the relative locations of x and y change at linktime.
76 /// We want both these things in different places.
77 bool NeedsSet; // Defaults to false.
79 /// MaxInstLength - This is the maximum possible length of an instruction,
80 /// which is needed to compute the size of an inline asm.
81 unsigned MaxInstLength; // Defaults to 4.
83 /// PCSymbol - The symbol used to represent the current PC. Used in PC
84 /// relative expressions.
85 const char *PCSymbol; // Defaults to "$".
87 /// SeparatorChar - This character, if specified, is used to separate
88 /// instructions from each other when on the same line. This is used to
89 /// measure inline asm instructions.
90 char SeparatorChar; // Defaults to ';'
92 /// CommentString - This indicates the comment character used by the
94 const char *CommentString; // Defaults to "#"
96 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
97 /// onto all global symbols. This is often used for "_" or ".".
98 const char *GlobalPrefix; // Defaults to ""
100 /// PrivateGlobalPrefix - This prefix is used for globals like constant
101 /// pool entries that are completely private to the .o file and should not
102 /// have names in the .o file. This is often "." or "L".
103 const char *PrivateGlobalPrefix; // Defaults to "."
105 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
106 /// emitted before jump tables with the specified prefix.
107 const char *JumpTableSpecialLabelPrefix; // Default to null.
109 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
110 /// will enclose any GlobalVariable (that isn't a function)
112 const char *GlobalVarAddrPrefix; // Defaults to ""
113 const char *GlobalVarAddrSuffix; // Defaults to ""
115 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
116 /// will enclose any GlobalVariable that points to a function.
117 /// For example, this is used by the IA64 backend to materialize
118 /// function descriptors, by decorating the ".data8" object with the
119 /// @verbatim @fptr( ) @endverbatim
120 /// link-relocation operator.
122 const char *FunctionAddrPrefix; // Defaults to ""
123 const char *FunctionAddrSuffix; // Defaults to ""
125 /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
126 /// enclose any personality function in the common frame section.
128 const char *PersonalityPrefix; // Defaults to ""
129 const char *PersonalitySuffix; // Defaults to ""
131 /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
134 bool NeedsIndirectEncoding; // Defaults to false
136 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
137 /// emit before and after an inline assembly statement.
138 const char *InlineAsmStart; // Defaults to "#APP\n"
139 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
141 /// AssemblerDialect - Which dialect of an assembler variant to use.
142 unsigned AssemblerDialect; // Defaults to 0
144 //===--- Data Emission Directives -------------------------------------===//
146 /// ZeroDirective - this should be set to the directive used to get some
147 /// number of zero bytes emitted to the current section. Common cases are
148 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
149 /// Data*bitsDirective's will be used to emit zero bytes.
150 const char *ZeroDirective; // Defaults to "\t.zero\t"
151 const char *ZeroDirectiveSuffix; // Defaults to ""
153 /// AsciiDirective - This directive allows emission of an ascii string with
154 /// the standard C escape characters embedded into it.
155 const char *AsciiDirective; // Defaults to "\t.ascii\t"
157 /// AscizDirective - If not null, this allows for special handling of
158 /// zero terminated strings on this target. This is commonly supported as
159 /// ".asciz". If a target doesn't support this, it can be set to null.
160 const char *AscizDirective; // Defaults to "\t.asciz\t"
162 /// DataDirectives - These directives are used to output some unit of
163 /// integer data to the current section. If a data directive is set to
164 /// null, smaller data directives will be used to emit the large sizes.
165 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
166 const char *Data16bitsDirective; // Defaults to "\t.short\t"
167 const char *Data32bitsDirective; // Defaults to "\t.long\t"
168 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
170 //===--- Alignment Information ----------------------------------------===//
172 /// AlignDirective - The directive used to emit round up to an alignment
175 const char *AlignDirective; // Defaults to "\t.align\t"
177 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
178 /// emits ".align N" directives, where N is the number of bytes to align to.
179 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
181 bool AlignmentIsInBytes; // Defaults to true
183 /// TextAlignFillValue - If non-zero, this is used to fill the executable
184 /// space created as the result of a alignment directive.
185 unsigned TextAlignFillValue;
187 //===--- Section Switching Directives ---------------------------------===//
189 /// SwitchToSectionDirective - This is the directive used when we want to
190 /// emit a global to an arbitrary section. The section name is emited after
192 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
194 /// TextSectionStartSuffix - This is printed after each start of section
195 /// directive for text sections.
196 const char *TextSectionStartSuffix; // Defaults to "".
198 /// DataSectionStartSuffix - This is printed after each start of section
199 /// directive for data sections.
200 const char *DataSectionStartSuffix; // Defaults to "".
202 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
203 /// section with the section name and this suffix printed.
204 const char *SectionEndDirectiveSuffix;// Defaults to null.
206 /// ConstantPoolSection - This is the section that we SwitchToSection right
207 /// before emitting the constant pool for a function.
208 const char *ConstantPoolSection; // Defaults to "\t.section .rodata"
210 /// JumpTableDataSection - This is the section that we SwitchToSection right
211 /// before emitting the jump tables for a function when the relocation model
213 const char *JumpTableDataSection; // Defaults to "\t.section .rodata"
215 /// JumpTableDirective - if non-null, the directive to emit before a jump
217 const char *JumpTableDirective;
219 /// CStringSection - If not null, this allows for special handling of
220 /// cstring constants (null terminated string that does not contain any
221 /// other null bytes) on this target. This is commonly supported as
223 const char *CStringSection; // Defaults to NULL
225 /// StaticCtorsSection - This is the directive that is emitted to switch to
226 /// a section to emit the static constructor list.
227 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
228 const char *StaticCtorsSection;
230 /// StaticDtorsSection - This is the directive that is emitted to switch to
231 /// a section to emit the static destructor list.
232 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
233 const char *StaticDtorsSection;
235 /// FourByteConstantSection, EightByteConstantSection,
236 /// SixteenByteConstantSection - These are special sections where we place
237 /// 4-, 8-, and 16- byte constant literals.
238 const char *FourByteConstantSection;
239 const char *EightByteConstantSection;
240 const char *SixteenByteConstantSection;
242 /// ReadOnlySection - This is the directive that is emitted to switch to a
243 /// read-only section for constant data (e.g. data declared const,
245 const char *ReadOnlySection; // Defaults to NULL
247 //===--- Global Variable Emission Directives --------------------------===//
249 /// GlobalDirective - This is the directive used to declare a global entity.
251 const char *GlobalDirective; // Defaults to NULL.
253 /// SetDirective - This is the name of a directive that can be used to tell
254 /// the assembler to set the value of a variable to some expression.
255 const char *SetDirective; // Defaults to null.
257 /// LCOMMDirective - This is the name of a directive (if supported) that can
258 /// be used to efficiently declare a local (internal) block of zero
259 /// initialized data in the .bss/.data section. The syntax expected is:
260 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
262 const char *LCOMMDirective; // Defaults to null.
264 const char *COMMDirective; // Defaults to "\t.comm\t".
266 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
267 /// argument that specifies the alignment of the declaration.
268 bool COMMDirectiveTakesAlignment; // Defaults to true.
270 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
271 /// directives, this is true for most ELF targets.
272 bool HasDotTypeDotSizeDirective; // Defaults to true.
274 /// UsedDirective - This directive, if non-null, is used to declare a global
275 /// as being used somehow that the assembler can't see. This prevents dead
276 /// code elimination on some targets.
277 const char *UsedDirective; // Defaults to null.
279 /// WeakRefDirective - This directive, if non-null, is used to declare a
280 /// global as being a weak undefined symbol.
281 const char *WeakRefDirective; // Defaults to null.
283 /// WeakDefDirective - This directive, if non-null, is used to declare a
284 /// global as being a weak defined symbol.
285 const char *WeakDefDirective; // Defaults to null.
287 /// HiddenDirective - This directive, if non-null, is used to declare a
288 /// global or function as having hidden visibility.
289 const char *HiddenDirective; // Defaults to "\t.hidden\t".
291 /// ProtectedDirective - This directive, if non-null, is used to declare a
292 /// global or function as having protected visibility.
293 const char *ProtectedDirective; // Defaults to "\t.protected\t".
295 //===--- Dwarf Emission Directives -----------------------------------===//
297 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
298 /// offsets for debug information. Defaults to false.
299 bool AbsoluteDebugSectionOffsets;
301 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
302 /// offsets for EH information. Defaults to false.
303 bool AbsoluteEHSectionOffsets;
305 /// HasLEB128 - True if target asm supports leb128 directives.
307 bool HasLEB128; // Defaults to false.
309 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
310 /// directives for emitting debugging information.
312 bool HasDotLocAndDotFile; // Defaults to false.
314 /// SupportsDebugInformation - True if target supports emission of debugging
316 bool SupportsDebugInformation;
318 /// SupportsExceptionHandling - True if target supports
319 /// exception handling.
321 bool SupportsExceptionHandling; // Defaults to false.
323 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
325 bool DwarfRequiresFrameSection; // Defaults to true.
327 /// GlobalEHDirective - This is the directive used to make exception frame
328 /// tables globally visible.
330 const char *GlobalEHDirective; // Defaults to NULL.
332 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
333 /// handle a weak_definition of constant 0 for an omitted EH frame.
334 bool SupportsWeakOmittedEHFrame; // Defaults to true.
336 /// ShortenEHDataON64Bit - True if target exception table format requires
337 /// 32-bit data in certain places even when targeting 64-bits.
338 bool ShortenEHDataOn64Bit; // Defaults to false.
340 /// DwarfSectionOffsetDirective - Special section offset directive.
341 const char* DwarfSectionOffsetDirective; // Defaults to NULL
343 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
345 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
347 /// DwarfInfoSection - Section directive for Dwarf info.
349 const char *DwarfInfoSection; // Defaults to ".debug_info".
351 /// DwarfLineSection - Section directive for Dwarf info.
353 const char *DwarfLineSection; // Defaults to ".debug_line".
355 /// DwarfFrameSection - Section directive for Dwarf info.
357 const char *DwarfFrameSection; // Defaults to ".debug_frame".
359 /// DwarfPubNamesSection - Section directive for Dwarf info.
361 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
363 /// DwarfPubTypesSection - Section directive for Dwarf info.
365 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
367 /// DwarfStrSection - Section directive for Dwarf info.
369 const char *DwarfStrSection; // Defaults to ".debug_str".
371 /// DwarfLocSection - Section directive for Dwarf info.
373 const char *DwarfLocSection; // Defaults to ".debug_loc".
375 /// DwarfARangesSection - Section directive for Dwarf info.
377 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
379 /// DwarfRangesSection - Section directive for Dwarf info.
381 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
383 /// DwarfMacInfoSection - Section directive for Dwarf info.
385 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
387 /// DwarfEHFrameSection - Section directive for Exception frames.
389 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
391 /// DwarfExceptionSection - Section directive for Exception table.
393 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
396 //===--- CBE Asm Translation Table -----------------------------------===//
398 const char *const *AsmTransCBE; // Defaults to empty
402 virtual ~TargetAsmInfo();
404 /// Measure the specified inline asm to determine an approximation of its
406 virtual unsigned getInlineAsmLength(const char *Str) const;
408 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
409 /// call to be explicit llvm code if it wants to. This is useful for
410 /// turning simple inline asms into LLVM intrinsics, which gives the
411 /// compiler more information about the behavior of the code.
412 virtual bool ExpandInlineAsm(CallInst *CI) const {
416 /// PreferredEHDataFormat - This hook allows the target to select data
417 /// format used for encoding pointers in exception handling data. Reason is
418 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
419 /// if the symbol can be relocated.
420 virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
425 const char *getTextSection() const {
428 const char *getDataSection() const {
431 const char *getBSSSection() const {
434 const char *getTLSDataSection() const {
435 return TLSDataSection;
437 const char *getTLSBSSSection() const {
438 return TLSBSSSection;
440 const char *getZeroFillDirective() const {
441 return ZeroFillDirective;
443 bool needsSet() const {
446 const char *getPCSymbol() const {
449 char getSeparatorChar() const {
450 return SeparatorChar;
452 const char *getCommentString() const {
453 return CommentString;
455 const char *getGlobalPrefix() const {
458 const char *getPrivateGlobalPrefix() const {
459 return PrivateGlobalPrefix;
461 const char *getJumpTableSpecialLabelPrefix() const {
462 return JumpTableSpecialLabelPrefix;
464 const char *getGlobalVarAddrPrefix() const {
465 return GlobalVarAddrPrefix;
467 const char *getGlobalVarAddrSuffix() const {
468 return GlobalVarAddrSuffix;
470 const char *getFunctionAddrPrefix() const {
471 return FunctionAddrPrefix;
473 const char *getFunctionAddrSuffix() const {
474 return FunctionAddrSuffix;
476 const char *getPersonalityPrefix() const {
477 return PersonalityPrefix;
479 const char *getPersonalitySuffix() const {
480 return PersonalitySuffix;
482 bool getNeedsIndirectEncoding() const {
483 return NeedsIndirectEncoding;
485 const char *getInlineAsmStart() const {
486 return InlineAsmStart;
488 const char *getInlineAsmEnd() const {
491 unsigned getAssemblerDialect() const {
492 return AssemblerDialect;
494 const char *getZeroDirective() const {
495 return ZeroDirective;
497 const char *getZeroDirectiveSuffix() const {
498 return ZeroDirectiveSuffix;
500 const char *getAsciiDirective() const {
501 return AsciiDirective;
503 const char *getAscizDirective() const {
504 return AscizDirective;
506 const char *getData8bitsDirective() const {
507 return Data8bitsDirective;
509 const char *getData16bitsDirective() const {
510 return Data16bitsDirective;
512 const char *getData32bitsDirective() const {
513 return Data32bitsDirective;
515 const char *getData64bitsDirective() const {
516 return Data64bitsDirective;
518 const char *getJumpTableDirective() const {
519 return JumpTableDirective;
521 const char *getAlignDirective() const {
522 return AlignDirective;
524 bool getAlignmentIsInBytes() const {
525 return AlignmentIsInBytes;
527 unsigned getTextAlignFillValue() const {
528 return TextAlignFillValue;
530 const char *getSwitchToSectionDirective() const {
531 return SwitchToSectionDirective;
533 const char *getTextSectionStartSuffix() const {
534 return TextSectionStartSuffix;
536 const char *getDataSectionStartSuffix() const {
537 return DataSectionStartSuffix;
539 const char *getSectionEndDirectiveSuffix() const {
540 return SectionEndDirectiveSuffix;
542 const char *getConstantPoolSection() const {
543 return ConstantPoolSection;
545 const char *getJumpTableDataSection() const {
546 return JumpTableDataSection;
548 const char *getCStringSection() const {
549 return CStringSection;
551 const char *getStaticCtorsSection() const {
552 return StaticCtorsSection;
554 const char *getStaticDtorsSection() const {
555 return StaticDtorsSection;
557 const char *getFourByteConstantSection() const {
558 return FourByteConstantSection;
560 const char *getEightByteConstantSection() const {
561 return EightByteConstantSection;
563 const char *getSixteenByteConstantSection() const {
564 return SixteenByteConstantSection;
566 const char *getReadOnlySection() const {
567 return ReadOnlySection;
569 const char *getGlobalDirective() const {
570 return GlobalDirective;
572 const char *getSetDirective() const {
575 const char *getLCOMMDirective() const {
576 return LCOMMDirective;
578 const char *getCOMMDirective() const {
579 return COMMDirective;
581 bool getCOMMDirectiveTakesAlignment() const {
582 return COMMDirectiveTakesAlignment;
584 bool hasDotTypeDotSizeDirective() const {
585 return HasDotTypeDotSizeDirective;
587 const char *getUsedDirective() const {
588 return UsedDirective;
590 const char *getWeakRefDirective() const {
591 return WeakRefDirective;
593 const char *getWeakDefDirective() const {
594 return WeakDefDirective;
596 const char *getHiddenDirective() const {
597 return HiddenDirective;
599 const char *getProtectedDirective() const {
600 return ProtectedDirective;
602 bool isAbsoluteDebugSectionOffsets() const {
603 return AbsoluteDebugSectionOffsets;
605 bool isAbsoluteEHSectionOffsets() const {
606 return AbsoluteEHSectionOffsets;
608 bool hasLEB128() const {
611 bool hasDotLocAndDotFile() const {
612 return HasDotLocAndDotFile;
614 bool doesSupportDebugInformation() const {
615 return SupportsDebugInformation;
617 bool doesSupportExceptionHandling() const {
618 return SupportsExceptionHandling;
620 bool doesDwarfRequireFrameSection() const {
621 return DwarfRequiresFrameSection;
623 const char *getGlobalEHDirective() const {
624 return GlobalEHDirective;
626 bool getSupportsWeakOmittedEHFrame() const {
627 return SupportsWeakOmittedEHFrame;
629 bool getShortenEHDataOn64Bit() const {
630 return ShortenEHDataOn64Bit;
632 const char *getDwarfSectionOffsetDirective() const {
633 return DwarfSectionOffsetDirective;
635 const char *getDwarfAbbrevSection() const {
636 return DwarfAbbrevSection;
638 const char *getDwarfInfoSection() const {
639 return DwarfInfoSection;
641 const char *getDwarfLineSection() const {
642 return DwarfLineSection;
644 const char *getDwarfFrameSection() const {
645 return DwarfFrameSection;
647 const char *getDwarfPubNamesSection() const {
648 return DwarfPubNamesSection;
650 const char *getDwarfPubTypesSection() const {
651 return DwarfPubTypesSection;
653 const char *getDwarfStrSection() const {
654 return DwarfStrSection;
656 const char *getDwarfLocSection() const {
657 return DwarfLocSection;
659 const char *getDwarfARangesSection() const {
660 return DwarfARangesSection;
662 const char *getDwarfRangesSection() const {
663 return DwarfRangesSection;
665 const char *getDwarfMacInfoSection() const {
666 return DwarfMacInfoSection;
668 const char *getDwarfEHFrameSection() const {
669 return DwarfEHFrameSection;
671 const char *getDwarfExceptionSection() const {
672 return DwarfExceptionSection;
674 const char *const *getAsmCBE() const {