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;
36 class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter {
37 const X86Subtarget *Subtarget;
39 explicit X86ATTAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
40 const MCAsmInfo *T, bool V)
41 : AsmPrinter(O, TM, T, V) {
42 Subtarget = &TM.getSubtarget<X86Subtarget>();
45 virtual const char *getPassName() const {
46 return "X86 AT&T-Style Assembly Printer";
49 const X86Subtarget &getSubtarget() const { return *Subtarget; }
51 void getAnalysisUsage(AnalysisUsage &AU) const {
53 if (Subtarget->isTargetDarwin() ||
54 Subtarget->isTargetELF() ||
55 Subtarget->isTargetCygMing()) {
56 AU.addRequired<MachineModuleInfo>();
58 AU.addRequired<DwarfWriter>();
59 AsmPrinter::getAnalysisUsage(AU);
62 bool doFinalization(Module &M);
64 void printInstructionThroughMCStreamer(const MachineInstr *MI);
67 // New MCInst printing stuff.
68 void printInstruction(const MCInst *MI);
71 virtual void printMCInst(const MCInst *MI) { printInstruction(MI); }
73 void printSymbolOperand(const MachineOperand &MO);
74 void printOperand(const MCInst *MI, unsigned OpNo,
75 const char *Modifier = 0);
76 void printMemReference(const MCInst *MI, unsigned Op);
77 void printLeaMemReference(const MCInst *MI, unsigned Op);
78 void printSSECC(const MCInst *MI, unsigned Op);
79 void printPICLabel(const MCInst *MI, unsigned Op);
80 void print_pcrel_imm(const MCInst *MI, unsigned OpNo);
82 void printopaquemem(const MCInst *MI, unsigned OpNo) {
83 printMemReference(MI, OpNo);
86 void printi8mem(const MCInst *MI, unsigned OpNo) {
87 printMemReference(MI, OpNo);
89 void printi16mem(const MCInst *MI, unsigned OpNo) {
90 printMemReference(MI, OpNo);
92 void printi32mem(const MCInst *MI, unsigned OpNo) {
93 printMemReference(MI, OpNo);
95 void printi64mem(const MCInst *MI, unsigned OpNo) {
96 printMemReference(MI, OpNo);
98 void printi128mem(const MCInst *MI, unsigned OpNo) {
99 printMemReference(MI, OpNo);
101 void printf32mem(const MCInst *MI, unsigned OpNo) {
102 printMemReference(MI, OpNo);
104 void printf64mem(const MCInst *MI, unsigned OpNo) {
105 printMemReference(MI, OpNo);
107 void printf80mem(const MCInst *MI, unsigned OpNo) {
108 printMemReference(MI, OpNo);
110 void printf128mem(const MCInst *MI, unsigned OpNo) {
111 printMemReference(MI, OpNo);
113 void printlea32mem(const MCInst *MI, unsigned OpNo) {
114 printLeaMemReference(MI, OpNo);
116 void printlea64mem(const MCInst *MI, unsigned OpNo) {
117 printLeaMemReference(MI, OpNo);
119 void printlea64_32mem(const MCInst *MI, unsigned OpNo) {
120 printLeaMemReference(MI, OpNo);
125 // These methods are used by the tablegen'erated instruction printer.
126 void printOperand(const MachineInstr *MI, unsigned OpNo,
127 const char *Modifier = 0);
128 void print_pcrel_imm(const MachineInstr *MI, unsigned OpNo);
130 void printopaquemem(const MachineInstr *MI, unsigned OpNo) {
131 printMemReference(MI, OpNo);
134 void printi8mem(const MachineInstr *MI, unsigned OpNo) {
135 printMemReference(MI, OpNo);
137 void printi16mem(const MachineInstr *MI, unsigned OpNo) {
138 printMemReference(MI, OpNo);
140 void printi32mem(const MachineInstr *MI, unsigned OpNo) {
141 printMemReference(MI, OpNo);
143 void printi64mem(const MachineInstr *MI, unsigned OpNo) {
144 printMemReference(MI, OpNo);
146 void printi128mem(const MachineInstr *MI, unsigned OpNo) {
147 printMemReference(MI, OpNo);
149 void printi256mem(const MachineInstr *MI, unsigned OpNo) {
150 printMemReference(MI, OpNo);
152 void printf32mem(const MachineInstr *MI, unsigned OpNo) {
153 printMemReference(MI, OpNo);
155 void printf64mem(const MachineInstr *MI, unsigned OpNo) {
156 printMemReference(MI, OpNo);
158 void printf80mem(const MachineInstr *MI, unsigned OpNo) {
159 printMemReference(MI, OpNo);
161 void printf128mem(const MachineInstr *MI, unsigned OpNo) {
162 printMemReference(MI, OpNo);
164 void printf256mem(const MachineInstr *MI, unsigned OpNo) {
165 printMemReference(MI, OpNo);
167 void printlea32mem(const MachineInstr *MI, unsigned OpNo) {
168 printLeaMemReference(MI, OpNo);
170 void printlea64mem(const MachineInstr *MI, unsigned OpNo) {
171 printLeaMemReference(MI, OpNo);
173 void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) {
174 printLeaMemReference(MI, OpNo, "subreg64");
177 bool printAsmMRegister(const MachineOperand &MO, char Mode);
178 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
179 unsigned AsmVariant, const char *ExtraCode);
180 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
181 unsigned AsmVariant, const char *ExtraCode);
183 void printMachineInstruction(const MachineInstr *MI);
184 void printSSECC(const MachineInstr *MI, unsigned Op);
185 void printMemReference(const MachineInstr *MI, unsigned Op,
186 const char *Modifier=NULL);
187 void printLeaMemReference(const MachineInstr *MI, unsigned Op,
188 const char *Modifier=NULL);
189 void printPICJumpTableSetLabel(unsigned uid,
190 const MachineBasicBlock *MBB) const;
191 void printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
192 const MachineBasicBlock *MBB) const {
193 AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB);
195 void printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
196 const MachineBasicBlock *MBB,
199 void printPICLabel(const MachineInstr *MI, unsigned Op);
200 void PrintGlobalVariable(const GlobalVariable* GVar);
202 void PrintPICBaseSymbol() const;
204 bool runOnMachineFunction(MachineFunction &F);
206 void emitFunctionHeader(const MachineFunction &MF);
208 // Necessary for Darwin to print out the appropriate types of linker stubs.
209 DenseMap<MCSymbol*, MCSymbol*> FnStubs; // Darwin $stub stubs.
210 DenseMap<MCSymbol*, MCSymbol*> GVStubs; // Darwin $non_lazy_ptr stub.
211 DenseMap<MCSymbol*, MCSymbol*> HiddenGVStubs; // Darwin $non_lazy_ptr stub.
213 // Necessary for dllexport support
214 StringSet<> CygMingStubs, DLLExportedFns, DLLExportedGVs;
216 // We have to propagate some information about MachineFunction to
217 // AsmPrinter. It's ok, when we're printing the function, since we have
218 // access to MachineFunction and can get the appropriate MachineFunctionInfo.
219 // Unfortunately, this is not possible when we're printing reference to
220 // Function (e.g. calling it and so on). Even more, there is no way to get the
221 // corresponding MachineFunctions: it can even be not created at all. That's
222 // why we should use additional structure, when we're collecting all necessary
225 // This structure is using e.g. for name decoration for stdcall & fastcall'ed
226 // function, since we have to use arguments' size for decoration.
227 typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap;
228 FMFInfoMap FunctionInfoMap;
230 void DecorateCygMingName(std::string &Name, const GlobalValue *GV);
231 void DecorateCygMingName(SmallVectorImpl<char> &Name, const GlobalValue *GV);
234 } // end namespace llvm