blob: c9ca072baf5e6fe919a3b32dc6814c7f6ac2bbad [file] [log] [blame]
Chris Lattnerb9740462005-07-01 22:44:09 +00001//===-- X86IntelAsmPrinter.h - Convert X86 LLVM code to Intel assembly ----===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Lattnerb9740462005-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
Anton Korobeynikov4e9dfe82008-06-28 11:07:54 +000017#include "X86.h"
18#include "X86MachineFunctionInfo.h"
19#include "X86TargetMachine.h"
20#include "llvm/CodeGen/AsmPrinter.h"
21#include "llvm/ADT/StringSet.h"
22#include "llvm/Support/Compiler.h"
Chris Lattnerb9740462005-07-01 22:44:09 +000023
24namespace llvm {
Chris Lattnerb9740462005-07-01 22:44:09 +000025
Anton Korobeynikov4e9dfe82008-06-28 11:07:54 +000026struct VISIBILITY_HIDDEN X86IntelAsmPrinter : public AsmPrinter {
Jim Laskey261779b2006-09-07 22:06:40 +000027 X86IntelAsmPrinter(std::ostream &O, X86TargetMachine &TM,
28 const TargetAsmInfo *T)
Anton Korobeynikov4e9dfe82008-06-28 11:07:54 +000029 : AsmPrinter(O, TM, T) {
Jim Laskeya6211dc2006-09-06 18:34:40 +000030 }
Chris Lattnerb9740462005-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 Lattnerd62a3bf2006-02-06 23:41:19 +000043 void printOperand(const MachineInstr *MI, unsigned OpNo,
44 const char *Modifier = 0) {
Chris Lattnerb9740462005-07-01 22:44:09 +000045 const MachineOperand &MO = MI->getOperand(OpNo);
Chris Lattner10b71c02006-05-04 18:05:43 +000046 if (MO.isRegister()) {
Dan Gohman3a4be0f2008-02-10 18:45:23 +000047 assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
48 "Not physreg??");
Evan Cheng90a92af2008-07-07 22:21:06 +000049 O << TM.getRegisterInfo()->get(MO.getReg()).Name; // Capitalized names
Chris Lattnerb9740462005-07-01 22:44:09 +000050 } else {
Chris Lattnerd62a3bf2006-02-06 23:41:19 +000051 printOp(MO, Modifier);
Chris Lattnerb9740462005-07-01 22:44:09 +000052 }
53 }
54
Nate Begeman6f8c1ac2005-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 Begeman11695c02005-11-30 18:57:39 +000064 O << "DWORD PTR ";
Nate Begeman6f8c1ac2005-11-30 18:54:35 +000065 printMemReference(MI, OpNo);
66 }
67 void printi64mem(const MachineInstr *MI, unsigned OpNo) {
Nate Begeman11695c02005-11-30 18:57:39 +000068 O << "QWORD PTR ";
Nate Begeman6f8c1ac2005-11-30 18:54:35 +000069 printMemReference(MI, OpNo);
70 }
Evan Cheng9e252e32006-02-22 02:26:30 +000071 void printi128mem(const MachineInstr *MI, unsigned OpNo) {
72 O << "XMMWORD PTR ";
73 printMemReference(MI, OpNo);
74 }
Nate Begeman6f8c1ac2005-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 Johannesenb1888e72007-08-05 18:49:15 +000083 void printf80mem(const MachineInstr *MI, unsigned OpNo) {
84 O << "XWORD PTR ";
85 printMemReference(MI, OpNo);
86 }
Evan Cheng72d5c252006-01-31 22:28:30 +000087 void printf128mem(const MachineInstr *MI, unsigned OpNo) {
88 O << "XMMWORD PTR ";
Chris Lattnerb9740462005-07-01 22:44:09 +000089 printMemReference(MI, OpNo);
90 }
Evan Cheng11b0a5d2006-09-08 06:48:29 +000091 void printlea64_32mem(const MachineInstr *MI, unsigned OpNo) {
92 O << "QWORD PTR ";
93 printMemReference(MI, OpNo, "subreg64");
94 }
Chris Lattnerb9740462005-07-01 22:44:09 +000095
Evan Chengd3696032006-04-28 23:19:39 +000096 bool printAsmMRegister(const MachineOperand &MO, const char Mode);
Evan Cheng68a44dc2006-04-28 21:19:05 +000097 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
98 unsigned AsmVariant, const char *ExtraCode);
99 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
100 unsigned AsmVariant, const char *ExtraCode);
Jeff Cohen24a62a92006-05-02 01:16:28 +0000101 void printMachineInstruction(const MachineInstr *MI);
Chris Lattnerd62a3bf2006-02-06 23:41:19 +0000102 void printOp(const MachineOperand &MO, const char *Modifier = 0);
Nate Begeman6f8c1ac2005-11-30 18:54:35 +0000103 void printSSECC(const MachineInstr *MI, unsigned Op);
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000104 void printMemReference(const MachineInstr *MI, unsigned Op,
105 const char *Modifier=NULL);
Evan Cheng797d56f2007-11-09 01:32:10 +0000106 void printPICJumpTableSetLabel(unsigned uid,
107 const MachineBasicBlock *MBB) const;
108 void printPICJumpTableSetLabel(unsigned uid, unsigned uid2,
109 const MachineBasicBlock *MBB) const {
110 AsmPrinter::printPICJumpTableSetLabel(uid, uid2, MBB);
111 }
Evan Cheng5588de92006-02-18 00:15:05 +0000112 void printPICLabel(const MachineInstr *MI, unsigned Op);
Chris Lattnerb9740462005-07-01 22:44:09 +0000113 bool runOnMachineFunction(MachineFunction &F);
114 bool doInitialization(Module &M);
Jeff Cohenbfe9ffb2006-05-02 03:11:50 +0000115 bool doFinalization(Module &M);
Anton Korobeynikov4e9dfe82008-06-28 11:07:54 +0000116
117 // We have to propagate some information about MachineFunction to
118 // AsmPrinter. It's ok, when we're printing the function, since we have
119 // access to MachineFunction and can get the appropriate MachineFunctionInfo.
120 // Unfortunately, this is not possible when we're printing reference to
121 // Function (e.g. calling it and so on). Even more, there is no way to get the
122 // corresponding MachineFunctions: it can even be not created at all. That's
123 // why we should use additional structure, when we're collecting all necessary
124 // information.
125 //
126 // This structure is using e.g. for name decoration for stdcall & fastcall'ed
127 // function, since we have to use arguments' size for decoration.
128 typedef std::map<const Function*, X86MachineFunctionInfo> FMFInfoMap;
129 FMFInfoMap FunctionInfoMap;
130
131 void decorateName(std::string& Name, const GlobalValue* GV);
132
Chris Lattnerb82247b2006-10-05 02:43:52 +0000133 /// getSectionForFunction - Return the section that we should emit the
134 /// specified function body into.
135 virtual std::string getSectionForFunction(const Function &F) const;
Jeff Cohen24a62a92006-05-02 01:16:28 +0000136
Jeff Cohen24a62a92006-05-02 01:16:28 +0000137 virtual void EmitString(const ConstantArray *CVA) const;
Anton Korobeynikov4e9dfe82008-06-28 11:07:54 +0000138
139 // Necessary for dllexport support
140 StringSet<> DLLExportedFns, DLLExportedGVs;
Chris Lattnerb9740462005-07-01 22:44:09 +0000141};
142
Chris Lattnerb9740462005-07-01 22:44:09 +0000143} // end namespace llvm
144
145#endif