Reimplement rip-relative addressing in the X86-64 backend. The new
[oota-llvm.git] / lib / Target / X86 / AsmPrinter / X86ATTAsmPrinter.h
1 //===-- X86ATTAsmPrinter.h - Convert X86 LLVM code to AT&T assembly -------===//
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 // AT&T assembly code printer class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef X86ATTASMPRINTER_H
15 #define X86ATTASMPRINTER_H
16
17 #include "../X86.h"
18 #include "../X86MachineFunctionInfo.h"
19 #include "../X86TargetMachine.h"
20 #include "llvm/ADT/StringSet.h"
21 #include "llvm/CodeGen/AsmPrinter.h"
22 #include "llvm/CodeGen/DwarfWriter.h"
23 #include "llvm/CodeGen/MachineModuleInfo.h"
24 #include "llvm/CodeGen/ValueTypes.h"
25 #include "llvm/Support/Compiler.h"
26
27 namespace llvm {
28
29 class MachineJumpTableInfo;
30 class MCContext;
31 class MCInst;
32 class MCStreamer;
33
34 class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
35   const X86Subtarget *Subtarget;
36   
37   MCContext *Context;
38   MCStreamer *Streamer;
39  public:
40   explicit X86ATTAsmPrinter(raw_ostream &O, X86TargetMachine &TM,
41                             const TargetAsmInfo *T, CodeGenOpt::Level OL,
42                             bool V)
43     : AsmPrinter(O, TM, T, OL, V) {
44     Subtarget = &TM.getSubtarget<X86Subtarget>();
45     Context = 0;
46     Streamer = 0;
47   }
48
49   virtual const char *getPassName() const {
50     return "X86 AT&T-Style Assembly Printer";
51   }
52
53   void getAnalysisUsage(AnalysisUsage &AU) const {
54     AU.setPreservesAll();
55     if (Subtarget->isTargetDarwin() ||
56         Subtarget->isTargetELF() ||
57         Subtarget->isTargetCygMing()) {
58       AU.addRequired<MachineModuleInfo>();
59     }
60     AU.addRequired<DwarfWriter>();
61     AsmPrinter::getAnalysisUsage(AU);
62   }
63
64   bool doInitialization(Module &M);
65   bool doFinalization(Module &M);
66
67   /// printInstruction - This method is automatically generated by tablegen
68   /// from the instruction set description.  This method returns true if the
69   /// machine instruction was sufficiently described to print it, otherwise it
70   /// returns false.
71   bool printInstruction(const MachineInstr *MI);
72   
73   
74   // New MCInst printing stuff.
75   bool printInstruction(const MCInst *MI);
76
77   void printOperand(const MCInst *MI, unsigned OpNo,
78                     const char *Modifier = 0);
79   void printMemReference(const MCInst *MI, unsigned Op);
80   void printLeaMemReference(const MCInst *MI, unsigned Op);
81   void printSSECC(const MCInst *MI, unsigned Op);
82   void printPICLabel(const MCInst *MI, unsigned Op);
83   void print_pcrel_imm(const MCInst *MI, unsigned OpNo);
84   
85   void printi8mem(const MCInst *MI, unsigned OpNo) {
86     printMemReference(MI, OpNo);
87   }
88   void printi16mem(const MCInst *MI, unsigned OpNo) {
89     printMemReference(MI, OpNo);
90   }
91   void printi32mem(const MCInst *MI, unsigned OpNo) {
92     printMemReference(MI, OpNo);
93   }
94   void printi64mem(const MCInst *MI, unsigned OpNo) {
95     printMemReference(MI, OpNo);
96   }
97   void printi128mem(const MCInst *MI, unsigned OpNo) {
98     printMemReference(MI, OpNo);
99   }
100   void printf32mem(const MCInst *MI, unsigned OpNo) {
101     printMemReference(MI, OpNo);
102   }
103   void printf64mem(const MCInst *MI, unsigned OpNo) {
104     printMemReference(MI, OpNo);
105   }
106   void printf80mem(const MCInst *MI, unsigned OpNo) {
107     printMemReference(MI, OpNo);
108   }
109   void printf128mem(const MCInst *MI, unsigned OpNo) {
110     printMemReference(MI, OpNo);
111   }
112   void printlea32mem(const MCInst *MI, unsigned OpNo) {
113     printLeaMemReference(MI, OpNo);
114   }
115   void printlea64mem(const MCInst *MI, unsigned OpNo) {
116     printLeaMemReference(MI, OpNo);
117   }
118   void printlea64_32mem(const MCInst *MI, unsigned OpNo) {
119     printLeaMemReference(MI, OpNo);
120   }
121   
122   
123
124   // These methods are used by the tablegen'erated instruction printer.
125   void printOperand(const MachineInstr *MI, unsigned OpNo,
126                     const char *Modifier = 0);
127   void print_pcrel_imm(const MachineInstr *MI, unsigned OpNo);
128   void printi8mem(const MachineInstr *MI, unsigned OpNo) {
129     printMemReference(MI, OpNo);
130   }
131   void printi16mem(const MachineInstr *MI, unsigned OpNo) {
132     printMemReference(MI, OpNo);
133   }
134   void printi32mem(const MachineInstr *MI, unsigned OpNo) {
135     printMemReference(MI, OpNo);
136   }
137   void printi64mem(const MachineInstr *MI, unsigned OpNo) {
138     printMemReference(MI, OpNo);
139   }
140   void printi128mem(const MachineInstr *MI, unsigned OpNo) {
141     printMemReference(MI, OpNo);
142   }
143   void printf32mem(const MachineInstr *MI, unsigned OpNo) {
144     printMemReference(MI, OpNo);
145   }
146   void printf64mem(const MachineInstr *MI, unsigned OpNo) {
147     printMemReference(MI, OpNo);
148   }
149   void printf80mem(const MachineInstr *MI, unsigned OpNo) {
150     printMemReference(MI, OpNo);
151   }
152   void printf128mem(const MachineInstr *MI, unsigned OpNo) {
153     printMemReference(MI, OpNo);
154   }
155   void printlea32mem(const MachineInstr *MI, unsigned OpNo) {
156     printLeaMemReference(MI, OpNo);
157   }
158   void printlea64mem(const MachineInstr *MI, unsigned OpNo) {
159     printLeaMemReference(MI, OpNo);
160   }
161   void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) {
162     printLeaMemReference(MI, OpNo, "subreg64");
163   }
164
165   bool printAsmMRegister(const MachineOperand &MO, char Mode);
166   bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
167                        unsigned AsmVariant, const char *ExtraCode);
168   bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
169                              unsigned AsmVariant, const char *ExtraCode);
170
171   void printMachineInstruction(const MachineInstr *MI);
172   void printSSECC(const MachineInstr *MI, unsigned Op);
173   void printMemReference(const MachineInstr *MI, unsigned Op,
174                          const char *Modifier=NULL);
175   void printLeaMemReference(const MachineInstr *MI, unsigned Op,
176                             const char *Modifier=NULL);
177   void printPICJumpTableSetLabel(unsigned uid,
178                                  const MachineBasicBlock *MBB) const;
179   void printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
180                                  const MachineBasicBlock *MBB) const {
181     AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB);
182   }
183   void printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
184                               const MachineBasicBlock *MBB,
185                               unsigned uid) const;
186
187   void printPICLabel(const MachineInstr *MI, unsigned Op);
188   void printModuleLevelGV(const GlobalVariable* GVar);
189
190   void PrintPICBaseSymbol() const;
191   
192   bool runOnMachineFunction(MachineFunction &F);
193
194   void emitFunctionHeader(const MachineFunction &MF);
195
196   // Necessary for Darwin to print out the apprioriate types of linker stubs
197   StringSet<> FnStubs, GVStubs, HiddenGVStubs;
198
199   // Necessary for dllexport support
200   StringSet<> DLLExportedFns, DLLExportedGVs;
201
202   // We have to propagate some information about MachineFunction to
203   // AsmPrinter. It's ok, when we're printing the function, since we have
204   // access to MachineFunction and can get the appropriate MachineFunctionInfo.
205   // Unfortunately, this is not possible when we're printing reference to
206   // Function (e.g. calling it and so on). Even more, there is no way to get the
207   // corresponding MachineFunctions: it can even be not created at all. That's
208   // why we should use additional structure, when we're collecting all necessary
209   // information.
210   //
211   // This structure is using e.g. for name decoration for stdcall & fastcall'ed
212   // function, since we have to use arguments' size for decoration.
213   typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap;
214   FMFInfoMap FunctionInfoMap;
215
216   void decorateName(std::string& Name, const GlobalValue* GV);
217 };
218
219 } // end namespace llvm
220
221 #endif