blob: 52d551894a2aee5c04f5ba384d319c09dd8aeb68 [file] [log] [blame]
Chris Lattnerb36cbd02005-07-01 22:44:09 +00001//===-- X86ATTAsmPrinter.cpp - Convert X86 LLVM code to Intel assembly ----===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains a printer that converts from our internal representation
11// of machine-dependent LLVM code to AT&T format assembly
12// language. This printer is the output mechanism used by `llc'.
13//
14//===----------------------------------------------------------------------===//
15
16#include "X86ATTAsmPrinter.h"
17#include "X86.h"
18#include "X86TargetMachine.h"
Jim Laskeya0f3d172006-09-07 22:06:40 +000019#include "X86TargetAsmInfo.h"
Chris Lattnerb36cbd02005-07-01 22:44:09 +000020#include "llvm/Module.h"
21#include "llvm/Support/Mangler.h"
Jim Laskeya0f3d172006-09-07 22:06:40 +000022#include "llvm/Target/TargetAsmInfo.h"
Evan Cheng7ccced62006-02-18 00:15:05 +000023#include "llvm/Target/TargetOptions.h"
Chris Lattner2c2c6c62006-01-22 23:41:00 +000024#include <iostream>
Chris Lattnerb36cbd02005-07-01 22:44:09 +000025using namespace llvm;
Chris Lattnerb36cbd02005-07-01 22:44:09 +000026
27/// runOnMachineFunction - This uses the printMachineInstruction()
28/// method to print assembly for each instruction.
29///
30bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Jim Laskeyea348582006-07-27 02:05:13 +000031 if (Subtarget->isTargetDarwin()) {
Jim Laskeye29c2f52006-07-19 11:54:50 +000032 // Let PassManager know we need debug information and relay
33 // the MachineDebugInfo address on to DwarfWriter.
34 DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>());
35 }
Evan Cheng3c992d22006-03-07 02:02:57 +000036
Chris Lattner8b8b9512005-11-21 07:51:23 +000037 SetupMachineFunction(MF);
Chris Lattnerb36cbd02005-07-01 22:44:09 +000038 O << "\n\n";
39
40 // Print out constants referenced by the function
Chris Lattnerd939f6c2005-11-21 08:32:23 +000041 EmitConstantPool(MF.getConstantPool());
Chris Lattnerb36cbd02005-07-01 22:44:09 +000042
43 // Print out labels for the function.
Evan Cheng2338c5c2006-02-07 08:38:37 +000044 const Function *F = MF.getFunction();
45 switch (F->getLinkage()) {
46 default: assert(0 && "Unknown linkage type!");
47 case Function::InternalLinkage: // Symbols default to internal.
Jim Laskey563321a2006-09-06 18:34:40 +000048 SwitchToTextSection(TAI->getTextSection(), F);
Evan Cheng2338c5c2006-02-07 08:38:37 +000049 EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
50 break;
Anton Korobeynikovb74ed072006-09-14 18:23:27 +000051 case Function::DLLExportLinkage:
52 DLLExportedFns.insert(Mang->makeNameProper(F->getName(), ""));
53 //FALLS THROUGH
Evan Cheng2338c5c2006-02-07 08:38:37 +000054 case Function::ExternalLinkage:
Jim Laskey563321a2006-09-06 18:34:40 +000055 SwitchToTextSection(TAI->getTextSection(), F);
Evan Cheng2338c5c2006-02-07 08:38:37 +000056 EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
Anton Korobeynikovb74ed072006-09-14 18:23:27 +000057 O << "\t.globl\t" << CurrentFnName << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +000058 break;
59 case Function::WeakLinkage:
60 case Function::LinkOnceLinkage:
Jim Laskeyea348582006-07-27 02:05:13 +000061 if (Subtarget->isTargetDarwin()) {
Chris Lattner4632d7a2006-05-09 04:59:56 +000062 SwitchToTextSection(
63 ".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F);
Evan Chengf1616da2006-02-22 23:59:57 +000064 O << "\t.globl\t" << CurrentFnName << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +000065 O << "\t.weak_definition\t" << CurrentFnName << "\n";
Anton Korobeynikovbcb97702006-09-17 20:25:45 +000066 } else if (Subtarget->isTargetCygwin()) {
Evan Cheng932ad512006-05-25 21:59:08 +000067 EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
68 O << "\t.section\t.llvm.linkonce.t." << CurrentFnName
69 << ",\"ax\"\n";
70 SwitchToTextSection("", F);
71 O << "\t.weak " << CurrentFnName << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +000072 } else {
73 EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
74 O << "\t.section\t.llvm.linkonce.t." << CurrentFnName
75 << ",\"ax\",@progbits\n";
Chris Lattner4632d7a2006-05-09 04:59:56 +000076 SwitchToTextSection("", F);
Evan Cheng2338c5c2006-02-07 08:38:37 +000077 O << "\t.weak " << CurrentFnName << "\n";
78 }
79 break;
80 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +000081 O << CurrentFnName << ":\n";
82
Jim Laskeyea348582006-07-27 02:05:13 +000083 if (Subtarget->isTargetDarwin()) {
Jim Laskey6b92b8e2006-04-07 20:44:42 +000084 // Emit pre-function debug information.
Jim Laskey89d67fa2006-06-23 12:51:53 +000085 DW.BeginFunction(&MF);
Jim Laskey6b92b8e2006-04-07 20:44:42 +000086 }
87
Chris Lattnerb36cbd02005-07-01 22:44:09 +000088 // Print out code for the function.
89 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
90 I != E; ++I) {
91 // Print a label for the basic block.
Nate Begemancdf38c42006-05-02 05:37:32 +000092 if (I->pred_begin() != I->pred_end()) {
93 printBasicBlockLabel(I, true);
94 O << '\n';
95 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +000096 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
97 II != E; ++II) {
98 // Print the assembly for the instruction.
99 O << "\t";
100 printMachineInstruction(II);
101 }
102 }
Evan Cheng67afece2006-08-28 22:14:16 +0000103
104 // Print out jump tables referenced by the function
105 // Mac OS X requires at least one non-local (e.g. L1) labels before local
106 // lables that are used in jump table expressions (e.g. LBB1_1-LJT1_0).
107 EmitJumpTableInfo(MF.getJumpTableInfo());
108
Jim Laskey563321a2006-09-06 18:34:40 +0000109 if (TAI->hasDotTypeDotSizeDirective())
Nate Begeman73213f62005-07-12 01:37:28 +0000110 O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n";
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000111
Jim Laskeyea348582006-07-27 02:05:13 +0000112 if (Subtarget->isTargetDarwin()) {
Evan Chengd5948812006-03-07 02:23:26 +0000113 // Emit post-function debug information.
Jim Laskey99db0442006-03-23 18:09:44 +0000114 DW.EndFunction();
Evan Chengd5948812006-03-07 02:23:26 +0000115 }
Evan Cheng3c992d22006-03-07 02:02:57 +0000116
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000117 // We didn't modify anything.
118 return false;
119}
120
Chris Lattnera3b8c572006-02-06 23:41:19 +0000121void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
122 const char *Modifier) {
123 const MachineOperand &MO = MI->getOperand(OpNo);
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000124 const MRegisterInfo &RI = *TM.getRegisterInfo();
125 switch (MO.getType()) {
Evan Cheng8f7f7122006-05-05 05:40:20 +0000126 case MachineOperand::MO_Register: {
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000127 assert(MRegisterInfo::isPhysicalRegister(MO.getReg()) &&
128 "Virtual registers should not make it this far!");
129 O << '%';
Evan Cheng8f7f7122006-05-05 05:40:20 +0000130 unsigned Reg = MO.getReg();
Evan Chengcbe70e12006-05-31 22:34:26 +0000131 if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
Evan Cheng25ab6902006-09-08 06:48:29 +0000132 MVT::ValueType VT = (strcmp(Modifier+6,"64") == 0) ?
133 MVT::i64 : ((strcmp(Modifier+6, "32") == 0) ? MVT::i32 :
134 ((strcmp(Modifier+6,"16") == 0) ? MVT::i16 : MVT::i8));
Evan Cheng8f7f7122006-05-05 05:40:20 +0000135 Reg = getX86SubSuperRegister(Reg, VT);
136 }
137 for (const char *Name = RI.get(Reg).Name; *Name; ++Name)
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000138 O << (char)tolower(*Name);
139 return;
Evan Cheng8f7f7122006-05-05 05:40:20 +0000140 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000141
Chris Lattner63b3d712006-05-04 17:21:20 +0000142 case MachineOperand::MO_Immediate:
Evan Cheng3c992d22006-03-07 02:02:57 +0000143 if (!Modifier || strcmp(Modifier, "debug") != 0)
144 O << '$';
Evan Cheng138a24e2006-05-26 08:04:31 +0000145 O << MO.getImmedValue();
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000146 return;
Nate Begeman37efe672006-04-22 18:53:45 +0000147 case MachineOperand::MO_MachineBasicBlock:
148 printBasicBlockLabel(MO.getMachineBasicBlock());
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000149 return;
Nate Begeman37efe672006-04-22 18:53:45 +0000150 case MachineOperand::MO_JumpTableIndex: {
151 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
152 if (!isMemOp) O << '$';
Jim Laskey563321a2006-09-06 18:34:40 +0000153 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << "_"
Nate Begeman37efe672006-04-22 18:53:45 +0000154 << MO.getJumpTableIndex();
Evan Cheng25ab6902006-09-08 06:48:29 +0000155 if (X86PICStyle == PICStyle::Stub &&
Nate Begeman2f1ae882006-07-27 01:13:04 +0000156 TM.getRelocationModel() == Reloc::PIC_)
157 O << "-\"L" << getFunctionNumber() << "$pb\"";
Evan Cheng25ab6902006-09-08 06:48:29 +0000158 if (Subtarget->is64Bit())
159 O << "(%rip)";
Nate Begeman37efe672006-04-22 18:53:45 +0000160 return;
161 }
Evan Chenga09bd812006-02-26 08:28:12 +0000162 case MachineOperand::MO_ConstantPoolIndex: {
163 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
164 if (!isMemOp) O << '$';
Jim Laskey563321a2006-09-06 18:34:40 +0000165 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
Evan Chenga09bd812006-02-26 08:28:12 +0000166 << MO.getConstantPoolIndex();
Evan Cheng25ab6902006-09-08 06:48:29 +0000167 if (X86PICStyle == PICStyle::Stub &&
Chris Lattner35d86fe2006-07-26 21:12:04 +0000168 TM.getRelocationModel() == Reloc::PIC_)
Evan Chenga09bd812006-02-26 08:28:12 +0000169 O << "-\"L" << getFunctionNumber() << "$pb\"";
170 int Offset = MO.getOffset();
171 if (Offset > 0)
172 O << "+" << Offset;
173 else if (Offset < 0)
174 O << Offset;
Evan Cheng25ab6902006-09-08 06:48:29 +0000175
176 if (Subtarget->is64Bit())
177 O << "(%rip)";
Evan Chenga09bd812006-02-26 08:28:12 +0000178 return;
179 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000180 case MachineOperand::MO_GlobalAddress: {
Chris Lattnera3b8c572006-02-06 23:41:19 +0000181 bool isCallOp = Modifier && !strcmp(Modifier, "call");
Evan Cheng2338c5c2006-02-07 08:38:37 +0000182 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
Evan Cheng7ccced62006-02-18 00:15:05 +0000183 if (!isMemOp && !isCallOp) O << '$';
Evan Cheng25ab6902006-09-08 06:48:29 +0000184
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000185 GlobalValue *GV = MO.getGlobal();
Evan Cheng25ab6902006-09-08 06:48:29 +0000186 std::string Name = Mang->getValueName(GV);
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000187
Evan Cheng25ab6902006-09-08 06:48:29 +0000188 bool isExt = (GV->isExternal() || GV->hasWeakLinkage() ||
189 GV->hasLinkOnceLinkage());
190 if (X86PICStyle == PICStyle::Stub &&
Evan Cheng932ad512006-05-25 21:59:08 +0000191 TM.getRelocationModel() != Reloc::Static) {
Evan Cheng2338c5c2006-02-07 08:38:37 +0000192 // Link-once, External, or Weakly-linked global variables need
193 // non-lazily-resolved stubs
Evan Cheng25ab6902006-09-08 06:48:29 +0000194 if (isExt) {
Evan Cheng2338c5c2006-02-07 08:38:37 +0000195 // Dynamically-resolved functions need a stub for the function.
Evan Cheng25ab6902006-09-08 06:48:29 +0000196 if (isCallOp && isa<Function>(GV)) {
Evan Cheng2338c5c2006-02-07 08:38:37 +0000197 FnStubs.insert(Name);
198 O << "L" << Name << "$stub";
199 } else {
200 GVStubs.insert(Name);
201 O << "L" << Name << "$non_lazy_ptr";
202 }
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000203 } else {
204 if (GV->hasDLLImportLinkage()) {
205 // FIXME: This should be fixed with full support of stdcall & fastcall
206 // CC's
207 O << "__imp_";
208 }
Evan Cheng25ab6902006-09-08 06:48:29 +0000209 O << Name;
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000210 }
211
Chris Lattner35d86fe2006-07-26 21:12:04 +0000212 if (!isCallOp && TM.getRelocationModel() == Reloc::PIC_)
Evan Chenga0ea0532006-02-23 02:43:52 +0000213 O << "-\"L" << getFunctionNumber() << "$pb\"";
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000214 } else {
215 if (GV->hasDLLImportLinkage()) {
216 // FIXME: This should be fixed with full support of stdcall & fastcall
217 // CC's
218 O << "__imp_";
219 }
Evan Cheng25ab6902006-09-08 06:48:29 +0000220 O << Name;
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000221
222 }
223
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000224 int Offset = MO.getOffset();
225 if (Offset > 0)
226 O << "+" << Offset;
227 else if (Offset < 0)
228 O << Offset;
Evan Cheng25ab6902006-09-08 06:48:29 +0000229
230 if (!isCallOp &&
231 Subtarget->is64Bit()) {
232 if (isExt && TM.getRelocationModel() != Reloc::Static)
233 O << "@GOTPCREL";
234 O << "(%rip)";
235 }
236
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000237 return;
238 }
Chris Lattnera3b8c572006-02-06 23:41:19 +0000239 case MachineOperand::MO_ExternalSymbol: {
240 bool isCallOp = Modifier && !strcmp(Modifier, "call");
Evan Cheng932ad512006-05-25 21:59:08 +0000241 if (isCallOp &&
Evan Cheng25ab6902006-09-08 06:48:29 +0000242 X86PICStyle == PICStyle::Stub &&
Evan Cheng932ad512006-05-25 21:59:08 +0000243 TM.getRelocationModel() != Reloc::Static) {
Jim Laskey563321a2006-09-06 18:34:40 +0000244 std::string Name(TAI->getGlobalPrefix());
Evan Cheng4c1aa862006-02-22 20:19:42 +0000245 Name += MO.getSymbolName();
Nate Begeman72b286b2005-07-08 00:23:26 +0000246 FnStubs.insert(Name);
247 O << "L" << Name << "$stub";
248 return;
249 }
Evan Cheng4c1aa862006-02-22 20:19:42 +0000250 if (!isCallOp) O << '$';
Jim Laskey563321a2006-09-06 18:34:40 +0000251 O << TAI->getGlobalPrefix() << MO.getSymbolName();
Evan Cheng25ab6902006-09-08 06:48:29 +0000252
253 if (!isCallOp &&
254 Subtarget->is64Bit())
255 O << "(%rip)";
256
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000257 return;
Chris Lattnera3b8c572006-02-06 23:41:19 +0000258 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000259 default:
260 O << "<unknown operand type>"; return;
261 }
262}
263
Nate Begeman391c5d22005-11-30 18:54:35 +0000264void X86ATTAsmPrinter::printSSECC(const MachineInstr *MI, unsigned Op) {
Nate Begeman6c7cb292005-07-14 22:52:25 +0000265 unsigned char value = MI->getOperand(Op).getImmedValue();
266 assert(value <= 7 && "Invalid ssecc argument!");
267 switch (value) {
268 case 0: O << "eq"; break;
269 case 1: O << "lt"; break;
270 case 2: O << "le"; break;
271 case 3: O << "unord"; break;
272 case 4: O << "neq"; break;
273 case 5: O << "nlt"; break;
274 case 6: O << "nle"; break;
275 case 7: O << "ord"; break;
276 }
277}
278
Evan Cheng25ab6902006-09-08 06:48:29 +0000279void X86ATTAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
280 const char *Modifier){
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000281 assert(isMem(MI, Op) && "Invalid memory reference!");
282
283 const MachineOperand &BaseReg = MI->getOperand(Op);
284 int ScaleVal = MI->getOperand(Op+1).getImmedValue();
285 const MachineOperand &IndexReg = MI->getOperand(Op+2);
286 const MachineOperand &DispSpec = MI->getOperand(Op+3);
287
288 if (BaseReg.isFrameIndex()) {
289 O << "[frame slot #" << BaseReg.getFrameIndex();
290 if (DispSpec.getImmedValue())
291 O << " + " << DispSpec.getImmedValue();
292 O << "]";
293 return;
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000294 }
295
Evan Chengc9676de2006-08-29 22:14:48 +0000296 if (DispSpec.isGlobalAddress() ||
297 DispSpec.isConstantPoolIndex() ||
298 DispSpec.isJumpTableIndex()) {
Evan Cheng2338c5c2006-02-07 08:38:37 +0000299 printOperand(MI, Op+3, "mem");
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000300 } else {
301 int DispVal = DispSpec.getImmedValue();
302 if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg()))
303 O << DispVal;
304 }
305
306 if (IndexReg.getReg() || BaseReg.getReg()) {
307 O << "(";
Evan Cheng25ab6902006-09-08 06:48:29 +0000308 if (BaseReg.getReg()) {
309 printOperand(MI, Op, Modifier);
310 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000311
312 if (IndexReg.getReg()) {
313 O << ",";
Evan Cheng25ab6902006-09-08 06:48:29 +0000314 printOperand(MI, Op+2, Modifier);
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000315 if (ScaleVal != 1)
316 O << "," << ScaleVal;
317 }
318
319 O << ")";
320 }
321}
322
Evan Cheng7ccced62006-02-18 00:15:05 +0000323void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
324 O << "\"L" << getFunctionNumber() << "$pb\"\n";
325 O << "\"L" << getFunctionNumber() << "$pb\":";
326}
327
Evan Cheng62f27002006-04-28 23:11:40 +0000328
Evan Cheng55c25f22006-04-28 23:19:39 +0000329bool X86ATTAsmPrinter::printAsmMRegister(const MachineOperand &MO,
Evan Cheng62f27002006-04-28 23:11:40 +0000330 const char Mode) {
331 const MRegisterInfo &RI = *TM.getRegisterInfo();
332 unsigned Reg = MO.getReg();
Evan Cheng62f27002006-04-28 23:11:40 +0000333 switch (Mode) {
334 default: return true; // Unknown mode.
335 case 'b': // Print QImode register
Evan Cheng8f7f7122006-05-05 05:40:20 +0000336 Reg = getX86SubSuperRegister(Reg, MVT::i8);
Evan Cheng62f27002006-04-28 23:11:40 +0000337 break;
338 case 'h': // Print QImode high register
Evan Cheng8f7f7122006-05-05 05:40:20 +0000339 Reg = getX86SubSuperRegister(Reg, MVT::i8, true);
Evan Cheng62f27002006-04-28 23:11:40 +0000340 break;
341 case 'w': // Print HImode register
Evan Cheng8f7f7122006-05-05 05:40:20 +0000342 Reg = getX86SubSuperRegister(Reg, MVT::i16);
Evan Cheng62f27002006-04-28 23:11:40 +0000343 break;
344 case 'k': // Print SImode register
Evan Cheng8f7f7122006-05-05 05:40:20 +0000345 Reg = getX86SubSuperRegister(Reg, MVT::i32);
Evan Cheng62f27002006-04-28 23:11:40 +0000346 break;
347 }
348
Evan Cheng8f7f7122006-05-05 05:40:20 +0000349 O << '%';
350 for (const char *Name = RI.get(Reg).Name; *Name; ++Name)
351 O << (char)tolower(*Name);
Evan Cheng62f27002006-04-28 23:11:40 +0000352 return false;
353}
354
Evan Cheng3d48a902006-04-28 21:19:05 +0000355/// PrintAsmOperand - Print out an operand for an inline asm expression.
356///
357bool X86ATTAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
358 unsigned AsmVariant,
359 const char *ExtraCode) {
360 // Does this asm operand have a single letter operand modifier?
361 if (ExtraCode && ExtraCode[0]) {
362 if (ExtraCode[1] != 0) return true; // Unknown modifier.
363
364 switch (ExtraCode[0]) {
365 default: return true; // Unknown modifier.
Evan Cheng62f27002006-04-28 23:11:40 +0000366 case 'b': // Print QImode register
367 case 'h': // Print QImode high register
368 case 'w': // Print HImode register
369 case 'k': // Print SImode register
Evan Cheng55c25f22006-04-28 23:19:39 +0000370 return printAsmMRegister(MI->getOperand(OpNo), ExtraCode[0]);
Evan Cheng3d48a902006-04-28 21:19:05 +0000371 }
372 }
373
374 printOperand(MI, OpNo);
375 return false;
376}
377
378bool X86ATTAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
379 unsigned OpNo,
380 unsigned AsmVariant,
381 const char *ExtraCode) {
382 if (ExtraCode && ExtraCode[0])
383 return true; // Unknown modifier.
384 printMemReference(MI, OpNo);
385 return false;
386}
387
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000388/// printMachineInstruction -- Print out a single X86 LLVM instruction
389/// MI in Intel syntax to the current output stream.
390///
391void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
392 ++EmittedInsts;
Evan Cheng67caa392006-01-26 02:27:43 +0000393
Evan Cheng8f7f7122006-05-05 05:40:20 +0000394 // See if a truncate instruction can be turned into a nop.
395 switch (MI->getOpcode()) {
396 default: break;
Evan Cheng25ab6902006-09-08 06:48:29 +0000397 case X86::TRUNC_64to32:
398 case X86::TRUNC_64to16:
399 case X86::TRUNC_32to16:
400 case X86::TRUNC_32to8:
401 case X86::TRUNC_16to8:
402 case X86::TRUNC_32_to8:
403 case X86::TRUNC_16_to8: {
Evan Cheng8f7f7122006-05-05 05:40:20 +0000404 const MachineOperand &MO0 = MI->getOperand(0);
405 const MachineOperand &MO1 = MI->getOperand(1);
406 unsigned Reg0 = MO0.getReg();
407 unsigned Reg1 = MO1.getReg();
Evan Cheng25ab6902006-09-08 06:48:29 +0000408 unsigned Opc = MI->getOpcode();
409 if (Opc == X86::TRUNC_64to32)
410 Reg1 = getX86SubSuperRegister(Reg1, MVT::i32);
411 else if (Opc == X86::TRUNC_32to16 || Opc == X86::TRUNC_64to16)
Evan Cheng403be7e2006-05-08 08:01:26 +0000412 Reg1 = getX86SubSuperRegister(Reg1, MVT::i16);
Evan Cheng8f7f7122006-05-05 05:40:20 +0000413 else
Evan Cheng403be7e2006-05-08 08:01:26 +0000414 Reg1 = getX86SubSuperRegister(Reg1, MVT::i8);
Jim Laskey563321a2006-09-06 18:34:40 +0000415 O << TAI->getCommentString() << " TRUNCATE ";
Evan Cheng403be7e2006-05-08 08:01:26 +0000416 if (Reg0 != Reg1)
417 O << "\n\t";
Evan Cheng8f7f7122006-05-05 05:40:20 +0000418 break;
419 }
Evan Cheng25ab6902006-09-08 06:48:29 +0000420 case X86::PsMOVZX64rr32:
421 O << TAI->getCommentString() << " ZERO-EXTEND " << "\n\t";
422 break;
Evan Cheng8f7f7122006-05-05 05:40:20 +0000423 }
424
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000425 // Call the autogenerated instruction printer routines.
426 printInstruction(MI);
427}
428
429// Include the auto-generated portion of the assembly writer.
430#include "X86GenAsmWriter.inc"
431