* Fix one more bug in PIC codegen: extra load is needed for *all*
[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.
43     ///
44     const char *BSSSection;               // Default to ".bss".
45     
46     /// AddressSize - Size of addresses used in file.
47     ///
48     unsigned AddressSize;                 // Defaults to 4.
49
50     /// NeedsSet - True if target asm can't compute addresses on data
51     /// directives.
52     bool NeedsSet;                        // Defaults to false.
53     
54     /// MaxInstLength - This is the maximum possible length of an instruction,
55     /// which is needed to compute the size of an inline asm.
56     unsigned MaxInstLength;               // Defaults to 4.
57     
58     /// SeparatorChar - This character, if specified, is used to separate
59     /// instructions from each other when on the same line.  This is used to
60     /// measure inline asm instructions.
61     char SeparatorChar;                   // Defaults to ';'
62
63     /// CommentString - This indicates the comment character used by the
64     /// assembler.
65     const char *CommentString;            // Defaults to "#"
66
67     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
68     /// onto all global symbols.  This is often used for "_" or ".".
69     const char *GlobalPrefix;             // Defaults to ""
70
71     /// PrivateGlobalPrefix - This prefix is used for globals like constant
72     /// pool entries that are completely private to the .o file and should not
73     /// have names in the .o file.  This is often "." or "L".
74     const char *PrivateGlobalPrefix;      // Defaults to "."
75     
76     /// GlobalVarAddrPrefix/Suffix - If these are nonempty, these strings
77     /// will enclose any GlobalVariable (that isn't a function)
78     ///
79     const char *GlobalVarAddrPrefix;      // Defaults to ""
80     const char *GlobalVarAddrSuffix;      // Defaults to ""
81
82     /// FunctionAddrPrefix/Suffix - If these are nonempty, these strings
83     /// will enclose any GlobalVariable that points to a function.
84     /// For example, this is used by the IA64 backend to materialize
85     /// function descriptors, by decorating the ".data8" object with the
86     /// \literal @fptr( ) \endliteral
87     /// link-relocation operator.
88     ///
89     const char *FunctionAddrPrefix;       // Defaults to ""
90     const char *FunctionAddrSuffix;       // Defaults to ""
91
92     /// InlineAsmStart/End - If these are nonempty, they contain a directive to
93     /// emit before and after an inline assembly statement.
94     const char *InlineAsmStart;           // Defaults to "#APP\n"
95     const char *InlineAsmEnd;             // Defaults to "#NO_APP\n"
96
97     /// AssemblerDialect - Which dialect of an assembler variant to use.
98     unsigned AssemblerDialect;            // Defaults to 0
99
100     //===--- Data Emission Directives -------------------------------------===//
101
102     /// ZeroDirective - this should be set to the directive used to get some
103     /// number of zero bytes emitted to the current section.  Common cases are
104     /// "\t.zero\t" and "\t.space\t".  If this is set to null, the
105     /// Data*bitsDirective's will be used to emit zero bytes.
106     const char *ZeroDirective;            // Defaults to "\t.zero\t"
107     const char *ZeroDirectiveSuffix;      // Defaults to ""
108
109     /// AsciiDirective - This directive allows emission of an ascii string with
110     /// the standard C escape characters embedded into it.
111     const char *AsciiDirective;           // Defaults to "\t.ascii\t"
112     
113     /// AscizDirective - If not null, this allows for special handling of
114     /// zero terminated strings on this target.  This is commonly supported as
115     /// ".asciz".  If a target doesn't support this, it can be set to null.
116     const char *AscizDirective;           // Defaults to "\t.asciz\t"
117
118     /// DataDirectives - These directives are used to output some unit of
119     /// integer data to the current section.  If a data directive is set to
120     /// null, smaller data directives will be used to emit the large sizes.
121     const char *Data8bitsDirective;       // Defaults to "\t.byte\t"
122     const char *Data16bitsDirective;      // Defaults to "\t.short\t"
123     const char *Data32bitsDirective;      // Defaults to "\t.long\t"
124     const char *Data64bitsDirective;      // Defaults to "\t.quad\t"
125
126     //===--- Alignment Information ----------------------------------------===//
127
128     /// AlignDirective - The directive used to emit round up to an alignment
129     /// boundary.
130     ///
131     const char *AlignDirective;           // Defaults to "\t.align\t"
132
133     /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
134     /// emits ".align N" directives, where N is the number of bytes to align to.
135     /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
136     /// boundary.
137     bool AlignmentIsInBytes;              // Defaults to true
138
139     //===--- Section Switching Directives ---------------------------------===//
140     
141     /// SwitchToSectionDirective - This is the directive used when we want to
142     /// emit a global to an arbitrary section.  The section name is emited after
143     /// this.
144     const char *SwitchToSectionDirective; // Defaults to "\t.section\t"
145     
146     /// TextSectionStartSuffix - This is printed after each start of section
147     /// directive for text sections.
148     const char *TextSectionStartSuffix;   // Defaults to "".
149
150     /// DataSectionStartSuffix - This is printed after each start of section
151     /// directive for data sections.
152     const char *DataSectionStartSuffix;   // Defaults to "".
153     
154     /// SectionEndDirectiveSuffix - If non-null, the asm printer will close each
155     /// section with the section name and this suffix printed.
156     const char *SectionEndDirectiveSuffix;// Defaults to null.
157     
158     /// ConstantPoolSection - This is the section that we SwitchToSection right
159     /// before emitting the constant pool for a function.
160     const char *ConstantPoolSection;      // Defaults to "\t.section .rodata\n"
161
162     /// JumpTableDataSection - This is the section that we SwitchToSection right
163     /// before emitting the jump tables for a function when the relocation model
164     /// is not PIC.
165     const char *JumpTableDataSection;     // Defaults to "\t.section .rodata\n"
166     
167     /// JumpTableDirective - if non-null, the directive to emit before a jump
168     /// table.
169     const char *JumpTableDirective;
170
171     /// CStringSection - If not null, this allows for special handling of
172     /// cstring constants (\0 terminated string that does not contain any
173     /// other null bytes) on this target. This is commonly supported as
174     /// ".cstring".
175     const char *CStringSection;           // Defaults to NULL
176
177     /// StaticCtorsSection - This is the directive that is emitted to switch to
178     /// a section to emit the static constructor list.
179     /// Defaults to "\t.section .ctors,\"aw\",@progbits".
180     const char *StaticCtorsSection;
181
182     /// StaticDtorsSection - This is the directive that is emitted to switch to
183     /// a section to emit the static destructor list.
184     /// Defaults to "\t.section .dtors,\"aw\",@progbits".
185     const char *StaticDtorsSection;
186
187     /// FourByteConstantSection, EightByteConstantSection,
188     /// SixteenByteConstantSection - These are special sections where we place
189     /// 4-, 8-, and 16- byte constant literals.
190     const char *FourByteConstantSection;
191     const char *EightByteConstantSection;
192     const char *SixteenByteConstantSection;
193     
194     //===--- Global Variable Emission Directives --------------------------===//
195     
196     /// SetDirective - This is the name of a directive that can be used to tell
197     /// the assembler to set the value of a variable to some expression.
198     const char *SetDirective;             // Defaults to null.
199     
200     /// LCOMMDirective - This is the name of a directive (if supported) that can
201     /// be used to efficiently declare a local (internal) block of zero
202     /// initialized data in the .bss/.data section.  The syntax expected is:
203     /// \literal <LCOMMDirective> SYMBOLNAME LENGTHINBYTES, ALIGNMENT
204     /// \endliteral
205     const char *LCOMMDirective;           // Defaults to null.
206     
207     const char *COMMDirective;            // Defaults to "\t.comm\t".
208
209     /// COMMDirectiveTakesAlignment - True if COMMDirective take a third
210     /// argument that specifies the alignment of the declaration.
211     bool COMMDirectiveTakesAlignment;     // Defaults to true.
212     
213     /// HasDotTypeDotSizeDirective - True if the target has .type and .size
214     /// directives, this is true for most ELF targets.
215     bool HasDotTypeDotSizeDirective;      // Defaults to true.
216     
217     /// UsedDirective - This directive, if non-null, is used to declare a global
218     /// as being used somehow that the assembler can't see.  This prevents dead
219     /// code elimination on some targets.
220     const char *UsedDirective;            // Defaults to null.
221
222     /// WeakRefDirective - This directive, if non-null, is used to declare a
223     /// global as being a weak undefined symbol.
224     const char *WeakRefDirective;         // Defaults to null.
225     
226     /// HiddenDirective - This directive, if non-null, is used to declare a
227     /// global or function as having hidden visibility.
228     const char *HiddenDirective;          // Defaults to "\t.hidden\t".
229     
230     //===--- Dwarf Emission Directives -----------------------------------===//
231
232     /// HasLEB128 - True if target asm supports leb128 directives.
233     ///
234     bool HasLEB128; // Defaults to false.
235     
236     /// hasDotLoc - True if target asm supports .loc directives.
237     ///
238     bool HasDotLoc; // Defaults to false.
239     
240     /// HasDotFile - True if target asm supports .file directives.
241     ///
242     bool HasDotFile; // Defaults to false.
243     
244     /// RequiresFrameSection - true if the Dwarf2 output needs a frame section
245     ///
246     bool DwarfRequiresFrameSection; // Defaults to true.
247
248     /// DwarfAbbrevSection - Section directive for Dwarf abbrev.
249     ///
250     const char *DwarfAbbrevSection; // Defaults to ".debug_abbrev".
251
252     /// DwarfInfoSection - Section directive for Dwarf info.
253     ///
254     const char *DwarfInfoSection; // Defaults to ".debug_info".
255
256     /// DwarfLineSection - Section directive for Dwarf info.
257     ///
258     const char *DwarfLineSection; // Defaults to ".debug_line".
259     
260     /// DwarfFrameSection - Section directive for Dwarf info.
261     ///
262     const char *DwarfFrameSection; // Defaults to ".debug_frame".
263     
264     /// DwarfPubNamesSection - Section directive for Dwarf info.
265     ///
266     const char *DwarfPubNamesSection; // Defaults to ".debug_pubnames".
267     
268     /// DwarfPubTypesSection - Section directive for Dwarf info.
269     ///
270     const char *DwarfPubTypesSection; // Defaults to ".debug_pubtypes".
271     
272     /// DwarfStrSection - Section directive for Dwarf info.
273     ///
274     const char *DwarfStrSection; // Defaults to ".debug_str".
275
276     /// DwarfLocSection - Section directive for Dwarf info.
277     ///
278     const char *DwarfLocSection; // Defaults to ".debug_loc".
279
280     /// DwarfARangesSection - Section directive for Dwarf info.
281     ///
282     const char *DwarfARangesSection; // Defaults to ".debug_aranges".
283
284     /// DwarfRangesSection - Section directive for Dwarf info.
285     ///
286     const char *DwarfRangesSection; // Defaults to ".debug_ranges".
287
288     /// DwarfMacInfoSection - Section directive for Dwarf info.
289     ///
290     const char *DwarfMacInfoSection; // Defaults to ".debug_macinfo".
291
292     //===--- CBE Asm Translation Table -----------------------------------===//
293
294     const char** AsmTransCBE; // Defaults to empty
295
296   public:
297     TargetAsmInfo();
298     virtual ~TargetAsmInfo();
299
300     /// Measure the specified inline asm to determine an approximation of its
301     /// length.
302     unsigned getInlineAsmLength(const char *Str) const;
303
304     /// ExpandInlineAsm - This hook allows the target to expand an inline asm
305     /// call to be explicit llvm code if it wants to.  This is useful for
306     /// turning simple inline asms into LLVM intrinsics, which gives the
307     /// compiler more information about the behavior of the code.
308     virtual bool ExpandInlineAsm(CallInst *CI) const {
309       return false;
310     }
311     
312     // Accessors.
313     //
314     const char *getTextSection() const {
315       return TextSection;
316     }
317     const char *getDataSection() const {
318       return DataSection;
319     }
320     const char *getBSSSection() const {
321       return BSSSection;
322     }
323     unsigned getAddressSize() const {
324       return AddressSize;
325     }
326     bool needsSet() const {
327       return NeedsSet;
328     }
329     const char *getCommentString() const {
330       return CommentString;
331     }
332     const char *getGlobalPrefix() const {
333       return GlobalPrefix;
334     }
335     const char *getPrivateGlobalPrefix() const {
336       return PrivateGlobalPrefix;
337     }
338     const char *getGlobalVarAddrPrefix() const {
339       return GlobalVarAddrPrefix;
340     }
341     const char *getGlobalVarAddrSuffix() const {
342       return GlobalVarAddrSuffix;
343     }
344     const char *getFunctionAddrPrefix() const {
345       return FunctionAddrPrefix;
346     }
347     const char *getFunctionAddrSuffix() const {
348       return FunctionAddrSuffix;
349     }
350     const char *getInlineAsmStart() const {
351       return InlineAsmStart;
352     }
353     const char *getInlineAsmEnd() const {
354       return InlineAsmEnd;
355     }
356     unsigned getAssemblerDialect() const {
357       return AssemblerDialect;
358     }
359     const char *getZeroDirective() const {
360       return ZeroDirective;
361     }
362     const char *getZeroDirectiveSuffix() const {
363       return ZeroDirectiveSuffix;
364     }
365     const char *getAsciiDirective() const {
366       return AsciiDirective;
367     }
368     const char *getAscizDirective() const {
369       return AscizDirective;
370     }
371     const char *getData8bitsDirective() const {
372       return Data8bitsDirective;
373     }
374     const char *getData16bitsDirective() const {
375       return Data16bitsDirective;
376     }
377     const char *getData32bitsDirective() const {
378       return Data32bitsDirective;
379     }
380     const char *getData64bitsDirective() const {
381       return Data64bitsDirective;
382     }
383     const char *getJumpTableDirective() const {
384       return JumpTableDirective;
385     }
386     const char *getAlignDirective() const {
387       return AlignDirective;
388     }
389     bool getAlignmentIsInBytes() const {
390       return AlignmentIsInBytes;
391     }
392     const char *getSwitchToSectionDirective() const {
393       return SwitchToSectionDirective;
394     }
395     const char *getTextSectionStartSuffix() const {
396       return TextSectionStartSuffix;
397     }
398     const char *getDataSectionStartSuffix() const {
399       return DataSectionStartSuffix;
400     }
401     const char *getSectionEndDirectiveSuffix() const {
402       return SectionEndDirectiveSuffix;
403     }
404     const char *getConstantPoolSection() const {
405       return ConstantPoolSection;
406     }
407     const char *getJumpTableDataSection() const {
408       return JumpTableDataSection;
409     }
410     const char *getCStringSection() const {
411       return CStringSection;
412     }
413     const char *getStaticCtorsSection() const {
414       return StaticCtorsSection;
415     }
416     const char *getStaticDtorsSection() const {
417       return StaticDtorsSection;
418     }
419     const char *getFourByteConstantSection() const {
420       return FourByteConstantSection;
421     }
422     const char *getEightByteConstantSection() const {
423       return EightByteConstantSection;
424     }
425     const char *getSixteenByteConstantSection() const {
426       return SixteenByteConstantSection;
427     }
428     const char *getSetDirective() const {
429       return SetDirective;
430     }
431     const char *getLCOMMDirective() const {
432       return LCOMMDirective;
433     }
434     const char *getCOMMDirective() const {
435       return COMMDirective;
436     }
437     bool getCOMMDirectiveTakesAlignment() const {
438       return COMMDirectiveTakesAlignment;
439     }
440     bool hasDotTypeDotSizeDirective() const {
441       return HasDotTypeDotSizeDirective;
442     }
443     const char *getUsedDirective() const {
444       return UsedDirective;
445     }
446     const char *getWeakRefDirective() const {
447       return WeakRefDirective;
448     }
449     const char *getHiddenDirective() const {
450       return HiddenDirective;
451     }
452     bool hasLEB128() const {
453       return HasLEB128;
454     }
455     bool hasDotLoc() const {
456       return HasDotLoc;
457     }
458     bool hasDotFile() const {
459       return HasDotFile;
460     }
461     bool getDwarfRequiresFrameSection() const {
462       return DwarfRequiresFrameSection;
463     }
464     const char *getDwarfAbbrevSection() const {
465       return DwarfAbbrevSection;
466     }
467     const char *getDwarfInfoSection() const {
468       return DwarfInfoSection;
469     }
470     const char *getDwarfLineSection() const {
471       return DwarfLineSection;
472     }
473     const char *getDwarfFrameSection() const {
474       return DwarfFrameSection;
475     }
476     const char *getDwarfPubNamesSection() const {
477       return DwarfPubNamesSection;
478     }
479     const char *getDwarfPubTypesSection() const {
480       return DwarfPubTypesSection;
481     }
482     const char *getDwarfStrSection() const {
483       return DwarfStrSection;
484     }
485     const char *getDwarfLocSection() const {
486       return DwarfLocSection;
487     }
488     const char *getDwarfARangesSection() const {
489       return DwarfARangesSection;
490     }
491     const char *getDwarfRangesSection() const {
492       return DwarfRangesSection;
493     }
494     const char *getDwarfMacInfoSection() const {
495       return DwarfMacInfoSection;
496     }
497     const char** getAsmCBE() const {
498       return AsmTransCBE;
499     }
500   };
501 }
502
503 #endif
504