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 //===--- Data Emission Directives -------------------------------------===//
152 /// ZeroDirective - this should be set to the directive used to get some
153 /// number of zero bytes emitted to the current section. Common cases are
154 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
155 /// Data*bitsDirective's will be used to emit zero bytes.
156 const char *ZeroDirective; // Defaults to "\t.zero\t"
157 const char *ZeroDirectiveSuffix; // Defaults to ""
159 /// AsciiDirective - This directive allows emission of an ascii string with
160 /// the standard C escape characters embedded into it.
161 const char *AsciiDirective; // Defaults to "\t.ascii\t"
163 /// AscizDirective - If not null, this allows for special handling of
164 /// zero terminated strings on this target. This is commonly supported as
165 /// ".asciz". If a target doesn't support this, it can be set to null.
166 const char *AscizDirective; // Defaults to "\t.asciz\t"
168 /// DataDirectives - These directives are used to output some unit of
169 /// integer data to the current section. If a data directive is set to
170 /// null, smaller data directives will be used to emit the large sizes.
171 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
172 const char *Data16bitsDirective; // Defaults to "\t.short\t"
173 const char *Data32bitsDirective; // Defaults to "\t.long\t"
174 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
176 //===--- Alignment Information ----------------------------------------===//
178 /// AlignDirective - The directive used to emit round up to an alignment
181 const char *AlignDirective; // Defaults to "\t.align\t"
183 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
184 /// emits ".align N" directives, where N is the number of bytes to align to.
185 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
187 bool AlignmentIsInBytes; // Defaults to true
189 /// TextAlignFillValue - If non-zero, this is used to fill the executable
190 /// space created as the result of a alignment directive.
191 unsigned TextAlignFillValue;
193 //===--- Section Switching Directives ---------------------------------===//
195 /// SwitchToSectionDirective - This is the directive used when we want to
196 /// emit a global to an arbitrary section. The section name is emited after
198 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
200 /// TextSectionStartSuffix - This is printed after each start of section
201 /// directive for text sections.
202 const char *TextSectionStartSuffix; // Defaults to "".
204 /// DataSectionStartSuffix - This is printed after each start of section
205 /// directive for data sections.
206 const char *DataSectionStartSuffix; // Defaults to "".
208 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
209 /// section with the section name and this suffix printed.
210 const char *SectionEndDirectiveSuffix;// Defaults to null.
212 /// ConstantPoolSection - This is the section that we SwitchToSection right
213 /// before emitting the constant pool for a function.
214 const char *ConstantPoolSection; // Defaults to "\t.section .rodata"
216 /// JumpTableDataSection - This is the section that we SwitchToSection right
217 /// before emitting the jump tables for a function when the relocation model
219 const char *JumpTableDataSection; // Defaults to "\t.section .rodata"
221 /// JumpTableDirective - if non-null, the directive to emit before a jump
223 const char *JumpTableDirective;
225 /// CStringSection - If not null, this allows for special handling of
226 /// cstring constants (null terminated string that does not contain any
227 /// other null bytes) on this target. This is commonly supported as
229 const char *CStringSection; // Defaults to NULL
231 /// StaticCtorsSection - This is the directive that is emitted to switch to
232 /// a section to emit the static constructor list.
233 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
234 const char *StaticCtorsSection;
236 /// StaticDtorsSection - This is the directive that is emitted to switch to
237 /// a section to emit the static destructor list.
238 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
239 const char *StaticDtorsSection;
241 /// FourByteConstantSection, EightByteConstantSection,
242 /// SixteenByteConstantSection - These are special sections where we place
243 /// 4-, 8-, and 16- byte constant literals.
244 const char *FourByteConstantSection;
245 const char *EightByteConstantSection;
246 const char *SixteenByteConstantSection;
248 /// ReadOnlySection - This is the directive that is emitted to switch to a
249 /// read-only section for constant data (e.g. data declared const,
251 const char *ReadOnlySection; // Defaults to NULL
253 //===--- Global Variable Emission Directives --------------------------===//
255 /// GlobalDirective - This is the directive used to declare a global entity.
257 const char *GlobalDirective; // Defaults to NULL.
259 /// SetDirective - This is the name of a directive that can be used to tell
260 /// the assembler to set the value of a variable to some expression.
261 const char *SetDirective; // Defaults to null.
263 /// LCOMMDirective - This is the name of a directive (if supported) that can
264 /// be used to efficiently declare a local (internal) block of zero
265 /// initialized data in the .bss/.data section. The syntax expected is:
266 /// @verbatim <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
268 const char *LCOMMDirective; // Defaults to null.
270 const char *COMMDirective; // Defaults to "\t.comm\t".
272 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
273 /// argument that specifies the alignment of the declaration.
274 bool COMMDirectiveTakesAlignment; // Defaults to true.
276 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
277 /// directives, this is true for most ELF targets.
278 bool HasDotTypeDotSizeDirective; // Defaults to true.
280 /// UsedDirective - This directive, if non-null, is used to declare a global
281 /// as being used somehow that the assembler can't see. This prevents dead
282 /// code elimination on some targets.
283 const char *UsedDirective; // Defaults to null.
285 /// WeakRefDirective - This directive, if non-null, is used to declare a
286 /// global as being a weak undefined symbol.
287 const char *WeakRefDirective; // Defaults to null.
289 /// WeakDefDirective - This directive, if non-null, is used to declare a
290 /// global as being a weak defined symbol.
291 const char *WeakDefDirective; // Defaults to null.
293 /// HiddenDirective - This directive, if non-null, is used to declare a
294 /// global or function as having hidden visibility.
295 const char *HiddenDirective; // Defaults to "\t.hidden\t".
297 /// ProtectedDirective - This directive, if non-null, is used to declare a
298 /// global or function as having protected visibility.
299 const char *ProtectedDirective; // Defaults to "\t.protected\t".
301 //===--- Dwarf Emission Directives -----------------------------------===//
303 /// AbsoluteDebugSectionOffsets - True if we should emit abolute section
304 /// offsets for debug information. Defaults to false.
305 bool AbsoluteDebugSectionOffsets;
307 /// AbsoluteEHSectionOffsets - True if we should emit abolute section
308 /// offsets for EH information. Defaults to false.
309 bool AbsoluteEHSectionOffsets;
311 /// HasLEB128 - True if target asm supports leb128 directives.
313 bool HasLEB128; // Defaults to false.
315 /// hasDotLocAndDotFile - True if target asm supports .loc and .file
316 /// directives for emitting debugging information.
318 bool HasDotLocAndDotFile; // Defaults to false.
320 /// SupportsDebugInformation - True if target supports emission of debugging
322 bool SupportsDebugInformation;
324 /// SupportsExceptionHandling - True if target supports
325 /// exception handling.
327 bool SupportsExceptionHandling; // Defaults to false.
329 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
331 bool DwarfRequiresFrameSection; // Defaults to true.
333 /// GlobalEHDirective - This is the directive used to make exception frame
334 /// tables globally visible.
336 const char *GlobalEHDirective; // Defaults to NULL.
338 /// SupportsWeakEmptyEHFrame - True if target assembler and linker will
339 /// handle a weak_definition of constant 0 for an omitted EH frame.
340 bool SupportsWeakOmittedEHFrame; // Defaults to true.
342 /// DwarfSectionOffsetDirective - Special section offset directive.
343 const char* DwarfSectionOffsetDirective; // Defaults to NULL
345 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
347 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
349 /// DwarfInfoSection - Section directive for Dwarf info.
351 const char *DwarfInfoSection; // Defaults to ".debug_info".
353 /// DwarfLineSection - Section directive for Dwarf info.
355 const char *DwarfLineSection; // Defaults to ".debug_line".
357 /// DwarfFrameSection - Section directive for Dwarf info.
359 const char *DwarfFrameSection; // Defaults to ".debug_frame".
361 /// DwarfPubNamesSection - Section directive for Dwarf info.
363 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
365 /// DwarfPubTypesSection - Section directive for Dwarf info.
367 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
369 /// DwarfStrSection - Section directive for Dwarf info.
371 const char *DwarfStrSection; // Defaults to ".debug_str".
373 /// DwarfLocSection - Section directive for Dwarf info.
375 const char *DwarfLocSection; // Defaults to ".debug_loc".
377 /// DwarfARangesSection - Section directive for Dwarf info.
379 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
381 /// DwarfRangesSection - Section directive for Dwarf info.
383 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
385 /// DwarfMacInfoSection - Section directive for Dwarf info.
387 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
389 /// DwarfEHFrameSection - Section directive for Exception frames.
391 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
393 /// DwarfExceptionSection - Section directive for Exception table.
395 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
398 //===--- CBE Asm Translation Table -----------------------------------===//
400 const char *const *AsmTransCBE; // Defaults to empty
404 virtual ~TargetAsmInfo();
406 /// Measure the specified inline asm to determine an approximation of its
408 virtual unsigned getInlineAsmLength(const char *Str) const;
410 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
411 /// call to be explicit llvm code if it wants to. This is useful for
412 /// turning simple inline asms into LLVM intrinsics, which gives the
413 /// compiler more information about the behavior of the code.
414 virtual bool ExpandInlineAsm(CallInst *CI) const {
418 /// PreferredEHDataFormat - This hook allows the target to select data
419 /// format used for encoding pointers in exception handling data. Reason is
420 /// 0 for data, 1 for code labels, 2 for function pointers. Global is true
421 /// if the symbol can be relocated.
422 virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
427 const char *getTextSection() const {
430 const char *getDataSection() const {
433 const char *getBSSSection() const {
436 const char *getTLSDataSection() const {
437 return TLSDataSection;
439 const char *getTLSBSSSection() const {
440 return TLSBSSSection;
442 const char *getZeroFillDirective() const {
443 return ZeroFillDirective;
445 const char *getNonexecutableStackDirective() const {
446 return NonexecutableStackDirective;
448 bool needsSet() const {
451 const char *getPCSymbol() const {
454 char getSeparatorChar() const {
455 return SeparatorChar;
457 const char *getCommentString() const {
458 return CommentString;
460 const char *getGlobalPrefix() const {
463 const char *getPrivateGlobalPrefix() const {
464 return PrivateGlobalPrefix;
466 const char *getJumpTableSpecialLabelPrefix() const {
467 return JumpTableSpecialLabelPrefix;
469 const char *getGlobalVarAddrPrefix() const {
470 return GlobalVarAddrPrefix;
472 const char *getGlobalVarAddrSuffix() const {
473 return GlobalVarAddrSuffix;
475 const char *getFunctionAddrPrefix() const {
476 return FunctionAddrPrefix;
478 const char *getFunctionAddrSuffix() const {
479 return FunctionAddrSuffix;
481 const char *getPersonalityPrefix() const {
482 return PersonalityPrefix;
484 const char *getPersonalitySuffix() const {
485 return PersonalitySuffix;
487 bool getNeedsIndirectEncoding() const {
488 return NeedsIndirectEncoding;
490 const char *getInlineAsmStart() const {
491 return InlineAsmStart;
493 const char *getInlineAsmEnd() const {
496 unsigned getAssemblerDialect() const {
497 return AssemblerDialect;
499 const char *getZeroDirective() const {
500 return ZeroDirective;
502 const char *getZeroDirectiveSuffix() const {
503 return ZeroDirectiveSuffix;
505 const char *getAsciiDirective() const {
506 return AsciiDirective;
508 const char *getAscizDirective() const {
509 return AscizDirective;
511 const char *getData8bitsDirective() const {
512 return Data8bitsDirective;
514 const char *getData16bitsDirective() const {
515 return Data16bitsDirective;
517 const char *getData32bitsDirective() const {
518 return Data32bitsDirective;
520 const char *getData64bitsDirective() const {
521 return Data64bitsDirective;
523 const char *getJumpTableDirective() const {
524 return JumpTableDirective;
526 const char *getAlignDirective() const {
527 return AlignDirective;
529 bool getAlignmentIsInBytes() const {
530 return AlignmentIsInBytes;
532 unsigned getTextAlignFillValue() const {
533 return TextAlignFillValue;
535 const char *getSwitchToSectionDirective() const {
536 return SwitchToSectionDirective;
538 const char *getTextSectionStartSuffix() const {
539 return TextSectionStartSuffix;
541 const char *getDataSectionStartSuffix() const {
542 return DataSectionStartSuffix;
544 const char *getSectionEndDirectiveSuffix() const {
545 return SectionEndDirectiveSuffix;
547 const char *getConstantPoolSection() const {
548 return ConstantPoolSection;
550 const char *getJumpTableDataSection() const {
551 return JumpTableDataSection;
553 const char *getCStringSection() const {
554 return CStringSection;
556 const char *getStaticCtorsSection() const {
557 return StaticCtorsSection;
559 const char *getStaticDtorsSection() const {
560 return StaticDtorsSection;
562 const char *getFourByteConstantSection() const {
563 return FourByteConstantSection;
565 const char *getEightByteConstantSection() const {
566 return EightByteConstantSection;
568 const char *getSixteenByteConstantSection() const {
569 return SixteenByteConstantSection;
571 const char *getReadOnlySection() const {
572 return ReadOnlySection;
574 const char *getGlobalDirective() const {
575 return GlobalDirective;
577 const char *getSetDirective() const {
580 const char *getLCOMMDirective() const {
581 return LCOMMDirective;
583 const char *getCOMMDirective() const {
584 return COMMDirective;
586 bool getCOMMDirectiveTakesAlignment() const {
587 return COMMDirectiveTakesAlignment;
589 bool hasDotTypeDotSizeDirective() const {
590 return HasDotTypeDotSizeDirective;
592 const char *getUsedDirective() const {
593 return UsedDirective;
595 const char *getWeakRefDirective() const {
596 return WeakRefDirective;
598 const char *getWeakDefDirective() const {
599 return WeakDefDirective;
601 const char *getHiddenDirective() const {
602 return HiddenDirective;
604 const char *getProtectedDirective() const {
605 return ProtectedDirective;
607 bool isAbsoluteDebugSectionOffsets() const {
608 return AbsoluteDebugSectionOffsets;
610 bool isAbsoluteEHSectionOffsets() const {
611 return AbsoluteEHSectionOffsets;
613 bool hasLEB128() const {
616 bool hasDotLocAndDotFile() const {
617 return HasDotLocAndDotFile;
619 bool doesSupportDebugInformation() const {
620 return SupportsDebugInformation;
622 bool doesSupportExceptionHandling() const {
623 return SupportsExceptionHandling;
625 bool doesDwarfRequireFrameSection() const {
626 return DwarfRequiresFrameSection;
628 const char *getGlobalEHDirective() const {
629 return GlobalEHDirective;
631 bool getSupportsWeakOmittedEHFrame() const {
632 return SupportsWeakOmittedEHFrame;
634 const char *getDwarfSectionOffsetDirective() const {
635 return DwarfSectionOffsetDirective;
637 const char *getDwarfAbbrevSection() const {
638 return DwarfAbbrevSection;
640 const char *getDwarfInfoSection() const {
641 return DwarfInfoSection;
643 const char *getDwarfLineSection() const {
644 return DwarfLineSection;
646 const char *getDwarfFrameSection() const {
647 return DwarfFrameSection;
649 const char *getDwarfPubNamesSection() const {
650 return DwarfPubNamesSection;
652 const char *getDwarfPubTypesSection() const {
653 return DwarfPubTypesSection;
655 const char *getDwarfStrSection() const {
656 return DwarfStrSection;
658 const char *getDwarfLocSection() const {
659 return DwarfLocSection;
661 const char *getDwarfARangesSection() const {
662 return DwarfARangesSection;
664 const char *getDwarfRangesSection() const {
665 return DwarfRangesSection;
667 const char *getDwarfMacInfoSection() const {
668 return DwarfMacInfoSection;
670 const char *getDwarfEHFrameSection() const {
671 return DwarfEHFrameSection;
673 const char *getDwarfExceptionSection() const {
674 return DwarfExceptionSection;
676 const char *const *getAsmCBE() const {