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" |
Chris Lattner | a35a8e8 | 2005-11-21 22:39:40 +0000 | [diff] [blame] | 20 | #include "X86Subtarget.h" |
Chris Lattner | a046e0d | 2005-12-13 04:53:51 +0000 | [diff] [blame] | 21 | #include "llvm/Constants.h" |
Chris Lattner | d59414f | 2003-08-11 20:06:16 +0000 | [diff] [blame] | 22 | #include "llvm/Module.h" |
Chris Lattner | c41cc83 | 2005-11-21 06:46:22 +0000 | [diff] [blame] | 23 | #include "llvm/Type.h" |
Chris Lattner | d59414f | 2003-08-11 20:06:16 +0000 | [diff] [blame] | 24 | #include "llvm/Assembly/Writer.h" |
Brian Gaeke | d9fb37a | 2003-07-24 20:20:44 +0000 | [diff] [blame] | 25 | #include "llvm/Support/Mangler.h" |
Chris Lattner | 300d0ed | 2004-02-14 06:00:36 +0000 | [diff] [blame] | 26 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 27 | |
Evan Cheng | c4c6257 | 2006-03-13 23:20:37 +0000 | [diff] [blame] | 28 | Statistic<> llvm::EmittedInsts("asm-printer", |
| 29 | "Number of machine instrs printed"); |
Chris Lattner | 955f096 | 2004-10-04 07:31:08 +0000 | [diff] [blame] | 30 | |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 31 | X86TargetAsmInfo::X86TargetAsmInfo(X86TargetMachine &TM) { |
| 32 | const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>(); |
Chris Lattner | a35a8e8 | 2005-11-21 22:39:40 +0000 | [diff] [blame] | 33 | |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 34 | //FIXME - Should to be simplified. |
| 35 | |
Chris Lattner | a35a8e8 | 2005-11-21 22:39:40 +0000 | [diff] [blame] | 36 | switch (Subtarget->TargetType) { |
Chris Lattner | a35a8e8 | 2005-11-21 22:39:40 +0000 | [diff] [blame] | 37 | case X86Subtarget::isDarwin: |
Nate Begeman | 9d19eb4 | 2005-06-30 00:53:20 +0000 | [diff] [blame] | 38 | AlignmentIsInBytes = false; |
Chris Lattner | 8fccc97 | 2005-11-21 19:50:31 +0000 | [diff] [blame] | 39 | GlobalPrefix = "_"; |
Nate Begeman | 9035b99 | 2005-07-16 01:59:47 +0000 | [diff] [blame] | 40 | Data64bitsDirective = 0; // we can't emit a 64-bit unit |
| 41 | ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. |
Chris Lattner | c41cc83 | 2005-11-21 06:46:22 +0000 | [diff] [blame] | 42 | PrivateGlobalPrefix = "L"; // Marker for constant pool idxs |
Chris Lattner | d939f6c | 2005-11-21 08:32:23 +0000 | [diff] [blame] | 43 | ConstantPoolSection = "\t.const\n"; |
Nate Begeman | 2f1ae88 | 2006-07-27 01:13:04 +0000 | [diff] [blame] | 44 | JumpTableDataSection = "\t.const\n"; // FIXME: depends on PIC mode |
Evan Cheng | d3f6981 | 2006-06-29 00:33:06 +0000 | [diff] [blame] | 45 | FourByteConstantSection = "\t.literal4\n"; |
| 46 | EightByteConstantSection = "\t.literal8\n"; |
Chris Lattner | 8fccc97 | 2005-11-21 19:50:31 +0000 | [diff] [blame] | 47 | LCOMMDirective = "\t.lcomm\t"; |
| 48 | COMMDirectiveTakesAlignment = false; |
Chris Lattner | ac2902b | 2005-11-21 23:06:54 +0000 | [diff] [blame] | 49 | HasDotTypeDotSizeDirective = false; |
Chris Lattner | d1239b7 | 2005-12-13 06:32:50 +0000 | [diff] [blame] | 50 | StaticCtorsSection = ".mod_init_func"; |
| 51 | StaticDtorsSection = ".mod_term_func"; |
Chris Lattner | 7660ebc | 2006-05-05 21:48:50 +0000 | [diff] [blame] | 52 | InlineAsmStart = "# InlineAsm Start"; |
| 53 | InlineAsmEnd = "# InlineAsm End"; |
Nate Begeman | 52a51e38 | 2006-08-12 21:29:52 +0000 | [diff] [blame] | 54 | SetDirective = "\t.set"; |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 55 | |
| 56 | NeedsSet = true; |
| 57 | DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug"; |
| 58 | DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; |
| 59 | DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; |
| 60 | DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; |
| 61 | DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; |
| 62 | DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; |
| 63 | DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; |
| 64 | DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug"; |
| 65 | DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug"; |
| 66 | DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug"; |
| 67 | DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug"; |
Chris Lattner | a35a8e8 | 2005-11-21 22:39:40 +0000 | [diff] [blame] | 68 | break; |
| 69 | case X86Subtarget::isCygwin: |
Chris Lattner | 8fccc97 | 2005-11-21 19:50:31 +0000 | [diff] [blame] | 70 | GlobalPrefix = "_"; |
| 71 | COMMDirectiveTakesAlignment = false; |
Chris Lattner | ac2902b | 2005-11-21 23:06:54 +0000 | [diff] [blame] | 72 | HasDotTypeDotSizeDirective = false; |
Evan Cheng | 932ad51 | 2006-05-25 21:59:08 +0000 | [diff] [blame] | 73 | StaticCtorsSection = "\t.section .ctors,\"aw\""; |
| 74 | StaticDtorsSection = "\t.section .dtors,\"aw\""; |
Chris Lattner | a35a8e8 | 2005-11-21 22:39:40 +0000 | [diff] [blame] | 75 | break; |
| 76 | case X86Subtarget::isWindows: |
Chris Lattner | 8fccc97 | 2005-11-21 19:50:31 +0000 | [diff] [blame] | 77 | GlobalPrefix = "_"; |
Chris Lattner | ac2902b | 2005-11-21 23:06:54 +0000 | [diff] [blame] | 78 | HasDotTypeDotSizeDirective = false; |
Chris Lattner | a35a8e8 | 2005-11-21 22:39:40 +0000 | [diff] [blame] | 79 | break; |
| 80 | default: break; |
| 81 | } |
Chris Lattner | 8fccc97 | 2005-11-21 19:50:31 +0000 | [diff] [blame] | 82 | |
Jim Laskey | 05a059d | 2006-09-07 12:23:47 +0000 | [diff] [blame^] | 83 | if (Subtarget->isFlavorIntel()) { |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 84 | GlobalPrefix = "_"; |
| 85 | CommentString = ";"; |
| 86 | |
| 87 | PrivateGlobalPrefix = "$"; |
| 88 | AlignDirective = "\talign\t"; |
| 89 | ZeroDirective = "\tdb\t"; |
| 90 | ZeroDirectiveSuffix = " dup(0)"; |
| 91 | AsciiDirective = "\tdb\t"; |
| 92 | AscizDirective = 0; |
| 93 | Data8bitsDirective = "\tdb\t"; |
| 94 | Data16bitsDirective = "\tdw\t"; |
| 95 | Data32bitsDirective = "\tdd\t"; |
| 96 | Data64bitsDirective = "\tdq\t"; |
| 97 | HasDotTypeDotSizeDirective = false; |
| 98 | |
| 99 | TextSection = "_text"; |
| 100 | DataSection = "_data"; |
| 101 | SwitchToSectionDirective = ""; |
| 102 | TextSectionStartSuffix = "\tsegment 'CODE'"; |
| 103 | DataSectionStartSuffix = "\tsegment 'DATA'"; |
| 104 | SectionEndDirectiveSuffix = "\tends\n"; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /// doInitialization |
| 109 | bool X86SharedAsmPrinter::doInitialization(Module &M) { |
Jim Laskey | ea34858 | 2006-07-27 02:05:13 +0000 | [diff] [blame] | 110 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | d594881 | 2006-03-07 02:23:26 +0000 | [diff] [blame] | 111 | // Emit initial debug information. |
Jim Laskey | 99db044 | 2006-03-23 18:09:44 +0000 | [diff] [blame] | 112 | DW.BeginModule(&M); |
Evan Cheng | d594881 | 2006-03-07 02:23:26 +0000 | [diff] [blame] | 113 | } |
Evan Cheng | 3c992d2 | 2006-03-07 02:02:57 +0000 | [diff] [blame] | 114 | |
Reid Spencer | 5dc81f6 | 2005-01-23 03:52:14 +0000 | [diff] [blame] | 115 | return AsmPrinter::doInitialization(M); |
| 116 | } |
| 117 | |
Chris Lattner | ac5701c | 2004-10-04 07:24:48 +0000 | [diff] [blame] | 118 | bool X86SharedAsmPrinter::doFinalization(Module &M) { |
Jeff Cohen | d43b18d | 2006-05-06 21:27:14 +0000 | [diff] [blame] | 119 | // Note: this code is not shared by the Intel printer as it is too different |
| 120 | // from how MASM does things. When making changes here don't forget to look |
| 121 | // at X86IntelAsmPrinter::doFinalization(). |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 122 | const TargetData *TD = TM.getTargetData(); |
Chris Lattner | ac5701c | 2004-10-04 07:24:48 +0000 | [diff] [blame] | 123 | |
| 124 | // Print out module-level global variables here. |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 125 | for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); |
| 126 | I != E; ++I) { |
Chris Lattner | 9787c64 | 2005-11-21 22:48:18 +0000 | [diff] [blame] | 127 | if (!I->hasInitializer()) continue; // External global require no code |
| 128 | |
Chris Lattner | d1239b7 | 2005-12-13 06:32:50 +0000 | [diff] [blame] | 129 | // 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] | 130 | if (EmitSpecialLLVMGlobal(I)) |
Chris Lattner | d1239b7 | 2005-12-13 06:32:50 +0000 | [diff] [blame] | 131 | continue; |
Chris Lattner | a046e0d | 2005-12-13 04:53:51 +0000 | [diff] [blame] | 132 | |
Chris Lattner | 9787c64 | 2005-11-21 22:48:18 +0000 | [diff] [blame] | 133 | std::string name = Mang->getValueName(I); |
| 134 | Constant *C = I->getInitializer(); |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 135 | unsigned Size = TD->getTypeSize(C->getType()); |
Chris Lattner | ff805b5 | 2006-02-05 01:45:04 +0000 | [diff] [blame] | 136 | unsigned Align = getPreferredAlignmentLog(I); |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 137 | |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 138 | if (C->isNullValue() && /* FIXME: Verify correct */ |
| 139 | (I->hasInternalLinkage() || I->hasWeakLinkage() || |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 140 | I->hasLinkOnceLinkage() || |
Jim Laskey | ea34858 | 2006-07-27 02:05:13 +0000 | [diff] [blame] | 141 | (Subtarget->isTargetDarwin() && |
Evan Cheng | 932ad51 | 2006-05-25 21:59:08 +0000 | [diff] [blame] | 142 | I->hasExternalLinkage() && !I->hasSection()))) { |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 143 | if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it. |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 144 | if (I->hasExternalLinkage()) { |
Evan Cheng | a0ea053 | 2006-02-23 02:43:52 +0000 | [diff] [blame] | 145 | O << "\t.globl\t" << name << "\n"; |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 146 | O << "\t.zerofill __DATA__, __common, " << name << ", " |
| 147 | << Size << ", " << Align; |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 148 | } else { |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 149 | SwitchToDataSection(TAI->getDataSection(), I); |
| 150 | if (TAI->getLCOMMDirective() != NULL) { |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 151 | if (I->hasInternalLinkage()) { |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 152 | O << TAI->getLCOMMDirective() << name << "," << Size; |
Jim Laskey | ea34858 | 2006-07-27 02:05:13 +0000 | [diff] [blame] | 153 | if (Subtarget->isTargetDarwin()) |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 154 | O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align); |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 155 | } else |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 156 | O << TAI->getCOMMDirective() << name << "," << Size; |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 157 | } else { |
Evan Cheng | 57c0788 | 2006-05-26 06:22:34 +0000 | [diff] [blame] | 158 | if (Subtarget->TargetType != X86Subtarget::isCygwin) { |
Evan Cheng | 932ad51 | 2006-05-25 21:59:08 +0000 | [diff] [blame] | 159 | if (I->hasInternalLinkage()) |
| 160 | O << "\t.local\t" << name << "\n"; |
| 161 | } |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 162 | O << TAI->getCOMMDirective() << name << "," << Size; |
| 163 | if (TAI->getCOMMDirectiveTakesAlignment()) |
| 164 | O << "," << (TAI->getAlignmentIsInBytes() ? (1 << Align) : Align); |
Evan Cheng | 17ef92e | 2006-02-15 01:56:23 +0000 | [diff] [blame] | 165 | } |
Chris Lattner | b12c9fa | 2005-07-11 06:25:47 +0000 | [diff] [blame] | 166 | } |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 167 | O << "\t\t" << TAI->getCommentString() << " " << I->getName() << "\n"; |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 168 | } else { |
| 169 | switch (I->getLinkage()) { |
| 170 | case GlobalValue::LinkOnceLinkage: |
| 171 | case GlobalValue::WeakLinkage: |
Jim Laskey | ea34858 | 2006-07-27 02:05:13 +0000 | [diff] [blame] | 172 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | 5ada370 | 2006-02-07 23:32:58 +0000 | [diff] [blame] | 173 | O << "\t.globl " << name << "\n" |
| 174 | << "\t.weak_definition " << name << "\n"; |
Evan Cheng | f8614db | 2006-06-04 07:24:07 +0000 | [diff] [blame] | 175 | SwitchToDataSection(".section __DATA,__const_coal,coalesced", I); |
Evan Cheng | 932ad51 | 2006-05-25 21:59:08 +0000 | [diff] [blame] | 176 | } else if (Subtarget->TargetType == X86Subtarget::isCygwin) { |
| 177 | O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\"\n" |
| 178 | << "\t.weak " << name << "\n"; |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 179 | } else { |
Evan Cheng | 932ad51 | 2006-05-25 21:59:08 +0000 | [diff] [blame] | 180 | O << "\t.section\t.llvm.linkonce.d." << name << ",\"aw\",@progbits\n" |
| 181 | << "\t.weak " << name << "\n"; |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 182 | } |
| 183 | break; |
| 184 | case GlobalValue::AppendingLinkage: |
| 185 | // FIXME: appending linkage variables should go into a section of |
| 186 | // their name or something. For now, just emit them as external. |
| 187 | case GlobalValue::ExternalLinkage: |
| 188 | // If external or appending, declare as a global symbol |
| 189 | O << "\t.globl " << name << "\n"; |
| 190 | // FALL THROUGH |
| 191 | case GlobalValue::InternalLinkage: |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 192 | SwitchToDataSection(TAI->getDataSection(), I); |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 193 | break; |
| 194 | default: |
| 195 | assert(0 && "Unknown linkage type!"); |
| 196 | } |
Chris Lattner | 9787c64 | 2005-11-21 22:48:18 +0000 | [diff] [blame] | 197 | |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 198 | EmitAlignment(Align, I); |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 199 | O << name << ":\t\t\t\t" << TAI->getCommentString() << " " << I->getName() |
Evan Cheng | 5ada370 | 2006-02-07 23:32:58 +0000 | [diff] [blame] | 200 | << "\n"; |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 201 | if (TAI->hasDotTypeDotSizeDirective()) |
Evan Cheng | 5ada370 | 2006-02-07 23:32:58 +0000 | [diff] [blame] | 202 | O << "\t.size " << name << ", " << Size << "\n"; |
| 203 | |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 204 | EmitGlobalConstant(C); |
| 205 | O << '\n'; |
Chris Lattner | 9787c64 | 2005-11-21 22:48:18 +0000 | [diff] [blame] | 206 | } |
Chris Lattner | a35a8e8 | 2005-11-21 22:39:40 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Jim Laskey | ea34858 | 2006-07-27 02:05:13 +0000 | [diff] [blame] | 209 | if (Subtarget->isTargetDarwin()) { |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 210 | SwitchToDataSection("", 0); |
Nate Begeman | 73213f6 | 2005-07-12 01:37:28 +0000 | [diff] [blame] | 211 | |
Nate Begeman | 72b286b | 2005-07-08 00:23:26 +0000 | [diff] [blame] | 212 | // Output stubs for dynamically-linked functions |
| 213 | unsigned j = 1; |
| 214 | for (std::set<std::string>::iterator i = FnStubs.begin(), e = FnStubs.end(); |
Chris Lattner | b12c9fa | 2005-07-11 06:25:47 +0000 | [diff] [blame] | 215 | i != e; ++i, ++j) { |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 216 | SwitchToDataSection(".section __IMPORT,__jump_table,symbol_stubs," |
| 217 | "self_modifying_code+pure_instructions,5", 0); |
Nate Begeman | 72b286b | 2005-07-08 00:23:26 +0000 | [diff] [blame] | 218 | O << "L" << *i << "$stub:\n"; |
| 219 | O << "\t.indirect_symbol " << *i << "\n"; |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 220 | O << "\thlt ; hlt ; hlt ; hlt ; hlt\n"; |
Nate Begeman | 72b286b | 2005-07-08 00:23:26 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | O << "\n"; |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 224 | |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 225 | // Output stubs for external and common global variables. |
| 226 | if (GVStubs.begin() != GVStubs.end()) |
Chris Lattner | 4632d7a | 2006-05-09 04:59:56 +0000 | [diff] [blame] | 227 | SwitchToDataSection( |
| 228 | ".section __IMPORT,__pointers,non_lazy_symbol_pointers", 0); |
Evan Cheng | 2338c5c | 2006-02-07 08:38:37 +0000 | [diff] [blame] | 229 | for (std::set<std::string>::iterator i = GVStubs.begin(), e = GVStubs.end(); |
| 230 | i != e; ++i) { |
| 231 | O << "L" << *i << "$non_lazy_ptr:\n"; |
| 232 | O << "\t.indirect_symbol " << *i << "\n"; |
| 233 | O << "\t.long\t0\n"; |
Nate Begeman | 72b286b | 2005-07-08 00:23:26 +0000 | [diff] [blame] | 234 | } |
Chris Lattner | ac5701c | 2004-10-04 07:24:48 +0000 | [diff] [blame] | 235 | |
Evan Cheng | d594881 | 2006-03-07 02:23:26 +0000 | [diff] [blame] | 236 | // Emit initial debug information. |
Jim Laskey | 99db044 | 2006-03-23 18:09:44 +0000 | [diff] [blame] | 237 | DW.EndModule(); |
Evan Cheng | d594881 | 2006-03-07 02:23:26 +0000 | [diff] [blame] | 238 | |
| 239 | // Funny Darwin hack: This flag tells the linker that no global symbols |
| 240 | // contain code that falls through to other global symbols (e.g. the obvious |
| 241 | // implementation of multiple entry points). If this doesn't occur, the |
Jim Laskey | 99db044 | 2006-03-23 18:09:44 +0000 | [diff] [blame] | 242 | // linker can safely perform dead code stripping. Since LLVM never |
| 243 | // generates code that does this, it is always safe to set. |
Evan Cheng | d594881 | 2006-03-07 02:23:26 +0000 | [diff] [blame] | 244 | O << "\t.subsections_via_symbols\n"; |
| 245 | } |
Evan Cheng | 3c992d2 | 2006-03-07 02:02:57 +0000 | [diff] [blame] | 246 | |
Chris Lattner | ac5701c | 2004-10-04 07:24:48 +0000 | [diff] [blame] | 247 | AsmPrinter::doFinalization(M); |
| 248 | return false; // success |
| 249 | } |
| 250 | |
Chris Lattner | ac5701c | 2004-10-04 07:24:48 +0000 | [diff] [blame] | 251 | /// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code |
| 252 | /// for a MachineFunction to the given output stream, using the given target |
| 253 | /// machine description. |
| 254 | /// |
Evan Cheng | c4c6257 | 2006-03-13 23:20:37 +0000 | [diff] [blame] | 255 | FunctionPass *llvm::createX86CodePrinterPass(std::ostream &o, |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 256 | X86TargetMachine &tm) { |
Jim Laskey | 05a059d | 2006-09-07 12:23:47 +0000 | [diff] [blame^] | 257 | const X86Subtarget *Subtarget = &tm.getSubtarget<X86Subtarget>(); |
Jim Laskey | 563321a | 2006-09-06 18:34:40 +0000 | [diff] [blame] | 258 | TargetAsmInfo *TAI = new X86TargetAsmInfo(tm); |
| 259 | |
Jim Laskey | 05a059d | 2006-09-07 12:23:47 +0000 | [diff] [blame^] | 260 | if (Subtarget->isFlavorIntel()) { |
| 261 | return new X86IntelAsmPrinter(o, tm, TAI); |
| 262 | } else { |
| 263 | return new X86ATTAsmPrinter(o, tm, TAI); |
Chris Lattner | ac5701c | 2004-10-04 07:24:48 +0000 | [diff] [blame] | 264 | } |
Brian Gaeke | 9e474c4 | 2003-06-19 19:32:32 +0000 | [diff] [blame] | 265 | } |