blob: 77c965a17111b4ae134aa7293f9d7b24de7b7d5c [file] [log] [blame]
Chris Lattnerb36cbd02005-07-01 22:44:09 +00001//===-- X86AsmPrinter.cpp - Convert X86 LLVM IR to X86 assembly -----------===//
Misha Brukman0e0a7a452005-04-21 23:38:14 +00002//
John Criswellb576c942003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
Misha Brukman0e0a7a452005-04-21 23:38:14 +00007//
John Criswellb576c942003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner72614082002-10-25 22:55:53 +00009//
Chris Lattnerb36cbd02005-07-01 22:44:09 +000010// This file the shared super class printer that converts from our internal
11// representation of machine-dependent LLVM code to Intel and AT&T format
12// assembly language.
13// This printer is the output mechanism used by `llc'.
Chris Lattner72614082002-10-25 22:55:53 +000014//
15//===----------------------------------------------------------------------===//
16
Evan Chengc4c62572006-03-13 23:20:37 +000017#include "X86AsmPrinter.h"
Chris Lattnerb36cbd02005-07-01 22:44:09 +000018#include "X86ATTAsmPrinter.h"
19#include "X86IntelAsmPrinter.h"
Anton Korobeynikovf8248682006-09-20 22:03:51 +000020#include "X86MachineFunctionInfo.h"
Chris Lattnera35a8e82005-11-21 22:39:40 +000021#include "X86Subtarget.h"
Anton Korobeynikovf8248682006-09-20 22:03:51 +000022#include "llvm/ADT/StringExtras.h"
23#include "llvm/CallingConv.h"
Chris Lattnera046e0d2005-12-13 04:53:51 +000024#include "llvm/Constants.h"
Chris Lattnerd59414f2003-08-11 20:06:16 +000025#include "llvm/Module.h"
Chris Lattnerc41cc832005-11-21 06:46:22 +000026#include "llvm/Type.h"
Chris Lattnerd59414f2003-08-11 20:06:16 +000027#include "llvm/Assembly/Writer.h"
Brian Gaeked9fb37a2003-07-24 20:20:44 +000028#include "llvm/Support/Mangler.h"
Jim Laskeya0f3d172006-09-07 22:06:40 +000029#include "llvm/Target/TargetAsmInfo.h"
Anton Korobeynikovf8248682006-09-20 22:03:51 +000030
Chris Lattner300d0ed2004-02-14 06:00:36 +000031using namespace llvm;
Brian Gaeked0fde302003-11-11 22:41:34 +000032
Evan Chengc4c62572006-03-13 23:20:37 +000033Statistic<> llvm::EmittedInsts("asm-printer",
34 "Number of machine instrs printed");
Chris Lattner955f0962004-10-04 07:31:08 +000035
Chris Lattnere87e1152006-09-26 03:57:53 +000036static X86FunctionInfo calculateFunctionInfo(const Function *F,
37 const TargetData *TD) {
Anton Korobeynikovf8248682006-09-20 22:03:51 +000038 X86FunctionInfo Info;
Chris Lattnere87e1152006-09-26 03:57:53 +000039 uint64_t Size = 0;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000040
41 switch (F->getCallingConv()) {
Chris Lattnere87e1152006-09-26 03:57:53 +000042 case CallingConv::X86_StdCall:
Anton Korobeynikovf8248682006-09-20 22:03:51 +000043 Info.setDecorationStyle(StdCall);
44 break;
Chris Lattnere87e1152006-09-26 03:57:53 +000045 case CallingConv::X86_FastCall:
Anton Korobeynikovf8248682006-09-20 22:03:51 +000046 Info.setDecorationStyle(FastCall);
47 break;
Chris Lattnere87e1152006-09-26 03:57:53 +000048 default:
Anton Korobeynikovf8248682006-09-20 22:03:51 +000049 return Info;
50 }
51
Chris Lattnere87e1152006-09-26 03:57:53 +000052 for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
53 AI != AE; ++AI)
54 Size += TD->getTypeSize(AI->getType());
Anton Korobeynikovf8248682006-09-20 22:03:51 +000055
Anton Korobeynikov54b1cc62006-10-14 20:53:35 +000056 // Size should be aligned to DWORD boundary
57 Size = ((Size + 3)/4)*4;
58
Anton Korobeynikovf8248682006-09-20 22:03:51 +000059 // We're not supporting tooooo huge arguments :)
Chris Lattnere87e1152006-09-26 03:57:53 +000060 Info.setBytesToPopOnReturn((unsigned int)Size);
Anton Korobeynikovf8248682006-09-20 22:03:51 +000061 return Info;
62}
63
64
Chris Lattnere87e1152006-09-26 03:57:53 +000065/// decorateName - Query FunctionInfoMap and use this information for various
66/// name decoration.
67void X86SharedAsmPrinter::decorateName(std::string &Name,
68 const GlobalValue *GV) {
69 const Function *F = dyn_cast<Function>(GV);
70 if (!F) return;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000071
72 // We don't want to decorate non-stdcall or non-fastcall functions right now
Chris Lattnere87e1152006-09-26 03:57:53 +000073 unsigned CC = F->getCallingConv();
74 if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
Anton Korobeynikovf8248682006-09-20 22:03:51 +000075 return;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000076
77 FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
78
Chris Lattnere87e1152006-09-26 03:57:53 +000079 const X86FunctionInfo *Info;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000080 if (info_item == FunctionInfoMap.end()) {
81 // Calculate apropriate function info and populate map
82 FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData());
83 Info = &FunctionInfoMap[F];
84 } else {
Chris Lattnere87e1152006-09-26 03:57:53 +000085 Info = &info_item->second;
Anton Korobeynikovf8248682006-09-20 22:03:51 +000086 }
87
88 switch (Info->getDecorationStyle()) {
Chris Lattnere87e1152006-09-26 03:57:53 +000089 case None:
Anton Korobeynikovf8248682006-09-20 22:03:51 +000090 break;
Chris Lattnere87e1152006-09-26 03:57:53 +000091 case StdCall:
92 if (!F->isVarArg()) // Variadic functions do not receive @0 suffix.
Anton Korobeynikovf8248682006-09-20 22:03:51 +000093 Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
Anton Korobeynikovf8248682006-09-20 22:03:51 +000094 break;
Chris Lattnere87e1152006-09-26 03:57:53 +000095 case FastCall:
96 if (!F->isVarArg()) // Variadic functions do not receive @0 suffix.
Anton Korobeynikovf8248682006-09-20 22:03:51 +000097 Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
Chris Lattnere87e1152006-09-26 03:57:53 +000098
Anton Korobeynikovf8248682006-09-20 22:03:51 +000099 if (Name[0] == '_') {
100 Name[0] = '@';
101 } else {
102 Name = '@' + Name;
103 }
104 break;
Chris Lattnere87e1152006-09-26 03:57:53 +0000105 default:
Anton Korobeynikovf8248682006-09-20 22:03:51 +0000106 assert(0 && "Unsupported DecorationStyle");
107 }
Anton Korobeynikovf8248682006-09-20 22:03:51 +0000108}
109
Jim Laskey563321a2006-09-06 18:34:40 +0000110/// doInitialization
Evan Cheng25ab6902006-09-08 06:48:29 +0000111bool X86SharedAsmPrinter::doInitialization(Module &M) {
Jim Laskeyea348582006-07-27 02:05:13 +0000112 if (Subtarget->isTargetDarwin()) {
Evan Cheng25ab6902006-09-08 06:48:29 +0000113 if (!Subtarget->is64Bit())
114 X86PICStyle = PICStyle::Stub;
115
Evan Chengd5948812006-03-07 02:23:26 +0000116 // Emit initial debug information.
Jim Laskey99db0442006-03-23 18:09:44 +0000117 DW.BeginModule(&M);
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000118 } else if (Subtarget->isTargetELF() || Subtarget->isTargetCygwin()) {
Reid Spencer02b85112006-10-30 22:32:30 +0000119 // Emit initial debug information.
120 DW.BeginModule(&M);
Evan Chengd5948812006-03-07 02:23:26 +0000121 }
Evan Cheng3c992d22006-03-07 02:02:57 +0000122
Reid Spencer5dc81f62005-01-23 03:52:14 +0000123 return AsmPrinter::doInitialization(M);
124}
125
Chris Lattnerac5701c2004-10-04 07:24:48 +0000126bool X86SharedAsmPrinter::doFinalization(Module &M) {
Jeff Cohend43b18d2006-05-06 21:27:14 +0000127 // Note: this code is not shared by the Intel printer as it is too different
128 // from how MASM does things. When making changes here don't forget to look
129 // at X86IntelAsmPrinter::doFinalization().
Owen Andersona69571c2006-05-03 01:29:57 +0000130 const TargetData *TD = TM.getTargetData();
Anton Korobeynikov78ee7b72006-12-01 00:25:12 +0000131
Chris Lattnerac5701c2004-10-04 07:24:48 +0000132 // Print out module-level global variables here.
Evan Cheng2338c5c2006-02-07 08:38:37 +0000133 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
134 I != E; ++I) {
Anton Korobeynikov78ee7b72006-12-01 00:25:12 +0000135 if (!I->hasInitializer() && !I->hasExternalWeakLinkage())
136 continue; // External global require no code
Chris Lattner9787c642005-11-21 22:48:18 +0000137
Chris Lattnerd1239b72005-12-13 06:32:50 +0000138 // Check to see if this is a special global used by LLVM, if so, emit it.
Jim Laskey78098112006-03-07 22:00:35 +0000139 if (EmitSpecialLLVMGlobal(I))
Chris Lattnerd1239b72005-12-13 06:32:50 +0000140 continue;
Chris Lattnera046e0d2005-12-13 04:53:51 +0000141
Chris Lattner9787c642005-11-21 22:48:18 +0000142 std::string name = Mang->getValueName(I);
143 Constant *C = I->getInitializer();
Owen Andersona69571c2006-05-03 01:29:57 +0000144 unsigned Size = TD->getTypeSize(C->getType());
Devang Patelf9c197e2006-10-24 20:32:14 +0000145 unsigned Align = TD->getPreferredAlignmentLog(I);
Jeff Cohen00b168892005-07-27 06:12:32 +0000146
Evan Cheng2338c5c2006-02-07 08:38:37 +0000147 if (C->isNullValue() && /* FIXME: Verify correct */
Evan Cheng2e323aa2006-10-31 01:26:55 +0000148 !I->hasSection() &&
Evan Cheng2338c5c2006-02-07 08:38:37 +0000149 (I->hasInternalLinkage() || I->hasWeakLinkage() ||
Evan Cheng17ef92e2006-02-15 01:56:23 +0000150 I->hasLinkOnceLinkage() ||
Jim Laskeyea348582006-07-27 02:05:13 +0000151 (Subtarget->isTargetDarwin() &&
Evan Cheng2e323aa2006-10-31 01:26:55 +0000152 I->hasExternalLinkage()))) {
Evan Cheng2338c5c2006-02-07 08:38:37 +0000153 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
Evan Cheng17ef92e2006-02-15 01:56:23 +0000154 if (I->hasExternalLinkage()) {
Evan Chenga0ea0532006-02-23 02:43:52 +0000155 O << "\t.globl\t" << name << "\n";
Evan Cheng17ef92e2006-02-15 01:56:23 +0000156 O << "\t.zerofill __DATA__, __common, " << name << ", "
157 << Size << ", " << Align;
Evan Cheng2338c5c2006-02-07 08:38:37 +0000158 } else {
Jim Laskey563321a2006-09-06 18:34:40 +0000159 SwitchToDataSection(TAI->getDataSection(), I);
160 if (TAI->getLCOMMDirective() != NULL) {
Evan Cheng17ef92e2006-02-15 01:56:23 +0000161 if (I->hasInternalLinkage()) {
Jim Laskey563321a2006-09-06 18:34:40 +0000162 O << TAI->getLCOMMDirective() << name << "," << Size;
Jim Laskeyea348582006-07-27 02:05:13 +0000163 if (Subtarget->isTargetDarwin())
Jim Laskey563321a2006-09-06 18:34:40 +0000164 O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
Evan Cheng17ef92e2006-02-15 01:56:23 +0000165 } else
Jim Laskey563321a2006-09-06 18:34:40 +0000166 O << TAI->getCOMMDirective() << name << "," << Size;
Evan Cheng17ef92e2006-02-15 01:56:23 +0000167 } else {
Anton Korobeynikovbcb97702006-09-17 20:25:45 +0000168 if (!Subtarget->isTargetCygwin()) {
Evan Cheng932ad512006-05-25 21:59:08 +0000169 if (I->hasInternalLinkage())
170 O << "\t.local\t" << name << "\n";
171 }
Jim Laskey563321a2006-09-06 18:34:40 +0000172 O << TAI->getCOMMDirective() << name << "," << Size;
173 if (TAI->getCOMMDirectiveTakesAlignment())
174 O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
Evan Cheng17ef92e2006-02-15 01:56:23 +0000175 }
Chris Lattnerb12c9fa2005-07-11 06:25:47 +0000176 }
Jim Laskey563321a2006-09-06 18:34:40 +0000177 O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +0000178 } else {
179 switch (I->getLinkage()) {
Anton Korobeynikov78ee7b72006-12-01 00:25:12 +0000180 case GlobalValue::ExternalWeakLinkage:
181 if (Subtarget->isTargetDarwin()) {
182 assert(0 && "External weak linkage for Darwin not implemented yet");
183 } else if (Subtarget->isTargetCygwin()) {
184 // There is no external weak linkage on Mingw32 platform.
185 // Defaulting just to external
186 O << "\t.globl " << name << "\n";
187 } else {
188 O << "\t.weak " << name << "\n";
189 break;
190 }
Evan Cheng2338c5c2006-02-07 08:38:37 +0000191 case GlobalValue::LinkOnceLinkage:
192 case GlobalValue::WeakLinkage:
Jim Laskeyea348582006-07-27 02:05:13 +0000193 if (Subtarget->isTargetDarwin()) {
Evan Cheng5ada3702006-02-07 23:32:58 +0000194 O << "\t.globl " << name << "\n"
195 << "\t.weak_definition " << name << "\n";
Evan Chengf8614db2006-06-04 07:24:07 +0000196 SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
Anton Korobeynikovbcb97702006-09-17 20:25:45 +0000197 } else if (Subtarget->isTargetCygwin()) {
Anton Korobeynikov1a3ecbb2006-10-22 21:37:13 +0000198 std::string SectionName(".section\t.data$linkonce." +
199 name +
Evan Cheng2e323aa2006-10-31 01:26:55 +0000200 ",\"aw\"");
Anton Korobeynikov1a3ecbb2006-10-22 21:37:13 +0000201 SwitchToDataSection(SectionName.c_str(), I);
202 O << "\t.globl " << name << "\n"
Anton Korobeynikovb1c88022006-10-18 09:12:29 +0000203 << "\t.linkonce same_size\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +0000204 } else {
Anton Korobeynikov1a3ecbb2006-10-22 21:37:13 +0000205 std::string SectionName("\t.section\t.llvm.linkonce.d." +
206 name +
Evan Cheng2e323aa2006-10-31 01:26:55 +0000207 ",\"aw\",@progbits");
Anton Korobeynikov1a3ecbb2006-10-22 21:37:13 +0000208 SwitchToDataSection(SectionName.c_str(), I);
209 O << "\t.weak " << name << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +0000210 }
211 break;
212 case GlobalValue::AppendingLinkage:
213 // FIXME: appending linkage variables should go into a section of
214 // their name or something. For now, just emit them as external.
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000215 case GlobalValue::DLLExportLinkage:
216 DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
217 // FALL THROUGH
Evan Cheng2338c5c2006-02-07 08:38:37 +0000218 case GlobalValue::ExternalLinkage:
219 // If external or appending, declare as a global symbol
220 O << "\t.globl " << name << "\n";
221 // FALL THROUGH
Evan Cheng8910c1c2006-10-26 19:18:18 +0000222 case GlobalValue::InternalLinkage: {
Evan Cheng71aae622006-10-28 05:56:06 +0000223 if (I->isConstant()) {
Evan Cheng8910c1c2006-10-26 19:18:18 +0000224 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
Evan Cheng71aae622006-10-28 05:56:06 +0000225 if (TAI->getCStringSection() && CVA && CVA->isCString()) {
Evan Cheng8910c1c2006-10-26 19:18:18 +0000226 SwitchToDataSection(TAI->getCStringSection(), I);
227 break;
228 }
229 }
Evan Cheng2e323aa2006-10-31 01:26:55 +0000230 // FIXME: special handling for ".ctors" & ".dtors" sections
231 if (I->hasSection() &&
232 (I->getSection() == ".ctors" ||
233 I->getSection() == ".dtors")) {
234 std::string SectionName = ".section " + I->getSection();
235
236 if (Subtarget->isTargetCygwin()) {
237 SectionName += ",\"aw\"";
238 } else {
239 assert(!Subtarget->isTargetDarwin());
240 SectionName += ",\"aw\",@progbits";
241 }
242
Anton Korobeynikovb52cf1f2006-10-31 06:11:06 +0000243 SwitchToDataSection(SectionName.c_str());
Evan Cheng2e323aa2006-10-31 01:26:55 +0000244 } else {
245 SwitchToDataSection(TAI->getDataSection(), I);
246 }
247
Evan Cheng2338c5c2006-02-07 08:38:37 +0000248 break;
Evan Cheng8910c1c2006-10-26 19:18:18 +0000249 }
Evan Cheng2338c5c2006-02-07 08:38:37 +0000250 default:
251 assert(0 && "Unknown linkage type!");
252 }
Chris Lattner9787c642005-11-21 22:48:18 +0000253
Evan Cheng2338c5c2006-02-07 08:38:37 +0000254 EmitAlignment(Align, I);
Jim Laskey563321a2006-09-06 18:34:40 +0000255 O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
Evan Cheng5ada3702006-02-07 23:32:58 +0000256 << "\n";
Jim Laskey563321a2006-09-06 18:34:40 +0000257 if (TAI->hasDotTypeDotSizeDirective())
Evan Cheng5ada3702006-02-07 23:32:58 +0000258 O << "\t.size " << name << ", " << Size << "\n";
259
Evan Cheng2338c5c2006-02-07 08:38:37 +0000260 EmitGlobalConstant(C);
261 O << '\n';
Chris Lattner9787c642005-11-21 22:48:18 +0000262 }
Chris Lattnera35a8e82005-11-21 22:39:40 +0000263 }
264
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000265 // Output linker support code for dllexported globals
266 if (DLLExportedGVs.begin() != DLLExportedGVs.end()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000267 SwitchToDataSection(".section .drectve");
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000268 }
269
270 for (std::set<std::string>::iterator i = DLLExportedGVs.begin(),
271 e = DLLExportedGVs.end();
272 i != e; ++i) {
273 O << "\t.ascii \" -export:" << *i << ",data\"\n";
274 }
275
276 if (DLLExportedFns.begin() != DLLExportedFns.end()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000277 SwitchToDataSection(".section .drectve");
Anton Korobeynikovb74ed072006-09-14 18:23:27 +0000278 }
279
280 for (std::set<std::string>::iterator i = DLLExportedFns.begin(),
281 e = DLLExportedFns.end();
282 i != e; ++i) {
283 O << "\t.ascii \" -export:" << *i << "\"\n";
284 }
Anton Korobeynikov78ee7b72006-12-01 00:25:12 +0000285
Evan Chengf532c4f2006-12-01 07:15:24 +0000286 if (Subtarget->isTargetCygwin()) {
Anton Korobeynikov78ee7b72006-12-01 00:25:12 +0000287 // There is no external weak linkage on Mingw32 platform.
288 // Defaulting to external
289 } else {
290 if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
291 SwitchToDataSection("");
292
293 for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
Evan Chengde97f9c2006-12-01 07:17:00 +0000294 e = ExtWeakSymbols.end(); i != e; ++i) {
Evan Chengf532c4f2006-12-01 07:15:24 +0000295 O << (Subtarget->isTargetDarwin() ? "\t.weak_reference" : "\t.weak")
296 << " " << *i << "\n";
Anton Korobeynikov78ee7b72006-12-01 00:25:12 +0000297 }
298 }
299
Jim Laskeyea348582006-07-27 02:05:13 +0000300 if (Subtarget->isTargetDarwin()) {
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000301 SwitchToDataSection("");
Nate Begeman73213f62005-07-12 01:37:28 +0000302
Nate Begeman72b286b2005-07-08 00:23:26 +0000303 // Output stubs for dynamically-linked functions
304 unsigned j = 1;
305 for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
Chris Lattnerb12c9fa2005-07-11 06:25:47 +0000306 i != e; ++i, ++j) {
Chris Lattner4632d7a2006-05-09 04:59:56 +0000307 SwitchToDataSection(".section __IMPORT,__jump_table,symbol_stubs,"
308 "self_modifying_code+pure_instructions,5", 0);
Nate Begeman72b286b2005-07-08 00:23:26 +0000309 O << "L" << *i << "$stub:\n";
310 O << "\t.indirect_symbol " << *i << "\n";
Evan Cheng2338c5c2006-02-07 08:38:37 +0000311 O << "\thlt ; hlt ; hlt ; hlt ; hlt\n";
Nate Begeman72b286b2005-07-08 00:23:26 +0000312 }
313
314 O << "\n";
Jeff Cohen00b168892005-07-27 06:12:32 +0000315
Evan Cheng2338c5c2006-02-07 08:38:37 +0000316 // Output stubs for external and common global variables.
317 if (GVStubs.begin() != GVStubs.end())
Chris Lattner4632d7a2006-05-09 04:59:56 +0000318 SwitchToDataSection(
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000319 ".section __IMPORT,__pointers,non_lazy_symbol_pointers");
Evan Cheng2338c5c2006-02-07 08:38:37 +0000320 for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end();
321 i != e; ++i) {
322 O << "L" << *i << "$non_lazy_ptr:\n";
323 O << "\t.indirect_symbol " << *i << "\n";
324 O << "\t.long\t0\n";
Nate Begeman72b286b2005-07-08 00:23:26 +0000325 }
Chris Lattnerac5701c2004-10-04 07:24:48 +0000326
Reid Spencer02b85112006-10-30 22:32:30 +0000327 // Emit final debug information.
Jim Laskey99db0442006-03-23 18:09:44 +0000328 DW.EndModule();
Evan Chengd5948812006-03-07 02:23:26 +0000329
330 // Funny Darwin hack: This flag tells the linker that no global symbols
331 // contain code that falls through to other global symbols (e.g. the obvious
332 // implementation of multiple entry points). If this doesn't occur, the
Jim Laskey99db0442006-03-23 18:09:44 +0000333 // linker can safely perform dead code stripping. Since LLVM never
334 // generates code that does this, it is always safe to set.
Evan Chengd5948812006-03-07 02:23:26 +0000335 O << "\t.subsections_via_symbols\n";
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000336 } else if (Subtarget->isTargetELF() || Subtarget->isTargetCygwin()) {
Reid Spencer02b85112006-10-30 22:32:30 +0000337 // Emit final debug information.
338 DW.EndModule();
Evan Chengd5948812006-03-07 02:23:26 +0000339 }
Evan Cheng3c992d22006-03-07 02:02:57 +0000340
Chris Lattnerac5701c2004-10-04 07:24:48 +0000341 AsmPrinter::doFinalization(M);
342 return false; // success
343}
344
Chris Lattnerac5701c2004-10-04 07:24:48 +0000345/// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code
346/// for a MachineFunction to the given output stream, using the given target
347/// machine description.
348///
Evan Chengc4c62572006-03-13 23:20:37 +0000349FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o,
Jim Laskey563321a2006-09-06 18:34:40 +0000350 X86TargetMachine &tm) {
Jim Laskey05a059d2006-09-07 12:23:47 +0000351 const X86Subtarget *Subtarget = &tm.getSubtarget<X86Subtarget>();
Jim Laskey563321a2006-09-06 18:34:40 +0000352
Jim Laskey05a059d2006-09-07 12:23:47 +0000353 if (Subtarget->isFlavorIntel()) {
Jim Laskeya0f3d172006-09-07 22:06:40 +0000354 return new X86IntelAsmPrinter(o, tm, tm.getTargetAsmInfo());
Jim Laskey05a059d2006-09-07 12:23:47 +0000355 } else {
Jim Laskeya0f3d172006-09-07 22:06:40 +0000356 return new X86ATTAsmPrinter(o, tm, tm.getTargetAsmInfo());
Chris Lattnerac5701c2004-10-04 07:24:48 +0000357 }
Brian Gaeke9e474c42003-06-19 19:32:32 +0000358}