blob: bb16e6a91176417916f201d78f7c5ee1ac8019a9 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- X86ATTAsmPrinter.cpp - Convert X86 LLVM code to AT&T assembly -----===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
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#define DEBUG_TYPE "asm-printer"
17#include "X86ATTAsmPrinter.h"
Cédric Venet4fce6e22008-08-24 12:30:46 +000018#include "X86.h"
19#include "X86COFF.h"
20#include "X86MachineFunctionInfo.h"
21#include "X86TargetMachine.h"
22#include "X86TargetAsmInfo.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000023#include "llvm/CallingConv.h"
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +000024#include "llvm/DerivedTypes.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000025#include "llvm/Module.h"
Devang Patelf667ab42009-06-25 00:47:42 +000026#include "llvm/MDNode.h"
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +000027#include "llvm/Type.h"
28#include "llvm/ADT/Statistic.h"
29#include "llvm/ADT/StringExtras.h"
Chris Lattner7cf8daf2009-06-24 05:46:28 +000030#include "llvm/MC/MCContext.h"
Chris Lattner19b1bd52009-06-19 00:47:33 +000031#include "llvm/MC/MCInst.h"
Chris Lattner7cf8daf2009-06-24 05:46:28 +000032#include "llvm/MC/MCStreamer.h"
Bill Wendling4ff1cdf2009-02-18 23:12:06 +000033#include "llvm/CodeGen/DwarfWriter.h"
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +000034#include "llvm/CodeGen/MachineJumpTableInfo.h"
Chris Lattner19b1bd52009-06-19 00:47:33 +000035#include "llvm/Support/CommandLine.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000036#include "llvm/Support/Mangler.h"
Owen Anderson847b99b2008-08-21 00:14:44 +000037#include "llvm/Support/raw_ostream.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000038#include "llvm/Target/TargetAsmInfo.h"
39#include "llvm/Target/TargetOptions.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040using namespace llvm;
41
42STATISTIC(EmittedInsts, "Number of machine instrs printed");
43
Chris Lattner19b1bd52009-06-19 00:47:33 +000044static cl::opt<bool> NewAsmPrinter("experimental-asm-printer",
45 cl::Hidden);
46
Chris Lattner2e845952009-06-24 19:44:36 +000047//===----------------------------------------------------------------------===//
48// Primitive Helper Functions.
49//===----------------------------------------------------------------------===//
Chris Lattner14f791a2009-06-24 19:19:16 +000050
51void X86ATTAsmPrinter::PrintPICBaseSymbol() const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052 if (Subtarget->isTargetDarwin())
Chris Lattner14f791a2009-06-24 19:19:16 +000053 O << "\"L" << getFunctionNumber() << "$pb\"";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000054 else if (Subtarget->isTargetELF())
Chris Lattner14f791a2009-06-24 19:19:16 +000055 O << ".Lllvm$" << getFunctionNumber() << "." "$piclabel";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000056 else
57 assert(0 && "Don't know how to print PIC label!\n");
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058}
59
Chris Lattner2e845952009-06-24 19:44:36 +000060/// PrintUnmangledNameSafely - Print out the printable characters in the name.
61/// Don't print things like \\n or \\0.
62static void PrintUnmangledNameSafely(const Value *V, raw_ostream &OS) {
63 for (const char *Name = V->getNameStart(), *E = Name+V->getNameLen();
64 Name != E; ++Name)
65 if (isprint(*Name))
66 OS << *Name;
67}
Chris Lattner14f791a2009-06-24 19:19:16 +000068
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +000069static X86MachineFunctionInfo calculateFunctionInfo(const Function *F,
70 const TargetData *TD) {
71 X86MachineFunctionInfo Info;
72 uint64_t Size = 0;
73
74 switch (F->getCallingConv()) {
75 case CallingConv::X86_StdCall:
76 Info.setDecorationStyle(StdCall);
77 break;
78 case CallingConv::X86_FastCall:
79 Info.setDecorationStyle(FastCall);
80 break;
81 default:
82 return Info;
83 }
84
85 unsigned argNum = 1;
86 for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
87 AI != AE; ++AI, ++argNum) {
88 const Type* Ty = AI->getType();
89
90 // 'Dereference' type in case of byval parameter attribute
Devang Pateld222f862008-09-25 21:00:45 +000091 if (F->paramHasAttr(argNum, Attribute::ByVal))
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +000092 Ty = cast<PointerType>(Ty)->getElementType();
93
94 // Size should be aligned to DWORD boundary
Duncan Sandsec4f97d2009-05-09 07:06:46 +000095 Size += ((TD->getTypeAllocSize(Ty) + 3)/4)*4;
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +000096 }
97
98 // We're not supporting tooooo huge arguments :)
99 Info.setBytesToPopOnReturn((unsigned int)Size);
100 return Info;
101}
102
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000103/// decorateName - Query FunctionInfoMap and use this information for various
104/// name decoration.
105void X86ATTAsmPrinter::decorateName(std::string &Name,
106 const GlobalValue *GV) {
107 const Function *F = dyn_cast<Function>(GV);
108 if (!F) return;
109
110 // We don't want to decorate non-stdcall or non-fastcall functions right now
111 unsigned CC = F->getCallingConv();
112 if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
113 return;
114
115 // Decorate names only when we're targeting Cygwin/Mingw32 targets
116 if (!Subtarget->isTargetCygMing())
117 return;
118
119 FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
120
121 const X86MachineFunctionInfo *Info;
122 if (info_item == FunctionInfoMap.end()) {
123 // Calculate apropriate function info and populate map
124 FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData());
125 Info = &FunctionInfoMap[F];
126 } else {
127 Info = &info_item->second;
128 }
129
130 const FunctionType *FT = F->getFunctionType();
131 switch (Info->getDecorationStyle()) {
132 case None:
133 break;
134 case StdCall:
135 // "Pure" variadic functions do not receive @0 suffix.
136 if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
137 (FT->getNumParams() == 1 && F->hasStructRetAttr()))
138 Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
139 break;
140 case FastCall:
141 // "Pure" variadic functions do not receive @0 suffix.
142 if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
143 (FT->getNumParams() == 1 && F->hasStructRetAttr()))
144 Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
145
146 if (Name[0] == '_') {
147 Name[0] = '@';
148 } else {
149 Name = '@' + Name;
150 }
151 break;
152 default:
153 assert(0 && "Unsupported DecorationStyle");
154 }
155}
156
Chris Lattner2e845952009-06-24 19:44:36 +0000157
158
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000159void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000160 const Function *F = MF.getFunction();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000161
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000162 decorateName(CurrentFnName, F);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000163
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000164 SwitchToSection(TAI->SectionForGlobal(F));
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000165
Chris Lattner2e845952009-06-24 19:44:36 +0000166 // FIXME: A function's alignment should be part of MachineFunction. There
167 // shouldn't be a policy decision here.
Devang Patel93698d92008-10-01 23:18:38 +0000168 unsigned FnAlign = 4;
Devang Pateld3659412008-10-06 17:30:07 +0000169 if (F->hasFnAttr(Attribute::OptimizeForSize))
Devang Patel009a8d12008-09-04 21:03:41 +0000170 FnAlign = 1;
Chris Lattner2e845952009-06-24 19:44:36 +0000171
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000172 switch (F->getLinkage()) {
173 default: assert(0 && "Unknown linkage type!");
174 case Function::InternalLinkage: // Symbols default to internal.
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000175 case Function::PrivateLinkage:
Evan Cheng2e8d3d42008-03-25 22:29:46 +0000176 EmitAlignment(FnAlign, F);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000177 break;
178 case Function::DLLExportLinkage:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000179 case Function::ExternalLinkage:
Evan Cheng2e8d3d42008-03-25 22:29:46 +0000180 EmitAlignment(FnAlign, F);
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000181 O << "\t.globl\t" << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000182 break;
Duncan Sands19d161f2009-03-07 15:45:40 +0000183 case Function::LinkOnceAnyLinkage:
184 case Function::LinkOnceODRLinkage:
185 case Function::WeakAnyLinkage:
186 case Function::WeakODRLinkage:
Evan Cheng2e8d3d42008-03-25 22:29:46 +0000187 EmitAlignment(FnAlign, F);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000188 if (Subtarget->isTargetDarwin()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000189 O << "\t.globl\t" << CurrentFnName << '\n';
190 O << TAI->getWeakDefDirective() << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000191 } else if (Subtarget->isTargetCygMing()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000192 O << "\t.globl\t" << CurrentFnName << "\n"
193 "\t.linkonce discard\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194 } else {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000195 O << "\t.weak\t" << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000196 }
197 break;
198 }
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000199
200 printVisibility(CurrentFnName, F->getVisibility());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000201
202 if (Subtarget->isTargetELF())
Dan Gohman721e6582007-07-30 15:08:02 +0000203 O << "\t.type\t" << CurrentFnName << ",@function\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000204 else if (Subtarget->isTargetCygMing()) {
205 O << "\t.def\t " << CurrentFnName
206 << ";\t.scl\t" <<
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000207 (F->hasInternalLinkage() ? COFF::C_STAT : COFF::C_EXT)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000208 << ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
209 << ";\t.endef\n";
210 }
211
212 O << CurrentFnName << ":\n";
213 // Add some workaround for linkonce linkage on Cygwin\MinGW
214 if (Subtarget->isTargetCygMing() &&
Duncan Sands19d161f2009-03-07 15:45:40 +0000215 (F->hasLinkOnceLinkage() || F->hasWeakLinkage()))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216 O << "Lllvm$workaround$fake$stub$" << CurrentFnName << ":\n";
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000217}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000218
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000219/// runOnMachineFunction - This uses the printMachineInstruction()
220/// method to print assembly for each instruction.
221///
222bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
223 const Function *F = MF.getFunction();
Bill Wendlingb3b11262009-02-06 21:45:08 +0000224 this->MF = &MF;
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000225 unsigned CC = F->getCallingConv();
226
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000227 SetupMachineFunction(MF);
228 O << "\n\n";
229
230 // Populate function information map. Actually, We don't want to populate
231 // non-stdcall or non-fastcall functions' information right now.
232 if (CC == CallingConv::X86_StdCall || CC == CallingConv::X86_FastCall)
233 FunctionInfoMap[F] = *MF.getInfo<X86MachineFunctionInfo>();
234
235 // Print out constants referenced by the function
236 EmitConstantPool(MF.getConstantPool());
237
238 if (F->hasDLLExportLinkage())
239 DLLExportedFns.insert(Mang->makeNameProper(F->getName(), ""));
240
241 // Print the 'header' of function
242 emitFunctionHeader(MF);
243
244 // Emit pre-function debug and/or EH information.
245 if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
Devang Patelaa1e8432009-01-08 23:40:34 +0000246 DW->BeginFunction(&MF);
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000247
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000248 // Print out code for the function.
Dale Johannesenf35771f2008-04-08 00:37:56 +0000249 bool hasAnyRealCode = false;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000250 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
251 I != E; ++I) {
252 // Print a label for the basic block.
Dan Gohmand38f8762009-03-31 18:39:13 +0000253 if (!VerboseAsm && (I->pred_empty() || I->isOnlyReachableByFallthrough())) {
254 // This is an entry block or a block that's only reachable via a
255 // fallthrough edge. In non-VerboseAsm mode, don't print the label.
256 } else {
Evan Cheng11db8142009-03-24 00:17:40 +0000257 printBasicBlockLabel(I, true, true, VerboseAsm);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000258 O << '\n';
259 }
Bill Wendlingb5880a72008-01-26 09:03:52 +0000260 for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
261 II != IE; ++II) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000262 // Print the assembly for the instruction.
Dan Gohmanfa607c92008-07-01 00:05:16 +0000263 if (!II->isLabel())
Dale Johannesenf35771f2008-04-08 00:37:56 +0000264 hasAnyRealCode = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000265 printMachineInstruction(II);
266 }
267 }
268
Dale Johannesenf35771f2008-04-08 00:37:56 +0000269 if (Subtarget->isTargetDarwin() && !hasAnyRealCode) {
270 // If the function is empty, then we need to emit *something*. Otherwise,
271 // the function's label might be associated with something that it wasn't
272 // meant to be associated with. We emit a noop in this situation.
273 // We are assuming inline asms are code.
274 O << "\tnop\n";
275 }
276
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000277 if (TAI->hasDotTypeDotSizeDirective())
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000278 O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000279
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000280 // Emit post-function debug information.
Devang Patel4d438ce2009-06-19 23:21:20 +0000281 if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
Devang Patelaa1e8432009-01-08 23:40:34 +0000282 DW->EndFunction(&MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000283
284 // Print out jump tables referenced by the function.
285 EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000286
Dan Gohmaneb94abd2008-11-07 19:49:17 +0000287 O.flush();
288
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000289 // We didn't modify anything.
290 return false;
291}
292
Rafael Espindolae0ac18d2008-06-09 09:52:31 +0000293static inline bool shouldPrintPLT(TargetMachine &TM, const X86Subtarget* ST) {
Chris Lattner50315f22009-06-25 17:58:52 +0000294 return ST->isTargetELF() && TM.getRelocationModel() == Reloc::PIC_;
Rafael Espindolae0ac18d2008-06-09 09:52:31 +0000295}
296
297static inline bool shouldPrintStub(TargetMachine &TM, const X86Subtarget* ST) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000298 return ST->isPICStyleStub() && TM.getRelocationModel() != Reloc::Static;
299}
300
Chris Lattner357a0ca2009-06-20 19:34:09 +0000301/// print_pcrel_imm - This is used to print an immediate value that ends up
302/// being encoded as a pc-relative value. These print slightly differently, for
303/// example, a $ is not emitted.
304void X86ATTAsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo) {
305 const MachineOperand &MO = MI->getOperand(OpNo);
306 switch (MO.getType()) {
307 default: assert(0 && "Unknown pcrel immediate operand");
308 case MachineOperand::MO_Immediate:
309 O << MO.getImm();
310 return;
311 case MachineOperand::MO_MachineBasicBlock:
312 printBasicBlockLabel(MO.getMBB(), false, false, VerboseAsm);
313 return;
314
315 case MachineOperand::MO_GlobalAddress: {
316 const GlobalValue *GV = MO.getGlobal();
317 std::string Name = Mang->getValueName(GV);
318 decorateName(Name, GV);
319
320 bool needCloseParen = false;
321 if (Name[0] == '$') {
322 // The name begins with a dollar-sign. In order to avoid having it look
323 // like an integer immediate to the assembler, enclose it in parens.
324 O << '(';
325 needCloseParen = true;
326 }
327
328 if (shouldPrintStub(TM, Subtarget)) {
Chris Lattner50315f22009-06-25 17:58:52 +0000329 // DARWIN/X86-32 in != static mode.
330
Chris Lattner357a0ca2009-06-20 19:34:09 +0000331 // Link-once, declaration, or Weakly-linked global variables need
332 // non-lazily-resolved stubs
333 if (GV->isDeclaration() || GV->isWeakForLinker()) {
334 // Dynamically-resolved functions need a stub for the function.
335 if (isa<Function>(GV)) {
336 // Function stubs are no longer needed for Mac OS X 10.5 and up.
337 if (Subtarget->isTargetDarwin() && Subtarget->getDarwinVers() >= 9) {
338 O << Name;
339 } else {
340 FnStubs.insert(Name);
341 printSuffixedName(Name, "$stub");
342 }
343 } else if (GV->hasHiddenVisibility()) {
344 if (!GV->isDeclaration() && !GV->hasCommonLinkage())
345 // Definition is not definitely in the current translation unit.
346 O << Name;
347 else {
348 HiddenGVStubs.insert(Name);
349 printSuffixedName(Name, "$non_lazy_ptr");
350 }
351 } else {
352 GVStubs.insert(Name);
353 printSuffixedName(Name, "$non_lazy_ptr");
354 }
355 } else {
356 if (GV->hasDLLImportLinkage())
357 O << "__imp_";
358 O << Name;
359 }
360 } else {
Chris Lattner50315f22009-06-25 17:58:52 +0000361 if (GV->hasDLLImportLinkage())
Chris Lattner357a0ca2009-06-20 19:34:09 +0000362 O << "__imp_";
Chris Lattner357a0ca2009-06-20 19:34:09 +0000363 O << Name;
364
365 if (shouldPrintPLT(TM, Subtarget)) {
366 // Assemble call via PLT for externally visible symbols
367 if (!GV->hasHiddenVisibility() && !GV->hasProtectedVisibility() &&
368 !GV->hasLocalLinkage())
369 O << "@PLT";
370 }
371 if (Subtarget->isTargetCygMing() && GV->isDeclaration())
372 // Save function name for later type emission
373 FnStubs.insert(Name);
374 }
375
Chris Lattner357a0ca2009-06-20 19:34:09 +0000376 printOffset(MO.getOffset());
377
378 if (needCloseParen)
379 O << ')';
380 return;
381 }
382
383 case MachineOperand::MO_ExternalSymbol: {
384 bool needCloseParen = false;
385 std::string Name(TAI->getGlobalPrefix());
386 Name += MO.getSymbolName();
387 // Print function stub suffix unless it's Mac OS X 10.5 and up.
388 if (shouldPrintStub(TM, Subtarget) &&
Chris Lattner50315f22009-06-25 17:58:52 +0000389 // DARWIN/X86-32 in != static mode.
Chris Lattner357a0ca2009-06-20 19:34:09 +0000390 !(Subtarget->isTargetDarwin() && Subtarget->getDarwinVers() >= 9)) {
Chris Lattner50315f22009-06-25 17:58:52 +0000391
Chris Lattner357a0ca2009-06-20 19:34:09 +0000392 FnStubs.insert(Name);
393 printSuffixedName(Name, "$stub");
394 return;
395 }
396
397 if (Name[0] == '$') {
398 // The name begins with a dollar-sign. In order to avoid having it look
399 // like an integer immediate to the assembler, enclose it in parens.
400 O << '(';
401 needCloseParen = true;
402 }
403
404 O << Name;
405
Chris Lattner13d6c2d2009-06-25 17:38:33 +0000406 if (MO.getTargetFlags() == X86II::MO_GOT_ABSOLUTE_ADDRESS) {
407 O << " + [.-";
408 PrintPICBaseSymbol();
409 O << ']';
Chris Lattner357a0ca2009-06-20 19:34:09 +0000410 }
411
Chris Lattner13d6c2d2009-06-25 17:38:33 +0000412 if (shouldPrintPLT(TM, Subtarget))
413 O << "@PLT";
414
Chris Lattner357a0ca2009-06-20 19:34:09 +0000415 if (needCloseParen)
416 O << ')';
417
418 return;
419 }
420 }
421}
422
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000423void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000424 const char *Modifier) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000425 const MachineOperand &MO = MI->getOperand(OpNo);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000426 switch (MO.getType()) {
427 case MachineOperand::MO_Register: {
Dan Gohman1e57df32008-02-10 18:45:23 +0000428 assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000429 "Virtual registers should not make it this far!");
430 O << '%';
431 unsigned Reg = MO.getReg();
432 if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
Duncan Sands92c43912008-06-06 12:08:01 +0000433 MVT VT = (strcmp(Modifier+6,"64") == 0) ?
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000434 MVT::i64 : ((strcmp(Modifier+6, "32") == 0) ? MVT::i32 :
435 ((strcmp(Modifier+6,"16") == 0) ? MVT::i16 : MVT::i8));
436 Reg = getX86SubSuperRegister(Reg, VT);
437 }
Evan Cheng00d04a72008-07-07 22:21:06 +0000438 O << TRI->getAsmName(Reg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000439 return;
440 }
441
442 case MachineOperand::MO_Immediate:
Evan Cheng0af5a042009-03-12 18:15:39 +0000443 if (!Modifier || (strcmp(Modifier, "debug") &&
Chris Lattner357a0ca2009-06-20 19:34:09 +0000444 strcmp(Modifier, "mem")))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000445 O << '$';
Chris Lattnera96056a2007-12-30 20:49:49 +0000446 O << MO.getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000447 return;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000448 case MachineOperand::MO_JumpTableIndex: {
449 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
450 if (!isMemOp) O << '$';
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000451 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << '_'
Chris Lattner6017d482007-12-30 23:10:15 +0000452 << MO.getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000453
Chris Lattneradd6df82009-06-26 18:55:01 +0000454 switch (MO.getTargetFlags()) {
455 default:
456 assert(0 && "Unknown target flag on jump table operand");
457 case X86II::MO_NO_FLAG:
458 // FIXME: REMOVE EVENTUALLY.
459 if (TM.getRelocationModel() == Reloc::PIC_) {
460 assert(!Subtarget->isPICStyleStub() &&
461 !Subtarget->isPICStyleGOT() &&
462 "Should have operand flag!");
Chris Lattner2e845952009-06-24 19:44:36 +0000463 }
Chris Lattneradd6df82009-06-26 18:55:01 +0000464
465 break;
466 case X86II::MO_PIC_BASE_OFFSET:
467 O << '-';
468 PrintPICBaseSymbol();
469 break;
470 case X86II::MO_GOTOFF:
471 O << "@GOTOFF";
472 break;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000473 }
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000474
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000475 return;
476 }
477 case MachineOperand::MO_ConstantPoolIndex: {
478 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
479 if (!isMemOp) O << '$';
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000480 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
Chris Lattner6017d482007-12-30 23:10:15 +0000481 << MO.getIndex();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000482
Chris Lattner40f56902009-06-26 20:00:05 +0000483 printOffset(MO.getOffset());
484
Chris Lattner5062b3b2009-06-26 19:22:52 +0000485 switch (MO.getTargetFlags()) {
Chris Lattner40f56902009-06-26 20:00:05 +0000486 default:
Chris Lattner5062b3b2009-06-26 19:22:52 +0000487 assert(0 && "Unknown target flag on constant pool operand");
488 case X86II::MO_NO_FLAG:
489 // FIXME: REMOVE EVENTUALLY.
490 if (TM.getRelocationModel() == Reloc::PIC_) {
491 assert(!Subtarget->isPICStyleStub() &&
492 !Subtarget->isPICStyleGOT() &&
493 "Should have operand flag!");
494 }
495
496 break;
497 case X86II::MO_PIC_BASE_OFFSET:
498 O << '-';
499 PrintPICBaseSymbol();
500 break;
501 case X86II::MO_GOTOFF:
502 O << "@GOTOFF";
503 break;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000504 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000505
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506 return;
507 }
508 case MachineOperand::MO_GlobalAddress: {
Chris Lattner4b06b6b2009-06-21 01:27:55 +0000509 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000510 bool needCloseParen = false;
511
Anton Korobeynikovdd9dc5d2008-03-11 22:38:53 +0000512 const GlobalValue *GV = MO.getGlobal();
513 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
514 if (!GVar) {
Anton Korobeynikov85149302008-03-22 07:53:40 +0000515 // If GV is an alias then use the aliasee for determining
516 // thread-localness.
Anton Korobeynikovdd9dc5d2008-03-11 22:38:53 +0000517 if (const GlobalAlias *GA = dyn_cast<GlobalAlias>(GV))
Chris Lattner4b06b6b2009-06-21 01:27:55 +0000518 GVar =dyn_cast_or_null<GlobalVariable>(GA->resolveAliasedGlobal(false));
Anton Korobeynikovdd9dc5d2008-03-11 22:38:53 +0000519 }
520
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000521 bool isThreadLocal = GVar && GVar->isThreadLocal();
522
523 std::string Name = Mang->getValueName(GV);
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000524 decorateName(Name, GV);
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000525
Chris Lattner357a0ca2009-06-20 19:34:09 +0000526 if (!isMemOp)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000527 O << '$';
528 else if (Name[0] == '$') {
529 // The name begins with a dollar-sign. In order to avoid having it look
530 // like an integer immediate to the assembler, enclose it in parens.
531 O << '(';
532 needCloseParen = true;
533 }
534
Rafael Espindolae0ac18d2008-06-09 09:52:31 +0000535 if (shouldPrintStub(TM, Subtarget)) {
Chris Lattner50315f22009-06-25 17:58:52 +0000536 // DARWIN/X86-32 in != static mode.
537
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000538 // Link-once, declaration, or Weakly-linked global variables need
539 // non-lazily-resolved stubs
Duncan Sands19d161f2009-03-07 15:45:40 +0000540 if (GV->isDeclaration() || GV->isWeakForLinker()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000541 // Dynamically-resolved functions need a stub for the function.
Chris Lattner357a0ca2009-06-20 19:34:09 +0000542 if (GV->hasHiddenVisibility()) {
Evan Chenga65854f2008-12-05 01:06:39 +0000543 if (!GV->isDeclaration() && !GV->hasCommonLinkage())
544 // Definition is not definitely in the current translation unit.
545 O << Name;
546 else {
547 HiddenGVStubs.insert(Name);
548 printSuffixedName(Name, "$non_lazy_ptr");
549 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000550 } else {
551 GVStubs.insert(Name);
Dale Johannesena21b5202008-05-19 21:38:18 +0000552 printSuffixedName(Name, "$non_lazy_ptr");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553 }
554 } else {
555 if (GV->hasDLLImportLinkage())
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000556 O << "__imp_";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000557 O << Name;
558 }
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000559
Chris Lattner14f791a2009-06-24 19:19:16 +0000560 if (TM.getRelocationModel() == Reloc::PIC_) {
561 O << '-';
562 PrintPICBaseSymbol();
563 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564 } else {
Chris Lattner4b06b6b2009-06-21 01:27:55 +0000565 if (GV->hasDLLImportLinkage())
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000566 O << "__imp_";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000567 O << Name;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000568 }
569
Anton Korobeynikov440f23d2008-11-22 16:15:34 +0000570 printOffset(MO.getOffset());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000571
Chris Lattnerdabfe572009-06-21 02:22:53 +0000572 if (needCloseParen)
573 O << ')';
574
Chris Lattner40f56902009-06-26 20:00:05 +0000575 switch (MO.getTargetFlags()) {
576 default:
577 assert(0 && "Unknown target flag on GV operand");
578 case X86II::MO_NO_FLAG:
Chris Lattnerec7cfd42009-06-26 21:20:29 +0000579 // FIXME: RIP THIS CHECKING CODE OUT EVENTUALLY.
580 if (isThreadLocal)
581 assert(0 && "Not lowered right");
582 break;
Chris Lattner5bdaa522009-06-27 05:39:56 +0000583 case X86II::MO_TLSGD: O << "@TLSGD"; break;
584 case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break;
585 case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
586 case X86II::MO_TPOFF: O << "@TPOFF"; break;
587 case X86II::MO_NTPOFF: O << "@NTPOFF"; break;
588 case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break;
589 case X86II::MO_GOT: O << "@GOT"; break;
590 case X86II::MO_GOTOFF: O << "@GOTOFF"; break;
Chris Lattner40f56902009-06-26 20:00:05 +0000591 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000592 return;
593 }
594 case MachineOperand::MO_ExternalSymbol: {
Chris Lattnerce003822009-06-26 21:47:27 +0000595 /// NOTE: MO_ExternalSymbol in a non-pcrel_imm context is *only* generated
596 /// by _GLOBAL_OFFSET_TABLE_ on X86-32. All others are call operands, which
597 /// are pcrel_imm's.
598 assert(!Subtarget->is64Bit() && !Subtarget->isPICStyleRIPRel());
599 // These are never used as memory operands.
600 assert(!(Modifier && !strcmp(Modifier, "mem")));
601
602 O << '$';
603 O << TAI->getGlobalPrefix();
604 O << MO.getSymbolName();
605
Chris Lattner13d6c2d2009-06-25 17:38:33 +0000606 if (MO.getTargetFlags() == X86II::MO_GOT_ABSOLUTE_ADDRESS) {
607 O << " + [.-";
608 PrintPICBaseSymbol();
609 O << ']';
Chris Lattner20bdd192009-06-26 21:25:00 +0000610 } else {
611 assert(MO.getTargetFlags() == X86II::MO_NO_FLAG &&
612 "Unknown operand flag for external symbol");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000613 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000614 return;
615 }
616 default:
617 O << "<unknown operand type>"; return;
618 }
619}
620
621void X86ATTAsmPrinter::printSSECC(const MachineInstr *MI, unsigned Op) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000622 unsigned char value = MI->getOperand(Op).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000623 assert(value <= 7 && "Invalid ssecc argument!");
624 switch (value) {
625 case 0: O << "eq"; break;
626 case 1: O << "lt"; break;
627 case 2: O << "le"; break;
628 case 3: O << "unord"; break;
629 case 4: O << "neq"; break;
630 case 5: O << "nlt"; break;
631 case 6: O << "nle"; break;
632 case 7: O << "ord"; break;
633 }
634}
635
Rafael Espindolabca99f72009-04-08 21:14:34 +0000636void X86ATTAsmPrinter::printLeaMemReference(const MachineInstr *MI, unsigned Op,
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000637 const char *Modifier) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000638 MachineOperand BaseReg = MI->getOperand(Op);
639 MachineOperand IndexReg = MI->getOperand(Op+2);
640 const MachineOperand &DispSpec = MI->getOperand(Op+3);
641
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000642 if (DispSpec.isGlobal() ||
643 DispSpec.isCPI() ||
Dan Gohman96f096e2009-04-23 00:57:37 +0000644 DispSpec.isJTI() ||
645 DispSpec.isSymbol()) {
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000646 printOperand(MI, Op+3, "mem");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000647 } else {
Chris Lattnera96056a2007-12-30 20:49:49 +0000648 int DispVal = DispSpec.getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000649 if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg()))
650 O << DispVal;
651 }
652
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000653 if ((IndexReg.getReg() || BaseReg.getReg()) &&
654 (Modifier == 0 || strcmp(Modifier, "no-rip"))) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000655 unsigned ScaleVal = MI->getOperand(Op+1).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000656 unsigned BaseRegOperand = 0, IndexRegOperand = 2;
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000657
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000658 // There are cases where we can end up with ESP/RSP in the indexreg slot.
659 // If this happens, swap the base/index register to support assemblers that
660 // don't work when the index is *SP.
661 if (IndexReg.getReg() == X86::ESP || IndexReg.getReg() == X86::RSP) {
662 assert(ScaleVal == 1 && "Scale not supported for stack pointer!");
663 std::swap(BaseReg, IndexReg);
664 std::swap(BaseRegOperand, IndexRegOperand);
665 }
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000666
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000667 O << '(';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000668 if (BaseReg.getReg())
669 printOperand(MI, Op+BaseRegOperand, Modifier);
670
671 if (IndexReg.getReg()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000672 O << ',';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000673 printOperand(MI, Op+IndexRegOperand, Modifier);
674 if (ScaleVal != 1)
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000675 O << ',' << ScaleVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000676 }
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000677 O << ')';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000678 }
679}
680
Rafael Espindolabca99f72009-04-08 21:14:34 +0000681void X86ATTAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000682 const char *Modifier) {
Rafael Espindolabca99f72009-04-08 21:14:34 +0000683 assert(isMem(MI, Op) && "Invalid memory reference!");
684 MachineOperand Segment = MI->getOperand(Op+4);
685 if (Segment.getReg()) {
686 printOperand(MI, Op+4, Modifier);
687 O << ':';
688 }
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000689 printLeaMemReference(MI, Op, Modifier);
Rafael Espindolabca99f72009-04-08 21:14:34 +0000690}
691
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000692void X86ATTAsmPrinter::printPICJumpTableSetLabel(unsigned uid,
Evan Cheng6fb06762007-11-09 01:32:10 +0000693 const MachineBasicBlock *MBB) const {
694 if (!TAI->getSetDirective())
695 return;
Anton Korobeynikov5772c672007-11-14 09:18:41 +0000696
697 // We don't need .set machinery if we have GOT-style relocations
698 if (Subtarget->isPICStyleGOT())
699 return;
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000700
Evan Cheng6fb06762007-11-09 01:32:10 +0000701 O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
702 << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
Evan Cheng45c1edb2008-02-28 00:43:03 +0000703 printBasicBlockLabel(MBB, false, false, false);
Evan Cheng5da12252007-11-09 19:11:23 +0000704 if (Subtarget->isPICStyleRIPRel())
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000705 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Evan Cheng5da12252007-11-09 19:11:23 +0000706 << '_' << uid << '\n';
Chris Lattner14f791a2009-06-24 19:19:16 +0000707 else {
708 O << '-';
709 PrintPICBaseSymbol();
710 O << '\n';
711 }
Evan Cheng6fb06762007-11-09 01:32:10 +0000712}
713
Chris Lattner14f791a2009-06-24 19:19:16 +0000714
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000715void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
Chris Lattner14f791a2009-06-24 19:19:16 +0000716 PrintPICBaseSymbol();
717 O << '\n';
718 PrintPICBaseSymbol();
719 O << ':';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000720}
721
722
Anton Korobeynikov5772c672007-11-14 09:18:41 +0000723void X86ATTAsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
724 const MachineBasicBlock *MBB,
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000725 unsigned uid) const
726{
Anton Korobeynikov5772c672007-11-14 09:18:41 +0000727 const char *JTEntryDirective = MJTI->getEntrySize() == 4 ?
728 TAI->getData32bitsDirective() : TAI->getData64bitsDirective();
729
730 O << JTEntryDirective << ' ';
731
732 if (TM.getRelocationModel() == Reloc::PIC_) {
733 if (Subtarget->isPICStyleRIPRel() || Subtarget->isPICStyleStub()) {
734 O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
735 << '_' << uid << "_set_" << MBB->getNumber();
736 } else if (Subtarget->isPICStyleGOT()) {
Evan Cheng45c1edb2008-02-28 00:43:03 +0000737 printBasicBlockLabel(MBB, false, false, false);
Anton Korobeynikov5772c672007-11-14 09:18:41 +0000738 O << "@GOTOFF";
739 } else
740 assert(0 && "Don't know how to print MBB label for this PIC mode");
741 } else
Evan Cheng45c1edb2008-02-28 00:43:03 +0000742 printBasicBlockLabel(MBB, false, false, false);
Anton Korobeynikov5772c672007-11-14 09:18:41 +0000743}
744
Chris Lattner8bb96e42009-06-15 04:42:32 +0000745bool X86ATTAsmPrinter::printAsmMRegister(const MachineOperand &MO, char Mode) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000746 unsigned Reg = MO.getReg();
747 switch (Mode) {
748 default: return true; // Unknown mode.
749 case 'b': // Print QImode register
750 Reg = getX86SubSuperRegister(Reg, MVT::i8);
751 break;
752 case 'h': // Print QImode high register
753 Reg = getX86SubSuperRegister(Reg, MVT::i8, true);
754 break;
755 case 'w': // Print HImode register
756 Reg = getX86SubSuperRegister(Reg, MVT::i16);
757 break;
758 case 'k': // Print SImode register
759 Reg = getX86SubSuperRegister(Reg, MVT::i32);
760 break;
Chris Lattner1fabfaa2007-10-29 03:09:07 +0000761 case 'q': // Print DImode register
762 Reg = getX86SubSuperRegister(Reg, MVT::i64);
763 break;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000764 }
765
Evan Cheng00d04a72008-07-07 22:21:06 +0000766 O << '%'<< TRI->getAsmName(Reg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000767 return false;
768}
769
770/// PrintAsmOperand - Print out an operand for an inline asm expression.
771///
Anton Korobeynikov0737ff52008-06-28 11:09:48 +0000772bool X86ATTAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000773 unsigned AsmVariant,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000774 const char *ExtraCode) {
775 // Does this asm operand have a single letter operand modifier?
776 if (ExtraCode && ExtraCode[0]) {
777 if (ExtraCode[1] != 0) return true; // Unknown modifier.
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000778
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000779 switch (ExtraCode[0]) {
780 default: return true; // Unknown modifier.
781 case 'c': // Don't print "$" before a global var name or constant.
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000782 printOperand(MI, OpNo, "mem");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000783 return false;
784 case 'b': // Print QImode register
785 case 'h': // Print QImode high register
786 case 'w': // Print HImode register
787 case 'k': // Print SImode register
Chris Lattner1fabfaa2007-10-29 03:09:07 +0000788 case 'q': // Print DImode register
Dan Gohmanb9f4fa72008-10-03 15:45:36 +0000789 if (MI->getOperand(OpNo).isReg())
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000790 return printAsmMRegister(MI->getOperand(OpNo), ExtraCode[0]);
791 printOperand(MI, OpNo);
792 return false;
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000793
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000794 case 'P': // Don't print @PLT, but do print as memory.
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000795 printOperand(MI, OpNo, "mem");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000796 return false;
Evan Cheng9eba17b2009-06-26 22:00:19 +0000797
798 case 'n': { // Negate the immediate or print a '-' before the operand.
799 // Note: this is a temporary solution. It should be handled target
800 // independently as part of the 'MC' work.
801 const MachineOperand &MO = MI->getOperand(OpNo);
802 if (MO.isImm()) {
803 O << -MO.getImm();
804 return false;
805 }
806 O << '-';
807 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000808 }
809 }
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000810
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000811 printOperand(MI, OpNo);
812 return false;
813}
814
Anton Korobeynikov3ab60792008-06-28 11:10:06 +0000815bool X86ATTAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000816 unsigned OpNo,
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000817 unsigned AsmVariant,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000818 const char *ExtraCode) {
Chris Lattner1fabfaa2007-10-29 03:09:07 +0000819 if (ExtraCode && ExtraCode[0]) {
820 if (ExtraCode[1] != 0) return true; // Unknown modifier.
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000821
Chris Lattner1fabfaa2007-10-29 03:09:07 +0000822 switch (ExtraCode[0]) {
823 default: return true; // Unknown modifier.
824 case 'b': // Print QImode register
825 case 'h': // Print QImode high register
826 case 'w': // Print HImode register
827 case 'k': // Print SImode register
828 case 'q': // Print SImode register
829 // These only apply to registers, ignore on mem.
830 break;
Chris Lattnerd1595722009-01-23 22:33:40 +0000831 case 'P': // Don't print @PLT, but do print as memory.
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000832 printMemReference(MI, OpNo, "no-rip");
Chris Lattnerd1595722009-01-23 22:33:40 +0000833 return false;
Chris Lattner1fabfaa2007-10-29 03:09:07 +0000834 }
835 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000836 printMemReference(MI, OpNo);
837 return false;
838}
839
Chris Lattnerf5da5902009-06-20 07:03:18 +0000840static void lower_lea64_32mem(MCInst *MI, unsigned OpNo) {
841 // Convert registers in the addr mode according to subreg64.
842 for (unsigned i = 0; i != 4; ++i) {
843 if (!MI->getOperand(i).isReg()) continue;
844
845 unsigned Reg = MI->getOperand(i).getReg();
846 if (Reg == 0) continue;
847
848 MI->getOperand(i).setReg(getX86SubSuperRegister(Reg, MVT::i64));
849 }
850}
851
Bill Wendlingb3b11262009-02-06 21:45:08 +0000852/// printMachineInstruction -- Print out a single X86 LLVM instruction MI in
853/// AT&T syntax to the current output stream.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000854///
855void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
856 ++EmittedInsts;
857
Chris Lattner19b1bd52009-06-19 00:47:33 +0000858 if (NewAsmPrinter) {
Chris Lattnerf5da5902009-06-20 07:03:18 +0000859 if (MI->getOpcode() == TargetInstrInfo::INLINEASM) {
860 O << "\t";
861 printInlineAsm(MI);
862 return;
863 } else if (MI->isLabel()) {
864 printLabel(MI);
865 return;
866 } else if (MI->getOpcode() == TargetInstrInfo::DECLARE) {
867 printDeclare(MI);
868 return;
869 } else if (MI->getOpcode() == TargetInstrInfo::IMPLICIT_DEF) {
870 printImplicitDef(MI);
871 return;
872 }
873
Chris Lattnere67184e2009-06-19 23:59:57 +0000874 O << "NEW: ";
Chris Lattner19b1bd52009-06-19 00:47:33 +0000875 MCInst TmpInst;
Chris Lattner4ebc52f2009-06-20 00:49:26 +0000876
877 TmpInst.setOpcode(MI->getOpcode());
878
879 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
880 const MachineOperand &MO = MI->getOperand(i);
881
882 MCOperand MCOp;
883 if (MO.isReg()) {
884 MCOp.MakeReg(MO.getReg());
885 } else if (MO.isImm()) {
886 MCOp.MakeImm(MO.getImm());
Chris Lattnerf5da5902009-06-20 07:03:18 +0000887 } else if (MO.isMBB()) {
888 MCOp.MakeMBBLabel(getFunctionNumber(), MO.getMBB()->getNumber());
Chris Lattner4ebc52f2009-06-20 00:49:26 +0000889 } else {
890 assert(0 && "Unimp");
891 }
892
893 TmpInst.addOperand(MCOp);
894 }
895
Chris Lattner6b9f7742009-06-20 07:59:10 +0000896 switch (TmpInst.getOpcode()) {
897 case X86::LEA64_32r:
898 // Handle the 'subreg rewriting' for the lea64_32mem operand.
Chris Lattnerf5da5902009-06-20 07:03:18 +0000899 lower_lea64_32mem(&TmpInst, 1);
Chris Lattner6b9f7742009-06-20 07:59:10 +0000900 break;
Chris Lattner4ebc52f2009-06-20 00:49:26 +0000901 }
902
Chris Lattner19b1bd52009-06-19 00:47:33 +0000903 // FIXME: Convert TmpInst.
Chris Lattnere67184e2009-06-19 23:59:57 +0000904 printInstruction(&TmpInst);
905 O << "OLD: ";
Chris Lattner19b1bd52009-06-19 00:47:33 +0000906 }
907
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000908 // Call the autogenerated instruction printer routines.
909 printInstruction(MI);
910}
911
Devang Patelc20079e2009-06-20 01:00:07 +0000912/// doInitialization
913bool X86ATTAsmPrinter::doInitialization(Module &M) {
Chris Lattner7cf8daf2009-06-24 05:46:28 +0000914 if (NewAsmPrinter) {
915 Context = new MCContext();
916 // FIXME: Send this to "O" instead of outs(). For now, we force it to
917 // stdout to make it easy to compare.
918 Streamer = createAsmStreamer(*Context, outs());
919 }
920
Devang Patelc20079e2009-06-20 01:00:07 +0000921 return AsmPrinter::doInitialization(M);
922}
923
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000924void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000925 const TargetData *TD = TM.getTargetData();
926
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000927 if (!GVar->hasInitializer())
928 return; // External global require no code
929
930 // Check to see if this is a special global used by LLVM, if so, emit it.
931 if (EmitSpecialLLVMGlobal(GVar)) {
932 if (Subtarget->isTargetDarwin() &&
933 TM.getRelocationModel() == Reloc::Static) {
934 if (GVar->getName() == "llvm.global_ctors")
935 O << ".reference .constructors_used\n";
936 else if (GVar->getName() == "llvm.global_dtors")
937 O << ".reference .destructors_used\n";
938 }
939 return;
940 }
941
942 std::string name = Mang->getValueName(GVar);
943 Constant *C = GVar->getInitializer();
Devang Patel880595f2009-06-26 02:26:12 +0000944 if (isa<MDNode>(C) || isa<MDString>(C))
Devang Patelf667ab42009-06-25 00:47:42 +0000945 return;
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000946 const Type *Type = C->getType();
Duncan Sandsec4f97d2009-05-09 07:06:46 +0000947 unsigned Size = TD->getTypeAllocSize(Type);
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000948 unsigned Align = TD->getPreferredAlignmentLog(GVar);
949
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000950 printVisibility(name, GVar->getVisibility());
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000951
952 if (Subtarget->isTargetELF())
953 O << "\t.type\t" << name << ",@object\n";
954
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000955 SwitchToSection(TAI->SectionForGlobal(GVar));
Anton Korobeynikov7f3fa2c2008-07-09 13:27:16 +0000956
Evan Chengcf84b142009-02-18 02:19:52 +0000957 if (C->isNullValue() && !GVar->hasSection() &&
958 !(Subtarget->isTargetDarwin() &&
959 TAI->SectionKindForGlobal(GVar) == SectionKind::RODataMergeStr)) {
Anton Korobeynikov7f3fa2c2008-07-09 13:27:16 +0000960 // FIXME: This seems to be pretty darwin-specific
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000961 if (GVar->hasExternalLinkage()) {
962 if (const char *Directive = TAI->getZeroFillDirective()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000963 O << "\t.globl " << name << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000964 O << Directive << "__DATA, __common, " << name << ", "
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000965 << Size << ", " << Align << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000966 return;
967 }
968 }
969
970 if (!GVar->isThreadLocal() &&
Duncan Sands19d161f2009-03-07 15:45:40 +0000971 (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000972 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
Anton Korobeynikov7f3fa2c2008-07-09 13:27:16 +0000973
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000974 if (TAI->getLCOMMDirective() != NULL) {
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000975 if (GVar->hasLocalLinkage()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000976 O << TAI->getLCOMMDirective() << name << ',' << Size;
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000977 if (Subtarget->isTargetDarwin())
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000978 O << ',' << Align;
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000979 } else if (Subtarget->isTargetDarwin() && !GVar->hasCommonLinkage()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000980 O << "\t.globl " << name << '\n'
981 << TAI->getWeakDefDirective() << name << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000982 EmitAlignment(Align, GVar);
Evan Cheng11db8142009-03-24 00:17:40 +0000983 O << name << ":";
984 if (VerboseAsm) {
Evan Cheng4c7969e2009-03-25 01:08:42 +0000985 O << "\t\t\t\t" << TAI->getCommentString() << ' ';
Evan Cheng11db8142009-03-24 00:17:40 +0000986 PrintUnmangledNameSafely(GVar, O);
987 }
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000988 O << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000989 EmitGlobalConstant(C);
990 return;
991 } else {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000992 O << TAI->getCOMMDirective() << name << ',' << Size;
Anton Korobeynikov16876eb2008-08-08 18:25:52 +0000993 if (TAI->getCOMMDirectiveTakesAlignment())
994 O << ',' << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000995 }
996 } else {
997 if (!Subtarget->isTargetCygMing()) {
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000998 if (GVar->hasLocalLinkage())
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000999 O << "\t.local\t" << name << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001000 }
Dan Gohman12ebe3f2008-06-30 22:03:41 +00001001 O << TAI->getCOMMDirective() << name << ',' << Size;
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001002 if (TAI->getCOMMDirectiveTakesAlignment())
Dan Gohman12ebe3f2008-06-30 22:03:41 +00001003 O << ',' << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001004 }
Evan Cheng11db8142009-03-24 00:17:40 +00001005 if (VerboseAsm) {
1006 O << "\t\t" << TAI->getCommentString() << ' ';
1007 PrintUnmangledNameSafely(GVar, O);
1008 }
Dan Gohman12ebe3f2008-06-30 22:03:41 +00001009 O << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001010 return;
1011 }
1012 }
1013
1014 switch (GVar->getLinkage()) {
Duncan Sandsb95df792009-03-11 20:14:15 +00001015 case GlobalValue::CommonLinkage:
Duncan Sands19d161f2009-03-07 15:45:40 +00001016 case GlobalValue::LinkOnceAnyLinkage:
1017 case GlobalValue::LinkOnceODRLinkage:
1018 case GlobalValue::WeakAnyLinkage:
1019 case GlobalValue::WeakODRLinkage:
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001020 if (Subtarget->isTargetDarwin()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +00001021 O << "\t.globl " << name << '\n'
1022 << TAI->getWeakDefDirective() << name << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001023 } else if (Subtarget->isTargetCygMing()) {
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001024 O << "\t.globl\t" << name << "\n"
Dan Gohman12ebe3f2008-06-30 22:03:41 +00001025 "\t.linkonce same_size\n";
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001026 } else {
Dan Gohman12ebe3f2008-06-30 22:03:41 +00001027 O << "\t.weak\t" << name << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001028 }
1029 break;
Evan Cheng630c5612008-08-08 06:43:59 +00001030 case GlobalValue::DLLExportLinkage:
1031 case GlobalValue::AppendingLinkage:
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001032 // FIXME: appending linkage variables should go into a section of
1033 // their name or something. For now, just emit them as external.
Evan Cheng630c5612008-08-08 06:43:59 +00001034 case GlobalValue::ExternalLinkage:
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001035 // If external or appending, declare as a global symbol
Dan Gohman12ebe3f2008-06-30 22:03:41 +00001036 O << "\t.globl " << name << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001037 // FALL THROUGH
Rafael Espindolaa168fc92009-01-15 20:18:42 +00001038 case GlobalValue::PrivateLinkage:
Evan Cheng630c5612008-08-08 06:43:59 +00001039 case GlobalValue::InternalLinkage:
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001040 break;
Evan Cheng630c5612008-08-08 06:43:59 +00001041 default:
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001042 assert(0 && "Unknown linkage type!");
1043 }
1044
1045 EmitAlignment(Align, GVar);
Evan Cheng11db8142009-03-24 00:17:40 +00001046 O << name << ":";
1047 if (VerboseAsm){
Evan Cheng4c7969e2009-03-25 01:08:42 +00001048 O << "\t\t\t\t" << TAI->getCommentString() << ' ';
Evan Cheng11db8142009-03-24 00:17:40 +00001049 PrintUnmangledNameSafely(GVar, O);
1050 }
Dan Gohman12ebe3f2008-06-30 22:03:41 +00001051 O << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001052 if (TAI->hasDotTypeDotSizeDirective())
Dan Gohman12ebe3f2008-06-30 22:03:41 +00001053 O << "\t.size\t" << name << ", " << Size << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001054
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001055 EmitGlobalConstant(C);
1056}
1057
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001058bool X86ATTAsmPrinter::doFinalization(Module &M) {
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001059 // Print out module-level global variables here.
1060 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
Anton Korobeynikov0737ff52008-06-28 11:09:48 +00001061 I != E; ++I) {
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +00001062 printModuleLevelGV(I);
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001063
Anton Korobeynikov0737ff52008-06-28 11:09:48 +00001064 if (I->hasDLLExportLinkage())
1065 DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
Anton Korobeynikov480218b2009-02-21 11:53:32 +00001066 }
1067
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001068 if (Subtarget->isTargetDarwin()) {
1069 SwitchToDataSection("");
Chris Lattner2e860262009-06-24 18:24:09 +00001070
Chris Lattner8b4c72c2009-06-24 18:17:00 +00001071 // Add the (possibly multiple) personalities to the set of global value
1072 // stubs. Only referenced functions get into the Personalities list.
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001073 if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
Chris Lattner8b4c72c2009-06-24 18:17:00 +00001074 const std::vector<Function*> &Personalities = MMI->getPersonalities();
1075 for (unsigned i = 0, e = Personalities.size(); i != e; ++i) {
1076 if (Personalities[i] == 0)
Evan Cheng76443dc2008-07-08 00:55:58 +00001077 continue;
Chris Lattner8b4c72c2009-06-24 18:17:00 +00001078 std::string Name = Mang->getValueName(Personalities[i]);
1079 decorateName(Name, Personalities[i]);
1080 GVStubs.insert(Name);
Evan Cheng76443dc2008-07-08 00:55:58 +00001081 }
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001082 }
1083
Chris Lattner2e860262009-06-24 18:24:09 +00001084 // Output stubs for dynamically-linked functions
1085 if (!FnStubs.empty()) {
1086 for (StringSet<>::iterator I = FnStubs.begin(), E = FnStubs.end();
1087 I != E; ++I) {
1088 SwitchToDataSection("\t.section __IMPORT,__jump_table,symbol_stubs,"
1089 "self_modifying_code+pure_instructions,5", 0);
1090 const char *Name = I->getKeyData();
1091 printSuffixedName(Name, "$stub");
1092 O << ":\n"
1093 "\t.indirect_symbol " << Name << "\n"
1094 "\thlt ; hlt ; hlt ; hlt ; hlt\n";
1095 }
1096 O << '\n';
1097 }
1098
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001099 // Output stubs for external and common global variables.
Chris Lattner2e860262009-06-24 18:24:09 +00001100 if (!GVStubs.empty()) {
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001101 SwitchToDataSection(
1102 "\t.section __IMPORT,__pointers,non_lazy_symbol_pointers");
Chris Lattner2e860262009-06-24 18:24:09 +00001103 for (StringSet<>::iterator I = GVStubs.begin(), E = GVStubs.end();
1104 I != E; ++I) {
1105 const char *Name = I->getKeyData();
1106 printSuffixedName(Name, "$non_lazy_ptr");
1107 O << ":\n\t.indirect_symbol " << Name << "\n\t.long\t0\n";
1108 }
1109 }
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001110
Evan Chenga65854f2008-12-05 01:06:39 +00001111 if (!HiddenGVStubs.empty()) {
1112 SwitchToSection(TAI->getDataSection());
Chris Lattnerfadd47d2009-06-24 18:24:42 +00001113 EmitAlignment(2);
Chris Lattner2e860262009-06-24 18:24:09 +00001114 for (StringSet<>::iterator I = HiddenGVStubs.begin(),
1115 E = HiddenGVStubs.end(); I != E; ++I) {
Chris Lattner2e860262009-06-24 18:24:09 +00001116 const char *Name = I->getKeyData();
1117 printSuffixedName(Name, "$non_lazy_ptr");
1118 O << ":\n" << TAI->getData32bitsDirective() << Name << '\n';
1119 }
Evan Chenga65854f2008-12-05 01:06:39 +00001120 }
1121
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001122 // Funny Darwin hack: This flag tells the linker that no global symbols
1123 // contain code that falls through to other global symbols (e.g. the obvious
1124 // implementation of multiple entry points). If this doesn't occur, the
1125 // linker can safely perform dead code stripping. Since LLVM never
1126 // generates code that does this, it is always safe to set.
1127 O << "\t.subsections_via_symbols\n";
1128 } else if (Subtarget->isTargetCygMing()) {
1129 // Emit type information for external functions
1130 for (StringSet<>::iterator i = FnStubs.begin(), e = FnStubs.end();
1131 i != e; ++i) {
1132 O << "\t.def\t " << i->getKeyData()
1133 << ";\t.scl\t" << COFF::C_EXT
1134 << ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
1135 << ";\t.endef\n";
1136 }
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001137 }
Chris Lattner5ec2b662009-06-24 05:47:59 +00001138
Chris Lattnerdb191f02009-06-24 18:52:01 +00001139
1140 // Output linker support code for dllexported globals on windows.
1141 if (!DLLExportedGVs.empty()) {
1142 SwitchToDataSection(".section .drectve");
1143
1144 for (StringSet<>::iterator i = DLLExportedGVs.begin(),
1145 e = DLLExportedGVs.end(); i != e; ++i)
1146 O << "\t.ascii \" -export:" << i->getKeyData() << ",data\"\n";
1147 }
1148
1149 if (!DLLExportedFns.empty()) {
1150 SwitchToDataSection(".section .drectve");
1151
1152 for (StringSet<>::iterator i = DLLExportedFns.begin(),
1153 e = DLLExportedFns.end();
1154 i != e; ++i)
1155 O << "\t.ascii \" -export:" << i->getKeyData() << "\"\n";
1156 }
1157
Chris Lattnerdb191f02009-06-24 18:52:01 +00001158 // Do common shutdown.
1159 bool Changed = AsmPrinter::doFinalization(M);
Chris Lattner5ec2b662009-06-24 05:47:59 +00001160
Chris Lattner7cf8daf2009-06-24 05:46:28 +00001161 if (NewAsmPrinter) {
1162 Streamer->Finish();
1163
1164 delete Streamer;
1165 delete Context;
1166 Streamer = 0;
1167 Context = 0;
1168 }
1169
Chris Lattnerdb191f02009-06-24 18:52:01 +00001170 return Changed;
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001171}
1172
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001173// Include the auto-generated portion of the assembly writer.
1174#include "X86GenAsmWriter.inc"