1 //===-- llvm/Target/TargetAsmInfo.h - Asm info ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by James M. Laskey and is distributed under
6 // the University of Illinois Open Source 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 /// DwarfSectionOffsetDirective - Special section offset directive.
313 const char* DwarfSectionOffsetDirective; // Defaults to NULL
315 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
317 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
319 /// DwarfInfoSection - Section directive for Dwarf info.
321 const char *DwarfInfoSection; // Defaults to ".debug_info".
323 /// DwarfLineSection - Section directive for Dwarf info.
325 const char *DwarfLineSection; // Defaults to ".debug_line".
327 /// DwarfFrameSection - Section directive for Dwarf info.
329 const char *DwarfFrameSection; // Defaults to ".debug_frame".
331 /// DwarfPubNamesSection - Section directive for Dwarf info.
333 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
335 /// DwarfPubTypesSection - Section directive for Dwarf info.
337 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
339 /// DwarfStrSection - Section directive for Dwarf info.
341 const char *DwarfStrSection; // Defaults to ".debug_str".
343 /// DwarfLocSection - Section directive for Dwarf info.
345 const char *DwarfLocSection; // Defaults to ".debug_loc".
347 /// DwarfARangesSection - Section directive for Dwarf info.
349 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
351 /// DwarfRangesSection - Section directive for Dwarf info.
353 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
355 /// DwarfMacInfoSection - Section directive for Dwarf info.
357 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
359 /// DwarfEHFrameSection - Section directive for Exception frames.
361 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
363 /// DwarfExceptionSection - Section directive for Exception table.
365 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
368 //===--- CBE Asm Translation Table -----------------------------------===//
370 const char** AsmTransCBE; // Defaults to empty
374 virtual ~TargetAsmInfo();
376 /// Measure the specified inline asm to determine an approximation of its
378 virtual unsigned getInlineAsmLength(const char *Str) const;
380 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
381 /// call to be explicit llvm code if it wants to. This is useful for
382 /// turning simple inline asms into LLVM intrinsics, which gives the
383 /// compiler more information about the behavior of the code.
384 virtual bool ExpandInlineAsm(CallInst *CI) const {
390 const char *getTextSection() const {
393 const char *getDataSection() const {
396 const char *getBSSSection() const {
399 const char *getTLSDataSection() const {
400 return TLSDataSection;
402 const char *getTLSBSSSection() const {
403 return TLSBSSSection;
405 const char *getZeroFillDirective() const {
406 return ZeroFillDirective;
408 bool needsSet() const {
411 const char *getPCSymbol() const {
414 char getSeparatorChar() const {
415 return SeparatorChar;
417 const char *getCommentString() const {
418 return CommentString;
420 const char *getGlobalPrefix() const {
423 const char *getPrivateGlobalPrefix() const {
424 return PrivateGlobalPrefix;
426 const char *getJumpTableSpecialLabelPrefix() const {
427 return JumpTableSpecialLabelPrefix;
429 const char *getGlobalVarAddrPrefix() const {
430 return GlobalVarAddrPrefix;
432 const char *getGlobalVarAddrSuffix() const {
433 return GlobalVarAddrSuffix;
435 const char *getFunctionAddrPrefix() const {
436 return FunctionAddrPrefix;
438 const char *getFunctionAddrSuffix() const {
439 return FunctionAddrSuffix;
441 const char *getPersonalityPrefix() const {
442 return PersonalityPrefix;
444 const char *getPersonalitySuffix() const {
445 return PersonalitySuffix;
447 bool getNeedsIndirectEncoding() const {
448 return NeedsIndirectEncoding;
450 const char *getInlineAsmStart() const {
451 return InlineAsmStart;
453 const char *getInlineAsmEnd() const {
456 unsigned getAssemblerDialect() const {
457 return AssemblerDialect;
459 const char *getZeroDirective() const {
460 return ZeroDirective;
462 const char *getZeroDirectiveSuffix() const {
463 return ZeroDirectiveSuffix;
465 const char *getAsciiDirective() const {
466 return AsciiDirective;
468 const char *getAscizDirective() const {
469 return AscizDirective;
471 const char *getData8bitsDirective() const {
472 return Data8bitsDirective;
474 const char *getData16bitsDirective() const {
475 return Data16bitsDirective;
477 const char *getData32bitsDirective() const {
478 return Data32bitsDirective;
480 const char *getData64bitsDirective() const {
481 return Data64bitsDirective;
483 const char *getJumpTableDirective() const {
484 return JumpTableDirective;
486 const char *getAlignDirective() const {
487 return AlignDirective;
489 bool getAlignmentIsInBytes() const {
490 return AlignmentIsInBytes;
492 const char *getSwitchToSectionDirective() const {
493 return SwitchToSectionDirective;
495 const char *getTextSectionStartSuffix() const {
496 return TextSectionStartSuffix;
498 const char *getDataSectionStartSuffix() const {
499 return DataSectionStartSuffix;
501 const char *getSectionEndDirectiveSuffix() const {
502 return SectionEndDirectiveSuffix;
504 const char *getConstantPoolSection() const {
505 return ConstantPoolSection;
507 const char *getJumpTableDataSection() const {
508 return JumpTableDataSection;
510 const char *getCStringSection() const {
511 return CStringSection;
513 const char *getStaticCtorsSection() const {
514 return StaticCtorsSection;
516 const char *getStaticDtorsSection() const {
517 return StaticDtorsSection;
519 const char *getFourByteConstantSection() const {
520 return FourByteConstantSection;
522 const char *getEightByteConstantSection() const {
523 return EightByteConstantSection;
525 const char *getSixteenByteConstantSection() const {
526 return SixteenByteConstantSection;
528 const char *getReadOnlySection() const {
529 return ReadOnlySection;
531 const char *getGlobalDirective() const {
532 return GlobalDirective;
534 const char *getSetDirective() const {
537 const char *getLCOMMDirective() const {
538 return LCOMMDirective;
540 const char *getCOMMDirective() const {
541 return COMMDirective;
543 bool getCOMMDirectiveTakesAlignment() const {
544 return COMMDirectiveTakesAlignment;
546 bool hasDotTypeDotSizeDirective() const {
547 return HasDotTypeDotSizeDirective;
549 const char *getUsedDirective() const {
550 return UsedDirective;
552 const char *getWeakRefDirective() const {
553 return WeakRefDirective;
555 const char *getWeakDefDirective() const {
556 return WeakDefDirective;
558 const char *getHiddenDirective() const {
559 return HiddenDirective;
561 const char *getProtectedDirective() const {
562 return ProtectedDirective;
564 bool isAbsoluteDebugSectionOffsets() const {
565 return AbsoluteDebugSectionOffsets;
567 bool isAbsoluteEHSectionOffsets() const {
568 return AbsoluteEHSectionOffsets;
570 bool hasLEB128() const {
573 bool hasDotLocAndDotFile() const {
574 return HasDotLocAndDotFile;
576 bool doesSupportDebugInformation() const {
577 return SupportsDebugInformation;
579 bool doesSupportExceptionHandling() const {
580 return SupportsExceptionHandling;
582 bool doesDwarfRequireFrameSection() const {
583 return DwarfRequiresFrameSection;
585 const char *getGlobalEHDirective() const {
586 return GlobalEHDirective;
588 const char *getDwarfSectionOffsetDirective() const {
589 return DwarfSectionOffsetDirective;
591 const char *getDwarfAbbrevSection() const {
592 return DwarfAbbrevSection;
594 const char *getDwarfInfoSection() const {
595 return DwarfInfoSection;
597 const char *getDwarfLineSection() const {
598 return DwarfLineSection;
600 const char *getDwarfFrameSection() const {
601 return DwarfFrameSection;
603 const char *getDwarfPubNamesSection() const {
604 return DwarfPubNamesSection;
606 const char *getDwarfPubTypesSection() const {
607 return DwarfPubTypesSection;
609 const char *getDwarfStrSection() const {
610 return DwarfStrSection;
612 const char *getDwarfLocSection() const {
613 return DwarfLocSection;
615 const char *getDwarfARangesSection() const {
616 return DwarfARangesSection;
618 const char *getDwarfRangesSection() const {
619 return DwarfRangesSection;
621 const char *getDwarfMacInfoSection() const {
622 return DwarfMacInfoSection;
624 const char *getDwarfEHFrameSection() const {
625 return DwarfEHFrameSection;
627 const char *getDwarfExceptionSection() const {
628 return DwarfExceptionSection;
630 const char** getAsmCBE() const {