Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 1 | //===-- X86AsmPrinter.cpp - Convert X86 LLVM IR to X86 assembly -----------===// |
Misha Brukman | 0e0a7a45 | 2005-04-21 23:38:14 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | 0e0a7a45 | 2005-04-21 23:38:14 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 10 | // 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 Lattner | 7261408 | 2002-10-25 22:55:53 +0000 | [diff] [blame] | 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Evan Cheng | c4c6257 | 2006-03-13 23:20:37 +0000 | [diff] [blame] | 17 | #include "X86AsmPrinter.h" |
Chris Lattner | b36cbd0 | 2005-07-01 22:44:09 +0000 | [diff] [blame] | 18 | #include "X86ATTAsmPrinter.h" |
| 19 | #include "X86IntelAsmPrinter.h" |
Anton Korobeynikov | f824868 | 2006-09-20 22:03:51 +0000 | [diff] [blame^] | 20 | #include "X86MachineFunctionInfo.h" |
Chris Lattner | a35a8e8 | 2005-11-21 22:39:40 +0000 | [diff] [blame] | 21 | #include "X86Subtarget.h" |
Anton Korobeynikov | f824868 | 2006-09-20 22:03:51 +0000 | [diff] [blame^] | 22 | #include "llvm/ADT/StringExtras.h" |
| 23 | #include "llvm/CallingConv.h" |
Chris Lattner | a046e0d | 2005-12-13 04:53:51 +0000 | [diff] [blame] | 24 | #include "llvm/Constants.h" |
Chris Lattner | d59414f | 2003-08-11 20:06:16 +0000 | [diff] [blame] | 25 | #include "llvm/Module.h" |
Chris Lattner | c41cc83 | 2005-11-21 06:46:22 +0000 | [diff] [blame] | 26 | #include "llvm/Type.h" |
Chris Lattner | d59414f | 2003-08-11 20:06:16 +0000 | [diff] [blame] | 27 | #include "llvm/Assembly/Writer.h" |
Brian Gaeke | d9fb37a | 2003-07-24 20:20:44 +0000 | [diff] [blame] | 28 | #include "llvm/Support/Mangler.h" |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 29 | #include "llvm/Target/TargetAsmInfo.h" |
Anton Korobeynikov | f824868 | 2006-09-20 22:03:51 +0000 | [diff] [blame^] | 30 | |
Chris Lattner | 300d0ed | 2004-02-14 06:00:36 +0000 | [diff] [blame] | 31 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 32 | |
Evan Cheng | c4c6257 | 2006-03-13 23:20:37 +0000 | [diff] [blame] | 33 | Statistic<> llvm::EmittedInsts("asm-printer", |
| 34 | "Number of machine instrs printed"); |
Chris Lattner | 955f096 | 2004-10-04 07:31:08 +0000 | [diff] [blame] | 35 | |
Anton Korobeynikov | f824868 | 2006-09-20 22:03:51 +0000 | [diff] [blame^] | 36 | static X86FunctionInfo calculateFunctionInfo(const Function* F, |
| 37 | const TargetData* TD) |
| 38 | { |
| 39 | X86FunctionInfo Info; |
| 40 | uint64_t size = 0; |
| 41 | |
| 42 | switch (F->getCallingConv()) { |
| 43 | case CallingConv::X86_StdCall: |
| 44 | Info.setDecorationStyle(StdCall); |
| 45 | break; |
| 46 | case CallingConv::X86_FastCall: |
| 47 | Info.setDecorationStyle(FastCall); |
| 48 | break; |
| 49 | default: |
| 50 | return Info; |
| 51 | } |
| 52 | |
| 53 | for (Function::const_arg_iterator AI = F->arg_begin(), |
| 54 | AE = F->arg_end(); |
| 55 | AI != AE; |
| 56 | ++AI) { |
| 57 | size += TD->getTypeSize(AI->getType()); |
| 58 | } |
| 59 | |
| 60 | // We're not supporting tooooo huge arguments :) |
| 61 | Info.setBytesToPopOnReturn((unsigned int)size); |
| 62 | |
| 63 | return Info; |
| 64 | } |
| 65 | |
| 66 | |
| 67 | // Query FunctionInfoMap and use this information for various name decoration |
| 68 | void X86SharedAsmPrinter::decorateName(std::string& Name, const GlobalValue* GV) |
| 69 | { |
| 70 | const X86FunctionInfo* Info; |
| 71 | const Function* F; |
| 72 | |
| 73 | if ((F = dyn_cast<Function>(GV)) == NULL) { |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | unsigned CC = F->getCallingConv(); |
| 78 | |
| 79 | // We don't want to decorate non-stdcall or non-fastcall functions right now |
| 80 | if (CC != CallingConv::X86_StdCall && CC != CallingConv::X86_FastCall) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | FMFInfoMap::const_iterator info_item = FunctionInfoMap.find(F); |
| 85 | |
| 86 | if (info_item == FunctionInfoMap.end()) { |
| 87 | // Calculate apropriate function info and populate map |
| 88 | FunctionInfoMap[F] = calculateFunctionInfo(F, TM.getTargetData()); |
| 89 | Info = &FunctionInfoMap[F]; |
| 90 | } else { |
| 91 | Info = &(info_item->second); |
| 92 | } |
| 93 | |
| 94 | switch (Info->getDecorationStyle()) { |
| 95 | case None: |
| 96 | break; |
| 97 | case StdCall: |
| 98 | if (!F->isVarArg()) { |
| 99 | // Variadic functions do not receive @0 suffix |
| 100 | Name += '@' + utostr_32(Info->getBytesToPopOnReturn()); |
| 101 | } |
| 102 | break; |
| 103 | case FastCall: |
| 104 | if (!F->isVarArg()) { |
| 105 | // Variadic functions do not receive @0 suffix |
| 106 | Name += '@' + utostr_32(Info->getBytesToPopOnReturn()); |
| 107 | } |
| 108 | if (Name[0] == '_') { |
| 109 | Name[0] = '@'; |
| 110 | } else { |
| 111 | Name = '@' + Name; |
| 112 | } |
| 113 | break; |
| 114 | default: |
| 115 | assert(0 && "Unsupported DecorationStyle"); |
| 116 | } |
| 117 | |
| 118 | } |
| 119 | |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 120 | /// doInitialization |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 121 | bool X86SharedAsmPrinter::doInitialization(Module &M) { |
Jim Laskey | ea34858 | 2006-07-27 02:05:13 +0000 | [diff] [blame] | 122 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 123 | const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>(); |
| 124 | if (!Subtarget->is64Bit()) |
| 125 | X86PICStyle = PICStyle::Stub; |
| 126 | |
Evan Cheng | d594881 | 2006-03-07 02:23:26 +0000 | [diff] [blame] | 127 | // Emit initial debug information. |
Jim Laskey | 99db044 | 2006-03-23 18:09:44 +0000 | [diff] [blame] | 128 | DW.BeginModule(&M); |
Evan Cheng | d594881 | 2006-03-07 02:23:26 +0000 | [diff] [blame] | 129 | } |
Evan Cheng | 3c992d2 | 2006-03-07 02:02:57 +0000 | [diff] [blame] | 130 | |
Reid Spencer | 5dc81f6 | 2005-01-23 03:52:14 +0000 | [diff] [blame] | 131 | return AsmPrinter::doInitialization(M); |
| 132 | } |
| 133 | |
Chris Lattner | ac5701c | 2004-10-04 07:24:48 +0000 | [diff] [blame] | 134 | bool X86SharedAsmPrinter::doFinalization(Module &M) { |
Jeff Cohen | d43b18d | 2006-05-06 21:27:14 +0000 | [diff] [blame] | 135 | // Note: this code is not shared by the Intel printer as it is too different |
| 136 | // from how MASM does things. When making changes here don't forget to look |
| 137 | // at X86IntelAsmPrinter::doFinalization(). |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 138 | const TargetData *TD = TM.getTargetData(); |
Chris Lattner | ac5701c | 2004-10-04 07:24:48 +0000 | [diff] [blame] | 139 | |
| 140 | // Print out module-level global variables here. |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 141 | for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); |
| 142 | I != E; ++I) { |
Chris Lattner | 9787c64 | 2005-11-21 22:48:18 +0000 | [diff] [blame] | 143 | if (!I->hasInitializer()) continue; // External global require no code |
| 144 | |
Chris Lattner | d1239b7 | 2005-12-13 06:32:50 +0000 | [diff] [blame] | 145 | // Check to see if this is a special global used by LLVM, if so, emit it. |
Jim Laskey | 7809811 | 2006-03-07 22:00:35 +0000 | [diff] [blame] | 146 | if (EmitSpecialLLVMGlobal(I)) |
Chris Lattner | d1239b7 | 2005-12-13 06:32:50 +0000 | [diff] [blame] | 147 | continue; |
Chris Lattner | a046e0d | 2005-12-13 04:53:51 +0000 | [diff] [blame] | 148 | |
Chris Lattner | 9787c64 | 2005-11-21 22:48:18 +0000 | [diff] [blame] | 149 | std::string name = Mang->getValueName(I); |
| 150 | Constant *C = I->getInitializer(); |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 151 | unsigned Size = TD->getTypeSize(C->getType()); |
Chris Lattner | ff805b5 | 2006-02-05 01:45:04 +0000 | [diff] [blame] | 152 | unsigned Align = getPreferredAlignmentLog(I); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 153 | |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 154 | if (C->isNullValue() && /* FIXME: Verify correct */ |
| 155 | (I->hasInternalLinkage() || I->hasWeakLinkage() || |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 156 | I->hasLinkOnceLinkage() || |
Jim Laskey | ea34858 | 2006-07-27 02:05:13 +0000 | [diff] [blame] | 157 | (Subtarget->isTargetDarwin() && |
Evan Cheng | 932ad51 | 2006-05-25 21:59:08 +0000 | [diff] [blame] | 158 | I->hasExternalLinkage() && !I->hasSection()))) { |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 159 | if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 160 | if (I->hasExternalLinkage()) { |
Evan Cheng | a0ea053 | 2006-02-23 02:43:52 +0000 | [diff] [blame] | 161 | O << "\t.globl\t" << name << "\n"; |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 162 | O << "\t.zerofill __DATA__, __common, " << name << ", " |
| 163 | << Size << ", " << Align; |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 164 | } else { |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 165 | SwitchToDataSection(TAI->getDataSection(), I); |
| 166 | if (TAI->getLCOMMDirective() != NULL) { |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 167 | if (I->hasInternalLinkage()) { |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 168 | O << TAI->getLCOMMDirective() << name << "," << Size; |
Jim Laskey | ea34858 | 2006-07-27 02:05:13 +0000 | [diff] [blame] | 169 | if (Subtarget->isTargetDarwin()) |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 170 | O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align); |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 171 | } else |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 172 | O << TAI->getCOMMDirective() << name << "," << Size; |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 173 | } else { |
Anton Korobeynikov | bcb9770 | 2006-09-17 20:25:45 +0000 | [diff] [blame] | 174 | if (!Subtarget->isTargetCygwin()) { |
Evan Cheng | 932ad51 | 2006-05-25 21:59:08 +0000 | [diff] [blame] | 175 | if (I->hasInternalLinkage()) |
| 176 | O << "\t.local\t" << name << "\n"; |
| 177 | } |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 178 | O << TAI->getCOMMDirective() << name << "," << Size; |
| 179 | if (TAI->getCOMMDirectiveTakesAlignment()) |
| 180 | O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align); |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 181 | } |
Chris Lattner | b12c9fa | 2005-07-11 06:25:47 +0000 | [diff] [blame] | 182 | } |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 183 | O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n"; |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 184 | } else { |
| 185 | switch (I->getLinkage()) { |
| 186 | case GlobalValue::LinkOnceLinkage: |
| 187 | case GlobalValue::WeakLinkage: |
Jim Laskey | ea34858 | 2006-07-27 02:05:13 +0000 | [diff] [blame] | 188 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | 5ada370 | 2006-02-07 23:32:58 +0000 | [diff] [blame] | 189 | O << "\t.globl " << name << "\n" |
| 190 | << "\t.weak_definition " << name << "\n"; |
Evan Cheng | f8614db | 2006-06-04 07:24:07 +0000 | [diff] [blame] | 191 | SwitchToDataSection(".section __DATA,__const_coal,coalesced", I); |
Anton Korobeynikov | bcb9770 | 2006-09-17 20:25:45 +0000 | [diff] [blame] | 192 | } else if (Subtarget->isTargetCygwin()) { |
Evan Cheng | 932ad51 | 2006-05-25 21:59:08 +0000 | [diff] [blame] | 193 | O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\"\n" |
| 194 | << "\t.weak " << name << "\n"; |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 195 | } else { |
Evan Cheng | 932ad51 | 2006-05-25 21:59:08 +0000 | [diff] [blame] | 196 | O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n" |
| 197 | << "\t.weak " << name << "\n"; |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 198 | } |
| 199 | break; |
| 200 | case GlobalValue::AppendingLinkage: |
| 201 | // FIXME: appending linkage variables should go into a section of |
| 202 | // their name or something. For now, just emit them as external. |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 203 | case GlobalValue::DLLExportLinkage: |
| 204 | DLLExportedGVs.insert(Mang->makeNameProper(I->getName(),"")); |
| 205 | // FALL THROUGH |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 206 | case GlobalValue::ExternalLinkage: |
| 207 | // If external or appending, declare as a global symbol |
| 208 | O << "\t.globl " << name << "\n"; |
| 209 | // FALL THROUGH |
| 210 | case GlobalValue::InternalLinkage: |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 211 | SwitchToDataSection(TAI->getDataSection(), I); |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 212 | break; |
| 213 | default: |
| 214 | assert(0 && "Unknown linkage type!"); |
| 215 | } |
Chris Lattner | 9787c64 | 2005-11-21 22:48:18 +0000 | [diff] [blame] | 216 | |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 217 | EmitAlignment(Align, I); |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 218 | O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName() |
Evan Cheng | 5ada370 | 2006-02-07 23:32:58 +0000 | [diff] [blame] | 219 | << "\n"; |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 220 | if (TAI->hasDotTypeDotSizeDirective()) |
Evan Cheng | 5ada370 | 2006-02-07 23:32:58 +0000 | [diff] [blame] | 221 | O << "\t.size " << name << ", " << Size << "\n"; |
| 222 | |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 223 | EmitGlobalConstant(C); |
| 224 | O << '\n'; |
Chris Lattner | 9787c64 | 2005-11-21 22:48:18 +0000 | [diff] [blame] | 225 | } |
Chris Lattner | a35a8e8 | 2005-11-21 22:39:40 +0000 | [diff] [blame] | 226 | } |
| 227 | |
Anton Korobeynikov | b74ed07 | 2006-09-14 18:23:27 +0000 | [diff] [blame] | 228 | // Output linker support code for dllexported globals |
| 229 | if (DLLExportedGVs.begin() != DLLExportedGVs.end()) { |
| 230 | SwitchToDataSection(".section .drectve", 0); |
| 231 | } |
| 232 | |
| 233 | for (std::set<std::string>::iterator i = DLLExportedGVs.begin(), |
| 234 | e = DLLExportedGVs.end(); |
| 235 | i != e; ++i) { |
| 236 | O << "\t.ascii \" -export:" << *i << ",data\"\n"; |
| 237 | } |
| 238 | |
| 239 | if (DLLExportedFns.begin() != DLLExportedFns.end()) { |
| 240 | SwitchToDataSection(".section .drectve", 0); |
| 241 | } |
| 242 | |
| 243 | for (std::set<std::string>::iterator i = DLLExportedFns.begin(), |
| 244 | e = DLLExportedFns.end(); |
| 245 | i != e; ++i) { |
| 246 | O << "\t.ascii \" -export:" << *i << "\"\n"; |
| 247 | } |
| 248 | |
Jim Laskey | ea34858 | 2006-07-27 02:05:13 +0000 | [diff] [blame] | 249 | if (Subtarget->isTargetDarwin()) { |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 250 | SwitchToDataSection("", 0); |
Nate Begeman | 73213f6 | 2005-07-12 01:37:28 +0000 | [diff] [blame] | 251 | |
Nate Begeman | 72b286b | 2005-07-08 00:23:26 +0000 | [diff] [blame] | 252 | // Output stubs for dynamically-linked functions |
| 253 | unsigned j = 1; |
| 254 | for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end(); |
Chris Lattner | b12c9fa | 2005-07-11 06:25:47 +0000 | [diff] [blame] | 255 | i != e; ++i, ++j) { |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 256 | SwitchToDataSection(".section __IMPORT,__jump_table,symbol_stubs," |
| 257 | "self_modifying_code+pure_instructions,5", 0); |
Nate Begeman | 72b286b | 2005-07-08 00:23:26 +0000 | [diff] [blame] | 258 | O << "L" << *i << "$stub:\n"; |
| 259 | O << "\t.indirect_symbol " << *i << "\n"; |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 260 | O << "\thlt ; hlt ; hlt ; hlt ; hlt\n"; |
Nate Begeman | 72b286b | 2005-07-08 00:23:26 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | O << "\n"; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 264 | |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 265 | // Output stubs for external and common global variables. |
| 266 | if (GVStubs.begin() != GVStubs.end()) |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 267 | SwitchToDataSection( |
| 268 | ".section __IMPORT,__pointers,non_lazy_symbol_pointers", 0); |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 269 | for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end(); |
| 270 | i != e; ++i) { |
| 271 | O << "L" << *i << "$non_lazy_ptr:\n"; |
| 272 | O << "\t.indirect_symbol " << *i << "\n"; |
| 273 | O << "\t.long\t0\n"; |
Nate Begeman | 72b286b | 2005-07-08 00:23:26 +0000 | [diff] [blame] | 274 | } |
Chris Lattner | ac5701c | 2004-10-04 07:24:48 +0000 | [diff] [blame] | 275 | |
Evan Cheng | d594881 | 2006-03-07 02:23:26 +0000 | [diff] [blame] | 276 | // Emit initial debug information. |
Jim Laskey | 99db044 | 2006-03-23 18:09:44 +0000 | [diff] [blame] | 277 | DW.EndModule(); |
Evan Cheng | d594881 | 2006-03-07 02:23:26 +0000 | [diff] [blame] | 278 | |
| 279 | // Funny Darwin hack: This flag tells the linker that no global symbols |
| 280 | // contain code that falls through to other global symbols (e.g. the obvious |
| 281 | // implementation of multiple entry points). If this doesn't occur, the |
Jim Laskey | 99db044 | 2006-03-23 18:09:44 +0000 | [diff] [blame] | 282 | // linker can safely perform dead code stripping. Since LLVM never |
| 283 | // generates code that does this, it is always safe to set. |
Evan Cheng | d594881 | 2006-03-07 02:23:26 +0000 | [diff] [blame] | 284 | O << "\t.subsections_via_symbols\n"; |
| 285 | } |
Evan Cheng | 3c992d2 | 2006-03-07 02:02:57 +0000 | [diff] [blame] | 286 | |
Chris Lattner | ac5701c | 2004-10-04 07:24:48 +0000 | [diff] [blame] | 287 | AsmPrinter::doFinalization(M); |
| 288 | return false; // success |
| 289 | } |
| 290 | |
Chris Lattner | ac5701c | 2004-10-04 07:24:48 +0000 | [diff] [blame] | 291 | /// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code |
| 292 | /// for a MachineFunction to the given output stream, using the given target |
| 293 | /// machine description. |
| 294 | /// |
Evan Cheng | c4c6257 | 2006-03-13 23:20:37 +0000 | [diff] [blame] | 295 | FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o, |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 296 | X86TargetMachine &tm) { |
Jim Laskey | 05a059d | 2006-09-07 12:23:47 +0000 | [diff] [blame] | 297 | const X86Subtarget *Subtarget = &tm.getSubtarget<X86Subtarget>(); |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 298 | |
Jim Laskey | 05a059d | 2006-09-07 12:23:47 +0000 | [diff] [blame] | 299 | if (Subtarget->isFlavorIntel()) { |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 300 | return new X86IntelAsmPrinter(o, tm, tm.getTargetAsmInfo()); |
Jim Laskey | 05a059d | 2006-09-07 12:23:47 +0000 | [diff] [blame] | 301 | } else { |
Jim Laskey | a0f3d17 | 2006-09-07 22:06:40 +0000 | [diff] [blame] | 302 | return new X86ATTAsmPrinter(o, tm, tm.getTargetAsmInfo()); |
Chris Lattner | ac5701c | 2004-10-04 07:24:48 +0000 | [diff] [blame] | 303 | } |
Brian Gaeke | 9e474c4 | 2003-06-19 19:32:32 +0000 | [diff] [blame] | 304 | } |