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 to use when generating unnamed
151 /// constant strings. These names get run through the Mangler later.
152 const char *StringConstantPrefix; // Defaults to ".str"
154 //===--- Data Emission Directives -------------------------------------===//
156 /// ZeroDirective - this should be set to the directive used to get some
157 /// number of zero bytes emitted to the current section. Common cases are
158 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
159 /// Data*bitsDirective's will be used to emit zero bytes.
160 const char *ZeroDirective; // Defaults to "\t.zero\t"
161 const char *ZeroDirectiveSuffix; // Defaults to ""
163 /// AsciiDirective - This directive allows emission of an ascii string with
164 /// the standard C escape characters embedded into it.
165 const char *AsciiDirective; // Defaults to "\t.ascii\t"
167 /// AscizDirective - If not null, this allows for special handling of
168 /// zero terminated strings on this target. This is commonly supported as
169 /// ".asciz". If a target doesn't support this, it can be set to null.
170 const char *AscizDirective; // Defaults to "\t.asciz\t"
172 /// DataDirectives - These directives are used to output some unit of
173 /// integer data to the current section. If a data directive is set to
174 /// null, smaller data directives will be used to emit the large sizes.
175 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
176 const char *Data16bitsDirective; // Defaults to "\t.short\t"
177 const char *Data32bitsDirective; // Defaults to "\t.long\t"
178 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
180 //===--- Alignment Information ----------------------------------------===//
182 /// AlignDirective - The directive used to emit round up to an alignment
185 const char *AlignDirective; // Defaults to "\t.align\t"
187 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
188 /// emits ".align N" directives, where N is the number of bytes to align to.
189 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
191 bool AlignmentIsInBytes; // Defaults to true
193 /// TextAlignFillValue - If non-zero, this is used to fill the executable
194 /// space created as the result of a alignment directive.
195 unsigned TextAlignFillValue;
197 //===--- Section Switching Directives ---------------------------------===//
199 /// SwitchToSectionDirective - This is the directive used when we want to
200 /// emit a global to an arbitrary section. The section name is emited after
202 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
204 /// TextSectionStartSuffix - This is printed after each start of section
205 /// directive for text sections.
206 const char *TextSectionStartSuffix; // Defaults to "".
208 /// DataSectionStartSuffix - This is printed after each start of section
209 /// directive for data sections.
210 const char *DataSectionStartSuffix; // Defaults to "".
212 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
213 /// section with the section name and this suffix printed.
214 const char *SectionEndDirectiveSuffix;// Defaults to null.
216 /// ConstantPoolSection - This is the section that we SwitchToSection right
217 /// before emitting the constant pool for a function.
218 const char *ConstantPoolSection; // Defaults to "\t.section .rodata"
220 /// JumpTableDataSection - This is the section that we SwitchToSection right
221 /// before emitting the jump tables for a function when the relocation model
223 const char *JumpTableDataSection; // Defaults to "\t.section .rodata"
225 /// JumpTableDirective - if non-null, the directive to emit before a jump
227 const char *JumpTableDirective;
229 /// CStringSection - If not null, this allows for special handling of
230 /// cstring constants (null terminated string that does not contain any
231 /// other null bytes) on this target. This is commonly supported as
233 const char *CStringSection; // Defaults to NULL
235 /// StaticCtorsSection - This is the directive that is emitted to switch to
236 /// a section to emit the static constructor list.
237 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
238 const char *StaticCtorsSection;
240 /// StaticDtorsSection - This is the directive that is emitted to switch to
241 /// a section to emit the static destructor list.
242 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
243 const char *StaticDtorsSection;
245 /// FourByteConstantSection, EightByteConstantSection,
246 /// SixteenByteConstantSection - These are special sections where we place
247 /// 4-, 8-, and 16- byte constant literals.
248 const char *FourByteConstantSection;
249 const char *EightByteConstantSection;
250 const char *SixteenByteConstantSection;
252 /// ReadOnlySection - This is the directive that is emitted to switch to a
253 /// read-only section for constant data (e.g. data declared const,
255 const char *ReadOnlySection; // Defaults to NULL
257 //===--- Global Variable Emission Directives --------------------------===//
259 /// GlobalDirective - This is the directive used to declare a global entity.
261 const char *GlobalDirective; // Defaults to NULL.
263 /// SetDirective - This is the name of a directive that can be used to tell
264 /// the assembler to set the value of a variable to some expression.
265 const char *SetDirective; // Defaults to null.
267 /// LCOMMDirective - This is the name of a directive (if supported) that can
268 /// be used to efficiently declare a local (internal) block of zero
269 /// initialized data in the .bss/.data section. The syntax expected is:
270 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
272 const char *LCOMMDirective; // Defaults to null.
274 const char *COMMDirective; // Defaults to "\t.comm\t".
276 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
277 /// argument that specifies the alignment of the declaration.
278 bool COMMDirectiveTakesAlignment; // Defaults to true.
280 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
281 /// directives, this is true for most ELF targets.
282 bool HasDotTypeDotSizeDirective; // Defaults to true.
284 /// UsedDirective - This directive, if non-null, is used to declare a global
285 /// as being used somehow that the assembler can't see. This prevents dead
286 /// code elimination on some targets.
287 const char *UsedDirective; // Defaults to null.
289 /// WeakRefDirective - This directive, if non-null, is used to declare a
290 /// global as being a weak undefined symbol.
291 const char *WeakRefDirective; // Defaults to null.
293 /// WeakDefDirective - This directive, if non-null, is used to declare a
294 /// global as being a weak defined symbol.
295 const char *WeakDefDirective; // Defaults to null.
297 /// HiddenDirective - This directive, if non-null, is used to declare a
298 /// global or function as having hidden visibility.
299 const char *HiddenDirective; // Defaults to "\t.hidden\t".
301 /// ProtectedDirective - This directive, if non-null, is used to declare a
302 /// global or function as having protected visibility.
303 const char *ProtectedDirective; // Defaults to "\t.protected\t".
305 //===--- Dwarf Emission Directives -----------------------------------===//
307 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
308 /// offsets for debug information. Defaults to false.
309 bool AbsoluteDebugSectionOffsets;
311 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
312 /// offsets for EH information. Defaults to false.
313 bool AbsoluteEHSectionOffsets;
315 /// HasLEB128 - True if target asm supports leb128 directives.
317 bool HasLEB128; // Defaults to false.
319 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
320 /// directives for emitting debugging information.
322 bool HasDotLocAndDotFile; // Defaults to false.
324 /// SupportsDebugInformation - True if target supports emission of debugging
326 bool SupportsDebugInformation;
328 /// SupportsExceptionHandling - True if target supports
329 /// exception handling.
331 bool SupportsExceptionHandling; // Defaults to false.
333 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
335 bool DwarfRequiresFrameSection; // Defaults to true.
337 /// GlobalEHDirective - This is the directive used to make exception frame
338 /// tables globally visible.
340 const char *GlobalEHDirective; // Defaults to NULL.
342 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
343 /// handle a weak_definition of constant 0 for an omitted EH frame.
344 bool SupportsWeakOmittedEHFrame; // Defaults to true.
346 /// DwarfSectionOffsetDirective - Special section offset directive.
347 const char* DwarfSectionOffsetDirective; // Defaults to NULL
349 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
351 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
353 /// DwarfInfoSection - Section directive for Dwarf info.
355 const char *DwarfInfoSection; // Defaults to ".debug_info".
357 /// DwarfLineSection - Section directive for Dwarf info.
359 const char *DwarfLineSection; // Defaults to ".debug_line".
361 /// DwarfFrameSection - Section directive for Dwarf info.
363 const char *DwarfFrameSection; // Defaults to ".debug_frame".
365 /// DwarfPubNamesSection - Section directive for Dwarf info.
367 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
369 /// DwarfPubTypesSection - Section directive for Dwarf info.
371 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
373 /// DwarfStrSection - Section directive for Dwarf info.
375 const char *DwarfStrSection; // Defaults to ".debug_str".
377 /// DwarfLocSection - Section directive for Dwarf info.
379 const char *DwarfLocSection; // Defaults to ".debug_loc".
381 /// DwarfARangesSection - Section directive for Dwarf info.
383 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
385 /// DwarfRangesSection - Section directive for Dwarf info.
387 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
389 /// DwarfMacInfoSection - Section directive for Dwarf info.
391 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
393 /// DwarfEHFrameSection - Section directive for Exception frames.
395 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
397 /// DwarfExceptionSection - Section directive for Exception table.
399 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
402 //===--- CBE Asm Translation Table -----------------------------------===//
404 const char *const *AsmTransCBE; // Defaults to empty
408 virtual ~TargetAsmInfo();
410 /// Measure the specified inline asm to determine an approximation of its
412 virtual unsigned getInlineAsmLength(const char *Str) const;
414 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
415 /// call to be explicit llvm code if it wants to. This is useful for
416 /// turning simple inline asms into LLVM intrinsics, which gives the
417 /// compiler more information about the behavior of the code.
418 virtual bool ExpandInlineAsm(CallInst *CI) const {
422 /// PreferredEHDataFormat - This hook allows the target to select data
423 /// format used for encoding pointers in exception handling data. Reason is
424 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
425 /// if the symbol can be relocated.
426 virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
431 const char *getTextSection() const {
434 const char *getDataSection() const {
437 const char *getBSSSection() const {
440 const char *getTLSDataSection() const {
441 return TLSDataSection;
443 const char *getTLSBSSSection() const {
444 return TLSBSSSection;
446 const char *getZeroFillDirective() const {
447 return ZeroFillDirective;
449 const char *getNonexecutableStackDirective() const {
450 return NonexecutableStackDirective;
452 bool needsSet() const {
455 const char *getPCSymbol() const {
458 char getSeparatorChar() const {
459 return SeparatorChar;
461 const char *getCommentString() const {
462 return CommentString;
464 const char *getGlobalPrefix() const {
467 const char *getPrivateGlobalPrefix() const {
468 return PrivateGlobalPrefix;
470 const char *getJumpTableSpecialLabelPrefix() const {
471 return JumpTableSpecialLabelPrefix;
473 const char *getGlobalVarAddrPrefix() const {
474 return GlobalVarAddrPrefix;
476 const char *getGlobalVarAddrSuffix() const {
477 return GlobalVarAddrSuffix;
479 const char *getFunctionAddrPrefix() const {
480 return FunctionAddrPrefix;
482 const char *getFunctionAddrSuffix() const {
483 return FunctionAddrSuffix;
485 const char *getPersonalityPrefix() const {
486 return PersonalityPrefix;
488 const char *getPersonalitySuffix() const {
489 return PersonalitySuffix;
491 bool getNeedsIndirectEncoding() const {
492 return NeedsIndirectEncoding;
494 const char *getInlineAsmStart() const {
495 return InlineAsmStart;
497 const char *getInlineAsmEnd() const {
500 unsigned getAssemblerDialect() const {
501 return AssemblerDialect;
503 const char *getStringConstantPrefix() const {
504 return StringConstantPrefix;
506 const char *getZeroDirective() const {
507 return ZeroDirective;
509 const char *getZeroDirectiveSuffix() const {
510 return ZeroDirectiveSuffix;
512 const char *getAsciiDirective() const {
513 return AsciiDirective;
515 const char *getAscizDirective() const {
516 return AscizDirective;
518 const char *getData8bitsDirective() const {
519 return Data8bitsDirective;
521 const char *getData16bitsDirective() const {
522 return Data16bitsDirective;
524 const char *getData32bitsDirective() const {
525 return Data32bitsDirective;
527 const char *getData64bitsDirective() const {
528 return Data64bitsDirective;
530 const char *getJumpTableDirective() const {
531 return JumpTableDirective;
533 const char *getAlignDirective() const {
534 return AlignDirective;
536 bool getAlignmentIsInBytes() const {
537 return AlignmentIsInBytes;
539 unsigned getTextAlignFillValue() const {
540 return TextAlignFillValue;
542 const char *getSwitchToSectionDirective() const {
543 return SwitchToSectionDirective;
545 const char *getTextSectionStartSuffix() const {
546 return TextSectionStartSuffix;
548 const char *getDataSectionStartSuffix() const {
549 return DataSectionStartSuffix;
551 const char *getSectionEndDirectiveSuffix() const {
552 return SectionEndDirectiveSuffix;
554 const char *getConstantPoolSection() const {
555 return ConstantPoolSection;
557 const char *getJumpTableDataSection() const {
558 return JumpTableDataSection;
560 const char *getCStringSection() const {
561 return CStringSection;
563 const char *getStaticCtorsSection() const {
564 return StaticCtorsSection;
566 const char *getStaticDtorsSection() const {
567 return StaticDtorsSection;
569 const char *getFourByteConstantSection() const {
570 return FourByteConstantSection;
572 const char *getEightByteConstantSection() const {
573 return EightByteConstantSection;
575 const char *getSixteenByteConstantSection() const {
576 return SixteenByteConstantSection;
578 const char *getReadOnlySection() const {
579 return ReadOnlySection;
581 const char *getGlobalDirective() const {
582 return GlobalDirective;
584 const char *getSetDirective() const {
587 const char *getLCOMMDirective() const {
588 return LCOMMDirective;
590 const char *getCOMMDirective() const {
591 return COMMDirective;
593 bool getCOMMDirectiveTakesAlignment() const {
594 return COMMDirectiveTakesAlignment;
596 bool hasDotTypeDotSizeDirective() const {
597 return HasDotTypeDotSizeDirective;
599 const char *getUsedDirective() const {
600 return UsedDirective;
602 const char *getWeakRefDirective() const {
603 return WeakRefDirective;
605 const char *getWeakDefDirective() const {
606 return WeakDefDirective;
608 const char *getHiddenDirective() const {
609 return HiddenDirective;
611 const char *getProtectedDirective() const {
612 return ProtectedDirective;
614 bool isAbsoluteDebugSectionOffsets() const {
615 return AbsoluteDebugSectionOffsets;
617 bool isAbsoluteEHSectionOffsets() const {
618 return AbsoluteEHSectionOffsets;
620 bool hasLEB128() const {
623 bool hasDotLocAndDotFile() const {
624 return HasDotLocAndDotFile;
626 bool doesSupportDebugInformation() const {
627 return SupportsDebugInformation;
629 bool doesSupportExceptionHandling() const {
630 return SupportsExceptionHandling;
632 bool doesDwarfRequireFrameSection() const {
633 return DwarfRequiresFrameSection;
635 const char *getGlobalEHDirective() const {
636 return GlobalEHDirective;
638 bool getSupportsWeakOmittedEHFrame() const {
639 return SupportsWeakOmittedEHFrame;
641 const char *getDwarfSectionOffsetDirective() const {
642 return DwarfSectionOffsetDirective;
644 const char *getDwarfAbbrevSection() const {
645 return DwarfAbbrevSection;
647 const char *getDwarfInfoSection() const {
648 return DwarfInfoSection;
650 const char *getDwarfLineSection() const {
651 return DwarfLineSection;
653 const char *getDwarfFrameSection() const {
654 return DwarfFrameSection;
656 const char *getDwarfPubNamesSection() const {
657 return DwarfPubNamesSection;
659 const char *getDwarfPubTypesSection() const {
660 return DwarfPubTypesSection;
662 const char *getDwarfStrSection() const {
663 return DwarfStrSection;
665 const char *getDwarfLocSection() const {
666 return DwarfLocSection;
668 const char *getDwarfARangesSection() const {
669 return DwarfARangesSection;
671 const char *getDwarfRangesSection() const {
672 return DwarfRangesSection;
674 const char *getDwarfMacInfoSection() const {
675 return DwarfMacInfoSection;
677 const char *getDwarfEHFrameSection() const {
678 return DwarfEHFrameSection;
680 const char *getDwarfExceptionSection() const {
681 return DwarfExceptionSection;
683 const char *const *getAsmCBE() const {