Remove the argument from EmitJumpTableInfo, because it doesn't need it.
[oota-llvm.git] / include / llvm / CodeGen / AsmPrinter.h
1 //===-- llvm/CodeGen/AsmPrinter.h - AsmPrinter Framework --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains a class to be used as the base class for target specific
11 // asm writers.  This class primarily handles common functionality used by
12 // all asm writers.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_CODEGEN_ASMPRINTER_H
17 #define LLVM_CODEGEN_ASMPRINTER_H
18
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/Support/DebugLoc.h"
21 #include "llvm/Target/TargetMachine.h"
22
23 namespace llvm {
24   class BlockAddress;
25   class GCStrategy;
26   class Constant;
27   class ConstantArray;
28   class ConstantFP;
29   class ConstantInt;
30   class ConstantStruct;
31   class ConstantVector;
32   class GCMetadataPrinter;
33   class GlobalValue;
34   class GlobalVariable;
35   class MachineBasicBlock;
36   class MachineFunction;
37   class MachineInstr;
38   class MachineLoopInfo;
39   class MachineLoop;
40   class MachineConstantPool;
41   class MachineConstantPoolEntry;
42   class MachineConstantPoolValue;
43   class MachineJumpTableInfo;
44   class MachineModuleInfo;
45   class MCInst;
46   class MCContext;
47   class MCSection;
48   class MCStreamer;
49   class MCSymbol;
50   class MDNode;
51   class DwarfWriter;
52   class Mangler;
53   class MCAsmInfo;
54   class TargetLoweringObjectFile;
55   class Twine;
56   class Type;
57   class formatted_raw_ostream;
58
59   /// AsmPrinter - This class is intended to be used as a driving class for all
60   /// asm writers.
61   class AsmPrinter : public MachineFunctionPass {
62     static char ID;
63
64     // GCMetadataPrinters - The garbage collection metadata printer table.
65     typedef DenseMap<GCStrategy*,GCMetadataPrinter*> gcp_map_type;
66     typedef gcp_map_type::iterator gcp_iterator;
67     gcp_map_type GCMetadataPrinters;
68
69     /// If VerboseAsm is set, a pointer to the loop info for this
70     /// function.
71     ///
72     MachineLoopInfo *LI;
73
74   public:
75     /// MMI - If available, this is a pointer to the current MachineModuleInfo.
76     MachineModuleInfo *MMI;
77     
78   protected:
79     /// DW - If available, this is a pointer to the current dwarf writer.
80     DwarfWriter *DW;
81
82   public:
83     /// Flags to specify different kinds of comments to output in
84     /// assembly code.  These flags carry semantic information not
85     /// otherwise easily derivable from the IR text.
86     ///
87     enum CommentFlag {
88       ReloadReuse = 0x1
89     };
90
91     /// Output stream on which we're printing assembly code.
92     ///
93     formatted_raw_ostream &O;
94
95     /// Target machine description.
96     ///
97     TargetMachine &TM;
98     
99     /// getObjFileLowering - Return information about object file lowering.
100     TargetLoweringObjectFile &getObjFileLowering() const;
101     
102     /// Target Asm Printer information.
103     ///
104     const MCAsmInfo *MAI;
105
106     /// Target Register Information.
107     ///
108     const TargetRegisterInfo *TRI;
109
110     /// OutContext - This is the context for the output file that we are
111     /// streaming.  This owns all of the global MC-related objects for the
112     /// generated translation unit.
113     MCContext &OutContext;
114     
115     /// OutStreamer - This is the MCStreamer object for the file we are
116     /// generating.  This contains the transient state for the current
117     /// translation unit that we are generating (such as the current section
118     /// etc).
119     MCStreamer &OutStreamer;
120     
121     /// The current machine function.
122     const MachineFunction *MF;
123
124     /// Name-mangler for global names.
125     ///
126     Mangler *Mang;
127
128     /// The symbol for the current function. This is recalculated at the
129     /// beginning of each call to runOnMachineFunction().
130     ///
131     MCSymbol *CurrentFnSym;
132     
133     /// getCurrentSection() - Return the current section we are emitting to.
134     const MCSection *getCurrentSection() const;
135     
136
137     /// VerboseAsm - Emit comments in assembly output if this is true.
138     ///
139     bool VerboseAsm;
140
141     /// Private state for PrintSpecial()
142     // Assign a unique ID to this machine instruction.
143     mutable const MachineInstr *LastMI;
144     mutable const Function *LastFn;
145     mutable unsigned Counter;
146     
147     // Private state for processDebugLoc()
148     mutable const MDNode *PrevDLT;
149
150   protected:
151     explicit AsmPrinter(formatted_raw_ostream &o, TargetMachine &TM,
152                         const MCAsmInfo *T, bool V);
153     
154   public:
155     virtual ~AsmPrinter();
156
157     /// isVerbose - Return true if assembly output should contain comments.
158     ///
159     bool isVerbose() const { return VerboseAsm; }
160
161     /// getFunctionNumber - Return a unique ID for the current function.
162     ///
163     unsigned getFunctionNumber() const;
164     
165   protected:
166     /// getAnalysisUsage - Record analysis usage.
167     /// 
168     void getAnalysisUsage(AnalysisUsage &AU) const;
169     
170     /// doInitialization - Set up the AsmPrinter when we are working on a new
171     /// module.  If your pass overrides this, it must make sure to explicitly
172     /// call this implementation.
173     bool doInitialization(Module &M);
174
175     /// EmitStartOfAsmFile - This virtual method can be overridden by targets
176     /// that want to emit something at the start of their file.
177     virtual void EmitStartOfAsmFile(Module &) {}
178     
179     /// EmitEndOfAsmFile - This virtual method can be overridden by targets that
180     /// want to emit something at the end of their file.
181     virtual void EmitEndOfAsmFile(Module &) {}
182     
183     /// doFinalization - Shut down the asmprinter.  If you override this in your
184     /// pass, you must make sure to call it explicitly.
185     bool doFinalization(Module &M);
186     
187     /// PrintSpecial - Print information related to the specified machine instr
188     /// that is independent of the operand, and may be independent of the instr
189     /// itself.  This can be useful for portably encoding the comment character
190     /// or other bits of target-specific knowledge into the asmstrings.  The
191     /// syntax used is ${:comment}.  Targets can override this to add support
192     /// for their own strange codes.
193     virtual void PrintSpecial(const MachineInstr *MI, const char *Code) const;
194
195     /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
196     /// instruction, using the specified assembler variant.  Targets should
197     /// override this to format as appropriate.  This method can return true if
198     /// the operand is erroneous.
199     virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
200                                  unsigned AsmVariant, const char *ExtraCode);
201     
202     /// PrintAsmMemoryOperand - Print the specified operand of MI, an INLINEASM
203     /// instruction, using the specified assembler variant as an address.
204     /// Targets should override this to format as appropriate.  This method can
205     /// return true if the operand is erroneous.
206     virtual bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
207                                        unsigned AsmVariant, 
208                                        const char *ExtraCode);
209     
210     /// SetupMachineFunction - This should be called when a new MachineFunction
211     /// is being processed from runOnMachineFunction.
212     void SetupMachineFunction(MachineFunction &MF);
213     
214     /// EmitFunctionHeader - This method emits the header for the current
215     /// function.
216     void EmitFunctionHeader();
217     
218     /// EmitFunctionBody - This method emits the body and trailer for a
219     /// function.
220     void EmitFunctionBody();
221
222     /// EmitInstruction - Targets should implement this to emit instructions.
223     virtual void EmitInstruction(const MachineInstr *MI) {
224       assert(0 && "EmitInstruction not implemented");
225     }
226     
227     /// EmitConstantPool - Print to the current output stream assembly
228     /// representations of the constants in the constant pool MCP. This is
229     /// used to print out constants which have been "spilled to memory" by
230     /// the code generator.
231     ///
232     virtual void EmitConstantPool();
233     
234     /// EmitJumpTableInfo - Print assembly representations of the jump tables 
235     /// used by the current function to the current output stream.  
236     ///
237     void EmitJumpTableInfo();
238     
239     /// EmitGlobalVariable - Emit the specified global variable to the .s file.
240     virtual void EmitGlobalVariable(const GlobalVariable *GV);
241     
242     /// EmitSpecialLLVMGlobal - Check to see if the specified global is a
243     /// special global used by LLVM.  If so, emit it and return true, otherwise
244     /// do nothing and return false.
245     bool EmitSpecialLLVMGlobal(const GlobalVariable *GV);
246
247   public:
248     //===------------------------------------------------------------------===//
249     // Emission and print routines
250     //
251
252     /// EmitInt8 - Emit a byte directive and value.
253     ///
254     void EmitInt8(int Value) const;
255
256     /// EmitInt16 - Emit a short directive and value.
257     ///
258     void EmitInt16(int Value) const;
259
260     /// EmitInt32 - Emit a long directive and value.
261     ///
262     void EmitInt32(int Value) const;
263
264     /// EmitInt64 - Emit a long long directive and value.
265     ///
266     void EmitInt64(uint64_t Value) const;
267
268     //===------------------------------------------------------------------===//
269
270     /// EmitAlignment - Emit an alignment directive to the specified power of
271     /// two boundary.  For example, if you pass in 3 here, you will get an 8
272     /// byte alignment.  If a global value is specified, and if that global has
273     /// an explicit alignment requested, it will unconditionally override the
274     /// alignment request.  However, if ForcedAlignBits is specified, this value
275     /// has final say: the ultimate alignment will be the max of ForcedAlignBits
276     /// and the alignment computed with NumBits and the global.  If UseFillExpr
277     /// is true, it also emits an optional second value FillValue which the
278     /// assembler uses to fill gaps to match alignment for text sections if the
279     /// has specified a non-zero fill value.
280     ///
281     /// The algorithm is:
282     ///     Align = NumBits;
283     ///     if (GV && GV->hasalignment) Align = GV->getalignment();
284     ///     Align = std::max(Align, ForcedAlignBits);
285     ///
286     void EmitAlignment(unsigned NumBits, const GlobalValue *GV = 0,
287                        unsigned ForcedAlignBits = 0,
288                        bool UseFillExpr = true) const;
289
290     /// printLabel - This method prints a local label used by debug and
291     /// exception handling tables.
292     void printLabel(const MachineInstr *MI) const;
293     void printLabel(unsigned Id) const;
294
295     /// printDeclare - This method prints a local variable declaration used by
296     /// debug tables.
297     void printDeclare(const MachineInstr *MI) const;
298
299     /// EmitComments - Pretty-print comments for instructions
300     void EmitComments(const MachineInstr &MI) const;
301
302     /// GetGlobalValueSymbol - Return the MCSymbol for the specified global
303     /// value.
304     MCSymbol *GetGlobalValueSymbol(const GlobalValue *GV) const;
305
306     /// GetSymbolWithGlobalValueBase - Return the MCSymbol for a symbol with
307     /// global value name as its base, with the specified suffix, and where the
308     /// symbol is forced to have private linkage if ForcePrivate is true.
309     MCSymbol *GetSymbolWithGlobalValueBase(const GlobalValue *GV,
310                                            StringRef Suffix,
311                                            bool ForcePrivate = true) const;
312     
313     /// GetExternalSymbolSymbol - Return the MCSymbol for the specified
314     /// ExternalSymbol.
315     MCSymbol *GetExternalSymbolSymbol(StringRef Sym) const;
316     
317     /// GetCPISymbol - Return the symbol for the specified constant pool entry.
318     MCSymbol *GetCPISymbol(unsigned CPID) const;
319
320     /// GetJTISymbol - Return the symbol for the specified jump table entry.
321     MCSymbol *GetJTISymbol(unsigned JTID, bool isLinkerPrivate = false) const;
322
323     /// GetJTSetSymbol - Return the symbol for the specified jump table .set
324     /// FIXME: privatize to AsmPrinter.
325     MCSymbol *GetJTSetSymbol(unsigned UID, unsigned MBBID) const;
326
327     /// GetBlockAddressSymbol - Return the MCSymbol used to satisfy BlockAddress
328     /// uses of the specified basic block.
329     MCSymbol *GetBlockAddressSymbol(const BlockAddress *BA,
330                                     const char *Suffix = "") const;
331     MCSymbol *GetBlockAddressSymbol(const Function *F,
332                                     const BasicBlock *BB,
333                                     const char *Suffix = "") const;
334
335     /// EmitBasicBlockStart - This method prints the label for the specified
336     /// MachineBasicBlock, an alignment (if present) and a comment describing
337     /// it if appropriate.
338     void EmitBasicBlockStart(const MachineBasicBlock *MBB) const;
339     
340     
341     // Data emission.
342     
343     /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
344     void EmitGlobalConstant(const Constant* CV, unsigned AddrSpace = 0);
345     
346   protected:
347     virtual void EmitFunctionEntryLabel();
348     
349     virtual void EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV);
350
351     /// processDebugLoc - Processes the debug information of each machine
352     /// instruction's DebugLoc. 
353     void processDebugLoc(const MachineInstr *MI, bool BeforePrintingInsn);
354     
355     /// printInlineAsm - This method formats and prints the specified machine
356     /// instruction that is an inline asm.
357     void printInlineAsm(const MachineInstr *MI) const;
358
359     /// printImplicitDef - This method prints the specified machine instruction
360     /// that is an implicit def.
361     void printImplicitDef(const MachineInstr *MI) const;
362
363     /// printKill - This method prints the specified kill machine instruction.
364     void printKill(const MachineInstr *MI) const;
365
366     /// printOffset - This is just convenient handler for printing offsets.
367     void printOffset(int64_t Offset) const;
368  
369   private:
370     /// EmitVisibility - This emits visibility information about symbol, if
371     /// this is suported by the target.
372     void EmitVisibility(MCSymbol *Sym, unsigned Visibility) const;
373     
374     void EmitLinkage(unsigned Linkage, MCSymbol *GVSym) const;
375     
376     void EmitJumpTableEntry(const MachineJumpTableInfo *MJTI,
377                             const MachineBasicBlock *MBB,
378                             unsigned uid) const;
379     void EmitLLVMUsedList(Constant *List);
380     void EmitXXStructorList(Constant *List);
381     GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C);
382   };
383 }
384
385 #endif