1 //===-- X86ATTAsmPrinter.h - Convert X86 LLVM code to AT&T assembly -------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // AT&T assembly code printer class.
12 //===----------------------------------------------------------------------===//
14 #ifndef X86ATTASMPRINTER_H
15 #define X86ATTASMPRINTER_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"
29 class MachineJumpTableInfo;
34 class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
35 const X86Subtarget *Subtarget;
37 explicit X86ATTAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
38 const TargetAsmInfo *T, bool V)
39 : AsmPrinter(O, TM, T, V) {
40 Subtarget = &TM.getSubtarget<X86Subtarget>();
43 virtual const char *getPassName() const {
44 return "X86 AT&T-Style Assembly Printer";
47 void getAnalysisUsage(AnalysisUsage &AU) const {
49 if (Subtarget->isTargetDarwin() ||
50 Subtarget->isTargetELF() ||
51 Subtarget->isTargetCygMing()) {
52 AU.addRequired<MachineModuleInfo>();
54 AU.addRequired<DwarfWriter>();
55 AsmPrinter::getAnalysisUsage(AU);
58 bool doFinalization(Module &M);
60 /// printInstruction - This method is automatically generated by tablegen
61 /// from the instruction set description. This method returns true if the
62 /// machine instruction was sufficiently described to print it, otherwise it
64 bool printInstruction(const MachineInstr *MI);
67 // New MCInst printing stuff.
68 bool printInstruction(const MCInst *MI);
70 void printSymbolOperand(const MachineOperand &MO);
71 void printOperand(const MCInst *MI, unsigned OpNo,
72 const char *Modifier = 0);
73 void printMemReference(const MCInst *MI, unsigned Op);
74 void printLeaMemReference(const MCInst *MI, unsigned Op);
75 void printSSECC(const MCInst *MI, unsigned Op);
76 void printPICLabel(const MCInst *MI, unsigned Op);
77 void print_pcrel_imm(const MCInst *MI, unsigned OpNo);
79 void printi8mem(const MCInst *MI, unsigned OpNo) {
80 printMemReference(MI, OpNo);
82 void printi16mem(const MCInst *MI, unsigned OpNo) {
83 printMemReference(MI, OpNo);
85 void printi32mem(const MCInst *MI, unsigned OpNo) {
86 printMemReference(MI, OpNo);
88 void printi64mem(const MCInst *MI, unsigned OpNo) {
89 printMemReference(MI, OpNo);
91 void printi128mem(const MCInst *MI, unsigned OpNo) {
92 printMemReference(MI, OpNo);
94 void printf32mem(const MCInst *MI, unsigned OpNo) {
95 printMemReference(MI, OpNo);
97 void printf64mem(const MCInst *MI, unsigned OpNo) {
98 printMemReference(MI, OpNo);
100 void printf80mem(const MCInst *MI, unsigned OpNo) {
101 printMemReference(MI, OpNo);
103 void printf128mem(const MCInst *MI, unsigned OpNo) {
104 printMemReference(MI, OpNo);
106 void printlea32mem(const MCInst *MI, unsigned OpNo) {
107 printLeaMemReference(MI, OpNo);
109 void printlea64mem(const MCInst *MI, unsigned OpNo) {
110 printLeaMemReference(MI, OpNo);
112 void printlea64_32mem(const MCInst *MI, unsigned OpNo) {
113 printLeaMemReference(MI, OpNo);
118 // These methods are used by the tablegen'erated instruction printer.
119 void printOperand(const MachineInstr *MI, unsigned OpNo,
120 const char *Modifier = 0);
121 void print_pcrel_imm(const MachineInstr *MI, unsigned OpNo);
122 void printi8mem(const MachineInstr *MI, unsigned OpNo) {
123 printMemReference(MI, OpNo);
125 void printi16mem(const MachineInstr *MI, unsigned OpNo) {
126 printMemReference(MI, OpNo);
128 void printi32mem(const MachineInstr *MI, unsigned OpNo) {
129 printMemReference(MI, OpNo);
131 void printi64mem(const MachineInstr *MI, unsigned OpNo) {
132 printMemReference(MI, OpNo);
134 void printi128mem(const MachineInstr *MI, unsigned OpNo) {
135 printMemReference(MI, OpNo);
137 void printi256mem(const MachineInstr *MI, unsigned OpNo) {
138 printMemReference(MI, OpNo);
140 void printf32mem(const MachineInstr *MI, unsigned OpNo) {
141 printMemReference(MI, OpNo);
143 void printf64mem(const MachineInstr *MI, unsigned OpNo) {
144 printMemReference(MI, OpNo);
146 void printf80mem(const MachineInstr *MI, unsigned OpNo) {
147 printMemReference(MI, OpNo);
149 void printf128mem(const MachineInstr *MI, unsigned OpNo) {
150 printMemReference(MI, OpNo);
152 void printf256mem(const MachineInstr *MI, unsigned OpNo) {
153 printMemReference(MI, OpNo);
155 void printlea32mem(const MachineInstr *MI, unsigned OpNo) {
156 printLeaMemReference(MI, OpNo);
158 void printlea64mem(const MachineInstr *MI, unsigned OpNo) {
159 printLeaMemReference(MI, OpNo);
161 void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) {
162 printLeaMemReference(MI, OpNo, "subreg64");
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);
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);
183 void printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
184 const MachineBasicBlock *MBB,
187 void printPICLabel(const MachineInstr *MI, unsigned Op);
188 void PrintGlobalVariable(const GlobalVariable* GVar);
190 void PrintPICBaseSymbol() const;
192 bool runOnMachineFunction(MachineFunction &F);
194 void emitFunctionHeader(const MachineFunction &MF);
196 // Necessary for Darwin to print out the apprioriate types of linker stubs
197 StringMap<std::string> FnStubs, GVStubs, HiddenGVStubs;
199 // Necessary for dllexport support
200 StringSet<> CygMingStubs, DLLExportedFns, DLLExportedGVs;
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
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;
216 void DecorateCygMingName(std::string &Name, const GlobalValue *GV);
219 } // end namespace llvm