Dan Gohman | 8bc49c2 | 2007-06-25 15:11:25 +0000 | [diff] [blame] | 1 | //===-- X86ATTAsmPrinter.h - Convert X86 LLVM code to AT&T assembly -------===// |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // AT&T assembly code printer class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef X86ATTASMPRINTER_H |
| 15 | #define X86ATTASMPRINTER_H |
| 16 | |
Cedric Venet | 94fb5f2 | 2008-08-17 18:24:26 +0000 | [diff] [blame] | 17 | #include "../X86.h" |
| 18 | #include "../X86MachineFunctionInfo.h" |
| 19 | #include "../X86TargetMachine.h" |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/StringSet.h" |
| 21 | #include "llvm/CodeGen/AsmPrinter.h" |
| 22 | #include "llvm/CodeGen/DwarfWriter.h" |
| 23 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 24 | #include "llvm/CodeGen/ValueTypes.h" |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Compiler.h" |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 26 | |
| 27 | namespace llvm { |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 28 | |
Bill Wendling | b877a1f | 2009-05-12 21:55:29 +0000 | [diff] [blame] | 29 | class MachineJumpTableInfo; |
Chris Lattner | 475370b | 2009-06-19 00:47:33 +0000 | [diff] [blame] | 30 | class MCInst; |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 31 | |
Bill Wendling | 57f0db8 | 2009-02-24 08:30:20 +0000 | [diff] [blame] | 32 | class VISIBILITY_HIDDEN X86ATTAsmPrinter : public AsmPrinter { |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 33 | MachineModuleInfo *MMI; |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 34 | const X86Subtarget *Subtarget; |
Bill Wendling | 57f0db8 | 2009-02-24 08:30:20 +0000 | [diff] [blame] | 35 | public: |
Bill Wendling | be8cc2a | 2009-04-29 00:15:41 +0000 | [diff] [blame] | 36 | explicit X86ATTAsmPrinter(raw_ostream &O, X86TargetMachine &TM, |
Bill Wendling | 98a366d | 2009-04-29 23:29:43 +0000 | [diff] [blame] | 37 | const TargetAsmInfo *T, CodeGenOpt::Level OL, |
| 38 | bool V) |
Devang Patel | 14a55d9 | 2009-06-19 21:54:26 +0000 | [diff] [blame] | 39 | : AsmPrinter(O, TM, T, OL, V), MMI(0) { |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 40 | Subtarget = &TM.getSubtarget<X86Subtarget>(); |
| 41 | } |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 42 | |
| 43 | virtual const char *getPassName() const { |
| 44 | return "X86 AT&T-Style Assembly Printer"; |
| 45 | } |
| 46 | |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 47 | void getAnalysisUsage(AnalysisUsage &AU) const { |
| 48 | AU.setPreservesAll(); |
| 49 | if (Subtarget->isTargetDarwin() || |
| 50 | Subtarget->isTargetELF() || |
| 51 | Subtarget->isTargetCygMing()) { |
| 52 | AU.addRequired<MachineModuleInfo>(); |
| 53 | } |
Devang Patel | eb3fc28 | 2009-01-08 23:40:34 +0000 | [diff] [blame] | 54 | AU.addRequired<DwarfWriter>(); |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 55 | AsmPrinter::getAnalysisUsage(AU); |
| 56 | } |
| 57 | |
Devang Patel | 66b4d3b | 2009-06-20 01:00:07 +0000 | [diff] [blame] | 58 | bool doInitialization(Module &M); |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 59 | bool doFinalization(Module &M); |
| 60 | |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 61 | /// printInstruction - This method is automatically generated by tablegen |
| 62 | /// from the instruction set description. This method returns true if the |
| 63 | /// machine instruction was sufficiently described to print it, otherwise it |
| 64 | /// returns false. |
| 65 | bool printInstruction(const MachineInstr *MI); |
Chris Lattner | 475370b | 2009-06-19 00:47:33 +0000 | [diff] [blame] | 66 | |
Chris Lattner | d5fb790 | 2009-06-19 23:59:57 +0000 | [diff] [blame] | 67 | |
| 68 | // New MCInst printing stuff. |
| 69 | bool printInstruction(const MCInst *MI); |
Chris Lattner | 475370b | 2009-06-19 00:47:33 +0000 | [diff] [blame] | 70 | |
Chris Lattner | d5fb790 | 2009-06-19 23:59:57 +0000 | [diff] [blame] | 71 | void printOperand(const MCInst *MI, unsigned OpNo, |
| 72 | const char *Modifier = 0, bool NotRIPRel = false); |
Chris Lattner | c124306 | 2009-06-20 07:03:18 +0000 | [diff] [blame] | 73 | void printMemReference(const MCInst *MI, unsigned Op); |
| 74 | void printLeaMemReference(const MCInst *MI, unsigned Op); |
Chris Lattner | d5fb790 | 2009-06-19 23:59:57 +0000 | [diff] [blame] | 75 | void printSSECC(const MCInst *MI, unsigned Op); |
| 76 | void printPICLabel(const MCInst *MI, unsigned Op); |
Chris Lattner | 7680e73 | 2009-06-20 19:34:09 +0000 | [diff] [blame] | 77 | void print_pcrel_imm(const MCInst *MI, unsigned OpNo); |
| 78 | |
Chris Lattner | d5fb790 | 2009-06-19 23:59:57 +0000 | [diff] [blame] | 79 | void printi8mem(const MCInst *MI, unsigned OpNo) { |
| 80 | printMemReference(MI, OpNo); |
| 81 | } |
| 82 | void printi16mem(const MCInst *MI, unsigned OpNo) { |
| 83 | printMemReference(MI, OpNo); |
| 84 | } |
| 85 | void printi32mem(const MCInst *MI, unsigned OpNo) { |
| 86 | printMemReference(MI, OpNo); |
| 87 | } |
| 88 | void printi64mem(const MCInst *MI, unsigned OpNo) { |
| 89 | printMemReference(MI, OpNo); |
| 90 | } |
| 91 | void printi128mem(const MCInst *MI, unsigned OpNo) { |
| 92 | printMemReference(MI, OpNo); |
| 93 | } |
| 94 | void printf32mem(const MCInst *MI, unsigned OpNo) { |
| 95 | printMemReference(MI, OpNo); |
| 96 | } |
| 97 | void printf64mem(const MCInst *MI, unsigned OpNo) { |
| 98 | printMemReference(MI, OpNo); |
| 99 | } |
| 100 | void printf80mem(const MCInst *MI, unsigned OpNo) { |
| 101 | printMemReference(MI, OpNo); |
| 102 | } |
| 103 | void printf128mem(const MCInst *MI, unsigned OpNo) { |
| 104 | printMemReference(MI, OpNo); |
| 105 | } |
| 106 | void printlea32mem(const MCInst *MI, unsigned OpNo) { |
| 107 | printLeaMemReference(MI, OpNo); |
| 108 | } |
| 109 | void printlea64mem(const MCInst *MI, unsigned OpNo) { |
| 110 | printLeaMemReference(MI, OpNo); |
| 111 | } |
| 112 | void printlea64_32mem(const MCInst *MI, unsigned OpNo) { |
Chris Lattner | c124306 | 2009-06-20 07:03:18 +0000 | [diff] [blame] | 113 | printLeaMemReference(MI, OpNo); |
Chris Lattner | d5fb790 | 2009-06-19 23:59:57 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 117 | |
Chris Lattner | a3b8c57 | 2006-02-06 23:41:19 +0000 | [diff] [blame] | 118 | // These methods are used by the tablegen'erated instruction printer. |
| 119 | void printOperand(const MachineInstr *MI, unsigned OpNo, |
Evan Cheng | 28b51439 | 2006-12-05 19:50:18 +0000 | [diff] [blame] | 120 | const char *Modifier = 0, bool NotRIPRel = false); |
Chris Lattner | 7680e73 | 2009-06-20 19:34:09 +0000 | [diff] [blame] | 121 | void print_pcrel_imm(const MachineInstr *MI, unsigned OpNo); |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 122 | void printi8mem(const MachineInstr *MI, unsigned OpNo) { |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 123 | printMemReference(MI, OpNo); |
| 124 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 125 | void printi16mem(const MachineInstr *MI, unsigned OpNo) { |
| 126 | printMemReference(MI, OpNo); |
| 127 | } |
| 128 | void printi32mem(const MachineInstr *MI, unsigned OpNo) { |
| 129 | printMemReference(MI, OpNo); |
| 130 | } |
| 131 | void printi64mem(const MachineInstr *MI, unsigned OpNo) { |
| 132 | printMemReference(MI, OpNo); |
| 133 | } |
Evan Cheng | 470a6ad | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 134 | void printi128mem(const MachineInstr *MI, unsigned OpNo) { |
| 135 | printMemReference(MI, OpNo); |
| 136 | } |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 137 | void printf32mem(const MachineInstr *MI, unsigned OpNo) { |
| 138 | printMemReference(MI, OpNo); |
| 139 | } |
| 140 | void printf64mem(const MachineInstr *MI, unsigned OpNo) { |
| 141 | printMemReference(MI, OpNo); |
| 142 | } |
Dale Johannesen | 59a5873 | 2007-08-05 18:49:15 +0000 | [diff] [blame] | 143 | void printf80mem(const MachineInstr *MI, unsigned OpNo) { |
| 144 | printMemReference(MI, OpNo); |
| 145 | } |
Evan Cheng | 223547a | 2006-01-31 22:28:30 +0000 | [diff] [blame] | 146 | void printf128mem(const MachineInstr *MI, unsigned OpNo) { |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 147 | printMemReference(MI, OpNo); |
| 148 | } |
Rafael Espindola | 094fad3 | 2009-04-08 21:14:34 +0000 | [diff] [blame] | 149 | void printlea32mem(const MachineInstr *MI, unsigned OpNo) { |
| 150 | printLeaMemReference(MI, OpNo); |
| 151 | } |
| 152 | void printlea64mem(const MachineInstr *MI, unsigned OpNo) { |
| 153 | printLeaMemReference(MI, OpNo); |
| 154 | } |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 155 | void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) { |
Rafael Espindola | 094fad3 | 2009-04-08 21:14:34 +0000 | [diff] [blame] | 156 | printLeaMemReference(MI, OpNo, "subreg64"); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 157 | } |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 158 | |
Chris Lattner | 3771071 | 2009-06-15 04:42:32 +0000 | [diff] [blame] | 159 | bool printAsmMRegister(const MachineOperand &MO, char Mode); |
Anton Korobeynikov | f0302cd | 2008-06-28 11:09:48 +0000 | [diff] [blame] | 160 | bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
Evan Cheng | 3d48a90 | 2006-04-28 21:19:05 +0000 | [diff] [blame] | 161 | unsigned AsmVariant, const char *ExtraCode); |
Anton Korobeynikov | f0302cd | 2008-06-28 11:09:48 +0000 | [diff] [blame] | 162 | bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
Evan Cheng | 3d48a90 | 2006-04-28 21:19:05 +0000 | [diff] [blame] | 163 | unsigned AsmVariant, const char *ExtraCode); |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 164 | |
Evan Cheng | 62f2700 | 2006-04-28 23:11:40 +0000 | [diff] [blame] | 165 | void printMachineInstruction(const MachineInstr *MI); |
Nate Begeman | 391c5d2 | 2005-11-30 18:54:35 +0000 | [diff] [blame] | 166 | void printSSECC(const MachineInstr *MI, unsigned Op); |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 167 | void printMemReference(const MachineInstr *MI, unsigned Op, |
Anton Korobeynikov | 573c92d | 2009-04-28 21:49:33 +0000 | [diff] [blame] | 168 | const char *Modifier=NULL, bool NotRIPRel = false); |
Rafael Espindola | 094fad3 | 2009-04-08 21:14:34 +0000 | [diff] [blame] | 169 | void printLeaMemReference(const MachineInstr *MI, unsigned Op, |
Anton Korobeynikov | 573c92d | 2009-04-28 21:49:33 +0000 | [diff] [blame] | 170 | const char *Modifier=NULL, bool NotRIPRel = false); |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 171 | void printPICJumpTableSetLabel(unsigned uid, |
| 172 | const MachineBasicBlock *MBB) const; |
| 173 | void printPICJumpTableSetLabel(unsigned uid, unsigned uid2, |
| 174 | const MachineBasicBlock *MBB) const { |
| 175 | AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB); |
| 176 | } |
Anton Korobeynikov | 9de1934 | 2007-11-14 09:18:41 +0000 | [diff] [blame] | 177 | void printPICJumpTableEntry(const MachineJumpTableInfo *MJTI, |
| 178 | const MachineBasicBlock *MBB, |
| 179 | unsigned uid) const; |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 180 | |
Evan Cheng | 7ccced6 | 2006-02-18 00:15:05 +0000 | [diff] [blame] | 181 | void printPICLabel(const MachineInstr *MI, unsigned Op); |
Anton Korobeynikov | e51ab44 | 2008-06-28 11:09:32 +0000 | [diff] [blame] | 182 | void printModuleLevelGV(const GlobalVariable* GVar); |
| 183 | |
Evan Cheng | 77c8f76 | 2008-07-08 00:55:58 +0000 | [diff] [blame] | 184 | void printGVStub(const char *GV, const char *Prefix = NULL); |
Evan Cheng | ae94e59 | 2008-12-05 01:06:39 +0000 | [diff] [blame] | 185 | void printHiddenGVStub(const char *GV, const char *Prefix = NULL); |
Evan Cheng | 77c8f76 | 2008-07-08 00:55:58 +0000 | [diff] [blame] | 186 | |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 187 | bool runOnMachineFunction(MachineFunction &F); |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 188 | |
Anton Korobeynikov | 1ecf0ee | 2008-06-28 11:09:01 +0000 | [diff] [blame] | 189 | void emitFunctionHeader(const MachineFunction &MF); |
| 190 | |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 191 | // Necessary for Darwin to print out the apprioriate types of linker stubs |
Evan Cheng | ae94e59 | 2008-12-05 01:06:39 +0000 | [diff] [blame] | 192 | StringSet<> FnStubs, GVStubs, HiddenGVStubs; |
Anton Korobeynikov | 75b6882 | 2008-06-28 11:08:27 +0000 | [diff] [blame] | 193 | |
| 194 | // Necessary for dllexport support |
| 195 | StringSet<> DLLExportedFns, DLLExportedGVs; |
| 196 | |
| 197 | // We have to propagate some information about MachineFunction to |
| 198 | // AsmPrinter. It's ok, when we're printing the function, since we have |
| 199 | // access to MachineFunction and can get the appropriate MachineFunctionInfo. |
| 200 | // Unfortunately, this is not possible when we're printing reference to |
| 201 | // Function (e.g. calling it and so on). Even more, there is no way to get the |
| 202 | // corresponding MachineFunctions: it can even be not created at all. That's |
| 203 | // why we should use additional structure, when we're collecting all necessary |
| 204 | // information. |
| 205 | // |
| 206 | // This structure is using e.g. for name decoration for stdcall & fastcall'ed |
| 207 | // function, since we have to use arguments' size for decoration. |
| 208 | typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap; |
| 209 | FMFInfoMap FunctionInfoMap; |
| 210 | |
| 211 | void decorateName(std::string& Name, const GlobalValue* GV); |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 212 | }; |
| 213 | |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 214 | } // end namespace llvm |
| 215 | |
| 216 | #endif |