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 /// ZeroFillDirective - Directive for emitting a global to the ZeroFill
48 /// section on this target. Null if this target doesn't support zerofill.
49 const char *ZeroFillDirective; // Default is null.
51 /// AddressSize - Size of addresses used in file.
53 unsigned AddressSize; // Defaults to 4.
55 /// NeedsSet - True if target asm can't compute addresses on data
57 bool NeedsSet; // Defaults to false.
59 /// MaxInstLength - This is the maximum possible length of an instruction,
60 /// which is needed to compute the size of an inline asm.
61 unsigned MaxInstLength; // Defaults to 4.
63 /// PCSymbol - The symbol used to represent the current PC. Used in PC
64 /// relative expressions.
65 const char *PCSymbol; // Defaults to "$".
67 /// SeparatorChar - This character, if specified, is used to separate
68 /// instructions from each other when on the same line. This is used to
69 /// measure inline asm instructions.
70 char SeparatorChar; // Defaults to ';'
72 /// CommentString - This indicates the comment character used by the
74 const char *CommentString; // Defaults to "#"
76 /// GlobalPrefix - If this is set to a non-empty string, it is prepended
77 /// onto all global symbols. This is often used for "_" or ".".
78 const char *GlobalPrefix; // Defaults to ""
80 /// PrivateGlobalPrefix - This prefix is used for globals like constant
81 /// pool entries that are completely private to the .o file and should not
82 /// have names in the .o file. This is often "." or "L".
83 const char *PrivateGlobalPrefix; // Defaults to "."
85 /// JumpTableSpecialLabelPrefix - If not null, a extra (dead) label is
86 /// emitted before jump tables with the specified prefix.
87 const char *JumpTableSpecialLabelPrefix; // Default to null.
89 /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
90 /// will enclose any GlobalVariable (that isn't a function)
92 const char *GlobalVarAddrPrefix; // Defaults to ""
93 const char *GlobalVarAddrSuffix; // Defaults to ""
95 /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
96 /// will enclose any GlobalVariable that points to a function.
97 /// For example, this is used by the IA64 backend to materialize
98 /// function descriptors, by decorating the ".data8" object with the
99 /// \literal @fptr( ) \endliteral
100 /// link-relocation operator.
102 const char *FunctionAddrPrefix; // Defaults to ""
103 const char *FunctionAddrSuffix; // Defaults to ""
105 /// InlineAsmStart/End - If these are nonempty, they contain a directive to
106 /// emit before and after an inline assembly statement.
107 const char *InlineAsmStart; // Defaults to "#APP\n"
108 const char *InlineAsmEnd; // Defaults to "#NO_APP\n"
110 /// AssemblerDialect - Which dialect of an assembler variant to use.
111 unsigned AssemblerDialect; // Defaults to 0
113 //===--- Data Emission Directives -------------------------------------===//
115 /// ZeroDirective - this should be set to the directive used to get some
116 /// number of zero bytes emitted to the current section. Common cases are
117 /// "\t.zero\t" and "\t.space\t". If this is set to null, the
118 /// Data*bitsDirective's will be used to emit zero bytes.
119 const char *ZeroDirective; // Defaults to "\t.zero\t"
120 const char *ZeroDirectiveSuffix; // Defaults to ""
122 /// AsciiDirective - This directive allows emission of an ascii string with
123 /// the standard C escape characters embedded into it.
124 const char *AsciiDirective; // Defaults to "\t.ascii\t"
126 /// AscizDirective - If not null, this allows for special handling of
127 /// zero terminated strings on this target. This is commonly supported as
128 /// ".asciz". If a target doesn't support this, it can be set to null.
129 const char *AscizDirective; // Defaults to "\t.asciz\t"
131 /// DataDirectives - These directives are used to output some unit of
132 /// integer data to the current section. If a data directive is set to
133 /// null, smaller data directives will be used to emit the large sizes.
134 const char *Data8bitsDirective; // Defaults to "\t.byte\t"
135 const char *Data16bitsDirective; // Defaults to "\t.short\t"
136 const char *Data32bitsDirective; // Defaults to "\t.long\t"
137 const char *Data64bitsDirective; // Defaults to "\t.quad\t"
139 //===--- Alignment Information ----------------------------------------===//
141 /// AlignDirective - The directive used to emit round up to an alignment
144 const char *AlignDirective; // Defaults to "\t.align\t"
146 /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
147 /// emits ".align N" directives, where N is the number of bytes to align to.
148 /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
150 bool AlignmentIsInBytes; // Defaults to true
152 //===--- Section Switching Directives ---------------------------------===//
154 /// SwitchToSectionDirective - This is the directive used when we want to
155 /// emit a global to an arbitrary section. The section name is emited after
157 const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
159 /// TextSectionStartSuffix - This is printed after each start of section
160 /// directive for text sections.
161 const char *TextSectionStartSuffix; // Defaults to "".
163 /// DataSectionStartSuffix - This is printed after each start of section
164 /// directive for data sections.
165 const char *DataSectionStartSuffix; // Defaults to "".
167 /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
168 /// section with the section name and this suffix printed.
169 const char *SectionEndDirectiveSuffix;// Defaults to null.
171 /// ConstantPoolSection - This is the section that we SwitchToSection right
172 /// before emitting the constant pool for a function.
173 const char *ConstantPoolSection; // Defaults to "\t.section .rodata\n"
175 /// JumpTableDataSection - This is the section that we SwitchToSection right
176 /// before emitting the jump tables for a function when the relocation model
178 const char *JumpTableDataSection; // Defaults to "\t.section .rodata\n"
180 /// JumpTableDirective - if non-null, the directive to emit before a jump
182 const char *JumpTableDirective;
184 /// CStringSection - If not null, this allows for special handling of
185 /// cstring constants (\0 terminated string that does not contain any
186 /// other null bytes) on this target. This is commonly supported as
188 const char *CStringSection; // Defaults to NULL
190 /// StaticCtorsSection - This is the directive that is emitted to switch to
191 /// a section to emit the static constructor list.
192 /// Defaults to "\t.section .ctors,\"aw\",@progbits".
193 const char *StaticCtorsSection;
195 /// StaticDtorsSection - This is the directive that is emitted to switch to
196 /// a section to emit the static destructor list.
197 /// Defaults to "\t.section .dtors,\"aw\",@progbits".
198 const char *StaticDtorsSection;
200 /// FourByteConstantSection, EightByteConstantSection,
201 /// SixteenByteConstantSection - These are special sections where we place
202 /// 4-, 8-, and 16- byte constant literals.
203 const char *FourByteConstantSection;
204 const char *EightByteConstantSection;
205 const char *SixteenByteConstantSection;
207 /// ReadOnlySection - This is the directive that is emitted to switch to a
208 /// read-only section for constant data (e.g. data declared const,
210 const char *ReadOnlySection; // Defaults to NULL
212 //===--- Global Variable Emission Directives --------------------------===//
214 /// GlobalDirective - This is the directive used to declare a global entity.
216 const char *GlobalDirective; // Defaults to NULL.
218 /// SetDirective - This is the name of a directive that can be used to tell
219 /// the assembler to set the value of a variable to some expression.
220 const char *SetDirective; // Defaults to null.
222 /// LCOMMDirective - This is the name of a directive (if supported) that can
223 /// be used to efficiently declare a local (internal) block of zero
224 /// initialized data in the .bss/.data section. The syntax expected is:
225 /// \literal <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
227 const char *LCOMMDirective; // Defaults to null.
229 const char *COMMDirective; // Defaults to "\t.comm\t".
231 /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
232 /// argument that specifies the alignment of the declaration.
233 bool COMMDirectiveTakesAlignment; // Defaults to true.
235 /// HasDotTypeDotSizeDirective - True if the target has .type and .size
236 /// directives, this is true for most ELF targets.
237 bool HasDotTypeDotSizeDirective; // Defaults to true.
239 /// UsedDirective - This directive, if non-null, is used to declare a global
240 /// as being used somehow that the assembler can't see. This prevents dead
241 /// code elimination on some targets.
242 const char *UsedDirective; // Defaults to null.
244 /// WeakRefDirective - This directive, if non-null, is used to declare a
245 /// global as being a weak undefined symbol.
246 const char *WeakRefDirective; // Defaults to null.
248 /// HiddenDirective - This directive, if non-null, is used to declare a
249 /// global or function as having hidden visibility.
250 const char *HiddenDirective; // Defaults to "\t.hidden\t".
252 //===--- Dwarf Emission Directives -----------------------------------===//
254 /// AbsoluteSectionOffsets - True if we should emit abolute section
255 /// offsets. Defaults to false.
256 bool AbsoluteSectionOffsets;
258 /// HasLEB128 - True if target asm supports leb128 directives.
260 bool HasLEB128; // Defaults to false.
262 /// hasDotLoc - True if target asm supports .loc directives.
264 bool HasDotLoc; // Defaults to false.
266 /// HasDotFile - True if target asm supports .file directives.
268 bool HasDotFile; // Defaults to false.
270 /// SupportsExceptionHandling - True if target supports exception handling.
272 bool SupportsExceptionHandling; // Defaults to false.
274 /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
276 bool DwarfRequiresFrameSection; // Defaults to true.
278 /// DwarfSectionOffsetDirective - Special section offset directive.
279 const char* DwarfSectionOffsetDirective; // Defaults to NULL
281 /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
283 const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
285 /// DwarfInfoSection - Section directive for Dwarf info.
287 const char *DwarfInfoSection; // Defaults to ".debug_info".
289 /// DwarfLineSection - Section directive for Dwarf info.
291 const char *DwarfLineSection; // Defaults to ".debug_line".
293 /// DwarfFrameSection - Section directive for Dwarf info.
295 const char *DwarfFrameSection; // Defaults to ".debug_frame".
297 /// DwarfPubNamesSection - Section directive for Dwarf info.
299 const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
301 /// DwarfPubTypesSection - Section directive for Dwarf info.
303 const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
305 /// DwarfStrSection - Section directive for Dwarf info.
307 const char *DwarfStrSection; // Defaults to ".debug_str".
309 /// DwarfLocSection - Section directive for Dwarf info.
311 const char *DwarfLocSection; // Defaults to ".debug_loc".
313 /// DwarfARangesSection - Section directive for Dwarf info.
315 const char *DwarfARangesSection; // Defaults to ".debug_aranges".
317 /// DwarfRangesSection - Section directive for Dwarf info.
319 const char *DwarfRangesSection; // Defaults to ".debug_ranges".
321 /// DwarfMacInfoSection - Section directive for Dwarf info.
323 const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
325 /// DwarfEHFrameSection - Section directive for Exception frames.
327 const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
329 /// DwarfExceptionSection - Section directive for Exception table.
331 const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
334 //===--- CBE Asm Translation Table -----------------------------------===//
336 const char** AsmTransCBE; // Defaults to empty
340 virtual ~TargetAsmInfo();
342 /// Measure the specified inline asm to determine an approximation of its
344 unsigned getInlineAsmLength(const char *Str) const;
346 /// ExpandInlineAsm - This hook allows the target to expand an inline asm
347 /// call to be explicit llvm code if it wants to. This is useful for
348 /// turning simple inline asms into LLVM intrinsics, which gives the
349 /// compiler more information about the behavior of the code.
350 virtual bool ExpandInlineAsm(CallInst *CI) const {
356 const char *getTextSection() const {
359 const char *getDataSection() const {
362 const char *getBSSSection() const {
365 const char *getZeroFillDirective() const {
366 return ZeroFillDirective;
368 unsigned getAddressSize() const {
371 bool needsSet() const {
374 const char *getPCSymbol() const {
377 char getSeparatorChar() const {
378 return SeparatorChar;
380 const char *getCommentString() const {
381 return CommentString;
383 const char *getGlobalPrefix() const {
386 const char *getPrivateGlobalPrefix() const {
387 return PrivateGlobalPrefix;
389 const char *getJumpTableSpecialLabelPrefix() const {
390 return JumpTableSpecialLabelPrefix;
392 const char *getGlobalVarAddrPrefix() const {
393 return GlobalVarAddrPrefix;
395 const char *getGlobalVarAddrSuffix() const {
396 return GlobalVarAddrSuffix;
398 const char *getFunctionAddrPrefix() const {
399 return FunctionAddrPrefix;
401 const char *getFunctionAddrSuffix() const {
402 return FunctionAddrSuffix;
404 const char *getInlineAsmStart() const {
405 return InlineAsmStart;
407 const char *getInlineAsmEnd() const {
410 unsigned getAssemblerDialect() const {
411 return AssemblerDialect;
413 const char *getZeroDirective() const {
414 return ZeroDirective;
416 const char *getZeroDirectiveSuffix() const {
417 return ZeroDirectiveSuffix;
419 const char *getAsciiDirective() const {
420 return AsciiDirective;
422 const char *getAscizDirective() const {
423 return AscizDirective;
425 const char *getData8bitsDirective() const {
426 return Data8bitsDirective;
428 const char *getData16bitsDirective() const {
429 return Data16bitsDirective;
431 const char *getData32bitsDirective() const {
432 return Data32bitsDirective;
434 const char *getData64bitsDirective() const {
435 return Data64bitsDirective;
437 const char *getJumpTableDirective() const {
438 return JumpTableDirective;
440 const char *getAlignDirective() const {
441 return AlignDirective;
443 bool getAlignmentIsInBytes() const {
444 return AlignmentIsInBytes;
446 const char *getSwitchToSectionDirective() const {
447 return SwitchToSectionDirective;
449 const char *getTextSectionStartSuffix() const {
450 return TextSectionStartSuffix;
452 const char *getDataSectionStartSuffix() const {
453 return DataSectionStartSuffix;
455 const char *getSectionEndDirectiveSuffix() const {
456 return SectionEndDirectiveSuffix;
458 const char *getConstantPoolSection() const {
459 return ConstantPoolSection;
461 const char *getJumpTableDataSection() const {
462 return JumpTableDataSection;
464 const char *getCStringSection() const {
465 return CStringSection;
467 const char *getStaticCtorsSection() const {
468 return StaticCtorsSection;
470 const char *getStaticDtorsSection() const {
471 return StaticDtorsSection;
473 const char *getFourByteConstantSection() const {
474 return FourByteConstantSection;
476 const char *getEightByteConstantSection() const {
477 return EightByteConstantSection;
479 const char *getSixteenByteConstantSection() const {
480 return SixteenByteConstantSection;
482 const char *getReadOnlySection() const {
483 return ReadOnlySection;
485 const char *getGlobalDirective() const {
486 return GlobalDirective;
488 const char *getSetDirective() const {
491 const char *getLCOMMDirective() const {
492 return LCOMMDirective;
494 const char *getCOMMDirective() const {
495 return COMMDirective;
497 bool getCOMMDirectiveTakesAlignment() const {
498 return COMMDirectiveTakesAlignment;
500 bool hasDotTypeDotSizeDirective() const {
501 return HasDotTypeDotSizeDirective;
503 const char *getUsedDirective() const {
504 return UsedDirective;
506 const char *getWeakRefDirective() const {
507 return WeakRefDirective;
509 const char *getHiddenDirective() const {
510 return HiddenDirective;
512 bool isAbsoluteSectionOffsets() const {
513 return AbsoluteSectionOffsets;
515 bool hasLEB128() const {
518 bool hasDotLoc() const {
521 bool hasDotFile() const {
524 bool getSupportsExceptionHandling() const {
525 return SupportsExceptionHandling;
527 bool getDwarfRequiresFrameSection() const {
528 return DwarfRequiresFrameSection;
530 const char *getDwarfSectionOffsetDirective() const {
531 return DwarfSectionOffsetDirective;
533 const char *getDwarfAbbrevSection() const {
534 return DwarfAbbrevSection;
536 const char *getDwarfInfoSection() const {
537 return DwarfInfoSection;
539 const char *getDwarfLineSection() const {
540 return DwarfLineSection;
542 const char *getDwarfFrameSection() const {
543 return DwarfFrameSection;
545 const char *getDwarfPubNamesSection() const {
546 return DwarfPubNamesSection;
548 const char *getDwarfPubTypesSection() const {
549 return DwarfPubTypesSection;
551 const char *getDwarfStrSection() const {
552 return DwarfStrSection;
554 const char *getDwarfLocSection() const {
555 return DwarfLocSection;
557 const char *getDwarfARangesSection() const {
558 return DwarfARangesSection;
560 const char *getDwarfRangesSection() const {
561 return DwarfRangesSection;
563 const char *getDwarfMacInfoSection() const {
564 return DwarfMacInfoSection;
566 const char *getDwarfEHFrameSection() const {
567 return DwarfEHFrameSection;
569 const char *getDwarfExceptionSection() const {
570 return DwarfExceptionSection;
572 const char** getAsmCBE() const {