blob: 093940f0854830823962695d4de446126bbc7837 [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"
Anton Korobeynikovf8248682006-09-20 22:03:51 +000018#include "X86MachineFunctionInfo.h"
Chris Lattnerb36cbd02005-07-01 22:44:09 +000019#include "X86TargetMachine.h"
Jim Laskeya0f3d172006-09-07 22:06:40 +000020#include "X86TargetAsmInfo.h"
Anton Korobeynikovf8248682006-09-20 22:03:51 +000021#include "llvm/CallingConv.h"
Chris Lattnerb36cbd02005-07-01 22:44:09 +000022#include "llvm/Module.h"
23#include "llvm/Support/Mangler.h"
Jim Laskeya0f3d172006-09-07 22:06:40 +000024#include "llvm/Target/TargetAsmInfo.h"
Evan Cheng7ccced62006-02-18 00:15:05 +000025#include "llvm/Target/TargetOptions.h"
Chris Lattner2c2c6c62006-01-22 23:41:00 +000026#include <iostream>
Chris Lattnerb36cbd02005-07-01 22:44:09 +000027using namespace llvm;
Chris Lattnerb36cbd02005-07-01 22:44:09 +000028
29/// runOnMachineFunction - This uses the printMachineInstruction()
30/// method to print assembly for each instruction.
31///
32bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Jim Laskeyea348582006-07-27 02:05:13 +000033 if (Subtarget->isTargetDarwin()) {
Jim Laskeye29c2f52006-07-19 11:54:50 +000034 // Let PassManager know we need debug information and relay
35 // the MachineDebugInfo address on to DwarfWriter.
36 DW.SetDebugInfo(&getAnalysis<MachineDebugInfo>());
37 }
Evan Cheng3c992d22006-03-07 02:02:57 +000038
Chris Lattner8b8b9512005-11-21 07:51:23 +000039 SetupMachineFunction(MF);
Chris Lattnerb36cbd02005-07-01 22:44:09 +000040 O << "\n\n";
41
42 // Print out constants referenced by the function
Chris Lattnerd939f6c2005-11-21 08:32:23 +000043 EmitConstantPool(MF.getConstantPool());
Chris Lattnerb36cbd02005-07-01 22:44:09 +000044
45 // Print out labels for the function.
Evan Cheng2338c5c2006-02-07 08:38:37 +000046 const Function *F = MF.getFunction();
Anton Korobeynikovf8248682006-09-20 22:03:51 +000047 unsigned CC = F->getCallingConv();
48
49 // Populate function information map. Actually, We don't want to populate
50 // non-stdcall or non-fastcall functions' information right now.
51 if (CC == CallingConv::X86_StdCall || CC == CallingConv::X86_FastCall) {
52 FunctionInfoMap[F] = *(MF.getInfo<X86FunctionInfo>());
53 }
54
55 X86SharedAsmPrinter::decorateName(CurrentFnName, F);
56
Evan Cheng2338c5c2006-02-07 08:38:37 +000057 switch (F->getLinkage()) {
58 default: assert(0 && "Unknown linkage type!");
59 case Function::InternalLinkage: // Symbols default to internal.
Jim Laskey563321a2006-09-06 18:34:40 +000060 SwitchToTextSection(TAI->getTextSection(), F);
Evan Cheng2338c5c2006-02-07 08:38:37 +000061 EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
62 break;
Anton Korobeynikovb74ed072006-09-14 18:23:27 +000063 case Function::DLLExportLinkage:
64 DLLExportedFns.insert(Mang->makeNameProper(F->getName(), ""));
65 //FALLS THROUGH
Evan Cheng2338c5c2006-02-07 08:38:37 +000066 case Function::ExternalLinkage:
Jim Laskey563321a2006-09-06 18:34:40 +000067 SwitchToTextSection(TAI->getTextSection(), F);
Evan Cheng2338c5c2006-02-07 08:38:37 +000068 EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
Anton Korobeynikovb74ed072006-09-14 18:23:27 +000069 O << "\t.globl\t" << CurrentFnName << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +000070 break;
71 case Function::WeakLinkage:
72 case Function::LinkOnceLinkage:
Jim Laskeyea348582006-07-27 02:05:13 +000073 if (Subtarget->isTargetDarwin()) {
Chris Lattner4632d7a2006-05-09 04:59:56 +000074 SwitchToTextSection(
75 ".section __TEXT,__textcoal_nt,coalesced,pure_instructions", F);
Evan Chengf1616da2006-02-22 23:59:57 +000076 O << "\t.globl\t" << CurrentFnName << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +000077 O << "\t.weak_definition\t" << CurrentFnName << "\n";
Anton Korobeynikovbcb97702006-09-17 20:25:45 +000078 } else if (Subtarget->isTargetCygwin()) {
Evan Cheng932ad512006-05-25 21:59:08 +000079 EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
80 O << "\t.section\t.llvm.linkonce.t." << CurrentFnName
81 << ",\"ax\"\n";
82 SwitchToTextSection("", F);
83 O << "\t.weak " << CurrentFnName << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +000084 } else {
85 EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
86 O << "\t.section\t.llvm.linkonce.t." << CurrentFnName
87 << ",\"ax\",@progbits\n";
Chris Lattner4632d7a2006-05-09 04:59:56 +000088 SwitchToTextSection("", F);
Evan Cheng2338c5c2006-02-07 08:38:37 +000089 O << "\t.weak " << CurrentFnName << "\n";
90 }
91 break;
92 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +000093 O << CurrentFnName << ":\n";
94
Jim Laskeyea348582006-07-27 02:05:13 +000095 if (Subtarget->isTargetDarwin()) {
Jim Laskey6b92b8e2006-04-07 20:44:42 +000096 // Emit pre-function debug information.
Jim Laskey89d67fa2006-06-23 12:51:53 +000097 DW.BeginFunction(&MF);
Jim Laskey6b92b8e2006-04-07 20:44:42 +000098 }
99
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000100 // Print out code for the function.
101 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
102 I != E; ++I) {
103 // Print a label for the basic block.
Nate Begemancdf38c42006-05-02 05:37:32 +0000104 if (I->pred_begin() != I->pred_end()) {
105 printBasicBlockLabel(I, true);
106 O << '\n';
107 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000108 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
109 II != E; ++II) {
110 // Print the assembly for the instruction.
111 O << "\t";
112 printMachineInstruction(II);
113 }
114 }
Evan Cheng67afece2006-08-28 22:14:16 +0000115
116 // Print out jump tables referenced by the function
117 // Mac OS X requires at least one non-local (e.g. L1) labels before local
118 // lables that are used in jump table expressions (e.g. LBB1_1-LJT1_0).
119 EmitJumpTableInfo(MF.getJumpTableInfo());
120
Jim Laskey563321a2006-09-06 18:34:40 +0000121 if (TAI->hasDotTypeDotSizeDirective())
Nate Begeman73213f62005-07-12 01:37:28 +0000122 O << "\t.size " << CurrentFnName << ", .-" << CurrentFnName << "\n";
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000123
Jim Laskeyea348582006-07-27 02:05:13 +0000124 if (Subtarget->isTargetDarwin()) {
Evan Chengd5948812006-03-07 02:23:26 +0000125 // Emit post-function debug information.
Jim Laskey99db0442006-03-23 18:09:44 +0000126 DW.EndFunction();
Evan Chengd5948812006-03-07 02:23:26 +0000127 }
Evan Cheng3c992d22006-03-07 02:02:57 +0000128
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000129 // We didn't modify anything.
130 return false;
131}
132
Chris Lattnera3b8c572006-02-06 23:41:19 +0000133void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
134 const char *Modifier) {
135 const MachineOperand &MO = MI->getOperand(OpNo);
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000136 const MRegisterInfo &RI = *TM.getRegisterInfo();
137 switch (MO.getType()) {
Evan Cheng8f7f7122006-05-05 05:40:20 +0000138 case MachineOperand::MO_Register: {
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000139 assert(MRegisterInfo::isPhysicalRegister(MO.getReg()) &&
140 "Virtual registers should not make it this far!");
141 O << '%';
Evan Cheng8f7f7122006-05-05 05:40:20 +0000142 unsigned Reg = MO.getReg();
Evan Chengcbe70e12006-05-31 22:34:26 +0000143 if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
Evan Cheng25ab6902006-09-08 06:48:29 +0000144 MVT::ValueType VT = (strcmp(Modifier+6,"64") == 0) ?
145 MVT::i64 : ((strcmp(Modifier+6, "32") == 0) ? MVT::i32 :
146 ((strcmp(Modifier+6,"16") == 0) ? MVT::i16 : MVT::i8));
Evan Cheng8f7f7122006-05-05 05:40:20 +0000147 Reg = getX86SubSuperRegister(Reg, VT);
148 }
149 for (const char *Name = RI.get(Reg).Name; *Name; ++Name)
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000150 O << (char)tolower(*Name);
151 return;
Evan Cheng8f7f7122006-05-05 05:40:20 +0000152 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000153
Chris Lattner63b3d712006-05-04 17:21:20 +0000154 case MachineOperand::MO_Immediate:
Evan Cheng3c992d22006-03-07 02:02:57 +0000155 if (!Modifier || strcmp(Modifier, "debug") != 0)
156 O << '$';
Evan Cheng138a24e2006-05-26 08:04:31 +0000157 O << MO.getImmedValue();
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000158 return;
Nate Begeman37efe672006-04-22 18:53:45 +0000159 case MachineOperand::MO_MachineBasicBlock:
160 printBasicBlockLabel(MO.getMachineBasicBlock());
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000161 return;
Nate Begeman37efe672006-04-22 18:53:45 +0000162 case MachineOperand::MO_JumpTableIndex: {
163 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
164 if (!isMemOp) O << '$';
Jim Laskey563321a2006-09-06 18:34:40 +0000165 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << "_"
Nate Begeman37efe672006-04-22 18:53:45 +0000166 << MO.getJumpTableIndex();
Evan Cheng25ab6902006-09-08 06:48:29 +0000167 if (X86PICStyle == PICStyle::Stub &&
Nate Begeman2f1ae882006-07-27 01:13:04 +0000168 TM.getRelocationModel() == Reloc::PIC_)
169 O << "-\"L" << getFunctionNumber() << "$pb\"";
Evan Cheng25ab6902006-09-08 06:48:29 +0000170 if (Subtarget->is64Bit())
171 O << "(%rip)";
Nate Begeman37efe672006-04-22 18:53:45 +0000172 return;
173 }
Evan Chenga09bd812006-02-26 08:28:12 +0000174 case MachineOperand::MO_ConstantPoolIndex: {
175 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
176 if (!isMemOp) O << '$';
Jim Laskey563321a2006-09-06 18:34:40 +0000177 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
Evan Chenga09bd812006-02-26 08:28:12 +0000178 << MO.getConstantPoolIndex();
Evan Cheng25ab6902006-09-08 06:48:29 +0000179 if (X86PICStyle == PICStyle::Stub &&
Chris Lattner35d86fe2006-07-26 21:12:04 +0000180 TM.getRelocationModel() == Reloc::PIC_)
Evan Chenga09bd812006-02-26 08:28:12 +0000181 O << "-\"L" << getFunctionNumber() << "$pb\"";
182 int Offset = MO.getOffset();
183 if (Offset > 0)
184 O << "+" << Offset;
185 else if (Offset < 0)
186 O << Offset;
Evan Cheng25ab6902006-09-08 06:48:29 +0000187
188 if (Subtarget->is64Bit())
189 O << "(%rip)";
Evan Chenga09bd812006-02-26 08:28:12 +0000190 return;
191 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000192 case MachineOperand::MO_GlobalAddress: {
Chris Lattnera3b8c572006-02-06 23:41:19 +0000193 bool isCallOp = Modifier && !strcmp(Modifier, "call");
Evan Cheng2338c5c2006-02-07 08:38:37 +0000194 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
Evan Cheng7ccced62006-02-18 00:15:05 +0000195 if (!isMemOp && !isCallOp) O << '$';
Evan Cheng25ab6902006-09-08 06:48:29 +0000196
Anton Korobeynikovf8248682006-09-20 22:03:51 +0000197 GlobalValue *GV = MO.getGlobal();
Evan Cheng25ab6902006-09-08 06:48:29 +0000198 std::string Name = Mang->getValueName(GV);
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000199
Evan Cheng25ab6902006-09-08 06:48:29 +0000200 bool isExt = (GV->isExternal() || GV->hasWeakLinkage() ||
201 GV->hasLinkOnceLinkage());
Anton Korobeynikovf8248682006-09-20 22:03:51 +0000202
203 X86SharedAsmPrinter::decorateName(Name, (Function*)GV);
204
Evan Cheng25ab6902006-09-08 06:48:29 +0000205 if (X86PICStyle == PICStyle::Stub &&
Evan Cheng932ad512006-05-25 21:59:08 +0000206 TM.getRelocationModel() != Reloc::Static) {
Evan Cheng2338c5c2006-02-07 08:38:37 +0000207 // Link-once, External, or Weakly-linked global variables need
208 // non-lazily-resolved stubs
Evan Cheng25ab6902006-09-08 06:48:29 +0000209 if (isExt) {
Evan Cheng2338c5c2006-02-07 08:38:37 +0000210 // Dynamically-resolved functions need a stub for the function.
Evan Cheng25ab6902006-09-08 06:48:29 +0000211 if (isCallOp && isa<Function>(GV)) {
Evan Cheng2338c5c2006-02-07 08:38:37 +0000212 FnStubs.insert(Name);
213 O << "L" << Name << "$stub";
214 } else {
215 GVStubs.insert(Name);
216 O << "L" << Name << "$non_lazy_ptr";
217 }
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000218 } else {
219 if (GV->hasDLLImportLinkage()) {
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000220 O << "__imp_";
221 }
Evan Cheng25ab6902006-09-08 06:48:29 +0000222 O << Name;
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000223 }
224
Chris Lattner35d86fe2006-07-26 21:12:04 +0000225 if (!isCallOp && TM.getRelocationModel() == Reloc::PIC_)
Evan Chenga0ea0532006-02-23 02:43:52 +0000226 O << "-\"L" << getFunctionNumber() << "$pb\"";
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000227 } else {
228 if (GV->hasDLLImportLinkage()) {
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000229 O << "__imp_";
230 }
Evan Cheng25ab6902006-09-08 06:48:29 +0000231 O << Name;
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000232 }
233
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000234 int Offset = MO.getOffset();
235 if (Offset > 0)
236 O << "+" << Offset;
237 else if (Offset < 0)
238 O << Offset;
Evan Cheng25ab6902006-09-08 06:48:29 +0000239
240 if (!isCallOp &&
241 Subtarget->is64Bit()) {
242 if (isExt && TM.getRelocationModel() != Reloc::Static)
243 O << "@GOTPCREL";
244 O << "(%rip)";
245 }
246
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000247 return;
248 }
Chris Lattnera3b8c572006-02-06 23:41:19 +0000249 case MachineOperand::MO_ExternalSymbol: {
250 bool isCallOp = Modifier && !strcmp(Modifier, "call");
Evan Cheng932ad512006-05-25 21:59:08 +0000251 if (isCallOp &&
Evan Cheng25ab6902006-09-08 06:48:29 +0000252 X86PICStyle == PICStyle::Stub &&
Evan Cheng932ad512006-05-25 21:59:08 +0000253 TM.getRelocationModel() != Reloc::Static) {
Jim Laskey563321a2006-09-06 18:34:40 +0000254 std::string Name(TAI->getGlobalPrefix());
Evan Cheng4c1aa862006-02-22 20:19:42 +0000255 Name += MO.getSymbolName();
Nate Begeman72b286b2005-07-08 00:23:26 +0000256 FnStubs.insert(Name);
257 O << "L" << Name << "$stub";
258 return;
259 }
Evan Cheng4c1aa862006-02-22 20:19:42 +0000260 if (!isCallOp) O << '$';
Jim Laskey563321a2006-09-06 18:34:40 +0000261 O << TAI->getGlobalPrefix() << MO.getSymbolName();
Evan Cheng25ab6902006-09-08 06:48:29 +0000262
263 if (!isCallOp &&
264 Subtarget->is64Bit())
265 O << "(%rip)";
266
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000267 return;
Chris Lattnera3b8c572006-02-06 23:41:19 +0000268 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000269 default:
270 O << "<unknown operand type>"; return;
271 }
272}
273
Nate Begeman391c5d22005-11-30 18:54:35 +0000274void X86ATTAsmPrinter::printSSECC(const MachineInstr *MI, unsigned Op) {
Nate Begeman6c7cb292005-07-14 22:52:25 +0000275 unsigned char value = MI->getOperand(Op).getImmedValue();
276 assert(value <= 7 && "Invalid ssecc argument!");
277 switch (value) {
278 case 0: O << "eq"; break;
279 case 1: O << "lt"; break;
280 case 2: O << "le"; break;
281 case 3: O << "unord"; break;
282 case 4: O << "neq"; break;
283 case 5: O << "nlt"; break;
284 case 6: O << "nle"; break;
285 case 7: O << "ord"; break;
286 }
287}
288
Evan Cheng25ab6902006-09-08 06:48:29 +0000289void X86ATTAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
290 const char *Modifier){
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000291 assert(isMem(MI, Op) && "Invalid memory reference!");
292
293 const MachineOperand &BaseReg = MI->getOperand(Op);
294 int ScaleVal = MI->getOperand(Op+1).getImmedValue();
295 const MachineOperand &IndexReg = MI->getOperand(Op+2);
296 const MachineOperand &DispSpec = MI->getOperand(Op+3);
297
298 if (BaseReg.isFrameIndex()) {
299 O << "[frame slot #" << BaseReg.getFrameIndex();
300 if (DispSpec.getImmedValue())
301 O << " + " << DispSpec.getImmedValue();
302 O << "]";
303 return;
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000304 }
305
Evan Chengc9676de2006-08-29 22:14:48 +0000306 if (DispSpec.isGlobalAddress() ||
307 DispSpec.isConstantPoolIndex() ||
308 DispSpec.isJumpTableIndex()) {
Evan Cheng2338c5c2006-02-07 08:38:37 +0000309 printOperand(MI, Op+3, "mem");
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000310 } else {
311 int DispVal = DispSpec.getImmedValue();
312 if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg()))
313 O << DispVal;
314 }
315
316 if (IndexReg.getReg() || BaseReg.getReg()) {
317 O << "(";
Evan Cheng25ab6902006-09-08 06:48:29 +0000318 if (BaseReg.getReg()) {
319 printOperand(MI, Op, Modifier);
320 }
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000321
322 if (IndexReg.getReg()) {
323 O << ",";
Evan Cheng25ab6902006-09-08 06:48:29 +0000324 printOperand(MI, Op+2, Modifier);
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000325 if (ScaleVal != 1)
326 O << "," << ScaleVal;
327 }
328
329 O << ")";
330 }
331}
332
Evan Cheng7ccced62006-02-18 00:15:05 +0000333void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
334 O << "\"L" << getFunctionNumber() << "$pb\"\n";
335 O << "\"L" << getFunctionNumber() << "$pb\":";
336}
337
Evan Cheng62f27002006-04-28 23:11:40 +0000338
Evan Cheng55c25f22006-04-28 23:19:39 +0000339bool X86ATTAsmPrinter::printAsmMRegister(const MachineOperand &MO,
Evan Cheng62f27002006-04-28 23:11:40 +0000340 const char Mode) {
341 const MRegisterInfo &RI = *TM.getRegisterInfo();
342 unsigned Reg = MO.getReg();
Evan Cheng62f27002006-04-28 23:11:40 +0000343 switch (Mode) {
344 default: return true; // Unknown mode.
345 case 'b': // Print QImode register
Evan Cheng8f7f7122006-05-05 05:40:20 +0000346 Reg = getX86SubSuperRegister(Reg, MVT::i8);
Evan Cheng62f27002006-04-28 23:11:40 +0000347 break;
348 case 'h': // Print QImode high register
Evan Cheng8f7f7122006-05-05 05:40:20 +0000349 Reg = getX86SubSuperRegister(Reg, MVT::i8, true);
Evan Cheng62f27002006-04-28 23:11:40 +0000350 break;
351 case 'w': // Print HImode register
Evan Cheng8f7f7122006-05-05 05:40:20 +0000352 Reg = getX86SubSuperRegister(Reg, MVT::i16);
Evan Cheng62f27002006-04-28 23:11:40 +0000353 break;
354 case 'k': // Print SImode register
Evan Cheng8f7f7122006-05-05 05:40:20 +0000355 Reg = getX86SubSuperRegister(Reg, MVT::i32);
Evan Cheng62f27002006-04-28 23:11:40 +0000356 break;
357 }
358
Evan Cheng8f7f7122006-05-05 05:40:20 +0000359 O << '%';
360 for (const char *Name = RI.get(Reg).Name; *Name; ++Name)
361 O << (char)tolower(*Name);
Evan Cheng62f27002006-04-28 23:11:40 +0000362 return false;
363}
364
Evan Cheng3d48a902006-04-28 21:19:05 +0000365/// PrintAsmOperand - Print out an operand for an inline asm expression.
366///
367bool X86ATTAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
368 unsigned AsmVariant,
369 const char *ExtraCode) {
370 // Does this asm operand have a single letter operand modifier?
371 if (ExtraCode && ExtraCode[0]) {
372 if (ExtraCode[1] != 0) return true; // Unknown modifier.
373
374 switch (ExtraCode[0]) {
375 default: return true; // Unknown modifier.
Evan Cheng62f27002006-04-28 23:11:40 +0000376 case 'b': // Print QImode register
377 case 'h': // Print QImode high register
378 case 'w': // Print HImode register
379 case 'k': // Print SImode register
Evan Cheng55c25f22006-04-28 23:19:39 +0000380 return printAsmMRegister(MI->getOperand(OpNo), ExtraCode[0]);
Evan Cheng3d48a902006-04-28 21:19:05 +0000381 }
382 }
383
384 printOperand(MI, OpNo);
385 return false;
386}
387
388bool X86ATTAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
389 unsigned OpNo,
390 unsigned AsmVariant,
391 const char *ExtraCode) {
392 if (ExtraCode && ExtraCode[0])
393 return true; // Unknown modifier.
394 printMemReference(MI, OpNo);
395 return false;
396}
397
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000398/// printMachineInstruction -- Print out a single X86 LLVM instruction
399/// MI in Intel syntax to the current output stream.
400///
401void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
402 ++EmittedInsts;
Evan Cheng67caa392006-01-26 02:27:43 +0000403
Evan Cheng8f7f7122006-05-05 05:40:20 +0000404 // See if a truncate instruction can be turned into a nop.
405 switch (MI->getOpcode()) {
406 default: break;
Evan Cheng25ab6902006-09-08 06:48:29 +0000407 case X86::TRUNC_64to32:
408 case X86::TRUNC_64to16:
409 case X86::TRUNC_32to16:
410 case X86::TRUNC_32to8:
411 case X86::TRUNC_16to8:
412 case X86::TRUNC_32_to8:
413 case X86::TRUNC_16_to8: {
Evan Cheng8f7f7122006-05-05 05:40:20 +0000414 const MachineOperand &MO0 = MI->getOperand(0);
415 const MachineOperand &MO1 = MI->getOperand(1);
416 unsigned Reg0 = MO0.getReg();
417 unsigned Reg1 = MO1.getReg();
Evan Cheng25ab6902006-09-08 06:48:29 +0000418 unsigned Opc = MI->getOpcode();
419 if (Opc == X86::TRUNC_64to32)
420 Reg1 = getX86SubSuperRegister(Reg1, MVT::i32);
421 else if (Opc == X86::TRUNC_32to16 || Opc == X86::TRUNC_64to16)
Evan Cheng403be7e2006-05-08 08:01:26 +0000422 Reg1 = getX86SubSuperRegister(Reg1, MVT::i16);
Evan Cheng8f7f7122006-05-05 05:40:20 +0000423 else
Evan Cheng403be7e2006-05-08 08:01:26 +0000424 Reg1 = getX86SubSuperRegister(Reg1, MVT::i8);
Jim Laskey563321a2006-09-06 18:34:40 +0000425 O << TAI->getCommentString() << " TRUNCATE ";
Evan Cheng403be7e2006-05-08 08:01:26 +0000426 if (Reg0 != Reg1)
427 O << "\n\t";
Evan Cheng8f7f7122006-05-05 05:40:20 +0000428 break;
429 }
Evan Cheng25ab6902006-09-08 06:48:29 +0000430 case X86::PsMOVZX64rr32:
431 O << TAI->getCommentString() << " ZERO-EXTEND " << "\n\t";
432 break;
Evan Cheng8f7f7122006-05-05 05:40:20 +0000433 }
434
Chris Lattnerb36cbd02005-07-01 22:44:09 +0000435 // Call the autogenerated instruction printer routines.
436 printInstruction(MI);
437}
438
439// Include the auto-generated portion of the assembly writer.
440#include "X86GenAsmWriter.inc"
441