blob: 97d1dd15de67ad11da7fe270aa81358ca638041e [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"
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +000026#include "llvm/Type.h"
27#include "llvm/ADT/Statistic.h"
28#include "llvm/ADT/StringExtras.h"
Dan Gohman2aa282f2009-08-13 01:36:44 +000029#include "llvm/Assembly/Writer.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 Lattner7f1ac7f2009-08-10 18:15:01 +000032#include "llvm/MC/MCSectionMachO.h"
Chris Lattner7cf8daf2009-06-24 05:46:28 +000033#include "llvm/MC/MCStreamer.h"
Bill Wendling4ff1cdf2009-02-18 23:12:06 +000034#include "llvm/CodeGen/DwarfWriter.h"
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +000035#include "llvm/CodeGen/MachineJumpTableInfo.h"
Chris Lattner19b1bd52009-06-19 00:47:33 +000036#include "llvm/Support/CommandLine.h"
Edwin Török675d5622009-07-11 20:10:48 +000037#include "llvm/Support/ErrorHandling.h"
David Greene302008d2009-07-14 20:18:05 +000038#include "llvm/Support/FormattedStream.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039#include "llvm/Support/Mangler.h"
40#include "llvm/Target/TargetAsmInfo.h"
Chris Lattnerc4c40a92009-07-28 03:13:23 +000041#include "llvm/Target/TargetLoweringObjectFile.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042#include "llvm/Target/TargetOptions.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000043using namespace llvm;
44
45STATISTIC(EmittedInsts, "Number of machine instrs printed");
46
Chris Lattner19b1bd52009-06-19 00:47:33 +000047static cl::opt<bool> NewAsmPrinter("experimental-asm-printer",
48 cl::Hidden);
49
Chris Lattner2e845952009-06-24 19:44:36 +000050//===----------------------------------------------------------------------===//
51// Primitive Helper Functions.
52//===----------------------------------------------------------------------===//
Chris Lattner14f791a2009-06-24 19:19:16 +000053
54void X86ATTAsmPrinter::PrintPICBaseSymbol() const {
Dan Gohmanf17a25c2007-07-18 16:29:46 +000055 if (Subtarget->isTargetDarwin())
Chris Lattner14f791a2009-06-24 19:19:16 +000056 O << "\"L" << getFunctionNumber() << "$pb\"";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000057 else if (Subtarget->isTargetELF())
Chris Lattner021ad452009-07-08 23:09:14 +000058 O << ".Lllvm$" << getFunctionNumber() << ".$piclabel";
Dan Gohmanf17a25c2007-07-18 16:29:46 +000059 else
Edwin Törökbd448e32009-07-14 16:55:14 +000060 llvm_unreachable("Don't know how to print PIC label!");
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061}
62
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +000063static X86MachineFunctionInfo calculateFunctionInfo(const Function *F,
64 const TargetData *TD) {
65 X86MachineFunctionInfo Info;
66 uint64_t Size = 0;
67
68 switch (F->getCallingConv()) {
69 case CallingConv::X86_StdCall:
70 Info.setDecorationStyle(StdCall);
71 break;
72 case CallingConv::X86_FastCall:
73 Info.setDecorationStyle(FastCall);
74 break;
75 default:
76 return Info;
77 }
78
79 unsigned argNum = 1;
80 for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
81 AI != AE; ++AI, ++argNum) {
82 const Type* Ty = AI->getType();
83
84 // 'Dereference' type in case of byval parameter attribute
Devang Pateld222f862008-09-25 21:00:45 +000085 if (F->paramHasAttr(argNum, Attribute::ByVal))
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +000086 Ty = cast<PointerType>(Ty)->getElementType();
87
88 // Size should be aligned to DWORD boundary
Duncan Sandsec4f97d2009-05-09 07:06:46 +000089 Size += ((TD->getTypeAllocSize(Ty) + 3)/4)*4;
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +000090 }
91
92 // We're not supporting tooooo huge arguments :)
93 Info.setBytesToPopOnReturn((unsigned int)Size);
94 return Info;
95}
96
Chris Lattner8cfe9142009-07-15 04:55:56 +000097/// DecorateCygMingName - Query FunctionInfoMap and use this information for
98/// various name decorations for Cygwin and MingW.
99void X86ATTAsmPrinter::DecorateCygMingName(std::string &Name,
100 const GlobalValue *GV) {
101 assert(Subtarget->isTargetCygMing() && "This is only for cygwin and mingw");
102
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000103 const Function *F = dyn_cast<Function>(GV);
104 if (!F) return;
105
Chris Lattnerb1f8d4f2009-07-10 21:57:21 +0000106 // Save function name for later type emission.
Chris Lattner8cfe9142009-07-15 04:55:56 +0000107 if (F->isDeclaration())
Chris Lattnerb1f8d4f2009-07-10 21:57:21 +0000108 CygMingStubs.insert(Name);
109
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000110 // 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
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000115
116 const X86MachineFunctionInfo *Info;
Chris Lattner8cfe9142009-07-15 04:55:56 +0000117
118 FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000119 if (info_item == FunctionInfoMap.end()) {
120 // Calculate apropriate function info and populate map
121 FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData());
122 Info = &FunctionInfoMap[F];
123 } else {
124 Info = &info_item->second;
125 }
126
127 const FunctionType *FT = F->getFunctionType();
128 switch (Info->getDecorationStyle()) {
129 case None:
130 break;
131 case StdCall:
132 // "Pure" variadic functions do not receive @0 suffix.
133 if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
134 (FT->getNumParams() == 1 && F->hasStructRetAttr()))
135 Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
136 break;
137 case FastCall:
138 // "Pure" variadic functions do not receive @0 suffix.
139 if (!FT->isVarArg() || (FT->getNumParams() == 0) ||
140 (FT->getNumParams() == 1 && F->hasStructRetAttr()))
141 Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
142
143 if (Name[0] == '_') {
144 Name[0] = '@';
145 } else {
146 Name = '@' + Name;
147 }
148 break;
149 default:
Edwin Törökbd448e32009-07-14 16:55:14 +0000150 llvm_unreachable("Unsupported DecorationStyle");
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000151 }
152}
153
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000154void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
Bill Wendling25a8ae32009-06-30 22:38:32 +0000155 unsigned FnAlign = MF.getAlignment();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000156 const Function *F = MF.getFunction();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000157
Chris Lattner8cfe9142009-07-15 04:55:56 +0000158 if (Subtarget->isTargetCygMing())
159 DecorateCygMingName(CurrentFnName, F);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000160
Chris Lattner2931fe42009-07-29 05:09:30 +0000161 SwitchToSection(getObjFileLowering().SectionForGlobal(F, Mang, TM));
Chris Lattner1b0ec672009-08-03 22:16:57 +0000162 EmitAlignment(FnAlign, F);
163
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000164 switch (F->getLinkage()) {
Edwin Törökbd448e32009-07-14 16:55:14 +0000165 default: llvm_unreachable("Unknown linkage type!");
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000166 case Function::InternalLinkage: // Symbols default to internal.
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000167 case Function::PrivateLinkage:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000168 break;
169 case Function::DLLExportLinkage:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000170 case Function::ExternalLinkage:
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000171 O << "\t.globl\t" << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000172 break;
Dale Johannesenf03574c2009-08-13 00:28:52 +0000173 case Function::LinkerPrivateLinkage:
Duncan Sands19d161f2009-03-07 15:45:40 +0000174 case Function::LinkOnceAnyLinkage:
175 case Function::LinkOnceODRLinkage:
176 case Function::WeakAnyLinkage:
177 case Function::WeakODRLinkage:
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000178 if (Subtarget->isTargetDarwin()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000179 O << "\t.globl\t" << CurrentFnName << '\n';
180 O << TAI->getWeakDefDirective() << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000181 } else if (Subtarget->isTargetCygMing()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000182 O << "\t.globl\t" << CurrentFnName << "\n"
183 "\t.linkonce discard\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000184 } else {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000185 O << "\t.weak\t" << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000186 }
187 break;
188 }
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000189
190 printVisibility(CurrentFnName, F->getVisibility());
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000191
192 if (Subtarget->isTargetELF())
Dan Gohman721e6582007-07-30 15:08:02 +0000193 O << "\t.type\t" << CurrentFnName << ",@function\n";
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000194 else if (Subtarget->isTargetCygMing()) {
195 O << "\t.def\t " << CurrentFnName
196 << ";\t.scl\t" <<
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000197 (F->hasInternalLinkage() ? COFF::C_STAT : COFF::C_EXT)
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000198 << ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
199 << ";\t.endef\n";
200 }
201
Dan Gohman2aa282f2009-08-13 01:36:44 +0000202 O << CurrentFnName << ':';
203 if (VerboseAsm) {
204 O.PadToColumn(TAI->getCommentColumn(), 1);
205 O << TAI->getCommentString() << ' ';
206 WriteAsOperand(O, F, /*PrintType=*/false, F->getParent());
207 }
208 O << '\n';
209
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000210 // Add some workaround for linkonce linkage on Cygwin\MinGW
211 if (Subtarget->isTargetCygMing() &&
Duncan Sands19d161f2009-03-07 15:45:40 +0000212 (F->hasLinkOnceLinkage() || F->hasWeakLinkage()))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000213 O << "Lllvm$workaround$fake$stub$" << CurrentFnName << ":\n";
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000214}
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000215
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000216/// runOnMachineFunction - This uses the printMachineInstruction()
217/// method to print assembly for each instruction.
218///
219bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
220 const Function *F = MF.getFunction();
Bill Wendlingb3b11262009-02-06 21:45:08 +0000221 this->MF = &MF;
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000222 unsigned CC = F->getCallingConv();
223
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000224 SetupMachineFunction(MF);
225 O << "\n\n";
226
227 // Populate function information map. Actually, We don't want to populate
228 // non-stdcall or non-fastcall functions' information right now.
229 if (CC == CallingConv::X86_StdCall || CC == CallingConv::X86_FastCall)
230 FunctionInfoMap[F] = *MF.getInfo<X86MachineFunctionInfo>();
231
232 // Print out constants referenced by the function
233 EmitConstantPool(MF.getConstantPool());
234
235 if (F->hasDLLExportLinkage())
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000236 DLLExportedFns.insert(Mang->getMangledName(F));
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000237
238 // Print the 'header' of function
239 emitFunctionHeader(MF);
240
241 // Emit pre-function debug and/or EH information.
242 if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
Devang Patelaa1e8432009-01-08 23:40:34 +0000243 DW->BeginFunction(&MF);
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000244
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000245 // Print out code for the function.
Dale Johannesenf35771f2008-04-08 00:37:56 +0000246 bool hasAnyRealCode = false;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000247 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
248 I != E; ++I) {
249 // Print a label for the basic block.
Dan Gohmand38f8762009-03-31 18:39:13 +0000250 if (!VerboseAsm && (I->pred_empty() || I->isOnlyReachableByFallthrough())) {
251 // This is an entry block or a block that's only reachable via a
252 // fallthrough edge. In non-VerboseAsm mode, don't print the label.
253 } else {
Evan Cheng11db8142009-03-24 00:17:40 +0000254 printBasicBlockLabel(I, true, true, VerboseAsm);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000255 O << '\n';
256 }
Bill Wendlingb5880a72008-01-26 09:03:52 +0000257 for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
258 II != IE; ++II) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000259 // Print the assembly for the instruction.
Dan Gohmanfa607c92008-07-01 00:05:16 +0000260 if (!II->isLabel())
Dale Johannesenf35771f2008-04-08 00:37:56 +0000261 hasAnyRealCode = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000262 printMachineInstruction(II);
263 }
264 }
265
Dale Johannesenf35771f2008-04-08 00:37:56 +0000266 if (Subtarget->isTargetDarwin() && !hasAnyRealCode) {
267 // If the function is empty, then we need to emit *something*. Otherwise,
268 // the function's label might be associated with something that it wasn't
269 // meant to be associated with. We emit a noop in this situation.
270 // We are assuming inline asms are code.
271 O << "\tnop\n";
272 }
273
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000274 if (TAI->hasDotTypeDotSizeDirective())
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000275 O << "\t.size\t" << CurrentFnName << ", .-" << CurrentFnName << '\n';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000276
Anton Korobeynikov30948e32008-06-28 11:09:01 +0000277 // Emit post-function debug information.
Devang Patel4d438ce2009-06-19 23:21:20 +0000278 if (TAI->doesSupportDebugInformation() || TAI->doesSupportExceptionHandling())
Devang Patelaa1e8432009-01-08 23:40:34 +0000279 DW->EndFunction(&MF);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000280
281 // Print out jump tables referenced by the function.
282 EmitJumpTableInfo(MF.getJumpTableInfo(), MF);
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000283
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000284 // We didn't modify anything.
285 return false;
286}
287
Chris Lattnerae8f9592009-07-13 21:53:19 +0000288/// printSymbolOperand - Print a raw symbol reference operand. This handles
289/// jump tables, constant pools, global address and external symbols, all of
290/// which print to a label with various suffixes for relocation types etc.
Chris Lattner207a0ca2009-07-13 21:41:08 +0000291void X86ATTAsmPrinter::printSymbolOperand(const MachineOperand &MO) {
292 switch (MO.getType()) {
Edwin Törökbd448e32009-07-14 16:55:14 +0000293 default: llvm_unreachable("unknown symbol type!");
Chris Lattnera45d3aa2009-07-13 22:28:21 +0000294 case MachineOperand::MO_JumpTableIndex:
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000295 O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() << '_'
Chris Lattner6017d482007-12-30 23:10:15 +0000296 << MO.getIndex();
Chris Lattner797a0782009-06-27 05:46:24 +0000297 break;
Chris Lattnera45d3aa2009-07-13 22:28:21 +0000298 case MachineOperand::MO_ConstantPoolIndex:
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000299 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
Chris Lattner6017d482007-12-30 23:10:15 +0000300 << MO.getIndex();
Chris Lattner40f56902009-06-26 20:00:05 +0000301 printOffset(MO.getOffset());
Chris Lattner797a0782009-06-27 05:46:24 +0000302 break;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000303 case MachineOperand::MO_GlobalAddress: {
Anton Korobeynikovdd9dc5d2008-03-11 22:38:53 +0000304 const GlobalValue *GV = MO.getGlobal();
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000305
306 const char *Suffix = "";
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000307 if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
308 Suffix = "$stub";
309 else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
310 MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE ||
311 MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
Chris Lattnerbd5f2922009-07-15 01:53:36 +0000312 MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000313 Suffix = "$non_lazy_ptr";
314
Chris Lattnerbd5f2922009-07-15 01:53:36 +0000315 std::string Name = Mang->getMangledName(GV, Suffix, Suffix[0] != '\0');
Chris Lattner8cfe9142009-07-15 04:55:56 +0000316 if (Subtarget->isTargetCygMing())
317 DecorateCygMingName(Name, GV);
Chris Lattner207a0ca2009-07-13 21:41:08 +0000318
Chris Lattner0cc2b792009-07-09 05:42:07 +0000319 // Handle dllimport linkage.
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000320 if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
321 Name = "__imp_" + Name;
Daniel Dunbarc5c467c2009-07-14 15:57:55 +0000322
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000323 if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
324 MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE)
325 GVStubs[Name] = Mang->getMangledName(GV);
326 else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
327 MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
328 HiddenGVStubs[Name] = Mang->getMangledName(GV);
329 else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
330 FnStubs[Name] = Mang->getMangledName(GV);
331
332 // If the name begins with a dollar-sign, enclose it in parens. We do this
333 // to avoid having it look like an integer immediate to the assembler.
334 if (Name[0] == '$')
335 O << '(' << Name << ')';
336 else
337 O << Name;
Chris Lattnerdabfe572009-06-21 02:22:53 +0000338
Chris Lattner0cc2b792009-07-09 05:42:07 +0000339 printOffset(MO.getOffset());
Chris Lattner797a0782009-06-27 05:46:24 +0000340 break;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000341 }
Chris Lattnera45d3aa2009-07-13 22:28:21 +0000342 case MachineOperand::MO_ExternalSymbol: {
Chris Lattner08be7a72009-07-15 03:01:23 +0000343 std::string Name = Mang->makeNameProper(MO.getSymbolName());
Daniel Dunbarc5c467c2009-07-14 15:57:55 +0000344 if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000345 FnStubs[Name+"$stub"] = Name;
346 Name += "$stub";
Daniel Dunbarc5c467c2009-07-14 15:57:55 +0000347 }
348
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000349 // If the name begins with a dollar-sign, enclose it in parens. We do this
350 // to avoid having it look like an integer immediate to the assembler.
351 if (Name[0] == '$')
352 O << '(' << Name << ')';
353 else
354 O << Name;
Chris Lattner797a0782009-06-27 05:46:24 +0000355 break;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000356 }
Chris Lattnera45d3aa2009-07-13 22:28:21 +0000357 }
Chris Lattner797a0782009-06-27 05:46:24 +0000358
359 switch (MO.getTargetFlags()) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000360 default:
Edwin Törökbd448e32009-07-14 16:55:14 +0000361 llvm_unreachable("Unknown target flag on GV operand");
Chris Lattner9ab4e662009-07-09 00:58:53 +0000362 case X86II::MO_NO_FLAG: // No flag.
Chris Lattnera3bde622009-07-09 06:59:17 +0000363 break;
364 case X86II::MO_DARWIN_NONLAZY:
365 case X86II::MO_DARWIN_HIDDEN_NONLAZY:
366 case X86II::MO_DLLIMPORT:
Chris Lattnere1cf8a12009-07-13 22:07:30 +0000367 case X86II::MO_DARWIN_STUB:
Chris Lattnera3bde622009-07-09 06:59:17 +0000368 // These affect the name of the symbol, not any suffix.
Chris Lattner797a0782009-06-27 05:46:24 +0000369 break;
370 case X86II::MO_GOT_ABSOLUTE_ADDRESS:
371 O << " + [.-";
372 PrintPICBaseSymbol();
373 O << ']';
374 break;
375 case X86II::MO_PIC_BASE_OFFSET:
Chris Lattnera3bde622009-07-09 06:59:17 +0000376 case X86II::MO_DARWIN_NONLAZY_PIC_BASE:
377 case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE:
Chris Lattner797a0782009-06-27 05:46:24 +0000378 O << '-';
379 PrintPICBaseSymbol();
380 break;
381 case X86II::MO_TLSGD: O << "@TLSGD"; break;
382 case X86II::MO_GOTTPOFF: O << "@GOTTPOFF"; break;
383 case X86II::MO_INDNTPOFF: O << "@INDNTPOFF"; break;
384 case X86II::MO_TPOFF: O << "@TPOFF"; break;
385 case X86II::MO_NTPOFF: O << "@NTPOFF"; break;
386 case X86II::MO_GOTPCREL: O << "@GOTPCREL"; break;
387 case X86II::MO_GOT: O << "@GOT"; break;
388 case X86II::MO_GOTOFF: O << "@GOTOFF"; break;
Chris Lattnere1cf8a12009-07-13 22:07:30 +0000389 case X86II::MO_PLT: O << "@PLT"; break;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000390 }
391}
392
Chris Lattnerae8f9592009-07-13 21:53:19 +0000393/// print_pcrel_imm - This is used to print an immediate value that ends up
394/// being encoded as a pc-relative value. These print slightly differently, for
395/// example, a $ is not emitted.
396void X86ATTAsmPrinter::print_pcrel_imm(const MachineInstr *MI, unsigned OpNo) {
397 const MachineOperand &MO = MI->getOperand(OpNo);
398 switch (MO.getType()) {
Edwin Törökbd448e32009-07-14 16:55:14 +0000399 default: llvm_unreachable("Unknown pcrel immediate operand");
Chris Lattnerae8f9592009-07-13 21:53:19 +0000400 case MachineOperand::MO_Immediate:
401 O << MO.getImm();
402 return;
403 case MachineOperand::MO_MachineBasicBlock:
Dan Gohman2aa282f2009-08-13 01:36:44 +0000404 printBasicBlockLabel(MO.getMBB(), false, false, false);
Chris Lattnerae8f9592009-07-13 21:53:19 +0000405 return;
Chris Lattnere1cf8a12009-07-13 22:07:30 +0000406 case MachineOperand::MO_GlobalAddress:
Chris Lattnere1cf8a12009-07-13 22:07:30 +0000407 case MachineOperand::MO_ExternalSymbol:
408 printSymbolOperand(MO);
Chris Lattnerae8f9592009-07-13 21:53:19 +0000409 return;
410 }
Chris Lattnerae8f9592009-07-13 21:53:19 +0000411}
412
413
Chris Lattner207a0ca2009-07-13 21:41:08 +0000414
415void X86ATTAsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNo,
416 const char *Modifier) {
417 const MachineOperand &MO = MI->getOperand(OpNo);
418 switch (MO.getType()) {
Edwin Törökbd448e32009-07-14 16:55:14 +0000419 default: llvm_unreachable("unknown operand type!");
Chris Lattner207a0ca2009-07-13 21:41:08 +0000420 case MachineOperand::MO_Register: {
421 assert(TargetRegisterInfo::isPhysicalRegister(MO.getReg()) &&
422 "Virtual registers should not make it this far!");
423 O << '%';
424 unsigned Reg = MO.getReg();
425 if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
Owen Andersonac9de032009-08-10 22:56:29 +0000426 EVT VT = (strcmp(Modifier+6,"64") == 0) ?
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000427 MVT::i64 : ((strcmp(Modifier+6, "32") == 0) ? MVT::i32 :
428 ((strcmp(Modifier+6,"16") == 0) ? MVT::i16 : MVT::i8));
Chris Lattner207a0ca2009-07-13 21:41:08 +0000429 Reg = getX86SubSuperRegister(Reg, VT);
430 }
431 O << TRI->getAsmName(Reg);
432 return;
433 }
434
435 case MachineOperand::MO_Immediate:
436 O << '$' << MO.getImm();
437 return;
438
439 case MachineOperand::MO_JumpTableIndex:
440 case MachineOperand::MO_ConstantPoolIndex:
441 case MachineOperand::MO_GlobalAddress:
442 case MachineOperand::MO_ExternalSymbol: {
Chris Lattnerb6047e62009-07-13 21:48:33 +0000443 O << '$';
Chris Lattner207a0ca2009-07-13 21:41:08 +0000444 printSymbolOperand(MO);
445 break;
446 }
447 }
448}
449
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000450void X86ATTAsmPrinter::printSSECC(const MachineInstr *MI, unsigned Op) {
Chris Lattnera96056a2007-12-30 20:49:49 +0000451 unsigned char value = MI->getOperand(Op).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000452 assert(value <= 7 && "Invalid ssecc argument!");
453 switch (value) {
454 case 0: O << "eq"; break;
455 case 1: O << "lt"; break;
456 case 2: O << "le"; break;
457 case 3: O << "unord"; break;
458 case 4: O << "neq"; break;
459 case 5: O << "nlt"; break;
460 case 6: O << "nle"; break;
461 case 7: O << "ord"; break;
462 }
463}
464
Rafael Espindolabca99f72009-04-08 21:14:34 +0000465void X86ATTAsmPrinter::printLeaMemReference(const MachineInstr *MI, unsigned Op,
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000466 const char *Modifier) {
Chris Lattner791fd482009-07-09 00:27:29 +0000467 const MachineOperand &BaseReg = MI->getOperand(Op);
468 const MachineOperand &IndexReg = MI->getOperand(Op+2);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000469 const MachineOperand &DispSpec = MI->getOperand(Op+3);
470
Chris Lattner791fd482009-07-09 00:27:29 +0000471 // If we really don't want to print out (rip), don't.
472 bool HasBaseReg = BaseReg.getReg() != 0;
473 if (HasBaseReg && Modifier && !strcmp(Modifier, "no-rip") &&
474 BaseReg.getReg() == X86::RIP)
475 HasBaseReg = false;
Chris Lattnerec112ef2009-07-09 00:32:12 +0000476
477 // HasParenPart - True if we will print out the () part of the mem ref.
478 bool HasParenPart = IndexReg.getReg() || HasBaseReg;
479
480 if (DispSpec.isImm()) {
481 int DispVal = DispSpec.getImm();
482 if (DispVal || !HasParenPart)
483 O << DispVal;
484 } else {
485 assert(DispSpec.isGlobal() || DispSpec.isCPI() ||
486 DispSpec.isJTI() || DispSpec.isSymbol());
Chris Lattnerb6047e62009-07-13 21:48:33 +0000487 printSymbolOperand(MI->getOperand(Op+3));
Chris Lattnerec112ef2009-07-09 00:32:12 +0000488 }
489
490 if (HasParenPart) {
Chris Lattner791fd482009-07-09 00:27:29 +0000491 assert(IndexReg.getReg() != X86::ESP &&
492 "X86 doesn't allow scaling by ESP");
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000493
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000494 O << '(';
Chris Lattner791fd482009-07-09 00:27:29 +0000495 if (HasBaseReg)
496 printOperand(MI, Op, Modifier);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497
498 if (IndexReg.getReg()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000499 O << ',';
Chris Lattner791fd482009-07-09 00:27:29 +0000500 printOperand(MI, Op+2, Modifier);
501 unsigned ScaleVal = MI->getOperand(Op+1).getImm();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000502 if (ScaleVal != 1)
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000503 O << ',' << ScaleVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000504 }
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000505 O << ')';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506 }
507}
508
Rafael Espindolabca99f72009-04-08 21:14:34 +0000509void X86ATTAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000510 const char *Modifier) {
Rafael Espindolabca99f72009-04-08 21:14:34 +0000511 assert(isMem(MI, Op) && "Invalid memory reference!");
Chris Lattner791fd482009-07-09 00:27:29 +0000512 const MachineOperand &Segment = MI->getOperand(Op+4);
Rafael Espindolabca99f72009-04-08 21:14:34 +0000513 if (Segment.getReg()) {
Chris Lattner791fd482009-07-09 00:27:29 +0000514 printOperand(MI, Op+4, Modifier);
515 O << ':';
516 }
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000517 printLeaMemReference(MI, Op, Modifier);
Rafael Espindolabca99f72009-04-08 21:14:34 +0000518}
519
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000520void X86ATTAsmPrinter::printPICJumpTableSetLabel(unsigned uid,
Evan Cheng6fb06762007-11-09 01:32:10 +0000521 const MachineBasicBlock *MBB) const {
522 if (!TAI->getSetDirective())
523 return;
Anton Korobeynikov5772c672007-11-14 09:18:41 +0000524
525 // We don't need .set machinery if we have GOT-style relocations
526 if (Subtarget->isPICStyleGOT())
527 return;
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000528
Evan Cheng6fb06762007-11-09 01:32:10 +0000529 O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
530 << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
Evan Cheng45c1edb2008-02-28 00:43:03 +0000531 printBasicBlockLabel(MBB, false, false, false);
Evan Cheng5da12252007-11-09 19:11:23 +0000532 if (Subtarget->isPICStyleRIPRel())
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000533 O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Evan Cheng5da12252007-11-09 19:11:23 +0000534 << '_' << uid << '\n';
Chris Lattner14f791a2009-06-24 19:19:16 +0000535 else {
536 O << '-';
537 PrintPICBaseSymbol();
538 O << '\n';
539 }
Evan Cheng6fb06762007-11-09 01:32:10 +0000540}
541
Chris Lattner14f791a2009-06-24 19:19:16 +0000542
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000543void X86ATTAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
Chris Lattner14f791a2009-06-24 19:19:16 +0000544 PrintPICBaseSymbol();
545 O << '\n';
546 PrintPICBaseSymbol();
547 O << ':';
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000548}
549
550
Anton Korobeynikov5772c672007-11-14 09:18:41 +0000551void X86ATTAsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
552 const MachineBasicBlock *MBB,
Chris Lattnerb1f8d4f2009-07-10 21:57:21 +0000553 unsigned uid) const {
Anton Korobeynikov5772c672007-11-14 09:18:41 +0000554 const char *JTEntryDirective = MJTI->getEntrySize() == 4 ?
555 TAI->getData32bitsDirective() : TAI->getData64bitsDirective();
556
557 O << JTEntryDirective << ' ';
558
Chris Lattner2e9393c2009-07-10 21:00:45 +0000559 if (Subtarget->isPICStyleRIPRel() || Subtarget->isPICStyleStubPIC()) {
Chris Lattner4a948932009-07-10 20:47:30 +0000560 O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
561 << '_' << uid << "_set_" << MBB->getNumber();
562 } else if (Subtarget->isPICStyleGOT()) {
563 printBasicBlockLabel(MBB, false, false, false);
564 O << "@GOTOFF";
Anton Korobeynikov5772c672007-11-14 09:18:41 +0000565 } else
Evan Cheng45c1edb2008-02-28 00:43:03 +0000566 printBasicBlockLabel(MBB, false, false, false);
Anton Korobeynikov5772c672007-11-14 09:18:41 +0000567}
568
Chris Lattner8bb96e42009-06-15 04:42:32 +0000569bool X86ATTAsmPrinter::printAsmMRegister(const MachineOperand &MO, char Mode) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000570 unsigned Reg = MO.getReg();
571 switch (Mode) {
572 default: return true; // Unknown mode.
573 case 'b': // Print QImode register
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000574 Reg = getX86SubSuperRegister(Reg, MVT::i8);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000575 break;
576 case 'h': // Print QImode high register
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000577 Reg = getX86SubSuperRegister(Reg, MVT::i8, true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000578 break;
579 case 'w': // Print HImode register
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000580 Reg = getX86SubSuperRegister(Reg, MVT::i16);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000581 break;
582 case 'k': // Print SImode register
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000583 Reg = getX86SubSuperRegister(Reg, MVT::i32);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000584 break;
Chris Lattner1fabfaa2007-10-29 03:09:07 +0000585 case 'q': // Print DImode register
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000586 Reg = getX86SubSuperRegister(Reg, MVT::i64);
Chris Lattner1fabfaa2007-10-29 03:09:07 +0000587 break;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000588 }
589
Evan Cheng00d04a72008-07-07 22:21:06 +0000590 O << '%'<< TRI->getAsmName(Reg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000591 return false;
592}
593
594/// PrintAsmOperand - Print out an operand for an inline asm expression.
595///
Anton Korobeynikov0737ff52008-06-28 11:09:48 +0000596bool X86ATTAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000597 unsigned AsmVariant,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000598 const char *ExtraCode) {
599 // Does this asm operand have a single letter operand modifier?
600 if (ExtraCode && ExtraCode[0]) {
601 if (ExtraCode[1] != 0) return true; // Unknown modifier.
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000602
Chris Lattnerb6047e62009-07-13 21:48:33 +0000603 const MachineOperand &MO = MI->getOperand(OpNo);
604
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000605 switch (ExtraCode[0]) {
606 default: return true; // Unknown modifier.
607 case 'c': // Don't print "$" before a global var name or constant.
Chris Lattnerb6047e62009-07-13 21:48:33 +0000608 if (MO.isImm())
609 O << MO.getImm();
610 else if (MO.isGlobal() || MO.isCPI() || MO.isJTI() || MO.isSymbol())
611 printSymbolOperand(MO);
Chris Lattner207a0ca2009-07-13 21:41:08 +0000612 else
Chris Lattnerb6047e62009-07-13 21:48:33 +0000613 printOperand(MI, OpNo);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000614 return false;
Dale Johannesen7ad82e52009-07-09 20:06:27 +0000615
616 case 'A': // Print '*' before a register (it must be a register)
Chris Lattnerb6047e62009-07-13 21:48:33 +0000617 if (MO.isReg()) {
Dale Johannesen7ad82e52009-07-09 20:06:27 +0000618 O << '*';
619 printOperand(MI, OpNo);
620 return false;
621 }
622 return true;
623
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000624 case 'b': // Print QImode register
625 case 'h': // Print QImode high register
626 case 'w': // Print HImode register
627 case 'k': // Print SImode register
Chris Lattner1fabfaa2007-10-29 03:09:07 +0000628 case 'q': // Print DImode register
Chris Lattnerb6047e62009-07-13 21:48:33 +0000629 if (MO.isReg())
630 return printAsmMRegister(MO, ExtraCode[0]);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000631 printOperand(MI, OpNo);
632 return false;
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000633
Dale Johannesen375b88b2009-07-07 23:28:22 +0000634 case 'P': // This is the operand of a call, treat specially.
Chris Lattner85dbcd52009-07-09 00:39:19 +0000635 print_pcrel_imm(MI, OpNo);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000636 return false;
Evan Cheng9eba17b2009-06-26 22:00:19 +0000637
Chris Lattnerb6047e62009-07-13 21:48:33 +0000638 case 'n': // Negate the immediate or print a '-' before the operand.
Evan Cheng9eba17b2009-06-26 22:00:19 +0000639 // Note: this is a temporary solution. It should be handled target
640 // independently as part of the 'MC' work.
Evan Cheng9eba17b2009-06-26 22:00:19 +0000641 if (MO.isImm()) {
642 O << -MO.getImm();
643 return false;
644 }
645 O << '-';
646 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000647 }
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000648
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000649 printOperand(MI, OpNo);
650 return false;
651}
652
Anton Korobeynikov3ab60792008-06-28 11:10:06 +0000653bool X86ATTAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000654 unsigned OpNo,
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000655 unsigned AsmVariant,
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000656 const char *ExtraCode) {
Chris Lattner1fabfaa2007-10-29 03:09:07 +0000657 if (ExtraCode && ExtraCode[0]) {
658 if (ExtraCode[1] != 0) return true; // Unknown modifier.
Anton Korobeynikovd97b85e2008-06-28 11:08:09 +0000659
Chris Lattner1fabfaa2007-10-29 03:09:07 +0000660 switch (ExtraCode[0]) {
661 default: return true; // Unknown modifier.
662 case 'b': // Print QImode register
663 case 'h': // Print QImode high register
664 case 'w': // Print HImode register
665 case 'k': // Print SImode register
666 case 'q': // Print SImode register
667 // These only apply to registers, ignore on mem.
668 break;
Chris Lattnerd1595722009-01-23 22:33:40 +0000669 case 'P': // Don't print @PLT, but do print as memory.
Chris Lattnerdc6fc472009-06-27 04:16:01 +0000670 printMemReference(MI, OpNo, "no-rip");
Chris Lattnerd1595722009-01-23 22:33:40 +0000671 return false;
Chris Lattner1fabfaa2007-10-29 03:09:07 +0000672 }
673 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000674 printMemReference(MI, OpNo);
675 return false;
676}
677
Chris Lattnerf5da5902009-06-20 07:03:18 +0000678static void lower_lea64_32mem(MCInst *MI, unsigned OpNo) {
679 // Convert registers in the addr mode according to subreg64.
680 for (unsigned i = 0; i != 4; ++i) {
681 if (!MI->getOperand(i).isReg()) continue;
682
683 unsigned Reg = MI->getOperand(i).getReg();
684 if (Reg == 0) continue;
685
Owen Anderson36e3a6e2009-08-11 20:47:22 +0000686 MI->getOperand(i).setReg(getX86SubSuperRegister(Reg, MVT::i64));
Chris Lattnerf5da5902009-06-20 07:03:18 +0000687 }
688}
689
Chris Lattner8fffd452009-08-16 03:12:25 +0000690/// LowerGlobalAddressOperand - Lower an MO_GlobalAddress operand to an
691/// MCOperand.
692MCOperand X86ATTAsmPrinter::LowerGlobalAddressOperand(const MachineOperand &MO){
693 //OutContext
694 const GlobalValue *GV = MO.getGlobal();
695
696 const char *Suffix = "";
697 if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
698 Suffix = "$stub";
699 else if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
700 MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE ||
701 MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
702 MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
703 Suffix = "$non_lazy_ptr";
704
705 std::string Name = Mang->getMangledName(GV, Suffix, Suffix[0] != '\0');
706 if (Subtarget->isTargetCygMing())
707 DecorateCygMingName(Name, GV);
708
709 // Handle dllimport linkage.
710 if (MO.getTargetFlags() == X86II::MO_DLLIMPORT)
711 Name = "__imp_" + Name;
712
713 if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
714 MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE)
715 GVStubs[Name] = Mang->getMangledName(GV);
716 else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY ||
717 MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE)
718 HiddenGVStubs[Name] = Mang->getMangledName(GV);
719 else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB)
720 FnStubs[Name] = Mang->getMangledName(GV);
721
722 // Create a symbol for the name.
723 MCSymbol *Sym = OutContext.GetOrCreateSymbol(Name);
724 return MCOperand::CreateMCValue(MCValue::get(Sym, 0, MO.getOffset()));
725}
726
Bill Wendlingb3b11262009-02-06 21:45:08 +0000727/// printMachineInstruction -- Print out a single X86 LLVM instruction MI in
728/// AT&T syntax to the current output stream.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000729///
730void X86ATTAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
731 ++EmittedInsts;
732
Chris Lattner19b1bd52009-06-19 00:47:33 +0000733 if (NewAsmPrinter) {
Chris Lattnerf5da5902009-06-20 07:03:18 +0000734 if (MI->getOpcode() == TargetInstrInfo::INLINEASM) {
735 O << "\t";
736 printInlineAsm(MI);
737 return;
738 } else if (MI->isLabel()) {
739 printLabel(MI);
740 return;
741 } else if (MI->getOpcode() == TargetInstrInfo::DECLARE) {
742 printDeclare(MI);
743 return;
744 } else if (MI->getOpcode() == TargetInstrInfo::IMPLICIT_DEF) {
745 printImplicitDef(MI);
746 return;
747 }
748
Chris Lattnere67184e2009-06-19 23:59:57 +0000749 O << "NEW: ";
Chris Lattner19b1bd52009-06-19 00:47:33 +0000750 MCInst TmpInst;
Chris Lattner4ebc52f2009-06-20 00:49:26 +0000751
752 TmpInst.setOpcode(MI->getOpcode());
753
754 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
755 const MachineOperand &MO = MI->getOperand(i);
756
757 MCOperand MCOp;
Chris Lattner8fffd452009-08-16 03:12:25 +0000758 switch (MO.getType()) {
759 default:
760 O.flush();
761 errs() << "Cannot lower operand #" << i << " of :" << *MI;
762 llvm_unreachable("Unimp");
763 case MachineOperand::MO_Register:
Daniel Dunbar511f4492009-08-02 00:09:22 +0000764 MCOp = MCOperand::CreateReg(MO.getReg());
Chris Lattner8fffd452009-08-16 03:12:25 +0000765 break;
766 case MachineOperand::MO_Immediate:
Daniel Dunbar511f4492009-08-02 00:09:22 +0000767 MCOp = MCOperand::CreateImm(MO.getImm());
Chris Lattner8fffd452009-08-16 03:12:25 +0000768 break;
769 case MachineOperand::MO_MachineBasicBlock:
Daniel Dunbar511f4492009-08-02 00:09:22 +0000770 MCOp = MCOperand::CreateMBBLabel(getFunctionNumber(),
771 MO.getMBB()->getNumber());
Chris Lattner8fffd452009-08-16 03:12:25 +0000772 break;
773 case MachineOperand::MO_GlobalAddress:
774 MCOp = LowerGlobalAddressOperand(MO);
775 break;
Chris Lattner4ebc52f2009-06-20 00:49:26 +0000776 }
777
778 TmpInst.addOperand(MCOp);
779 }
780
Chris Lattner6b9f7742009-06-20 07:59:10 +0000781 switch (TmpInst.getOpcode()) {
782 case X86::LEA64_32r:
783 // Handle the 'subreg rewriting' for the lea64_32mem operand.
Chris Lattnerf5da5902009-06-20 07:03:18 +0000784 lower_lea64_32mem(&TmpInst, 1);
Chris Lattner6b9f7742009-06-20 07:59:10 +0000785 break;
Chris Lattner4ebc52f2009-06-20 00:49:26 +0000786 }
787
Chris Lattner19b1bd52009-06-19 00:47:33 +0000788 // FIXME: Convert TmpInst.
Chris Lattnere67184e2009-06-19 23:59:57 +0000789 printInstruction(&TmpInst);
790 O << "OLD: ";
Chris Lattner19b1bd52009-06-19 00:47:33 +0000791 }
792
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000793 // Call the autogenerated instruction printer routines.
794 printInstruction(MI);
795}
796
Chris Lattnerae982212009-07-21 18:38:57 +0000797void X86ATTAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000798 const TargetData *TD = TM.getTargetData();
799
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000800 if (!GVar->hasInitializer())
801 return; // External global require no code
802
803 // Check to see if this is a special global used by LLVM, if so, emit it.
804 if (EmitSpecialLLVMGlobal(GVar)) {
805 if (Subtarget->isTargetDarwin() &&
806 TM.getRelocationModel() == Reloc::Static) {
Daniel Dunbare03513b2009-07-25 23:55:21 +0000807 if (GVar->getName() == "llvm.global_ctors")
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000808 O << ".reference .constructors_used\n";
Daniel Dunbare03513b2009-07-25 23:55:21 +0000809 else if (GVar->getName() == "llvm.global_dtors")
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000810 O << ".reference .destructors_used\n";
811 }
812 return;
813 }
814
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000815 std::string name = Mang->getMangledName(GVar);
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000816 Constant *C = GVar->getInitializer();
817 const Type *Type = C->getType();
Duncan Sandsec4f97d2009-05-09 07:06:46 +0000818 unsigned Size = TD->getTypeAllocSize(Type);
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000819 unsigned Align = TD->getPreferredAlignmentLog(GVar);
820
Anton Korobeynikov78d69aa2008-08-08 18:25:07 +0000821 printVisibility(name, GVar->getVisibility());
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000822
823 if (Subtarget->isTargetELF())
824 O << "\t.type\t" << name << ",@object\n";
825
Chris Lattner7215c7f2009-08-05 05:21:07 +0000826
827 SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GVar, TM);
828
829
830
Chris Lattnere6ad12f2009-07-31 18:48:30 +0000831 const MCSection *TheSection =
Chris Lattner7215c7f2009-08-05 05:21:07 +0000832 getObjFileLowering().SectionForGlobal(GVar, GVKind, Mang, TM);
Chris Lattner16b8d7f2009-07-24 03:49:17 +0000833 SwitchToSection(TheSection);
Anton Korobeynikov7f3fa2c2008-07-09 13:27:16 +0000834
Chris Lattnerdb727932009-08-04 05:35:56 +0000835 // FIXME: get this stuff from section kind flags.
Evan Chengcf84b142009-02-18 02:19:52 +0000836 if (C->isNullValue() && !GVar->hasSection() &&
Chris Lattner87bc69b2009-07-24 04:08:17 +0000837 // Don't put things that should go in the cstring section into "comm".
Chris Lattnerd8310522009-07-27 05:32:16 +0000838 !TheSection->getKind().isMergeableCString()) {
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000839 if (GVar->hasExternalLinkage()) {
840 if (const char *Directive = TAI->getZeroFillDirective()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000841 O << "\t.globl " << name << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000842 O << Directive << "__DATA, __common, " << name << ", "
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000843 << Size << ", " << Align << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000844 return;
845 }
846 }
847
848 if (!GVar->isThreadLocal() &&
Duncan Sands19d161f2009-03-07 15:45:40 +0000849 (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000850 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
Anton Korobeynikov7f3fa2c2008-07-09 13:27:16 +0000851
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000852 if (TAI->getLCOMMDirective() != NULL) {
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000853 if (GVar->hasLocalLinkage()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000854 O << TAI->getLCOMMDirective() << name << ',' << Size;
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000855 if (Subtarget->isTargetDarwin())
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000856 O << ',' << Align;
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000857 } else if (Subtarget->isTargetDarwin() && !GVar->hasCommonLinkage()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000858 O << "\t.globl " << name << '\n'
859 << TAI->getWeakDefDirective() << name << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000860 EmitAlignment(Align, GVar);
Evan Cheng11db8142009-03-24 00:17:40 +0000861 O << name << ":";
862 if (VerboseAsm) {
Dan Gohman167ff152009-08-12 18:55:32 +0000863 O.PadToColumn(TAI->getCommentColumn(), 1);
864 O << TAI->getCommentString() << ' ';
Dan Gohman2aa282f2009-08-13 01:36:44 +0000865 WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
Evan Cheng11db8142009-03-24 00:17:40 +0000866 }
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000867 O << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000868 EmitGlobalConstant(C);
869 return;
870 } else {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000871 O << TAI->getCOMMDirective() << name << ',' << Size;
Anton Korobeynikov16876eb2008-08-08 18:25:52 +0000872 if (TAI->getCOMMDirectiveTakesAlignment())
873 O << ',' << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000874 }
875 } else {
876 if (!Subtarget->isTargetCygMing()) {
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000877 if (GVar->hasLocalLinkage())
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000878 O << "\t.local\t" << name << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000879 }
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000880 O << TAI->getCOMMDirective() << name << ',' << Size;
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000881 if (TAI->getCOMMDirectiveTakesAlignment())
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000882 O << ',' << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000883 }
Evan Cheng11db8142009-03-24 00:17:40 +0000884 if (VerboseAsm) {
Dan Gohman167ff152009-08-12 18:55:32 +0000885 O.PadToColumn(TAI->getCommentColumn(), 1);
886 O << TAI->getCommentString() << ' ';
Dan Gohman2aa282f2009-08-13 01:36:44 +0000887 WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
Evan Cheng11db8142009-03-24 00:17:40 +0000888 }
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000889 O << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000890 return;
891 }
892 }
893
894 switch (GVar->getLinkage()) {
Duncan Sandsb95df792009-03-11 20:14:15 +0000895 case GlobalValue::CommonLinkage:
Duncan Sands19d161f2009-03-07 15:45:40 +0000896 case GlobalValue::LinkOnceAnyLinkage:
897 case GlobalValue::LinkOnceODRLinkage:
898 case GlobalValue::WeakAnyLinkage:
899 case GlobalValue::WeakODRLinkage:
Dale Johannesenf03574c2009-08-13 00:28:52 +0000900 case GlobalValue::LinkerPrivateLinkage:
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000901 if (Subtarget->isTargetDarwin()) {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000902 O << "\t.globl " << name << '\n'
903 << TAI->getWeakDefDirective() << name << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000904 } else if (Subtarget->isTargetCygMing()) {
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000905 O << "\t.globl\t" << name << "\n"
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000906 "\t.linkonce same_size\n";
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000907 } else {
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000908 O << "\t.weak\t" << name << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000909 }
910 break;
Evan Cheng630c5612008-08-08 06:43:59 +0000911 case GlobalValue::DLLExportLinkage:
912 case GlobalValue::AppendingLinkage:
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000913 // FIXME: appending linkage variables should go into a section of
914 // their name or something. For now, just emit them as external.
Evan Cheng630c5612008-08-08 06:43:59 +0000915 case GlobalValue::ExternalLinkage:
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000916 // If external or appending, declare as a global symbol
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000917 O << "\t.globl " << name << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000918 // FALL THROUGH
Rafael Espindolaa168fc92009-01-15 20:18:42 +0000919 case GlobalValue::PrivateLinkage:
Evan Cheng630c5612008-08-08 06:43:59 +0000920 case GlobalValue::InternalLinkage:
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000921 break;
Evan Cheng630c5612008-08-08 06:43:59 +0000922 default:
Edwin Törökbd448e32009-07-14 16:55:14 +0000923 llvm_unreachable("Unknown linkage type!");
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000924 }
925
926 EmitAlignment(Align, GVar);
Evan Cheng11db8142009-03-24 00:17:40 +0000927 O << name << ":";
928 if (VerboseAsm){
Dan Gohman167ff152009-08-12 18:55:32 +0000929 O.PadToColumn(TAI->getCommentColumn(), 1);
930 O << TAI->getCommentString() << ' ';
Dan Gohman2aa282f2009-08-13 01:36:44 +0000931 WriteAsOperand(O, GVar, /*PrintType=*/false, GVar->getParent());
Evan Cheng11db8142009-03-24 00:17:40 +0000932 }
Dan Gohman12ebe3f2008-06-30 22:03:41 +0000933 O << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000934
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000935 EmitGlobalConstant(C);
Dan Gohman2aa282f2009-08-13 01:36:44 +0000936
937 if (TAI->hasDotTypeDotSizeDirective())
938 O << "\t.size\t" << name << ", " << Size << '\n';
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000939}
940
Anton Korobeynikovfc3efd82008-06-28 11:09:32 +0000941bool X86ATTAsmPrinter::doFinalization(Module &M) {
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000942 // Print out module-level global variables here.
943 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
Anton Korobeynikov0737ff52008-06-28 11:09:48 +0000944 I != E; ++I) {
Anton Korobeynikov0737ff52008-06-28 11:09:48 +0000945 if (I->hasDLLExportLinkage())
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000946 DLLExportedGVs.insert(Mang->getMangledName(I));
Anton Korobeynikov480218b2009-02-21 11:53:32 +0000947 }
948
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000949 if (Subtarget->isTargetDarwin()) {
Chris Lattner92873462009-08-03 21:53:27 +0000950 // All darwin targets use mach-o.
951 TargetLoweringObjectFileMachO &TLOFMacho =
952 static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
Chris Lattner2e860262009-06-24 18:24:09 +0000953
Chris Lattner8b4c72c2009-06-24 18:17:00 +0000954 // Add the (possibly multiple) personalities to the set of global value
955 // stubs. Only referenced functions get into the Personalities list.
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000956 if (TAI->doesSupportExceptionHandling() && MMI && !Subtarget->is64Bit()) {
Chris Lattner8b4c72c2009-06-24 18:17:00 +0000957 const std::vector<Function*> &Personalities = MMI->getPersonalities();
958 for (unsigned i = 0, e = Personalities.size(); i != e; ++i) {
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000959 if (Personalities[i])
960 GVStubs[Mang->getMangledName(Personalities[i], "$non_lazy_ptr",
961 true /*private label*/)] =
962 Mang->getMangledName(Personalities[i]);
Evan Cheng76443dc2008-07-08 00:55:58 +0000963 }
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000964 }
965
Chris Lattner2e860262009-06-24 18:24:09 +0000966 // Output stubs for dynamically-linked functions
967 if (!FnStubs.empty()) {
Chris Lattner92873462009-08-03 21:53:27 +0000968 const MCSection *TheSection =
Chris Lattner72a676a2009-08-10 01:39:42 +0000969 TLOFMacho.getMachOSection("__IMPORT", "__jump_table",
970 MCSectionMachO::S_SYMBOL_STUBS |
971 MCSectionMachO::S_ATTR_SELF_MODIFYING_CODE |
972 MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS,
973 5, SectionKind::getMetadata());
Chris Lattner92873462009-08-03 21:53:27 +0000974 SwitchToSection(TheSection);
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000975 for (StringMap<std::string>::iterator I = FnStubs.begin(),
976 E = FnStubs.end(); I != E; ++I)
977 O << I->getKeyData() << ":\n" << "\t.indirect_symbol " << I->second
978 << "\n\thlt ; hlt ; hlt ; hlt ; hlt\n";
Chris Lattner2e860262009-06-24 18:24:09 +0000979 O << '\n';
980 }
981
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000982 // Output stubs for external and common global variables.
Chris Lattner2e860262009-06-24 18:24:09 +0000983 if (!GVStubs.empty()) {
Chris Lattner92873462009-08-03 21:53:27 +0000984 const MCSection *TheSection =
Chris Lattner72a676a2009-08-10 01:39:42 +0000985 TLOFMacho.getMachOSection("__IMPORT", "__pointers",
986 MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS,
Chris Lattner92873462009-08-03 21:53:27 +0000987 SectionKind::getMetadata());
988 SwitchToSection(TheSection);
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000989 for (StringMap<std::string>::iterator I = GVStubs.begin(),
990 E = GVStubs.end(); I != E; ++I)
991 O << I->getKeyData() << ":\n\t.indirect_symbol "
992 << I->second << "\n\t.long\t0\n";
Chris Lattner2e860262009-06-24 18:24:09 +0000993 }
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +0000994
Evan Chenga65854f2008-12-05 01:06:39 +0000995 if (!HiddenGVStubs.empty()) {
Chris Lattnerc4c40a92009-07-28 03:13:23 +0000996 SwitchToSection(getObjFileLowering().getDataSection());
Chris Lattnerfadd47d2009-06-24 18:24:42 +0000997 EmitAlignment(2);
Chris Lattnerb3cdde62009-07-14 18:17:16 +0000998 for (StringMap<std::string>::iterator I = HiddenGVStubs.begin(),
999 E = HiddenGVStubs.end(); I != E; ++I)
1000 O << I->getKeyData() << ":\n" << TAI->getData32bitsDirective()
1001 << I->second << '\n';
Evan Chenga65854f2008-12-05 01:06:39 +00001002 }
1003
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001004 // Funny Darwin hack: This flag tells the linker that no global symbols
1005 // contain code that falls through to other global symbols (e.g. the obvious
1006 // implementation of multiple entry points). If this doesn't occur, the
1007 // linker can safely perform dead code stripping. Since LLVM never
1008 // generates code that does this, it is always safe to set.
1009 O << "\t.subsections_via_symbols\n";
1010 } else if (Subtarget->isTargetCygMing()) {
1011 // Emit type information for external functions
Chris Lattner0f10ba62009-07-09 05:09:24 +00001012 for (StringSet<>::iterator i = CygMingStubs.begin(), e = CygMingStubs.end();
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001013 i != e; ++i) {
1014 O << "\t.def\t " << i->getKeyData()
1015 << ";\t.scl\t" << COFF::C_EXT
1016 << ";\t.type\t" << (COFF::DT_FCN << COFF::N_BTSHFT)
1017 << ";\t.endef\n";
1018 }
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001019 }
Chris Lattner5ec2b662009-06-24 05:47:59 +00001020
Chris Lattnerdb191f02009-06-24 18:52:01 +00001021
1022 // Output linker support code for dllexported globals on windows.
Chris Lattner92873462009-08-03 21:53:27 +00001023 if (!DLLExportedGVs.empty() || !DLLExportedFns.empty()) {
1024 // dllexport symbols only exist on coff targets.
1025 TargetLoweringObjectFileCOFF &TLOFMacho =
1026 static_cast<TargetLoweringObjectFileCOFF&>(getObjFileLowering());
1027
1028 SwitchToSection(TLOFMacho.getCOFFSection(".section .drectve", true,
1029 SectionKind::getMetadata()));
Chris Lattnerdb191f02009-06-24 18:52:01 +00001030
1031 for (StringSet<>::iterator i = DLLExportedGVs.begin(),
1032 e = DLLExportedGVs.end(); i != e; ++i)
1033 O << "\t.ascii \" -export:" << i->getKeyData() << ",data\"\n";
Chris Lattnerdb191f02009-06-24 18:52:01 +00001034
1035 for (StringSet<>::iterator i = DLLExportedFns.begin(),
1036 e = DLLExportedFns.end();
1037 i != e; ++i)
1038 O << "\t.ascii \" -export:" << i->getKeyData() << "\"\n";
1039 }
1040
Chris Lattnerdb191f02009-06-24 18:52:01 +00001041 // Do common shutdown.
Chris Lattner1eb0ad02009-07-27 21:28:04 +00001042 return AsmPrinter::doFinalization(M);
Anton Korobeynikovab6c6a42008-06-28 11:08:27 +00001043}
1044
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001045// Include the auto-generated portion of the assembly writer.
1046#include "X86GenAsmWriter.inc"