blob: 021e55c5c5c0f5f53722a063955b1fe04e515a63 [file] [log] [blame]
Chris Lattnerb9740462005-07-01 22:44:09 +00001//===-- X86AsmPrinter.cpp - Convert X86 LLVM IR to X86 assembly -----------===//
Misha Brukmanc88330a2005-04-21 23:38:14 +00002//
John Criswell482202a2003-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 Brukmanc88330a2005-04-21 23:38:14 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattnerd92fb002002-10-25 22:55:53 +00009//
Chris Lattnerb9740462005-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 Lattnerd92fb002002-10-25 22:55:53 +000014//
15//===----------------------------------------------------------------------===//
16
Evan Cheng2dd2c652006-03-13 23:20:37 +000017#include "X86AsmPrinter.h"
Chris Lattnerb9740462005-07-01 22:44:09 +000018#include "X86ATTAsmPrinter.h"
19#include "X86IntelAsmPrinter.h"
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000020#include "X86MachineFunctionInfo.h"
Chris Lattner99be8f72005-11-21 22:39:40 +000021#include "X86Subtarget.h"
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000022#include "llvm/ADT/StringExtras.h"
23#include "llvm/CallingConv.h"
Chris Lattner4d80f6e2005-12-13 04:53:51 +000024#include "llvm/Constants.h"
Chris Lattner1a2e6f72003-08-11 20:06:16 +000025#include "llvm/Module.h"
Chris Lattner618981f2005-11-21 06:46:22 +000026#include "llvm/Type.h"
Chris Lattner1a2e6f72003-08-11 20:06:16 +000027#include "llvm/Assembly/Writer.h"
Brian Gaeke46f8b712003-07-24 20:20:44 +000028#include "llvm/Support/Mangler.h"
Jim Laskey261779b2006-09-07 22:06:40 +000029#include "llvm/Target/TargetAsmInfo.h"
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000030
Chris Lattner9f75a552004-02-14 06:00:36 +000031using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000032
Chris Lattner700b8732006-12-06 17:46:33 +000033Statistic llvm::EmittedInsts("asm-printer",
Evan Cheng2dd2c652006-03-13 23:20:37 +000034 "Number of machine instrs printed");
Chris Lattnerd1ab3782004-10-04 07:31:08 +000035
Chris Lattner104aa5d2006-09-26 03:57:53 +000036static X86FunctionInfo calculateFunctionInfo(const Function *F,
37 const TargetData *TD) {
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000038 X86FunctionInfo Info;
Chris Lattner104aa5d2006-09-26 03:57:53 +000039 uint64_t Size = 0;
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000040
41 switch (F->getCallingConv()) {
Chris Lattner104aa5d2006-09-26 03:57:53 +000042 case CallingConv::X86_StdCall:
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000043 Info.setDecorationStyle(StdCall);
44 break;
Chris Lattner104aa5d2006-09-26 03:57:53 +000045 case CallingConv::X86_FastCall:
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000046 Info.setDecorationStyle(FastCall);
47 break;
Chris Lattner104aa5d2006-09-26 03:57:53 +000048 default:
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000049 return Info;
50 }
51
Chris Lattner104aa5d2006-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 Korobeynikov3c5b3df2006-09-20 22:03:51 +000055
Anton Korobeynikov34e051d2006-10-14 20:53:35 +000056 // Size should be aligned to DWORD boundary
57 Size = ((Size + 3)/4)*4;
58
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000059 // We're not supporting tooooo huge arguments :)
Chris Lattner104aa5d2006-09-26 03:57:53 +000060 Info.setBytesToPopOnReturn((unsigned int)Size);
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000061 return Info;
62}
63
64
Chris Lattner104aa5d2006-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 Korobeynikov3c5b3df2006-09-20 22:03:51 +000071
72 // We don't want to decorate non-stdcall or non-fastcall functions right now
Chris Lattner104aa5d2006-09-26 03:57:53 +000073 unsigned CC = F->getCallingConv();
74 if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall)
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000075 return;
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000076
77 FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F);
78
Chris Lattner104aa5d2006-09-26 03:57:53 +000079 const X86FunctionInfo *Info;
Anton Korobeynikov3c5b3df2006-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 Lattner104aa5d2006-09-26 03:57:53 +000085 Info = &info_item->second;
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000086 }
87
88 switch (Info->getDecorationStyle()) {
Chris Lattner104aa5d2006-09-26 03:57:53 +000089 case None:
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000090 break;
Chris Lattner104aa5d2006-09-26 03:57:53 +000091 case StdCall:
92 if (!F->isVarArg()) // Variadic functions do not receive @0 suffix.
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000093 Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000094 break;
Chris Lattner104aa5d2006-09-26 03:57:53 +000095 case FastCall:
96 if (!F->isVarArg()) // Variadic functions do not receive @0 suffix.
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000097 Name += '@' + utostr_32(Info->getBytesToPopOnReturn());
Chris Lattner104aa5d2006-09-26 03:57:53 +000098
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +000099 if (Name[0] == '_') {
100 Name[0] = '@';
101 } else {
102 Name = '@' + Name;
103 }
104 break;
Chris Lattner104aa5d2006-09-26 03:57:53 +0000105 default:
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +0000106 assert(0 && "Unsupported DecorationStyle");
107 }
Anton Korobeynikov3c5b3df2006-09-20 22:03:51 +0000108}
109
Jim Laskeya6211dc2006-09-06 18:34:40 +0000110/// doInitialization
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000111bool X86SharedAsmPrinter::doInitialization(Module &M) {
Jim Laskey3b4866e2006-07-27 02:05:13 +0000112 if (Subtarget->isTargetDarwin()) {
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000113 if (!Subtarget->is64Bit())
114 X86PICStyle = PICStyle::Stub;
115
Evan Chenga4a4ceb2006-03-07 02:23:26 +0000116 // Emit initial debug information.
Jim Laskeycf0166f2006-03-23 18:09:44 +0000117 DW.BeginModule(&M);
Anton Korobeynikovaa4c0f92006-10-31 08:31:24 +0000118 } else if (Subtarget->isTargetELF() || Subtarget->isTargetCygwin()) {
Reid Spencerb51b5c02006-10-30 22:32:30 +0000119 // Emit initial debug information.
120 DW.BeginModule(&M);
Evan Chenga4a4ceb2006-03-07 02:23:26 +0000121 }
Evan Cheng30d7b702006-03-07 02:02:57 +0000122
Reid Spencer30226da2005-01-23 03:52:14 +0000123 return AsmPrinter::doInitialization(M);
124}
125
Chris Lattner68ab0be2004-10-04 07:24:48 +0000126bool X86SharedAsmPrinter::doFinalization(Module &M) {
Jeff Cohence9b9fe2006-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 Anderson20a631f2006-05-03 01:29:57 +0000130 const TargetData *TD = TM.getTargetData();
Anton Korobeynikov12c94942006-12-01 00:25:12 +0000131
Chris Lattner68ab0be2004-10-04 07:24:48 +0000132 // Print out module-level global variables here.
Evan Cheng5a766802006-02-07 08:38:37 +0000133 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
134 I != E; ++I) {
Rafael Espindolab313efb2006-12-09 23:14:08 +0000135 if (!I->hasInitializer())
Anton Korobeynikov12c94942006-12-01 00:25:12 +0000136 continue; // External global require no code
Chris Lattner78161db2005-11-21 22:48:18 +0000137
Chris Lattner87079882005-12-13 06:32:50 +0000138 // Check to see if this is a special global used by LLVM, if so, emit it.
Jim Laskey313570f2006-03-07 22:00:35 +0000139 if (EmitSpecialLLVMGlobal(I))
Chris Lattner87079882005-12-13 06:32:50 +0000140 continue;
Chris Lattner4d80f6e2005-12-13 04:53:51 +0000141
Chris Lattner78161db2005-11-21 22:48:18 +0000142 std::string name = Mang->getValueName(I);
143 Constant *C = I->getInitializer();
Owen Anderson20a631f2006-05-03 01:29:57 +0000144 unsigned Size = TD->getTypeSize(C->getType());
Devang Patel71b99292006-10-24 20:32:14 +0000145 unsigned Align = TD->getPreferredAlignmentLog(I);
Jeff Cohen5f4ef3c2005-07-27 06:12:32 +0000146
Evan Cheng5a766802006-02-07 08:38:37 +0000147 if (C->isNullValue() && /* FIXME: Verify correct */
Evan Chengde5ecd62006-10-31 01:26:55 +0000148 !I->hasSection() &&
Evan Cheng5a766802006-02-07 08:38:37 +0000149 (I->hasInternalLinkage() || I->hasWeakLinkage() ||
Evan Cheng2d23c9f2006-02-15 01:56:23 +0000150 I->hasLinkOnceLinkage() ||
Jim Laskey3b4866e2006-07-27 02:05:13 +0000151 (Subtarget->isTargetDarwin() &&
Evan Chengde5ecd62006-10-31 01:26:55 +0000152 I->hasExternalLinkage()))) {
Evan Cheng5a766802006-02-07 08:38:37 +0000153 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
Evan Cheng2d23c9f2006-02-15 01:56:23 +0000154 if (I->hasExternalLinkage()) {
Evan Cheng1f342c22006-02-23 02:43:52 +0000155 O << "\t.globl\t" << name << "\n";
Evan Cheng2d23c9f2006-02-15 01:56:23 +0000156 O << "\t.zerofill __DATA__, __common, " << name << ", "
157 << Size << ", " << Align;
Evan Cheng5a766802006-02-07 08:38:37 +0000158 } else {
Jim Laskeya6211dc2006-09-06 18:34:40 +0000159 SwitchToDataSection(TAI->getDataSection(), I);
160 if (TAI->getLCOMMDirective() != NULL) {
Evan Cheng2d23c9f2006-02-15 01:56:23 +0000161 if (I->hasInternalLinkage()) {
Jim Laskeya6211dc2006-09-06 18:34:40 +0000162 O << TAI->getLCOMMDirective() << name << "," << Size;
Jim Laskey3b4866e2006-07-27 02:05:13 +0000163 if (Subtarget->isTargetDarwin())
Jim Laskeya6211dc2006-09-06 18:34:40 +0000164 O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
Evan Cheng2d23c9f2006-02-15 01:56:23 +0000165 } else
Jim Laskeya6211dc2006-09-06 18:34:40 +0000166 O << TAI->getCOMMDirective() << name << "," << Size;
Evan Cheng2d23c9f2006-02-15 01:56:23 +0000167 } else {
Anton Korobeynikov6f7072c2006-09-17 20:25:45 +0000168 if (!Subtarget->isTargetCygwin()) {
Evan Cheng2554e3d2006-05-25 21:59:08 +0000169 if (I->hasInternalLinkage())
170 O << "\t.local\t" << name << "\n";
171 }
Jim Laskeya6211dc2006-09-06 18:34:40 +0000172 O << TAI->getCOMMDirective() << name << "," << Size;
173 if (TAI->getCOMMDirectiveTakesAlignment())
174 O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align);
Evan Cheng2d23c9f2006-02-15 01:56:23 +0000175 }
Chris Lattner0d2f0432005-07-11 06:25:47 +0000176 }
Jim Laskeya6211dc2006-09-06 18:34:40 +0000177 O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n";
Evan Cheng5a766802006-02-07 08:38:37 +0000178 } else {
179 switch (I->getLinkage()) {
180 case GlobalValue::LinkOnceLinkage:
181 case GlobalValue::WeakLinkage:
Jim Laskey3b4866e2006-07-27 02:05:13 +0000182 if (Subtarget->isTargetDarwin()) {
Evan Chengadeb8fb2006-02-07 23:32:58 +0000183 O << "\t.globl " << name << "\n"
184 << "\t.weak_definition " << name << "\n";
Evan Cheng0de66672006-06-04 07:24:07 +0000185 SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
Anton Korobeynikov6f7072c2006-09-17 20:25:45 +0000186 } else if (Subtarget->isTargetCygwin()) {
Anton Korobeynikov41a83d72006-10-22 21:37:13 +0000187 std::string SectionName(".section\t.data$linkonce." +
188 name +
Evan Chengde5ecd62006-10-31 01:26:55 +0000189 ",\"aw\"");
Anton Korobeynikov41a83d72006-10-22 21:37:13 +0000190 SwitchToDataSection(SectionName.c_str(), I);
191 O << "\t.globl " << name << "\n"
Anton Korobeynikov24b7ac32006-10-18 09:12:29 +0000192 << "\t.linkonce same_size\n";
Evan Cheng5a766802006-02-07 08:38:37 +0000193 } else {
Anton Korobeynikov41a83d72006-10-22 21:37:13 +0000194 std::string SectionName("\t.section\t.llvm.linkonce.d." +
195 name +
Evan Chengde5ecd62006-10-31 01:26:55 +0000196 ",\"aw\",@progbits");
Anton Korobeynikov41a83d72006-10-22 21:37:13 +0000197 SwitchToDataSection(SectionName.c_str(), I);
198 O << "\t.weak " << name << "\n";
Evan Cheng5a766802006-02-07 08:38:37 +0000199 }
200 break;
201 case GlobalValue::AppendingLinkage:
202 // FIXME: appending linkage variables should go into a section of
203 // their name or something. For now, just emit them as external.
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000204 case GlobalValue::DLLExportLinkage:
205 DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),""));
206 // FALL THROUGH
Evan Cheng5a766802006-02-07 08:38:37 +0000207 case GlobalValue::ExternalLinkage:
208 // If external or appending, declare as a global symbol
209 O << "\t.globl " << name << "\n";
210 // FALL THROUGH
Evan Cheng392f6452006-10-26 19:18:18 +0000211 case GlobalValue::InternalLinkage: {
Evan Cheng0d782b42006-10-28 05:56:06 +0000212 if (I->isConstant()) {
Evan Cheng392f6452006-10-26 19:18:18 +0000213 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
Evan Cheng0d782b42006-10-28 05:56:06 +0000214 if (TAI->getCStringSection() && CVA && CVA->isCString()) {
Evan Cheng392f6452006-10-26 19:18:18 +0000215 SwitchToDataSection(TAI->getCStringSection(), I);
216 break;
217 }
218 }
Evan Chengde5ecd62006-10-31 01:26:55 +0000219 // FIXME: special handling for ".ctors" & ".dtors" sections
220 if (I->hasSection() &&
221 (I->getSection() == ".ctors" ||
222 I->getSection() == ".dtors")) {
223 std::string SectionName = ".section " + I->getSection();
224
225 if (Subtarget->isTargetCygwin()) {
226 SectionName += ",\"aw\"";
227 } else {
228 assert(!Subtarget->isTargetDarwin());
229 SectionName += ",\"aw\",@progbits";
230 }
231
Anton Korobeynikov49993522006-10-31 06:11:06 +0000232 SwitchToDataSection(SectionName.c_str());
Evan Chengde5ecd62006-10-31 01:26:55 +0000233 } else {
234 SwitchToDataSection(TAI->getDataSection(), I);
235 }
236
Evan Cheng5a766802006-02-07 08:38:37 +0000237 break;
Evan Cheng392f6452006-10-26 19:18:18 +0000238 }
Evan Cheng5a766802006-02-07 08:38:37 +0000239 default:
240 assert(0 && "Unknown linkage type!");
241 }
Chris Lattner78161db2005-11-21 22:48:18 +0000242
Evan Cheng5a766802006-02-07 08:38:37 +0000243 EmitAlignment(Align, I);
Jim Laskeya6211dc2006-09-06 18:34:40 +0000244 O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName()
Evan Chengadeb8fb2006-02-07 23:32:58 +0000245 << "\n";
Jim Laskeya6211dc2006-09-06 18:34:40 +0000246 if (TAI->hasDotTypeDotSizeDirective())
Evan Chengadeb8fb2006-02-07 23:32:58 +0000247 O << "\t.size " << name << ", " << Size << "\n";
248
Evan Cheng5fb2c762006-12-01 09:13:26 +0000249 // If the initializer is a extern weak symbol, remember to emit the weak
250 // reference!
251 if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
252 if (GV->hasExternalWeakLinkage())
253 ExtWeakSymbols.insert(Mang->getValueName(GV));
254
Evan Cheng5a766802006-02-07 08:38:37 +0000255 EmitGlobalConstant(C);
256 O << '\n';
Chris Lattner78161db2005-11-21 22:48:18 +0000257 }
Chris Lattner99be8f72005-11-21 22:39:40 +0000258 }
259
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000260 // Output linker support code for dllexported globals
261 if (DLLExportedGVs.begin() != DLLExportedGVs.end()) {
Anton Korobeynikovaa4c0f92006-10-31 08:31:24 +0000262 SwitchToDataSection(".section .drectve");
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000263 }
264
265 for (std::set<std::string>::iterator i = DLLExportedGVs.begin(),
266 e = DLLExportedGVs.end();
267 i != e; ++i) {
268 O << "\t.ascii \" -export:" << *i << ",data\"\n";
269 }
270
271 if (DLLExportedFns.begin() != DLLExportedFns.end()) {
Anton Korobeynikovaa4c0f92006-10-31 08:31:24 +0000272 SwitchToDataSection(".section .drectve");
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000273 }
274
275 for (std::set<std::string>::iterator i = DLLExportedFns.begin(),
276 e = DLLExportedFns.end();
277 i != e; ++i) {
278 O << "\t.ascii \" -export:" << *i << "\"\n";
279 }
Anton Korobeynikov12c94942006-12-01 00:25:12 +0000280
Evan Cheng022030a2006-12-01 20:47:11 +0000281 if (TAI->getWeakRefDirective()) {
Anton Korobeynikov12c94942006-12-01 00:25:12 +0000282 if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
283 SwitchToDataSection("");
Anton Korobeynikov12c94942006-12-01 00:25:12 +0000284 for (std::set<std::string>::iterator i = ExtWeakSymbols.begin(),
Evan Chengdb664562006-12-01 07:17:00 +0000285 e = ExtWeakSymbols.end(); i != e; ++i) {
Evan Cheng022030a2006-12-01 20:47:11 +0000286 O << TAI->getWeakRefDirective() << *i << "\n";
Anton Korobeynikov12c94942006-12-01 00:25:12 +0000287 }
288 }
289
Jim Laskey3b4866e2006-07-27 02:05:13 +0000290 if (Subtarget->isTargetDarwin()) {
Anton Korobeynikovaa4c0f92006-10-31 08:31:24 +0000291 SwitchToDataSection("");
Nate Begeman83b492b2005-07-12 01:37:28 +0000292
Nate Begemanb62a4c82005-07-08 00:23:26 +0000293 // Output stubs for dynamically-linked functions
294 unsigned j = 1;
295 for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end();
Chris Lattner0d2f0432005-07-11 06:25:47 +0000296 i != e; ++i, ++j) {
Chris Lattner8488ba22006-05-09 04:59:56 +0000297 SwitchToDataSection(".section __IMPORT,__jump_table,symbol_stubs,"
298 "self_modifying_code+pure_instructions,5", 0);
Nate Begemanb62a4c82005-07-08 00:23:26 +0000299 O << "L" << *i << "$stub:\n";
300 O << "\t.indirect_symbol " << *i << "\n";
Evan Cheng5a766802006-02-07 08:38:37 +0000301 O << "\thlt ; hlt ; hlt ; hlt ; hlt\n";
Nate Begemanb62a4c82005-07-08 00:23:26 +0000302 }
303
304 O << "\n";
Jeff Cohen5f4ef3c2005-07-27 06:12:32 +0000305
Evan Cheng5a766802006-02-07 08:38:37 +0000306 // Output stubs for external and common global variables.
307 if (GVStubs.begin() != GVStubs.end())
Chris Lattner8488ba22006-05-09 04:59:56 +0000308 SwitchToDataSection(
Anton Korobeynikovaa4c0f92006-10-31 08:31:24 +0000309 ".section __IMPORT,__pointers,non_lazy_symbol_pointers");
Evan Cheng5a766802006-02-07 08:38:37 +0000310 for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end();
311 i != e; ++i) {
312 O << "L" << *i << "$non_lazy_ptr:\n";
313 O << "\t.indirect_symbol " << *i << "\n";
314 O << "\t.long\t0\n";
Nate Begemanb62a4c82005-07-08 00:23:26 +0000315 }
Chris Lattner68ab0be2004-10-04 07:24:48 +0000316
Reid Spencerb51b5c02006-10-30 22:32:30 +0000317 // Emit final debug information.
Jim Laskeycf0166f2006-03-23 18:09:44 +0000318 DW.EndModule();
Evan Chenga4a4ceb2006-03-07 02:23:26 +0000319
320 // Funny Darwin hack: This flag tells the linker that no global symbols
321 // contain code that falls through to other global symbols (e.g. the obvious
322 // implementation of multiple entry points). If this doesn't occur, the
Jim Laskeycf0166f2006-03-23 18:09:44 +0000323 // linker can safely perform dead code stripping. Since LLVM never
324 // generates code that does this, it is always safe to set.
Evan Chenga4a4ceb2006-03-07 02:23:26 +0000325 O << "\t.subsections_via_symbols\n";
Anton Korobeynikovaa4c0f92006-10-31 08:31:24 +0000326 } else if (Subtarget->isTargetELF() || Subtarget->isTargetCygwin()) {
Reid Spencerb51b5c02006-10-30 22:32:30 +0000327 // Emit final debug information.
328 DW.EndModule();
Evan Chenga4a4ceb2006-03-07 02:23:26 +0000329 }
Evan Cheng30d7b702006-03-07 02:02:57 +0000330
Chris Lattner68ab0be2004-10-04 07:24:48 +0000331 AsmPrinter::doFinalization(M);
332 return false; // success
333}
334
Chris Lattner68ab0be2004-10-04 07:24:48 +0000335/// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code
336/// for a MachineFunction to the given output stream, using the given target
337/// machine description.
338///
Evan Cheng2dd2c652006-03-13 23:20:37 +0000339FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o,
Jim Laskeya6211dc2006-09-06 18:34:40 +0000340 X86TargetMachine &tm) {
Jim Laskeyc7abe472006-09-07 12:23:47 +0000341 const X86Subtarget *Subtarget = &tm.getSubtarget<X86Subtarget>();
Jim Laskeya6211dc2006-09-06 18:34:40 +0000342
Jim Laskeyc7abe472006-09-07 12:23:47 +0000343 if (Subtarget->isFlavorIntel()) {
Jim Laskey261779b2006-09-07 22:06:40 +0000344 return new X86IntelAsmPrinter(o, tm, tm.getTargetAsmInfo());
Jim Laskeyc7abe472006-09-07 12:23:47 +0000345 } else {
Jim Laskey261779b2006-09-07 22:06:40 +0000346 return new X86ATTAsmPrinter(o, tm, tm.getTargetAsmInfo());
Chris Lattner68ab0be2004-10-04 07:24:48 +0000347 }
Brian Gaeke259fdbc2003-06-19 19:32:32 +0000348}