blob: 853d3ed159f323d817223aef9a7cde20f58f0c63 [file] [log] [blame]
Daniel Dunbar12783d12010-02-21 21:54:14 +00001//===-- X86AsmBackend.cpp - X86 Assembler Backend -------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/Target/TargetAsmBackend.h"
11#include "X86.h"
Daniel Dunbar87190c42010-03-19 09:28:12 +000012#include "X86FixupKinds.h"
Daniel Dunbar82968002010-03-23 01:39:09 +000013#include "llvm/ADT/Twine.h"
Matt Fleming453db502010-08-16 18:36:14 +000014#include "llvm/MC/ELFObjectWriter.h"
Daniel Dunbar87190c42010-03-19 09:28:12 +000015#include "llvm/MC/MCAssembler.h"
Daniel Dunbara5d0b542010-05-06 20:34:01 +000016#include "llvm/MC/MCExpr.h"
Rafael Espindolaf230df92010-10-16 18:23:53 +000017#include "llvm/MC/MCObjectFormat.h"
Daniel Dunbar337055e2010-03-23 03:13:05 +000018#include "llvm/MC/MCObjectWriter.h"
Michael J. Spencerdfd30182010-07-27 06:46:15 +000019#include "llvm/MC/MCSectionCOFF.h"
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +000020#include "llvm/MC/MCSectionELF.h"
Daniel Dunbard6e59082010-03-15 21:56:50 +000021#include "llvm/MC/MCSectionMachO.h"
Daniel Dunbar1a9158c2010-03-19 10:43:26 +000022#include "llvm/MC/MachObjectWriter.h"
Daniel Dunbar82968002010-03-23 01:39:09 +000023#include "llvm/Support/ErrorHandling.h"
24#include "llvm/Support/raw_ostream.h"
Daniel Dunbar12783d12010-02-21 21:54:14 +000025#include "llvm/Target/TargetRegistry.h"
26#include "llvm/Target/TargetAsmBackend.h"
27using namespace llvm;
28
Daniel Dunbar12783d12010-02-21 21:54:14 +000029
Daniel Dunbar87190c42010-03-19 09:28:12 +000030static unsigned getFixupKindLog2Size(unsigned Kind) {
31 switch (Kind) {
32 default: assert(0 && "invalid fixup kind!");
33 case X86::reloc_pcrel_1byte:
34 case FK_Data_1: return 0;
Chris Lattner9fc05222010-07-07 22:27:31 +000035 case X86::reloc_pcrel_2byte:
Daniel Dunbar87190c42010-03-19 09:28:12 +000036 case FK_Data_2: return 1;
37 case X86::reloc_pcrel_4byte:
38 case X86::reloc_riprel_4byte:
39 case X86::reloc_riprel_4byte_movq_load:
Rafael Espindolaa8c02c32010-09-30 03:11:42 +000040 case X86::reloc_signed_4byte:
Daniel Dunbar87190c42010-03-19 09:28:12 +000041 case FK_Data_4: return 2;
42 case FK_Data_8: return 3;
43 }
44}
45
Chris Lattner9fc05222010-07-07 22:27:31 +000046namespace {
Daniel Dunbar12783d12010-02-21 21:54:14 +000047class X86AsmBackend : public TargetAsmBackend {
48public:
Daniel Dunbar6c27f5e2010-03-11 01:34:16 +000049 X86AsmBackend(const Target &T)
Daniel Dunbar12783d12010-02-21 21:54:14 +000050 : TargetAsmBackend(T) {}
Daniel Dunbar87190c42010-03-19 09:28:12 +000051
Daniel Dunbarc90e30a2010-05-26 15:18:56 +000052 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
Daniel Dunbar87190c42010-03-19 09:28:12 +000053 uint64_t Value) const {
Daniel Dunbar482ad802010-05-26 15:18:31 +000054 unsigned Size = 1 << getFixupKindLog2Size(Fixup.getKind());
Daniel Dunbar87190c42010-03-19 09:28:12 +000055
Daniel Dunbar482ad802010-05-26 15:18:31 +000056 assert(Fixup.getOffset() + Size <= DF.getContents().size() &&
Daniel Dunbar87190c42010-03-19 09:28:12 +000057 "Invalid fixup offset!");
58 for (unsigned i = 0; i != Size; ++i)
Daniel Dunbar482ad802010-05-26 15:18:31 +000059 DF.getContents()[Fixup.getOffset() + i] = uint8_t(Value >> (i * 8));
Daniel Dunbar87190c42010-03-19 09:28:12 +000060 }
Daniel Dunbar82968002010-03-23 01:39:09 +000061
Daniel Dunbar84882522010-05-26 17:45:29 +000062 bool MayNeedRelaxation(const MCInst &Inst) const;
Daniel Dunbar337055e2010-03-23 03:13:05 +000063
Daniel Dunbar95506d42010-05-26 18:15:06 +000064 void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
Daniel Dunbar8f9b80e2010-03-23 02:36:58 +000065
66 bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const;
Daniel Dunbar12783d12010-02-21 21:54:14 +000067};
Michael J. Spencerec38de22010-10-10 22:04:20 +000068} // end anonymous namespace
Daniel Dunbar12783d12010-02-21 21:54:14 +000069
Daniel Dunbar82968002010-03-23 01:39:09 +000070static unsigned getRelaxedOpcode(unsigned Op) {
71 switch (Op) {
72 default:
73 return Op;
74
75 case X86::JAE_1: return X86::JAE_4;
76 case X86::JA_1: return X86::JA_4;
77 case X86::JBE_1: return X86::JBE_4;
78 case X86::JB_1: return X86::JB_4;
79 case X86::JE_1: return X86::JE_4;
80 case X86::JGE_1: return X86::JGE_4;
81 case X86::JG_1: return X86::JG_4;
82 case X86::JLE_1: return X86::JLE_4;
83 case X86::JL_1: return X86::JL_4;
84 case X86::JMP_1: return X86::JMP_4;
85 case X86::JNE_1: return X86::JNE_4;
86 case X86::JNO_1: return X86::JNO_4;
87 case X86::JNP_1: return X86::JNP_4;
88 case X86::JNS_1: return X86::JNS_4;
89 case X86::JO_1: return X86::JO_4;
90 case X86::JP_1: return X86::JP_4;
91 case X86::JS_1: return X86::JS_4;
92 }
93}
94
Daniel Dunbar84882522010-05-26 17:45:29 +000095bool X86AsmBackend::MayNeedRelaxation(const MCInst &Inst) const {
96 // Check if this instruction is ever relaxable.
97 if (getRelaxedOpcode(Inst.getOpcode()) == Inst.getOpcode())
98 return false;
Daniel Dunbar482ad802010-05-26 15:18:31 +000099
Daniel Dunbar84882522010-05-26 17:45:29 +0000100 // If so, just assume it can be relaxed. Once we support relaxing more complex
101 // instructions we should check that the instruction actually has symbolic
102 // operands before doing this, but we need to be careful about things like
103 // PCrel.
104 return true;
Daniel Dunbar337055e2010-03-23 03:13:05 +0000105}
106
Daniel Dunbar82968002010-03-23 01:39:09 +0000107// FIXME: Can tblgen help at all here to verify there aren't other instructions
108// we can relax?
Daniel Dunbar95506d42010-05-26 18:15:06 +0000109void X86AsmBackend::RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
Daniel Dunbar82968002010-03-23 01:39:09 +0000110 // The only relaxations X86 does is from a 1byte pcrel to a 4byte pcrel.
Daniel Dunbar95506d42010-05-26 18:15:06 +0000111 unsigned RelaxedOp = getRelaxedOpcode(Inst.getOpcode());
Daniel Dunbar82968002010-03-23 01:39:09 +0000112
Daniel Dunbar95506d42010-05-26 18:15:06 +0000113 if (RelaxedOp == Inst.getOpcode()) {
Daniel Dunbar82968002010-03-23 01:39:09 +0000114 SmallString<256> Tmp;
115 raw_svector_ostream OS(Tmp);
Daniel Dunbar95506d42010-05-26 18:15:06 +0000116 Inst.dump_pretty(OS);
Daniel Dunbarc9adb8c2010-05-26 15:18:13 +0000117 OS << "\n";
Chris Lattner75361b62010-04-07 22:58:41 +0000118 report_fatal_error("unexpected instruction to relax: " + OS.str());
Daniel Dunbar82968002010-03-23 01:39:09 +0000119 }
120
Daniel Dunbar95506d42010-05-26 18:15:06 +0000121 Res = Inst;
Daniel Dunbar82968002010-03-23 01:39:09 +0000122 Res.setOpcode(RelaxedOp);
123}
124
Daniel Dunbar8f9b80e2010-03-23 02:36:58 +0000125/// WriteNopData - Write optimal nops to the output file for the \arg Count
126/// bytes. This returns the number of bytes written. It may return 0 if
127/// the \arg Count is more than the maximum optimal nops.
128///
129/// FIXME this is X86 32-bit specific and should move to a better place.
130bool X86AsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
131 static const uint8_t Nops[16][16] = {
132 // nop
133 {0x90},
134 // xchg %ax,%ax
135 {0x66, 0x90},
136 // nopl (%[re]ax)
137 {0x0f, 0x1f, 0x00},
138 // nopl 0(%[re]ax)
139 {0x0f, 0x1f, 0x40, 0x00},
140 // nopl 0(%[re]ax,%[re]ax,1)
141 {0x0f, 0x1f, 0x44, 0x00, 0x00},
142 // nopw 0(%[re]ax,%[re]ax,1)
143 {0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00},
144 // nopl 0L(%[re]ax)
145 {0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00},
146 // nopl 0L(%[re]ax,%[re]ax,1)
147 {0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00},
148 // nopw 0L(%[re]ax,%[re]ax,1)
149 {0x66, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00},
150 // nopw %cs:0L(%[re]ax,%[re]ax,1)
151 {0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00},
152 // nopl 0(%[re]ax,%[re]ax,1)
153 // nopw 0(%[re]ax,%[re]ax,1)
154 {0x0f, 0x1f, 0x44, 0x00, 0x00,
155 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00},
156 // nopw 0(%[re]ax,%[re]ax,1)
157 // nopw 0(%[re]ax,%[re]ax,1)
158 {0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00,
159 0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00},
160 // nopw 0(%[re]ax,%[re]ax,1)
161 // nopl 0L(%[re]ax) */
162 {0x66, 0x0f, 0x1f, 0x44, 0x00, 0x00,
163 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00},
164 // nopl 0L(%[re]ax)
165 // nopl 0L(%[re]ax)
166 {0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
167 0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00},
168 // nopl 0L(%[re]ax)
169 // nopl 0L(%[re]ax,%[re]ax,1)
170 {0x0f, 0x1f, 0x80, 0x00, 0x00, 0x00, 0x00,
171 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}
172 };
173
174 // Write an optimal sequence for the first 15 bytes.
175 uint64_t OptimalCount = (Count < 16) ? Count : 15;
176 for (uint64_t i = 0, e = OptimalCount; i != e; i++)
177 OW->Write8(Nops[OptimalCount - 1][i]);
178
179 // Finish with single byte nops.
180 for (uint64_t i = OptimalCount, e = Count; i != e; ++i)
181 OW->Write8(0x90);
182
183 return true;
184}
185
Daniel Dunbar82968002010-03-23 01:39:09 +0000186/* *** */
187
Chris Lattner9fc05222010-07-07 22:27:31 +0000188namespace {
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +0000189class ELFX86AsmBackend : public X86AsmBackend {
Rafael Espindolaf230df92010-10-16 18:23:53 +0000190 MCELFObjectFormat Format;
191
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +0000192public:
Roman Divacky5baf79e2010-09-09 17:57:50 +0000193 Triple::OSType OSType;
194 ELFX86AsmBackend(const Target &T, Triple::OSType _OSType)
195 : X86AsmBackend(T), OSType(_OSType) {
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +0000196 HasScatteredSymbols = true;
Rafael Espindola73ffea42010-09-25 05:42:19 +0000197 HasReliableSymbolDifference = true;
198 }
199
Rafael Espindolaf230df92010-10-16 18:23:53 +0000200 virtual const MCObjectFormat &getObjectFormat() const {
201 return Format;
202 }
203
Rafael Espindola73ffea42010-09-25 05:42:19 +0000204 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
205 const MCSectionELF &ES = static_cast<const MCSectionELF&>(Section);
206 return ES.getFlags() & MCSectionELF::SHF_MERGE;
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +0000207 }
208
209 bool isVirtualSection(const MCSection &Section) const {
210 const MCSectionELF &SE = static_cast<const MCSectionELF&>(Section);
Roman Divacky5baf79e2010-09-09 17:57:50 +0000211 return SE.getType() == MCSectionELF::SHT_NOBITS;
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +0000212 }
213};
214
Matt Fleming7efaef62010-05-21 11:39:07 +0000215class ELFX86_32AsmBackend : public ELFX86AsmBackend {
216public:
Roman Divacky5baf79e2010-09-09 17:57:50 +0000217 ELFX86_32AsmBackend(const Target &T, Triple::OSType OSType)
218 : ELFX86AsmBackend(T, OSType) {}
Matt Fleming453db502010-08-16 18:36:14 +0000219
Kevin Enderby8ebf6622010-09-30 16:38:07 +0000220 unsigned getPointerSize() const {
221 return 4;
222 }
223
Matt Fleming453db502010-08-16 18:36:14 +0000224 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
225 return new ELFObjectWriter(OS, /*Is64Bit=*/false,
Roman Divacky5baf79e2010-09-09 17:57:50 +0000226 OSType,
Matt Fleming453db502010-08-16 18:36:14 +0000227 /*IsLittleEndian=*/true,
228 /*HasRelocationAddend=*/false);
229 }
Matt Fleming7efaef62010-05-21 11:39:07 +0000230};
231
232class ELFX86_64AsmBackend : public ELFX86AsmBackend {
233public:
Roman Divacky5baf79e2010-09-09 17:57:50 +0000234 ELFX86_64AsmBackend(const Target &T, Triple::OSType OSType)
235 : ELFX86AsmBackend(T, OSType) {}
Matt Fleming453db502010-08-16 18:36:14 +0000236
Kevin Enderby8ebf6622010-09-30 16:38:07 +0000237 unsigned getPointerSize() const {
238 return 8;
239 }
240
Matt Fleming453db502010-08-16 18:36:14 +0000241 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
242 return new ELFObjectWriter(OS, /*Is64Bit=*/true,
Roman Divacky5baf79e2010-09-09 17:57:50 +0000243 OSType,
Matt Fleming453db502010-08-16 18:36:14 +0000244 /*IsLittleEndian=*/true,
245 /*HasRelocationAddend=*/true);
246 }
Matt Fleming7efaef62010-05-21 11:39:07 +0000247};
248
Michael J. Spencerdfd30182010-07-27 06:46:15 +0000249class WindowsX86AsmBackend : public X86AsmBackend {
Michael J. Spencerda0bfcd2010-08-21 05:58:13 +0000250 bool Is64Bit;
Rafael Espindolaf230df92010-10-16 18:23:53 +0000251 MCCOFFObjectFormat Format;
252
Michael J. Spencerdfd30182010-07-27 06:46:15 +0000253public:
Michael J. Spencerda0bfcd2010-08-21 05:58:13 +0000254 WindowsX86AsmBackend(const Target &T, bool is64Bit)
255 : X86AsmBackend(T)
256 , Is64Bit(is64Bit) {
Michael J. Spencerdfd30182010-07-27 06:46:15 +0000257 HasScatteredSymbols = true;
258 }
259
Rafael Espindolaf230df92010-10-16 18:23:53 +0000260 virtual const MCObjectFormat &getObjectFormat() const {
261 return Format;
262 }
263
Kevin Enderby8ebf6622010-09-30 16:38:07 +0000264 unsigned getPointerSize() const {
265 if (Is64Bit)
266 return 8;
267 else
268 return 4;
269 }
270
Michael J. Spencerdfd30182010-07-27 06:46:15 +0000271 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
Michael J. Spencerda0bfcd2010-08-21 05:58:13 +0000272 return createWinCOFFObjectWriter(OS, Is64Bit);
Michael J. Spencerdfd30182010-07-27 06:46:15 +0000273 }
274
275 bool isVirtualSection(const MCSection &Section) const {
276 const MCSectionCOFF &SE = static_cast<const MCSectionCOFF&>(Section);
277 return SE.getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
278 }
279};
280
Daniel Dunbar23ac7c72010-03-11 01:34:21 +0000281class DarwinX86AsmBackend : public X86AsmBackend {
Rafael Espindolaf230df92010-10-16 18:23:53 +0000282 MCMachOObjectFormat Format;
283
Daniel Dunbar23ac7c72010-03-11 01:34:21 +0000284public:
285 DarwinX86AsmBackend(const Target &T)
Daniel Dunbar06829512010-03-18 00:58:53 +0000286 : X86AsmBackend(T) {
Daniel Dunbar06829512010-03-18 00:58:53 +0000287 HasScatteredSymbols = true;
288 }
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +0000289
Rafael Espindolaf230df92010-10-16 18:23:53 +0000290 virtual const MCObjectFormat &getObjectFormat() const {
291 return Format;
292 }
293
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +0000294 bool isVirtualSection(const MCSection &Section) const {
295 const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
296 return (SMO.getType() == MCSectionMachO::S_ZEROFILL ||
Eric Christopher423c9e32010-05-17 21:02:07 +0000297 SMO.getType() == MCSectionMachO::S_GB_ZEROFILL ||
298 SMO.getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL);
Daniel Dunbarcc5b84c2010-03-19 09:29:03 +0000299 }
Daniel Dunbar23ac7c72010-03-11 01:34:21 +0000300};
301
Daniel Dunbard6e59082010-03-15 21:56:50 +0000302class DarwinX86_32AsmBackend : public DarwinX86AsmBackend {
303public:
304 DarwinX86_32AsmBackend(const Target &T)
305 : DarwinX86AsmBackend(T) {}
Daniel Dunbar1a9158c2010-03-19 10:43:26 +0000306
Kevin Enderby8ebf6622010-09-30 16:38:07 +0000307 unsigned getPointerSize() const {
308 return 4;
309 }
310
Daniel Dunbar1a9158c2010-03-19 10:43:26 +0000311 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
312 return new MachObjectWriter(OS, /*Is64Bit=*/false);
313 }
Daniel Dunbard6e59082010-03-15 21:56:50 +0000314};
315
316class DarwinX86_64AsmBackend : public DarwinX86AsmBackend {
317public:
318 DarwinX86_64AsmBackend(const Target &T)
Daniel Dunbar06829512010-03-18 00:58:53 +0000319 : DarwinX86AsmBackend(T) {
320 HasReliableSymbolDifference = true;
321 }
Daniel Dunbard6e59082010-03-15 21:56:50 +0000322
Kevin Enderby8ebf6622010-09-30 16:38:07 +0000323 unsigned getPointerSize() const {
324 return 8;
325 }
326
Daniel Dunbar1a9158c2010-03-19 10:43:26 +0000327 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
328 return new MachObjectWriter(OS, /*Is64Bit=*/true);
329 }
330
Daniel Dunbard6e59082010-03-15 21:56:50 +0000331 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
332 // Temporary labels in the string literals sections require symbols. The
333 // issue is that the x86_64 relocation format does not allow symbol +
334 // offset, and so the linker does not have enough information to resolve the
335 // access to the appropriate atom unless an external relocation is used. For
336 // non-cstring sections, we expect the compiler to use a non-temporary label
337 // for anything that could have an addend pointing outside the symbol.
338 //
339 // See <rdar://problem/4765733>.
340 const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
341 return SMO.getType() == MCSectionMachO::S_CSTRING_LITERALS;
342 }
Daniel Dunbara5f1d572010-05-12 00:38:17 +0000343
344 virtual bool isSectionAtomizable(const MCSection &Section) const {
345 const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
346 // Fixed sized data sections are uniqued, they cannot be diced into atoms.
347 switch (SMO.getType()) {
348 default:
349 return true;
350
351 case MCSectionMachO::S_4BYTE_LITERALS:
352 case MCSectionMachO::S_8BYTE_LITERALS:
353 case MCSectionMachO::S_16BYTE_LITERALS:
354 case MCSectionMachO::S_LITERAL_POINTERS:
355 case MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS:
356 case MCSectionMachO::S_LAZY_SYMBOL_POINTERS:
357 case MCSectionMachO::S_MOD_INIT_FUNC_POINTERS:
358 case MCSectionMachO::S_MOD_TERM_FUNC_POINTERS:
359 case MCSectionMachO::S_INTERPOSING:
360 return false;
361 }
362 }
Daniel Dunbard6e59082010-03-15 21:56:50 +0000363};
364
Michael J. Spencerec38de22010-10-10 22:04:20 +0000365} // end anonymous namespace
Daniel Dunbar12783d12010-02-21 21:54:14 +0000366
367TargetAsmBackend *llvm::createX86_32AsmBackend(const Target &T,
Daniel Dunbar6c27f5e2010-03-11 01:34:16 +0000368 const std::string &TT) {
Daniel Dunbar23ac7c72010-03-11 01:34:21 +0000369 switch (Triple(TT).getOS()) {
370 case Triple::Darwin:
Daniel Dunbard6e59082010-03-15 21:56:50 +0000371 return new DarwinX86_32AsmBackend(T);
Benjamin Kramer56d23942010-08-04 15:32:40 +0000372 case Triple::MinGW32:
373 case Triple::Cygwin:
Michael J. Spencerdfd30182010-07-27 06:46:15 +0000374 case Triple::Win32:
Michael J. Spencerda0bfcd2010-08-21 05:58:13 +0000375 return new WindowsX86AsmBackend(T, false);
Daniel Dunbar23ac7c72010-03-11 01:34:21 +0000376 default:
Roman Divacky5baf79e2010-09-09 17:57:50 +0000377 return new ELFX86_32AsmBackend(T, Triple(TT).getOS());
Daniel Dunbar23ac7c72010-03-11 01:34:21 +0000378 }
Daniel Dunbar12783d12010-02-21 21:54:14 +0000379}
380
381TargetAsmBackend *llvm::createX86_64AsmBackend(const Target &T,
Daniel Dunbar6c27f5e2010-03-11 01:34:16 +0000382 const std::string &TT) {
Daniel Dunbar23ac7c72010-03-11 01:34:21 +0000383 switch (Triple(TT).getOS()) {
384 case Triple::Darwin:
Daniel Dunbard6e59082010-03-15 21:56:50 +0000385 return new DarwinX86_64AsmBackend(T);
Michael J. Spencerda0bfcd2010-08-21 05:58:13 +0000386 case Triple::MinGW64:
387 case Triple::Cygwin:
388 case Triple::Win32:
389 return new WindowsX86AsmBackend(T, true);
Daniel Dunbar23ac7c72010-03-11 01:34:21 +0000390 default:
Roman Divacky5baf79e2010-09-09 17:57:50 +0000391 return new ELFX86_64AsmBackend(T, Triple(TT).getOS());
Daniel Dunbar23ac7c72010-03-11 01:34:21 +0000392 }
Daniel Dunbar12783d12010-02-21 21:54:14 +0000393}