implement Transforms/InstCombine/cast2.ll:test3 and PR1263
[oota-llvm.git] / include / llvm / Target / TargetAsmInfo.h
1 //===-- llvm/Target/TargetAsmInfo.h - Asm info ------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
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.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_TARGET_ASM_INFO_H
17 #define LLVM_TARGET_ASM_INFO_H
18
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/Support/DataTypes.h"
21
22 namespace llvm {
23   class TargetMachine;
24   class CallInst;
25
26   /// TargetAsmInfo - This class is intended to be used as a base class for asm
27   /// properties and features specific to the target.
28   class TargetAsmInfo {
29   protected:
30     //===------------------------------------------------------------------===//
31     // Properties to be set by the target writer, used to configure asm printer.
32     //
33     
34     /// TextSection - Section directive for standard text.
35     ///
36     const char *TextSection;              // Defaults to ".text".
37     
38     /// DataSection - Section directive for standard data.
39     ///
40     const char *DataSection;              // Defaults to ".data".
41
42     /// BSSSection - Section directive for uninitialized data.  Null if this
43     /// target doesn't support a BSS section.
44     ///
45     const char *BSSSection;               // Default to ".bss".
46     
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.
50     
51     /// AddressSize - Size of addresses used in file.
52     ///
53     unsigned AddressSize;                 // Defaults to 4.
54     
55     /// NeedsSet - True if target asm can't compute addresses on data
56     /// directives.
57     bool NeedsSet;                        // Defaults to false.
58     
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.
62     
63     /// PCSymbol - The symbol used to represent the current PC.  Used in PC
64     /// relative expressions.
65     const char *PCSymbol;                 // Defaults to "$".
66
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 ';'
71
72     /// CommentString - This indicates the comment character used by the
73     /// assembler.
74     const char *CommentString;            // Defaults to "#"
75
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 ""
79
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 "."
84     
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.
88     
89     /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
90     /// will enclose any GlobalVariable (that isn't a function)
91     ///
92     const char *GlobalVarAddrPrefix;      // Defaults to ""
93     const char *GlobalVarAddrSuffix;      // Defaults to ""
94
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.
101     ///
102     const char *FunctionAddrPrefix;       // Defaults to ""
103     const char *FunctionAddrSuffix;       // Defaults to ""
104
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"
109
110     /// AssemblerDialect - Which dialect of an assembler variant to use.
111     unsigned AssemblerDialect;            // Defaults to 0
112
113     //===--- Data Emission Directives -------------------------------------===//
114
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 ""
121
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"
125     
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"
130
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"
138
139     //===--- Alignment Information ----------------------------------------===//
140
141     /// AlignDirective - The directive used to emit round up to an alignment
142     /// boundary.
143     ///
144     const char *AlignDirective;           // Defaults to "\t.align\t"
145
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
149     /// boundary.
150     bool AlignmentIsInBytes;              // Defaults to true
151
152     //===--- Section Switching Directives ---------------------------------===//
153     
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
156     /// this.
157     const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
158     
159     /// TextSectionStartSuffix - This is printed after each start of section
160     /// directive for text sections.
161     const char *TextSectionStartSuffix;   // Defaults to "".
162
163     /// DataSectionStartSuffix - This is printed after each start of section
164     /// directive for data sections.
165     const char *DataSectionStartSuffix;   // Defaults to "".
166     
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.
170     
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"
174
175     /// JumpTableDataSection - This is the section that we SwitchToSection right
176     /// before emitting the jump tables for a function when the relocation model
177     /// is not PIC.
178     const char *JumpTableDataSection;     // Defaults to "\t.section .rodata\n"
179     
180     /// JumpTableDirective - if non-null, the directive to emit before a jump
181     /// table.
182     const char *JumpTableDirective;
183
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
187     /// ".cstring".
188     const char *CStringSection;           // Defaults to NULL
189
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;
194
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;
199
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;
206
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,
209     /// jump tables).
210     const char *ReadOnlySection;          // Defaults to NULL
211
212     //===--- Global Variable Emission Directives --------------------------===//
213     
214     /// GlobalDirective - This is the directive used to declare a global entity.
215     ///
216     const char *GlobalDirective;          // Defaults to NULL.
217     
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.
221     
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
226     /// \endliteral
227     const char *LCOMMDirective;           // Defaults to null.
228     
229     const char *COMMDirective;            // Defaults to "\t.comm\t".
230
231     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
232     /// argument that specifies the alignment of the declaration.
233     bool COMMDirectiveTakesAlignment;     // Defaults to true.
234     
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.
238     
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.
243
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.
247     
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".
251     
252     //===--- Dwarf Emission Directives -----------------------------------===//
253
254     /// AbsoluteSectionOffsets - True if we should emit abolute section
255     /// offsets. Defaults to false.
256     bool AbsoluteSectionOffsets;
257     
258     /// HasLEB128 - True if target asm supports leb128 directives.
259     ///
260     bool HasLEB128; // Defaults to false.
261     
262     /// hasDotLoc - True if target asm supports .loc directives.
263     ///
264     bool HasDotLoc; // Defaults to false.
265     
266     /// HasDotFile - True if target asm supports .file directives.
267     ///
268     bool HasDotFile; // Defaults to false.
269     
270     /// SupportsExceptionHandling - True if target supports exception handling.
271     ///
272     bool SupportsExceptionHandling; // Defaults to false.
273     
274     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
275     ///
276     bool DwarfRequiresFrameSection; // Defaults to true.
277
278     /// DwarfSectionOffsetDirective - Special section offset directive.
279     const char* DwarfSectionOffsetDirective; // Defaults to NULL
280     
281     /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
282     ///
283     const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
284
285     /// DwarfInfoSection - Section directive for Dwarf info.
286     ///
287     const char *DwarfInfoSection; // Defaults to ".debug_info".
288
289     /// DwarfLineSection - Section directive for Dwarf info.
290     ///
291     const char *DwarfLineSection; // Defaults to ".debug_line".
292     
293     /// DwarfFrameSection - Section directive for Dwarf info.
294     ///
295     const char *DwarfFrameSection; // Defaults to ".debug_frame".
296     
297     /// DwarfPubNamesSection - Section directive for Dwarf info.
298     ///
299     const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
300     
301     /// DwarfPubTypesSection - Section directive for Dwarf info.
302     ///
303     const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
304     
305     /// DwarfStrSection - Section directive for Dwarf info.
306     ///
307     const char *DwarfStrSection; // Defaults to ".debug_str".
308
309     /// DwarfLocSection - Section directive for Dwarf info.
310     ///
311     const char *DwarfLocSection; // Defaults to ".debug_loc".
312
313     /// DwarfARangesSection - Section directive for Dwarf info.
314     ///
315     const char *DwarfARangesSection; // Defaults to ".debug_aranges".
316
317     /// DwarfRangesSection - Section directive for Dwarf info.
318     ///
319     const char *DwarfRangesSection; // Defaults to ".debug_ranges".
320
321     /// DwarfMacInfoSection - Section directive for Dwarf info.
322     ///
323     const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
324     
325     /// DwarfEHFrameSection - Section directive for Exception frames.
326     ///
327     const char *DwarfEHFrameSection; // Defaults to ".eh_frame".
328     
329     /// DwarfExceptionSection - Section directive for Exception table.
330     ///
331     const char *DwarfExceptionSection; // Defaults to ".gcc_except_table".
332      
333
334     //===--- CBE Asm Translation Table -----------------------------------===//
335
336     const char** AsmTransCBE; // Defaults to empty
337
338   public:
339     TargetAsmInfo();
340     virtual ~TargetAsmInfo();
341
342     /// Measure the specified inline asm to determine an approximation of its
343     /// length.
344     unsigned getInlineAsmLength(const char *Str) const;
345
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 {
351       return false;
352     }
353     
354     // Accessors.
355     //
356     const char *getTextSection() const {
357       return TextSection;
358     }
359     const char *getDataSection() const {
360       return DataSection;
361     }
362     const char *getBSSSection() const {
363       return BSSSection;
364     }
365     const char *getZeroFillDirective() const {
366       return ZeroFillDirective;
367     }
368     unsigned getAddressSize() const {
369       return AddressSize;
370     }
371     bool needsSet() const {
372       return NeedsSet;
373     }
374     const char *getPCSymbol() const {
375       return PCSymbol;
376     }
377     char getSeparatorChar() const {
378       return SeparatorChar;
379     }
380     const char *getCommentString() const {
381       return CommentString;
382     }
383     const char *getGlobalPrefix() const {
384       return GlobalPrefix;
385     }
386     const char *getPrivateGlobalPrefix() const {
387       return PrivateGlobalPrefix;
388     }
389     const char *getJumpTableSpecialLabelPrefix() const {
390       return JumpTableSpecialLabelPrefix;
391     }
392     const char *getGlobalVarAddrPrefix() const {
393       return GlobalVarAddrPrefix;
394     }
395     const char *getGlobalVarAddrSuffix() const {
396       return GlobalVarAddrSuffix;
397     }
398     const char *getFunctionAddrPrefix() const {
399       return FunctionAddrPrefix;
400     }
401     const char *getFunctionAddrSuffix() const {
402       return FunctionAddrSuffix;
403     }
404     const char *getInlineAsmStart() const {
405       return InlineAsmStart;
406     }
407     const char *getInlineAsmEnd() const {
408       return InlineAsmEnd;
409     }
410     unsigned getAssemblerDialect() const {
411       return AssemblerDialect;
412     }
413     const char *getZeroDirective() const {
414       return ZeroDirective;
415     }
416     const char *getZeroDirectiveSuffix() const {
417       return ZeroDirectiveSuffix;
418     }
419     const char *getAsciiDirective() const {
420       return AsciiDirective;
421     }
422     const char *getAscizDirective() const {
423       return AscizDirective;
424     }
425     const char *getData8bitsDirective() const {
426       return Data8bitsDirective;
427     }
428     const char *getData16bitsDirective() const {
429       return Data16bitsDirective;
430     }
431     const char *getData32bitsDirective() const {
432       return Data32bitsDirective;
433     }
434     const char *getData64bitsDirective() const {
435       return Data64bitsDirective;
436     }
437     const char *getJumpTableDirective() const {
438       return JumpTableDirective;
439     }
440     const char *getAlignDirective() const {
441       return AlignDirective;
442     }
443     bool getAlignmentIsInBytes() const {
444       return AlignmentIsInBytes;
445     }
446     const char *getSwitchToSectionDirective() const {
447       return SwitchToSectionDirective;
448     }
449     const char *getTextSectionStartSuffix() const {
450       return TextSectionStartSuffix;
451     }
452     const char *getDataSectionStartSuffix() const {
453       return DataSectionStartSuffix;
454     }
455     const char *getSectionEndDirectiveSuffix() const {
456       return SectionEndDirectiveSuffix;
457     }
458     const char *getConstantPoolSection() const {
459       return ConstantPoolSection;
460     }
461     const char *getJumpTableDataSection() const {
462       return JumpTableDataSection;
463     }
464     const char *getCStringSection() const {
465       return CStringSection;
466     }
467     const char *getStaticCtorsSection() const {
468       return StaticCtorsSection;
469     }
470     const char *getStaticDtorsSection() const {
471       return StaticDtorsSection;
472     }
473     const char *getFourByteConstantSection() const {
474       return FourByteConstantSection;
475     }
476     const char *getEightByteConstantSection() const {
477       return EightByteConstantSection;
478     }
479     const char *getSixteenByteConstantSection() const {
480       return SixteenByteConstantSection;
481     }
482     const char *getReadOnlySection() const {
483       return ReadOnlySection;
484     }
485     const char *getGlobalDirective() const {
486       return GlobalDirective;
487     }
488     const char *getSetDirective() const {
489       return SetDirective;
490     }
491     const char *getLCOMMDirective() const {
492       return LCOMMDirective;
493     }
494     const char *getCOMMDirective() const {
495       return COMMDirective;
496     }
497     bool getCOMMDirectiveTakesAlignment() const {
498       return COMMDirectiveTakesAlignment;
499     }
500     bool hasDotTypeDotSizeDirective() const {
501       return HasDotTypeDotSizeDirective;
502     }
503     const char *getUsedDirective() const {
504       return UsedDirective;
505     }
506     const char *getWeakRefDirective() const {
507       return WeakRefDirective;
508     }
509     const char *getHiddenDirective() const {
510       return HiddenDirective;
511     }
512     bool isAbsoluteSectionOffsets() const {
513       return AbsoluteSectionOffsets;
514     }
515     bool hasLEB128() const {
516       return HasLEB128;
517     }
518     bool hasDotLoc() const {
519       return HasDotLoc;
520     }
521     bool hasDotFile() const {
522       return HasDotFile;
523     }
524     bool getSupportsExceptionHandling() const {
525       return SupportsExceptionHandling;
526     }
527     bool getDwarfRequiresFrameSection() const {
528       return DwarfRequiresFrameSection;
529     }
530     const char *getDwarfSectionOffsetDirective() const {
531       return DwarfSectionOffsetDirective;
532     }    
533     const char *getDwarfAbbrevSection() const {
534       return DwarfAbbrevSection;
535     }
536     const char *getDwarfInfoSection() const {
537       return DwarfInfoSection;
538     }
539     const char *getDwarfLineSection() const {
540       return DwarfLineSection;
541     }
542     const char *getDwarfFrameSection() const {
543       return DwarfFrameSection;
544     }
545     const char *getDwarfPubNamesSection() const {
546       return DwarfPubNamesSection;
547     }
548     const char *getDwarfPubTypesSection() const {
549       return DwarfPubTypesSection;
550     }
551     const char *getDwarfStrSection() const {
552       return DwarfStrSection;
553     }
554     const char *getDwarfLocSection() const {
555       return DwarfLocSection;
556     }
557     const char *getDwarfARangesSection() const {
558       return DwarfARangesSection;
559     }
560     const char *getDwarfRangesSection() const {
561       return DwarfRangesSection;
562     }
563     const char *getDwarfMacInfoSection() const {
564       return DwarfMacInfoSection;
565     }
566     const char *getDwarfEHFrameSection() const {
567       return DwarfEHFrameSection;
568     }
569     const char *getDwarfExceptionSection() const {
570       return DwarfExceptionSection;
571     }
572     const char** getAsmCBE() const {
573       return AsmTransCBE;
574     }
575   };
576 }
577
578 #endif
579