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"
26 /// TargetAsmInfo - This class is intended to be used as a base class for asm
27 /// properties and features specific to the target.
30 //===------------------------------------------------------------------===//
31 // Properties to be set by the target writer, used to configure asm printer.
34 /// TextSection - Section directive for standard text.
36 const char *TextSection; // Defaults to ".text".
38 /// DataSection - Section directive for standard data.
40 const char *DataSection; // Defaults to ".data".
42 /// BSSSection - Section directive for uninitialized data. Null if this
43 /// target doesn't support a BSS section.
45 const char *BSSSection; // Default to ".bss".
47 /// TLSDataSection - Section directive for Thread Local data.
49 const char *TLSDataSection;// Defaults to ".section .tdata,"awT",@progbits".
51 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
52 /// Null if this target doesn't support a BSS section.
54 const char *TLSBSSSection;// Default to ".section .tbss,"awT",@nobits".
55 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
56 /// section on this target. Null if this target doesn't support zerofill.
57 const char *ZeroFillDirective; // Default is null.
59 /// NeedsSet - True if target asm can't compute addresses on data
61 bool NeedsSet; // Defaults to false.
63 /// MaxInstLength - This is the maximum possible length of an instruction,
64 /// which is needed to compute the size of an inline asm.
65 unsigned MaxInstLength; // Defaults to 4.
67 /// PCSymbol - The symbol used to represent the current PC. Used in PC
68 /// relative expressions.
69 const char *PCSymbol; // Defaults to "$".
71 /// SeparatorChar - This character, if specified, is used to separate
72 /// instructions from each other when on the same line. This is used to
73 /// measure inline asm instructions.
74 char SeparatorChar; // Defaults to ';'
76 /// CommentString - This indicates the comment character used by the
78 const char *CommentString; // Defaults to "#"
80 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
81 /// onto all global symbols. This is often used for "_" or ".".
82 const char *GlobalPrefix; // Defaults to ""
84 /// PrivateGlobalPrefix - This prefix is used for globals like constant
85 /// pool entries that are completely private to the .o file and should not
86 /// have names in the .o file. This is often "." or "L".
87 const char *PrivateGlobalPrefix; // Defaults to "."
89 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
90 /// emitted before jump tables with the specified prefix.
91 const char *JumpTableSpecialLabelPrefix; // Default to null.
93 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
94 /// will enclose any GlobalVariable (that isn't a function)
96 const char *GlobalVarAddrPrefix; // Defaults to ""
97 const char *GlobalVarAddrSuffix; // Defaults to ""
99 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
100 /// will enclose any GlobalVariable that points to a function.
101 /// For example, this is used by the IA64 backend to materialize
102 /// function descriptors, by decorating the ".data8" object with the
103 /// @verbatim @fptr( ) @endverbatim
104 /// link-relocation operator.
106 const char *FunctionAddrPrefix; // Defaults to ""
107 const char *FunctionAddrSuffix; // Defaults to ""
109 /// PersonalityPrefix/Suffix - If these are nonempty, these strings will
110 /// enclose any personality function in the common frame section.
112 const char *PersonalityPrefix; // Defaults to ""
113 const char *PersonalitySuffix; // Defaults to ""
115 /// NeedsIndirectEncoding - If set, we need to set the indirect encoding bit
118 bool NeedsIndirectEncoding; // Defaults to false
120 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
121 /// emit before and after an inline assembly statement.
122 const char *InlineAsmStart; // Defaults to "#APP\n"
123 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
125 /// AssemblerDialect - Which dialect of an assembler variant to use.
126 unsigned AssemblerDialect; // Defaults to 0
128 //===--- Data Emission Directives -------------------------------------===//
130 /// ZeroDirective - this should be set to the directive used to get some
131 /// number of zero bytes emitted to the current section. Common cases are
132 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
133 /// Data*bitsDirective's will be used to emit zero bytes.
134 const char *ZeroDirective; // Defaults to "\t.zero\t"
135 const char *ZeroDirectiveSuffix; // Defaults to ""
137 /// AsciiDirective - This directive allows emission of an ascii string with
138 /// the standard C escape characters embedded into it.
139 const char *AsciiDirective; // Defaults to "\t.ascii\t"
141 /// AscizDirective - If not null, this allows for special handling of
142 /// zero terminated strings on this target. This is commonly supported as
143 /// ".asciz". If a target doesn't support this, it can be set to null.
144 const char *AscizDirective; // Defaults to "\t.asciz\t"
146 /// DataDirectives - These directives are used to output some unit of
147 /// integer data to the current section. If a data directive is set to
148 /// null, smaller data directives will be used to emit the large sizes.
149 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
150 const char *Data16bitsDirective; // Defaults to "\t.short\t"
151 const char *Data32bitsDirective; // Defaults to "\t.long\t"
152 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
154 //===--- Alignment Information ----------------------------------------===//
156 /// AlignDirective - The directive used to emit round up to an alignment
159 const char *AlignDirective; // Defaults to "\t.align\t"
161 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
162 /// emits ".align N" directives, where N is the number of bytes to align to.
163 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
165 bool AlignmentIsInBytes; // Defaults to true
167 //===--- Section Switching Directives ---------------------------------===//
169 /// SwitchToSectionDirective - This is the directive used when we want to
170 /// emit a global to an arbitrary section. The section name is emited after
172 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
174 /// TextSectionStartSuffix - This is printed after each start of section
175 /// directive for text sections.
176 const char *TextSectionStartSuffix; // Defaults to "".
178 /// DataSectionStartSuffix - This is printed after each start of section
179 /// directive for data sections.
180 const char *DataSectionStartSuffix; // Defaults to "".
182 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
183 /// section with the section name and this suffix printed.
184 const char *SectionEndDirectiveSuffix;// Defaults to null.
186 /// ConstantPoolSection - This is the section that we SwitchToSection right
187 /// before emitting the constant pool for a function.
188 const char *ConstantPoolSection; // Defaults to "\t.section .rodata"
190 /// JumpTableDataSection - This is the section that we SwitchToSection right
191 /// before emitting the jump tables for a function when the relocation model
193 const char *JumpTableDataSection; // Defaults to "\t.section .rodata"
195 /// JumpTableDirective - if non-null, the directive to emit before a jump
197 const char *JumpTableDirective;
199 /// CStringSection - If not null, this allows for special handling of
200 /// cstring constants (null terminated string that does not contain any
201 /// other null bytes) on this target. This is commonly supported as
203 const char *CStringSection; // Defaults to NULL
205 /// StaticCtorsSection - This is the directive that is emitted to switch to
206 /// a section to emit the static constructor list.
207 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
208 const char *StaticCtorsSection;
210 /// StaticDtorsSection - This is the directive that is emitted to switch to
211 /// a section to emit the static destructor list.
212 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
213 const char *StaticDtorsSection;
215 /// FourByteConstantSection, EightByteConstantSection,
216 /// SixteenByteConstantSection - These are special sections where we place
217 /// 4-, 8-, and 16- byte constant literals.
218 const char *FourByteConstantSection;
219 const char *EightByteConstantSection;
220 const char *SixteenByteConstantSection;
222 /// ReadOnlySection - This is the directive that is emitted to switch to a
223 /// read-only section for constant data (e.g. data declared const,
225 const char *ReadOnlySection; // Defaults to NULL
227 //===--- Global Variable Emission Directives --------------------------===//
229 /// GlobalDirective - This is the directive used to declare a global entity.
231 const char *GlobalDirective; // Defaults to NULL.
233 /// SetDirective - This is the name of a directive that can be used to tell
234 /// the assembler to set the value of a variable to some expression.
235 const char *SetDirective; // Defaults to null.
237 /// LCOMMDirective - This is the name of a directive (if supported) that can
238 /// be used to efficiently declare a local (internal) block of zero
239 /// initialized data in the .bss/.data section. The syntax expected is:
240 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
242 const char *LCOMMDirective; // Defaults to null.
244 const char *COMMDirective; // Defaults to "\t.comm\t".
246 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
247 /// argument that specifies the alignment of the declaration.
248 bool COMMDirectiveTakesAlignment; // Defaults to true.
250 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
251 /// directives, this is true for most ELF targets.
252 bool HasDotTypeDotSizeDirective; // Defaults to true.
254 /// UsedDirective - This directive, if non-null, is used to declare a global
255 /// as being used somehow that the assembler can't see. This prevents dead
256 /// code elimination on some targets.
257 const char *UsedDirective; // Defaults to null.
259 /// WeakRefDirective - This directive, if non-null, is used to declare a
260 /// global as being a weak undefined symbol.
261 const char *WeakRefDirective; // Defaults to null.
263 /// WeakDefDirective - This directive, if non-null, is used to declare a
264 /// global as being a weak defined symbol.
265 const char *WeakDefDirective; // Defaults to null.
267 /// HiddenDirective - This directive, if non-null, is used to declare a
268 /// global or function as having hidden visibility.
269 const char *HiddenDirective; // Defaults to "\t.hidden\t".
271 /// ProtectedDirective - This directive, if non-null, is used to declare a
272 /// global or function as having protected visibility.
273 const char *ProtectedDirective; // Defaults to "\t.protected\t".
275 //===--- Dwarf Emission Directives -----------------------------------===//
277 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
278 /// offsets for debug information. Defaults to false.
279 bool AbsoluteDebugSectionOffsets;
281 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
282 /// offsets for EH information. Defaults to false.
283 bool AbsoluteEHSectionOffsets;
285 /// HasLEB128 - True if target asm supports leb128 directives.
287 bool HasLEB128; // Defaults to false.
289 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
290 /// directives for emitting debugging information.
292 bool HasDotLocAndDotFile; // Defaults to false.
294 /// SupportsDebugInformation - True if target supports emission of debugging
296 bool SupportsDebugInformation;
298 /// SupportsExceptionHandling - True if target supports
299 /// exception handling.
301 bool SupportsExceptionHandling; // Defaults to false.
303 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
305 bool DwarfRequiresFrameSection; // Defaults to true.
307 /// GlobalEHDirective - This is the directive used to make exception frame
308 /// tables globally visible.
310 const char *GlobalEHDirective; // Defaults to NULL.
312 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
313 /// handle a weak_definition of constant 0 for an omitted EH frame.
314 bool SupportsWeakOmittedEHFrame; // Defaults to true.
316 /// ShortenEHDataON64Bit - True if target exception table format requires
317 /// 32-bit data in certain places even when targeting 64-bits.
318 bool ShortenEHDataOn64Bit; // Defaults to false.
320 /// DwarfSectionOffsetDirective - Special section offset directive.
321 const char* DwarfSectionOffsetDirective; // Defaults to NULL
323 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
325 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
327 /// DwarfInfoSection - Section directive for Dwarf info.
329 const char *DwarfInfoSection; // Defaults to ".debug_info".
331 /// DwarfLineSection - Section directive for Dwarf info.
333 const char *DwarfLineSection; // Defaults to ".debug_line".
335 /// DwarfFrameSection - Section directive for Dwarf info.
337 const char *DwarfFrameSection; // Defaults to ".debug_frame".
339 /// DwarfPubNamesSection - Section directive for Dwarf info.
341 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
343 /// DwarfPubTypesSection - Section directive for Dwarf info.
345 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
347 /// DwarfStrSection - Section directive for Dwarf info.
349 const char *DwarfStrSection; // Defaults to ".debug_str".
351 /// DwarfLocSection - Section directive for Dwarf info.
353 const char *DwarfLocSection; // Defaults to ".debug_loc".
355 /// DwarfARangesSection - Section directive for Dwarf info.
357 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
359 /// DwarfRangesSection - Section directive for Dwarf info.
361 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
363 /// DwarfMacInfoSection - Section directive for Dwarf info.
365 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
367 /// DwarfEHFrameSection - Section directive for Exception frames.
369 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
371 /// DwarfExceptionSection - Section directive for Exception table.
373 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
376 //===--- CBE Asm Translation Table -----------------------------------===//
378 const char** AsmTransCBE; // Defaults to empty
382 virtual ~TargetAsmInfo();
384 /// Measure the specified inline asm to determine an approximation of its
386 virtual unsigned getInlineAsmLength(const char *Str) const;
388 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
389 /// call to be explicit llvm code if it wants to. This is useful for
390 /// turning simple inline asms into LLVM intrinsics, which gives the
391 /// compiler more information about the behavior of the code.
392 virtual bool ExpandInlineAsm(CallInst *CI) const {
398 const char *getTextSection() const {
401 const char *getDataSection() const {
404 const char *getBSSSection() const {
407 const char *getTLSDataSection() const {
408 return TLSDataSection;
410 const char *getTLSBSSSection() const {
411 return TLSBSSSection;
413 const char *getZeroFillDirective() const {
414 return ZeroFillDirective;
416 bool needsSet() const {
419 const char *getPCSymbol() const {
422 char getSeparatorChar() const {
423 return SeparatorChar;
425 const char *getCommentString() const {
426 return CommentString;
428 const char *getGlobalPrefix() const {
431 const char *getPrivateGlobalPrefix() const {
432 return PrivateGlobalPrefix;
434 const char *getJumpTableSpecialLabelPrefix() const {
435 return JumpTableSpecialLabelPrefix;
437 const char *getGlobalVarAddrPrefix() const {
438 return GlobalVarAddrPrefix;
440 const char *getGlobalVarAddrSuffix() const {
441 return GlobalVarAddrSuffix;
443 const char *getFunctionAddrPrefix() const {
444 return FunctionAddrPrefix;
446 const char *getFunctionAddrSuffix() const {
447 return FunctionAddrSuffix;
449 const char *getPersonalityPrefix() const {
450 return PersonalityPrefix;
452 const char *getPersonalitySuffix() const {
453 return PersonalitySuffix;
455 bool getNeedsIndirectEncoding() const {
456 return NeedsIndirectEncoding;
458 const char *getInlineAsmStart() const {
459 return InlineAsmStart;
461 const char *getInlineAsmEnd() const {
464 unsigned getAssemblerDialect() const {
465 return AssemblerDialect;
467 const char *getZeroDirective() const {
468 return ZeroDirective;
470 const char *getZeroDirectiveSuffix() const {
471 return ZeroDirectiveSuffix;
473 const char *getAsciiDirective() const {
474 return AsciiDirective;
476 const char *getAscizDirective() const {
477 return AscizDirective;
479 const char *getData8bitsDirective() const {
480 return Data8bitsDirective;
482 const char *getData16bitsDirective() const {
483 return Data16bitsDirective;
485 const char *getData32bitsDirective() const {
486 return Data32bitsDirective;
488 const char *getData64bitsDirective() const {
489 return Data64bitsDirective;
491 const char *getJumpTableDirective() const {
492 return JumpTableDirective;
494 const char *getAlignDirective() const {
495 return AlignDirective;
497 bool getAlignmentIsInBytes() const {
498 return AlignmentIsInBytes;
500 const char *getSwitchToSectionDirective() const {
501 return SwitchToSectionDirective;
503 const char *getTextSectionStartSuffix() const {
504 return TextSectionStartSuffix;
506 const char *getDataSectionStartSuffix() const {
507 return DataSectionStartSuffix;
509 const char *getSectionEndDirectiveSuffix() const {
510 return SectionEndDirectiveSuffix;
512 const char *getConstantPoolSection() const {
513 return ConstantPoolSection;
515 const char *getJumpTableDataSection() const {
516 return JumpTableDataSection;
518 const char *getCStringSection() const {
519 return CStringSection;
521 const char *getStaticCtorsSection() const {
522 return StaticCtorsSection;
524 const char *getStaticDtorsSection() const {
525 return StaticDtorsSection;
527 const char *getFourByteConstantSection() const {
528 return FourByteConstantSection;
530 const char *getEightByteConstantSection() const {
531 return EightByteConstantSection;
533 const char *getSixteenByteConstantSection() const {
534 return SixteenByteConstantSection;
536 const char *getReadOnlySection() const {
537 return ReadOnlySection;
539 const char *getGlobalDirective() const {
540 return GlobalDirective;
542 const char *getSetDirective() const {
545 const char *getLCOMMDirective() const {
546 return LCOMMDirective;
548 const char *getCOMMDirective() const {
549 return COMMDirective;
551 bool getCOMMDirectiveTakesAlignment() const {
552 return COMMDirectiveTakesAlignment;
554 bool hasDotTypeDotSizeDirective() const {
555 return HasDotTypeDotSizeDirective;
557 const char *getUsedDirective() const {
558 return UsedDirective;
560 const char *getWeakRefDirective() const {
561 return WeakRefDirective;
563 const char *getWeakDefDirective() const {
564 return WeakDefDirective;
566 const char *getHiddenDirective() const {
567 return HiddenDirective;
569 const char *getProtectedDirective() const {
570 return ProtectedDirective;
572 bool isAbsoluteDebugSectionOffsets() const {
573 return AbsoluteDebugSectionOffsets;
575 bool isAbsoluteEHSectionOffsets() const {
576 return AbsoluteEHSectionOffsets;
578 bool hasLEB128() const {
581 bool hasDotLocAndDotFile() const {
582 return HasDotLocAndDotFile;
584 bool doesSupportDebugInformation() const {
585 return SupportsDebugInformation;
587 bool doesSupportExceptionHandling() const {
588 return SupportsExceptionHandling;
590 bool doesDwarfRequireFrameSection() const {
591 return DwarfRequiresFrameSection;
593 const char *getGlobalEHDirective() const {
594 return GlobalEHDirective;
596 bool getSupportsWeakOmittedEHFrame() const {
597 return SupportsWeakOmittedEHFrame;
599 bool getShortenEHDataOn64Bit() const {
600 return ShortenEHDataOn64Bit;
602 const char *getDwarfSectionOffsetDirective() const {
603 return DwarfSectionOffsetDirective;
605 const char *getDwarfAbbrevSection() const {
606 return DwarfAbbrevSection;
608 const char *getDwarfInfoSection() const {
609 return DwarfInfoSection;
611 const char *getDwarfLineSection() const {
612 return DwarfLineSection;
614 const char *getDwarfFrameSection() const {
615 return DwarfFrameSection;
617 const char *getDwarfPubNamesSection() const {
618 return DwarfPubNamesSection;
620 const char *getDwarfPubTypesSection() const {
621 return DwarfPubTypesSection;
623 const char *getDwarfStrSection() const {
624 return DwarfStrSection;
626 const char *getDwarfLocSection() const {
627 return DwarfLocSection;
629 const char *getDwarfARangesSection() const {
630 return DwarfARangesSection;
632 const char *getDwarfRangesSection() const {
633 return DwarfRangesSection;
635 const char *getDwarfMacInfoSection() const {
636 return DwarfMacInfoSection;
638 const char *getDwarfEHFrameSection() const {
639 return DwarfEHFrameSection;
641 const char *getDwarfExceptionSection() const {
642 return DwarfExceptionSection;
644 const char** getAsmCBE() const {