blob: 4b24ccc2d96e9be53bd052fb9a19939a01c2eca2 [file] [log] [blame]
Jim Laskey8e8de8f2006-09-07 22:05:02 +00001//===-- X86TargetAsmInfo.cpp - X86 asm properties ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jim Laskey8e8de8f2006-09-07 22:05:02 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file contains the declarations of the X86TargetAsmInfo properties.
11//
12//===----------------------------------------------------------------------===//
13
14#include "X86TargetAsmInfo.h"
15#include "X86TargetMachine.h"
16#include "X86Subtarget.h"
Reid Spencer7aa8a452007-01-12 23:22:14 +000017#include "llvm/DerivedTypes.h"
Chris Lattner625bd052006-11-29 01:14:06 +000018#include "llvm/InlineAsm.h"
19#include "llvm/Instructions.h"
Chris Lattner3e9f1d02007-04-01 20:49:36 +000020#include "llvm/Intrinsics.h"
Chris Lattner625bd052006-11-29 01:14:06 +000021#include "llvm/Module.h"
22#include "llvm/ADT/StringExtras.h"
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000023#include "llvm/Support/Dwarf.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000024#include "llvm/Support/ErrorHandling.h"
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000025
Jim Laskey8e8de8f2006-09-07 22:05:02 +000026using namespace llvm;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000027using namespace llvm::dwarf;
Jim Laskey8e8de8f2006-09-07 22:05:02 +000028
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000029const char *const llvm::x86_asm_table[] = {
30 "{si}", "S",
31 "{di}", "D",
32 "{ax}", "a",
33 "{cx}", "c",
34 "{memory}", "memory",
35 "{flags}", "",
36 "{dirflag}", "",
37 "{fpsr}", "",
38 "{cc}", "cc",
39 0,0};
Andrew Lenharth6c0695f2006-11-28 19:52:49 +000040
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000041X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000042 X86TargetAsmInfo<DarwinTargetAsmInfo>(TM) {
Dan Gohman8f092252008-11-03 18:22:42 +000043 const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
Anton Korobeynikov16b7f512008-08-08 18:25:52 +000044 bool is64Bit = Subtarget->is64Bit();
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000045
46 AlignmentIsInBytes = false;
47 TextAlignFillValue = 0x90;
Chris Lattner4e0f25b2009-06-19 00:08:39 +000048
49
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000050 if (!is64Bit)
51 Data64bitsDirective = 0; // we can't emit a 64-bit unit
52 ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000053 ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
Dan Gohman8f092252008-11-03 18:22:42 +000054 if (TM.getRelocationModel() != Reloc::Static)
Anton Korobeynikov7705ea32008-07-09 21:54:26 +000055 ConstantPoolSection = "\t.const_data";
56 else
57 ConstantPoolSection = "\t.const\n";
Chris Lattner4e0f25b2009-06-19 00:08:39 +000058 // FIXME: Why don't we always use this section?
59 if (is64Bit)
Anton Korobeynikov64818732008-09-24 22:18:54 +000060 SixteenByteConstantSection = getUnnamedSection("\t.literal16\n",
61 SectionFlags::Mergeable);
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000062 LCOMMDirective = "\t.lcomm\t";
Anton Korobeynikov16b7f512008-08-08 18:25:52 +000063 // Leopard and above support aligned common symbols.
64 COMMDirectiveTakesAlignment = (Subtarget->getDarwinVers() >= 9);
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000065 HasDotTypeDotSizeDirective = false;
Bill Wendling722f5f12008-12-24 08:05:17 +000066 NonLocalEHFrameLabel = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000067 if (is64Bit) {
68 PersonalityPrefix = "";
69 PersonalitySuffix = "+4@GOTPCREL";
70 } else {
71 PersonalityPrefix = "L";
72 PersonalitySuffix = "$non_lazy_ptr";
73 }
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000074 InlineAsmStart = "## InlineAsm Start";
75 InlineAsmEnd = "## InlineAsm End";
76 CommentString = "##";
77 SetDirective = "\t.set";
78 PCSymbol = ".";
79 UsedDirective = "\t.no_dead_strip\t";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000080 ProtectedDirective = "\t.globl\t";
81
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000082 SupportsDebugInformation = true;
Chris Lattner4e0f25b2009-06-19 00:08:39 +000083
Devang Patel0f7fef32009-04-13 17:02:03 +000084 DwarfDebugInlineSection = ".section __DWARF,__debug_inlined,regular,debug";
85 DwarfUsesInlineInfoSection = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000086
87 // Exceptions handling
88 SupportsExceptionHandling = true;
89 GlobalEHDirective = "\t.globl\t";
90 SupportsWeakOmittedEHFrame = false;
91 AbsoluteEHSectionOffsets = false;
92 DwarfEHFrameSection =
93 ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
94 DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
95}
96
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +000097unsigned
98X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
99 bool Global) const {
100 if (Reason == DwarfEncoding::Functions && Global)
101 return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
102 else if (Reason == DwarfEncoding::CodeLabels || !Global)
103 return DW_EH_PE_pcrel;
104 else
105 return DW_EH_PE_absptr;
106}
107
Rafael Espindola2f6fea92008-12-19 10:55:56 +0000108const char *
109X86DarwinTargetAsmInfo::getEHGlobalPrefix() const
110{
111 const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
112 if (Subtarget->getDarwinVers() > 9)
113 return PrivateGlobalPrefix;
114 else
115 return "";
116}
117
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000118X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000119 X86TargetAsmInfo<ELFTargetAsmInfo>(TM) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000120
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000121 CStringSection = ".rodata.str";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000122 PrivateGlobalPrefix = ".L";
123 WeakRefDirective = "\t.weak\t";
124 SetDirective = "\t.set\t";
125 PCSymbol = ".";
126
127 // Set up DWARF directives
128 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
129
130 // Debug Information
131 AbsoluteDebugSectionOffsets = true;
132 SupportsDebugInformation = true;
133 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
134 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
135 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
136 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
137 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
138 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
139 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
140 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
141 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
142 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000143 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000144
145 // Exceptions handling
Anton Korobeynikovc4da15a2008-09-08 21:13:08 +0000146 SupportsExceptionHandling = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000147 AbsoluteEHSectionOffsets = false;
148 DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
149 DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
150
151 // On Linux we must declare when we can use a non-executable stack.
Dan Gohman8f092252008-11-03 18:22:42 +0000152 if (TM.getSubtarget<X86Subtarget>().isLinux())
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000153 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
154}
155
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000156unsigned
157X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
158 bool Global) const {
Dan Gohman8f092252008-11-03 18:22:42 +0000159 CodeModel::Model CM = TM.getCodeModel();
160 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000161
Dan Gohman8f092252008-11-03 18:22:42 +0000162 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000163 unsigned Format = 0;
164
165 if (!is64Bit)
166 // 32 bit targets always encode pointers as 4 bytes
167 Format = DW_EH_PE_sdata4;
168 else {
169 // 64 bit targets encode pointers in 4 bytes iff:
170 // - code model is small OR
171 // - code model is medium and we're emitting externally visible symbols
172 // or any code symbols
173 if (CM == CodeModel::Small ||
174 (CM == CodeModel::Medium && (Global ||
175 Reason != DwarfEncoding::Data)))
176 Format = DW_EH_PE_sdata4;
177 else
178 Format = DW_EH_PE_sdata8;
179 }
180
181 if (Global)
182 Format |= DW_EH_PE_indirect;
183
184 return (Format | DW_EH_PE_pcrel);
185 } else {
186 if (is64Bit &&
187 (CM == CodeModel::Small ||
188 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
189 return DW_EH_PE_udata4;
190 else
191 return DW_EH_PE_absptr;
192 }
193}
194
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000195X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000196 X86GenericTargetAsmInfo(TM) {
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000197
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000198 GlobalPrefix = "_";
199 LCOMMDirective = "\t.lcomm\t";
200 COMMDirectiveTakesAlignment = false;
201 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +0000202 HasSingleParameterDotFile = false;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000203 StaticCtorsSection = "\t.section .ctors,\"aw\"";
204 StaticDtorsSection = "\t.section .dtors,\"aw\"";
205 HiddenDirective = NULL;
206 PrivateGlobalPrefix = "L"; // Prefix for private global symbols
207 WeakRefDirective = "\t.weak\t";
208 SetDirective = "\t.set\t";
209
210 // Set up DWARF directives
211 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
212 AbsoluteDebugSectionOffsets = true;
213 AbsoluteEHSectionOffsets = false;
214 SupportsDebugInformation = true;
215 DwarfSectionOffsetDirective = "\t.secrel32\t";
216 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\"";
217 DwarfInfoSection = "\t.section\t.debug_info,\"dr\"";
218 DwarfLineSection = "\t.section\t.debug_line,\"dr\"";
219 DwarfFrameSection = "\t.section\t.debug_frame,\"dr\"";
220 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
221 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
222 DwarfStrSection = "\t.section\t.debug_str,\"dr\"";
223 DwarfLocSection = "\t.section\t.debug_loc,\"dr\"";
224 DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
225 DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\"";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000226 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000227}
228
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000229unsigned
230X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
231 bool Global) const {
Dan Gohman8f092252008-11-03 18:22:42 +0000232 CodeModel::Model CM = TM.getCodeModel();
233 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000234
Dan Gohman8f092252008-11-03 18:22:42 +0000235 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000236 unsigned Format = 0;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000237
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000238 if (!is64Bit)
239 // 32 bit targets always encode pointers as 4 bytes
240 Format = DW_EH_PE_sdata4;
241 else {
242 // 64 bit targets encode pointers in 4 bytes iff:
243 // - code model is small OR
244 // - code model is medium and we're emitting externally visible symbols
245 // or any code symbols
246 if (CM == CodeModel::Small ||
247 (CM == CodeModel::Medium && (Global ||
248 Reason != DwarfEncoding::Data)))
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000249 Format = DW_EH_PE_sdata4;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000250 else
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000251 Format = DW_EH_PE_sdata8;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000252 }
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000253
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000254 if (Global)
255 Format |= DW_EH_PE_indirect;
256
257 return (Format | DW_EH_PE_pcrel);
258 } else {
259 if (is64Bit &&
260 (CM == CodeModel::Small ||
261 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
262 return DW_EH_PE_udata4;
263 else
264 return DW_EH_PE_absptr;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000265 }
266}
267
Anton Korobeynikovb9a02fc2008-07-09 13:21:29 +0000268std::string
269X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
270 SectionKind::Kind kind) const {
271 switch (kind) {
272 case SectionKind::Text:
273 return ".text$linkonce" + GV->getName();
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000274 case SectionKind::Data:
275 case SectionKind::BSS:
276 case SectionKind::ThreadData:
277 case SectionKind::ThreadBSS:
278 return ".data$linkonce" + GV->getName();
Anton Korobeynikovb9a02fc2008-07-09 13:21:29 +0000279 case SectionKind::ROData:
280 case SectionKind::RODataMergeConst:
281 case SectionKind::RODataMergeStr:
282 return ".rdata$linkonce" + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000283 default:
Torok Edwinc25e7582009-07-11 20:10:48 +0000284 LLVM_UNREACHABLE("Unknown section kind");
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000285 }
Devang Patel8a84e442009-01-05 17:31:22 +0000286 return NULL;
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000287}
288
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000289std::string X86COFFTargetAsmInfo::printSectionFlags(unsigned flags) const {
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000290 std::string Flags = ",\"";
291
292 if (flags & SectionFlags::Code)
293 Flags += 'x';
294 if (flags & SectionFlags::Writeable)
295 Flags += 'w';
296
297 Flags += "\"";
298
299 return Flags;
300}
301
302X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000303 X86GenericTargetAsmInfo(TM) {
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000304 GlobalPrefix = "_";
305 CommentString = ";";
306
Eli Friedmanaace4b12009-06-19 04:48:38 +0000307 InlineAsmStart = "; InlineAsm Start";
308 InlineAsmEnd = "; InlineAsm End";
309
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000310 PrivateGlobalPrefix = "$";
Eli Friedmanaace4b12009-06-19 04:48:38 +0000311 AlignDirective = "\tALIGN\t";
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000312 ZeroDirective = "\tdb\t";
313 ZeroDirectiveSuffix = " dup(0)";
314 AsciiDirective = "\tdb\t";
315 AscizDirective = 0;
316 Data8bitsDirective = "\tdb\t";
317 Data16bitsDirective = "\tdw\t";
318 Data32bitsDirective = "\tdd\t";
319 Data64bitsDirective = "\tdq\t";
320 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +0000321 HasSingleParameterDotFile = false;
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000322
Eli Friedmanaace4b12009-06-19 04:48:38 +0000323 AlignmentIsInBytes = true;
324
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000325 TextSection = getUnnamedSection("_text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000326 DataSection = getUnnamedSection("_data", SectionFlags::Writeable);
327
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000328 JumpTableDataSection = NULL;
329 SwitchToSectionDirective = "";
Eli Friedmanaace4b12009-06-19 04:48:38 +0000330 TextSectionStartSuffix = "\tSEGMENT PARA 'CODE'";
331 DataSectionStartSuffix = "\tSEGMENT PARA 'DATA'";
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000332 SectionEndDirectiveSuffix = "\tends\n";
333}
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000334
335template <class BaseTAI>
336bool X86TargetAsmInfo<BaseTAI>::LowerToBSwap(CallInst *CI) const {
337 // FIXME: this should verify that we are targetting a 486 or better. If not,
338 // we will turn this bswap into something that will be lowered to logical ops
339 // instead of emitting the bswap asm. For now, we don't support 486 or lower
340 // so don't worry about this.
341
342 // Verify this is a simple bswap.
343 if (CI->getNumOperands() != 2 ||
344 CI->getType() != CI->getOperand(1)->getType() ||
345 !CI->getType()->isInteger())
346 return false;
347
348 const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
349 if (!Ty || Ty->getBitWidth() % 16 != 0)
350 return false;
351
352 // Okay, we can do this xform, do so now.
353 const Type *Tys[] = { Ty };
354 Module *M = CI->getParent()->getParent()->getParent();
355 Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
356
357 Value *Op = CI->getOperand(1);
358 Op = CallInst::Create(Int, Op, CI->getName(), CI);
359
360 CI->replaceAllUsesWith(Op);
361 CI->eraseFromParent();
362 return true;
363}
364
365template <class BaseTAI>
366bool X86TargetAsmInfo<BaseTAI>::ExpandInlineAsm(CallInst *CI) const {
367 InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue());
368 std::vector<InlineAsm::ConstraintInfo> Constraints = IA->ParseConstraints();
369
370 std::string AsmStr = IA->getAsmString();
371
372 // TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a"
373 std::vector<std::string> AsmPieces;
374 SplitString(AsmStr, AsmPieces, "\n"); // ; as separator?
375
376 switch (AsmPieces.size()) {
377 default: return false;
378 case 1:
379 AsmStr = AsmPieces[0];
380 AsmPieces.clear();
381 SplitString(AsmStr, AsmPieces, " \t"); // Split with whitespace.
382
383 // bswap $0
384 if (AsmPieces.size() == 2 &&
Dan Gohman96264472009-03-17 02:45:40 +0000385 (AsmPieces[0] == "bswap" ||
386 AsmPieces[0] == "bswapq" ||
387 AsmPieces[0] == "bswapl") &&
388 (AsmPieces[1] == "$0" ||
389 AsmPieces[1] == "${0:q}")) {
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000390 // No need to check constraints, nothing other than the equivalent of
391 // "=r,0" would be valid here.
392 return LowerToBSwap(CI);
393 }
Dan Gohmandbf5f252009-01-21 23:40:54 +0000394 // rorw $$8, ${0:w} --> llvm.bswap.i16
395 if (CI->getType() == Type::Int16Ty &&
396 AsmPieces.size() == 3 &&
397 AsmPieces[0] == "rorw" &&
398 AsmPieces[1] == "$$8," &&
399 AsmPieces[2] == "${0:w}" &&
400 IA->getConstraintString() == "=r,0,~{dirflag},~{fpsr},~{flags},~{cc}") {
401 return LowerToBSwap(CI);
402 }
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000403 break;
404 case 3:
405 if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 &&
406 Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" &&
407 Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") {
408 // bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64
409 std::vector<std::string> Words;
410 SplitString(AsmPieces[0], Words, " \t");
411 if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%eax") {
412 Words.clear();
413 SplitString(AsmPieces[1], Words, " \t");
414 if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%edx") {
415 Words.clear();
416 SplitString(AsmPieces[2], Words, " \t,");
417 if (Words.size() == 3 && Words[0] == "xchgl" && Words[1] == "%eax" &&
418 Words[2] == "%edx") {
419 return LowerToBSwap(CI);
420 }
421 }
422 }
423 }
424 break;
425 }
426 return false;
427}
428
429// Instantiate default implementation.
430TEMPLATE_INSTANTIATION(class X86TargetAsmInfo<TargetAsmInfo>);