blob: 489d946790ee8b7b8dff25ea3a695562ce9d984a [file] [log] [blame]
Chris Lattnerb36cbd02005-07-01 22:44:09 +00001//===-- X86IntelAsmPrinter.h - Convert X86 LLVM code to Intel assembly ----===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerb36cbd02005-07-01 22:44:09 +00007//
8//===----------------------------------------------------------------------===//
9//
10// Intel assembly code printer class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef X86INTELASMPRINTER_H
15#define X86INTELASMPRINTER_H
16
Cedric Venet94fb5f22008-08-17 18:24:26 +000017#include "../X86.h"
18#include "../X86MachineFunctionInfo.h"
19#include "../X86TargetMachine.h"
Anton Korobeynikov1c4b5ea2008-06-28 11:07:54 +000020#include "llvm/CodeGen/AsmPrinter.h"
21#include "llvm/ADT/StringSet.h"
22#include "llvm/Support/Compiler.h"
Owen Andersoncb371882008-08-21 00:14:44 +000023#include "llvm/Support/raw_ostream.h"
Chris Lattnerb36cbd02005-07-01 22:44:09 +000024
25namespace llvm {
Chris Lattnerb36cbd02005-07-01 22:44:09 +000026
Anton Korobeynikov1c4b5ea2008-06-28 11:07:54 +000027struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public AsmPrinter {
Owen Andersoncb371882008-08-21 00:14:44 +000028 X86IntelAsmPrinter(raw_ostream &O, X86TargetMachine &TM,
Evan Cheng42bf74b2009-03-25 01:47:28 +000029 const TargetAsmInfo *T, bool F, bool V)
30 : AsmPrinter(O, TM, T, F, V) {}
Chris Lattnerb36cbd02005-07-01 22:44:09 +000031
32 virtual const char *getPassName() const {
33 return "X86 Intel-Style Assembly Printer";
34 }
35
36 /// printInstruction - This method is automatically generated by tablegen
37 /// from the instruction set description. This method returns true if the
38 /// machine instruction was sufficiently described to print it, otherwise it
39 /// returns false.
40 bool printInstruction(const MachineInstr *MI);
41
42 // This method is used by the tablegen'erated instruction printer.
Chris Lattnera3b8c572006-02-06 23:41:19 +000043 void printOperand(const MachineInstr *MI, unsigned OpNo,
44 const char *Modifier = 0) {
Chris Lattnerb36cbd02005-07-01 22:44:09 +000045 const MachineOperand &MO = MI->getOperand(OpNo);
Dan Gohmand735b802008-10-03 15:45:36 +000046 if (MO.isReg()) {
Dan Gohman6f0d0242008-02-10 18:45:23 +000047 assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
48 "Not physreg??");
Evan Chengae270f62008-07-07 22:21:06 +000049 O << TM.getRegisterInfo()->get(MO.getReg()).Name; // Capitalized names
Chris Lattnerb36cbd02005-07-01 22:44:09 +000050 } else {
Chris Lattnera3b8c572006-02-06 23:41:19 +000051 printOp(MO, Modifier);
Chris Lattnerb36cbd02005-07-01 22:44:09 +000052 }
53 }
54
Nate Begeman391c5d22005-11-30 18:54:35 +000055 void printi8mem(const MachineInstr *MI, unsigned OpNo) {
56 O << "BYTE PTR ";
57 printMemReference(MI, OpNo);
58 }
59 void printi16mem(const MachineInstr *MI, unsigned OpNo) {
60 O << "WORD PTR ";
61 printMemReference(MI, OpNo);
62 }
63 void printi32mem(const MachineInstr *MI, unsigned OpNo) {
Nate Begeman85a168a2005-11-30 18:57:39 +000064 O << "DWORD PTR ";
Nate Begeman391c5d22005-11-30 18:54:35 +000065 printMemReference(MI, OpNo);
66 }
67 void printi64mem(const MachineInstr *MI, unsigned OpNo) {
Nate Begeman85a168a2005-11-30 18:57:39 +000068 O << "QWORD PTR ";
Nate Begeman391c5d22005-11-30 18:54:35 +000069 printMemReference(MI, OpNo);
70 }
Evan Cheng470a6ad2006-02-22 02:26:30 +000071 void printi128mem(const MachineInstr *MI, unsigned OpNo) {
72 O << "XMMWORD PTR ";
73 printMemReference(MI, OpNo);
74 }
Nate Begeman391c5d22005-11-30 18:54:35 +000075 void printf32mem(const MachineInstr *MI, unsigned OpNo) {
76 O << "DWORD PTR ";
77 printMemReference(MI, OpNo);
78 }
79 void printf64mem(const MachineInstr *MI, unsigned OpNo) {
80 O << "QWORD PTR ";
81 printMemReference(MI, OpNo);
82 }
Dale Johannesen59a58732007-08-05 18:49:15 +000083 void printf80mem(const MachineInstr *MI, unsigned OpNo) {
84 O << "XWORD PTR ";
85 printMemReference(MI, OpNo);
86 }
Evan Cheng223547a2006-01-31 22:28:30 +000087 void printf128mem(const MachineInstr *MI, unsigned OpNo) {
88 O << "XMMWORD PTR ";
Chris Lattnerb36cbd02005-07-01 22:44:09 +000089 printMemReference(MI, OpNo);
90 }
Rafael Espindola2a6411b2009-04-07 21:37:46 +000091 void printlea32mem(const MachineInstr *MI, unsigned OpNo) {
92 O << "DWORD PTR ";
93 printLeaMemReference(MI, OpNo);
94 }
95 void printlea64mem(const MachineInstr *MI, unsigned OpNo) {
96 O << "QWORD PTR ";
97 printLeaMemReference(MI, OpNo);
98 }
Evan Cheng25ab6902006-09-08 06:48:29 +000099 void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) {
100 O << "QWORD PTR ";
Rafael Espindola2a6411b2009-04-07 21:37:46 +0000101 printLeaMemReference(MI, OpNo, "subreg64");
Evan Cheng25ab6902006-09-08 06:48:29 +0000102 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000103
Evan Cheng55c25f22006-04-28 23:19:39 +0000104 bool printAsmMRegister(const MachineOperand &MO, const char Mode);
Evan Cheng3d48a902006-04-28 21:19:05 +0000105 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
106 unsigned AsmVariant, const char *ExtraCode);
107 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
108 unsigned AsmVariant, const char *ExtraCode);
Jeff Cohenc884db42006-05-02 01:16:28 +0000109 void printMachineInstruction(const MachineInstr *MI);
Chris Lattnera3b8c572006-02-06 23:41:19 +0000110 void printOp(const MachineOperand &MO, const char *Modifier = 0);
Nate Begeman391c5d22005-11-30 18:54:35 +0000111 void printSSECC(const MachineInstr *MI, unsigned Op);
Evan Cheng25ab6902006-09-08 06:48:29 +0000112 void printMemReference(const MachineInstr *MI, unsigned Op,
113 const char *Modifier=NULL);
Rafael Espindola2a6411b2009-04-07 21:37:46 +0000114 void printLeaMemReference(const MachineInstr *MI, unsigned Op,
115 const char *Modifier=NULL);
Evan Chengcc415862007-11-09 01:32:10 +0000116 void printPICJumpTableSetLabel(unsigned uid,
117 const MachineBasicBlock *MBB) const;
118 void printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
119 const MachineBasicBlock *MBB) const {
120 AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB);
121 }
Evan Cheng7ccced62006-02-18 00:15:05 +0000122 void printPICLabel(const MachineInstr *MI, unsigned Op);
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000123 bool runOnMachineFunction(MachineFunction &F);
124 bool doInitialization(Module &M);
Jeff Cohen4f1ea1e2006-05-02 03:11:50 +0000125 bool doFinalization(Module &M);
Anton Korobeynikov1c4b5ea2008-06-28 11:07:54 +0000126
127 // We have to propagate some information about MachineFunction to
128 // AsmPrinter. It's ok, when we're printing the function, since we have
129 // access to MachineFunction and can get the appropriate MachineFunctionInfo.
130 // Unfortunately, this is not possible when we're printing reference to
131 // Function (e.g. calling it and so on). Even more, there is no way to get the
132 // corresponding MachineFunctions: it can even be not created at all. That's
133 // why we should use additional structure, when we're collecting all necessary
134 // information.
135 //
136 // This structure is using e.g. for name decoration for stdcall & fastcall'ed
137 // function, since we have to use arguments' size for decoration.
138 typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap;
139 FMFInfoMap FunctionInfoMap;
140
141 void decorateName(std::string& Name, const GlobalValue* GV);
142
Jeff Cohenc884db42006-05-02 01:16:28 +0000143 virtual void EmitString(const ConstantArray *CVA) const;
Anton Korobeynikov1c4b5ea2008-06-28 11:07:54 +0000144
145 // Necessary for dllexport support
146 StringSet<> DLLExportedFns, DLLExportedGVs;
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000147};
148
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000149} // end namespace llvm
150
151#endif