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;
40 explicit X86ATTAsmPrinter(raw_ostream &O, X86TargetMachine &TM,
41 const TargetAsmInfo *T, CodeGenOpt::Level OL,
43 : AsmPrinter(O, TM, T, OL, V) {
44 Subtarget = &TM.getSubtarget<X86Subtarget>();
49 virtual const char *getPassName() const {
50 return "X86 AT&T-Style Assembly Printer";
53 void getAnalysisUsage(AnalysisUsage &AU) const {
55 if (Subtarget->isTargetDarwin() ||
56 Subtarget->isTargetELF() ||
57 Subtarget->isTargetCygMing()) {
58 AU.addRequired<MachineModuleInfo>();
60 AU.addRequired<DwarfWriter>();
61 AsmPrinter::getAnalysisUsage(AU);
64 bool doInitialization(Module &M);
65 bool doFinalization(Module &M);
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
71 bool printInstruction(const MachineInstr *MI);
74 // New MCInst printing stuff.
75 bool printInstruction(const MCInst *MI);
77 void printOperand(const MCInst *MI, unsigned OpNo,
78 const char *Modifier = 0, bool NotRIPRel = false);
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);
85 void printi8mem(const MCInst *MI, unsigned OpNo) {
86 printMemReference(MI, OpNo);
88 void printi16mem(const MCInst *MI, unsigned OpNo) {
89 printMemReference(MI, OpNo);
91 void printi32mem(const MCInst *MI, unsigned OpNo) {
92 printMemReference(MI, OpNo);
94 void printi64mem(const MCInst *MI, unsigned OpNo) {
95 printMemReference(MI, OpNo);
97 void printi128mem(const MCInst *MI, unsigned OpNo) {
98 printMemReference(MI, OpNo);
100 void printf32mem(const MCInst *MI, unsigned OpNo) {
101 printMemReference(MI, OpNo);
103 void printf64mem(const MCInst *MI, unsigned OpNo) {
104 printMemReference(MI, OpNo);
106 void printf80mem(const MCInst *MI, unsigned OpNo) {
107 printMemReference(MI, OpNo);
109 void printf128mem(const MCInst *MI, unsigned OpNo) {
110 printMemReference(MI, OpNo);
112 void printlea32mem(const MCInst *MI, unsigned OpNo) {
113 printLeaMemReference(MI, OpNo);
115 void printlea64mem(const MCInst *MI, unsigned OpNo) {
116 printLeaMemReference(MI, OpNo);
118 void printlea64_32mem(const MCInst *MI, unsigned OpNo) {
119 printLeaMemReference(MI, OpNo);
124 // These methods are used by the tablegen'erated instruction printer.
125 void printOperand(const MachineInstr *MI, unsigned OpNo,
126 const char *Modifier = 0, bool NotRIPRel = false);
127 void print_pcrel_imm(const MachineInstr *MI, unsigned OpNo);
128 void printi8mem(const MachineInstr *MI, unsigned OpNo) {
129 printMemReference(MI, OpNo);
131 void printi16mem(const MachineInstr *MI, unsigned OpNo) {
132 printMemReference(MI, OpNo);
134 void printi32mem(const MachineInstr *MI, unsigned OpNo) {
135 printMemReference(MI, OpNo);
137 void printi64mem(const MachineInstr *MI, unsigned OpNo) {
138 printMemReference(MI, OpNo);
140 void printi128mem(const MachineInstr *MI, unsigned OpNo) {
141 printMemReference(MI, OpNo);
143 void printf32mem(const MachineInstr *MI, unsigned OpNo) {
144 printMemReference(MI, OpNo);
146 void printf64mem(const MachineInstr *MI, unsigned OpNo) {
147 printMemReference(MI, OpNo);
149 void printf80mem(const MachineInstr *MI, unsigned OpNo) {
150 printMemReference(MI, OpNo);
152 void printf128mem(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, bool NotRIPRel = false);
175 void printLeaMemReference(const MachineInstr *MI, unsigned Op,
176 const char *Modifier=NULL, bool NotRIPRel = false);
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 printModuleLevelGV(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 StringSet<> FnStubs, GVStubs, HiddenGVStubs;
199 // Necessary for dllexport support
200 StringSet<> 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 decorateName(std::string& Name, const GlobalValue* GV);
219 } // end namespace llvm