blob: 5a60bce43dcb430f4b6d931f40c1c6ff356d3de8 [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) {
Bill Wendlingb6be1392009-07-13 18:48:39 +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";
Bill Wendlingb6be1392009-07-13 18:48:39 +000063
Anton Korobeynikov16b7f512008-08-08 18:25:52 +000064 // Leopard and above support aligned common symbols.
65 COMMDirectiveTakesAlignment = (Subtarget->getDarwinVers() >= 9);
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000066 HasDotTypeDotSizeDirective = false;
Bill Wendling722f5f12008-12-24 08:05:17 +000067 NonLocalEHFrameLabel = true;
Bill Wendlingb6be1392009-07-13 18:48:39 +000068
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000069 if (is64Bit) {
70 PersonalityPrefix = "";
71 PersonalitySuffix = "+4@GOTPCREL";
72 } else {
73 PersonalityPrefix = "L";
74 PersonalitySuffix = "$non_lazy_ptr";
75 }
Bill Wendlingb6be1392009-07-13 18:48:39 +000076
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000077 InlineAsmStart = "## InlineAsm Start";
78 InlineAsmEnd = "## InlineAsm End";
79 CommentString = "##";
80 SetDirective = "\t.set";
81 PCSymbol = ".";
82 UsedDirective = "\t.no_dead_strip\t";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000083 ProtectedDirective = "\t.globl\t";
84
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000085 SupportsDebugInformation = true;
Devang Patel0f7fef32009-04-13 17:02:03 +000086 DwarfDebugInlineSection = ".section __DWARF,__debug_inlined,regular,debug";
87 DwarfUsesInlineInfoSection = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000088
89 // Exceptions handling
90 SupportsExceptionHandling = true;
91 GlobalEHDirective = "\t.globl\t";
92 SupportsWeakOmittedEHFrame = false;
93 AbsoluteEHSectionOffsets = false;
94 DwarfEHFrameSection =
95 ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
Bill Wendlingdb425492009-07-13 20:27:41 +000096 DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000097}
98
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +000099unsigned
100X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
101 bool Global) const {
102 if (Reason == DwarfEncoding::Functions && Global)
103 return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
104 else if (Reason == DwarfEncoding::CodeLabels || !Global)
105 return DW_EH_PE_pcrel;
106 else
107 return DW_EH_PE_absptr;
108}
109
Rafael Espindola2f6fea92008-12-19 10:55:56 +0000110const char *
111X86DarwinTargetAsmInfo::getEHGlobalPrefix() const
112{
113 const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
114 if (Subtarget->getDarwinVers() > 9)
115 return PrivateGlobalPrefix;
116 else
117 return "";
118}
119
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000120X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000121 X86TargetAsmInfo<ELFTargetAsmInfo>(TM) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000122
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000123 CStringSection = ".rodata.str";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000124 PrivateGlobalPrefix = ".L";
125 WeakRefDirective = "\t.weak\t";
126 SetDirective = "\t.set\t";
127 PCSymbol = ".";
128
129 // Set up DWARF directives
130 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
131
132 // Debug Information
133 AbsoluteDebugSectionOffsets = true;
134 SupportsDebugInformation = true;
135 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
136 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
137 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
138 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
139 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
140 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
141 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
142 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
143 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
144 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000145 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000146
147 // Exceptions handling
Anton Korobeynikovc4da15a2008-09-08 21:13:08 +0000148 SupportsExceptionHandling = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000149 AbsoluteEHSectionOffsets = false;
150 DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
151 DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
152
153 // On Linux we must declare when we can use a non-executable stack.
Dan Gohman8f092252008-11-03 18:22:42 +0000154 if (TM.getSubtarget<X86Subtarget>().isLinux())
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000155 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
156}
157
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000158unsigned
159X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
160 bool Global) const {
Dan Gohman8f092252008-11-03 18:22:42 +0000161 CodeModel::Model CM = TM.getCodeModel();
162 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000163
Dan Gohman8f092252008-11-03 18:22:42 +0000164 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000165 unsigned Format = 0;
166
167 if (!is64Bit)
168 // 32 bit targets always encode pointers as 4 bytes
169 Format = DW_EH_PE_sdata4;
170 else {
171 // 64 bit targets encode pointers in 4 bytes iff:
172 // - code model is small OR
173 // - code model is medium and we're emitting externally visible symbols
174 // or any code symbols
175 if (CM == CodeModel::Small ||
176 (CM == CodeModel::Medium && (Global ||
177 Reason != DwarfEncoding::Data)))
178 Format = DW_EH_PE_sdata4;
179 else
180 Format = DW_EH_PE_sdata8;
181 }
182
183 if (Global)
184 Format |= DW_EH_PE_indirect;
185
186 return (Format | DW_EH_PE_pcrel);
187 } else {
188 if (is64Bit &&
189 (CM == CodeModel::Small ||
190 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
191 return DW_EH_PE_udata4;
192 else
193 return DW_EH_PE_absptr;
194 }
195}
196
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000197X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000198 X86GenericTargetAsmInfo(TM) {
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000199
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000200 GlobalPrefix = "_";
201 LCOMMDirective = "\t.lcomm\t";
202 COMMDirectiveTakesAlignment = false;
203 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +0000204 HasSingleParameterDotFile = false;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000205 StaticCtorsSection = "\t.section .ctors,\"aw\"";
206 StaticDtorsSection = "\t.section .dtors,\"aw\"";
207 HiddenDirective = NULL;
208 PrivateGlobalPrefix = "L"; // Prefix for private global symbols
209 WeakRefDirective = "\t.weak\t";
210 SetDirective = "\t.set\t";
211
212 // Set up DWARF directives
213 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
214 AbsoluteDebugSectionOffsets = true;
215 AbsoluteEHSectionOffsets = false;
216 SupportsDebugInformation = true;
217 DwarfSectionOffsetDirective = "\t.secrel32\t";
218 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\"";
219 DwarfInfoSection = "\t.section\t.debug_info,\"dr\"";
220 DwarfLineSection = "\t.section\t.debug_line,\"dr\"";
221 DwarfFrameSection = "\t.section\t.debug_frame,\"dr\"";
222 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
223 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
224 DwarfStrSection = "\t.section\t.debug_str,\"dr\"";
225 DwarfLocSection = "\t.section\t.debug_loc,\"dr\"";
226 DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
227 DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\"";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000228 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000229}
230
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000231unsigned
232X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
233 bool Global) const {
Dan Gohman8f092252008-11-03 18:22:42 +0000234 CodeModel::Model CM = TM.getCodeModel();
235 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000236
Dan Gohman8f092252008-11-03 18:22:42 +0000237 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000238 unsigned Format = 0;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000239
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000240 if (!is64Bit)
241 // 32 bit targets always encode pointers as 4 bytes
242 Format = DW_EH_PE_sdata4;
243 else {
244 // 64 bit targets encode pointers in 4 bytes iff:
245 // - code model is small OR
246 // - code model is medium and we're emitting externally visible symbols
247 // or any code symbols
248 if (CM == CodeModel::Small ||
249 (CM == CodeModel::Medium && (Global ||
250 Reason != DwarfEncoding::Data)))
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000251 Format = DW_EH_PE_sdata4;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000252 else
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000253 Format = DW_EH_PE_sdata8;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000254 }
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000255
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000256 if (Global)
257 Format |= DW_EH_PE_indirect;
258
259 return (Format | DW_EH_PE_pcrel);
260 } else {
261 if (is64Bit &&
262 (CM == CodeModel::Small ||
263 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
264 return DW_EH_PE_udata4;
265 else
266 return DW_EH_PE_absptr;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000267 }
268}
269
Anton Korobeynikovb9a02fc2008-07-09 13:21:29 +0000270std::string
271X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
272 SectionKind::Kind kind) const {
273 switch (kind) {
274 case SectionKind::Text:
275 return ".text$linkonce" + GV->getName();
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000276 case SectionKind::Data:
277 case SectionKind::BSS:
278 case SectionKind::ThreadData:
279 case SectionKind::ThreadBSS:
280 return ".data$linkonce" + GV->getName();
Anton Korobeynikovb9a02fc2008-07-09 13:21:29 +0000281 case SectionKind::ROData:
282 case SectionKind::RODataMergeConst:
283 case SectionKind::RODataMergeStr:
284 return ".rdata$linkonce" + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000285 default:
Torok Edwinc25e7582009-07-11 20:10:48 +0000286 LLVM_UNREACHABLE("Unknown section kind");
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000287 }
Devang Patel8a84e442009-01-05 17:31:22 +0000288 return NULL;
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000289}
290
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000291std::string X86COFFTargetAsmInfo::printSectionFlags(unsigned flags) const {
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000292 std::string Flags = ",\"";
293
294 if (flags & SectionFlags::Code)
295 Flags += 'x';
296 if (flags & SectionFlags::Writeable)
297 Flags += 'w';
298
299 Flags += "\"";
300
301 return Flags;
302}
303
304X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000305 X86GenericTargetAsmInfo(TM) {
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000306 GlobalPrefix = "_";
307 CommentString = ";";
308
Eli Friedmanaace4b12009-06-19 04:48:38 +0000309 InlineAsmStart = "; InlineAsm Start";
310 InlineAsmEnd = "; InlineAsm End";
311
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000312 PrivateGlobalPrefix = "$";
Eli Friedmanaace4b12009-06-19 04:48:38 +0000313 AlignDirective = "\tALIGN\t";
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000314 ZeroDirective = "\tdb\t";
315 ZeroDirectiveSuffix = " dup(0)";
316 AsciiDirective = "\tdb\t";
317 AscizDirective = 0;
318 Data8bitsDirective = "\tdb\t";
319 Data16bitsDirective = "\tdw\t";
320 Data32bitsDirective = "\tdd\t";
321 Data64bitsDirective = "\tdq\t";
322 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +0000323 HasSingleParameterDotFile = false;
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000324
Eli Friedmanaace4b12009-06-19 04:48:38 +0000325 AlignmentIsInBytes = true;
326
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000327 TextSection = getUnnamedSection("_text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000328 DataSection = getUnnamedSection("_data", SectionFlags::Writeable);
329
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000330 JumpTableDataSection = NULL;
331 SwitchToSectionDirective = "";
Eli Friedmanaace4b12009-06-19 04:48:38 +0000332 TextSectionStartSuffix = "\tSEGMENT PARA 'CODE'";
333 DataSectionStartSuffix = "\tSEGMENT PARA 'DATA'";
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000334 SectionEndDirectiveSuffix = "\tends\n";
335}
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000336
337template <class BaseTAI>
338bool X86TargetAsmInfo<BaseTAI>::LowerToBSwap(CallInst *CI) const {
339 // FIXME: this should verify that we are targetting a 486 or better. If not,
340 // we will turn this bswap into something that will be lowered to logical ops
341 // instead of emitting the bswap asm. For now, we don't support 486 or lower
342 // so don't worry about this.
343
344 // Verify this is a simple bswap.
345 if (CI->getNumOperands() != 2 ||
346 CI->getType() != CI->getOperand(1)->getType() ||
347 !CI->getType()->isInteger())
348 return false;
349
350 const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
351 if (!Ty || Ty->getBitWidth() % 16 != 0)
352 return false;
353
354 // Okay, we can do this xform, do so now.
355 const Type *Tys[] = { Ty };
356 Module *M = CI->getParent()->getParent()->getParent();
357 Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
358
359 Value *Op = CI->getOperand(1);
360 Op = CallInst::Create(Int, Op, CI->getName(), CI);
361
362 CI->replaceAllUsesWith(Op);
363 CI->eraseFromParent();
364 return true;
365}
366
367template <class BaseTAI>
368bool X86TargetAsmInfo<BaseTAI>::ExpandInlineAsm(CallInst *CI) const {
369 InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue());
370 std::vector<InlineAsm::ConstraintInfo> Constraints = IA->ParseConstraints();
371
372 std::string AsmStr = IA->getAsmString();
373
374 // TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a"
375 std::vector<std::string> AsmPieces;
376 SplitString(AsmStr, AsmPieces, "\n"); // ; as separator?
377
378 switch (AsmPieces.size()) {
379 default: return false;
380 case 1:
381 AsmStr = AsmPieces[0];
382 AsmPieces.clear();
383 SplitString(AsmStr, AsmPieces, " \t"); // Split with whitespace.
384
385 // bswap $0
386 if (AsmPieces.size() == 2 &&
Dan Gohman96264472009-03-17 02:45:40 +0000387 (AsmPieces[0] == "bswap" ||
388 AsmPieces[0] == "bswapq" ||
389 AsmPieces[0] == "bswapl") &&
390 (AsmPieces[1] == "$0" ||
391 AsmPieces[1] == "${0:q}")) {
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000392 // No need to check constraints, nothing other than the equivalent of
393 // "=r,0" would be valid here.
394 return LowerToBSwap(CI);
395 }
Dan Gohmandbf5f252009-01-21 23:40:54 +0000396 // rorw $$8, ${0:w} --> llvm.bswap.i16
397 if (CI->getType() == Type::Int16Ty &&
398 AsmPieces.size() == 3 &&
399 AsmPieces[0] == "rorw" &&
400 AsmPieces[1] == "$$8," &&
401 AsmPieces[2] == "${0:w}" &&
402 IA->getConstraintString() == "=r,0,~{dirflag},~{fpsr},~{flags},~{cc}") {
403 return LowerToBSwap(CI);
404 }
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000405 break;
406 case 3:
407 if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 &&
408 Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" &&
409 Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") {
410 // bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64
411 std::vector<std::string> Words;
412 SplitString(AsmPieces[0], Words, " \t");
413 if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%eax") {
414 Words.clear();
415 SplitString(AsmPieces[1], Words, " \t");
416 if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%edx") {
417 Words.clear();
418 SplitString(AsmPieces[2], Words, " \t,");
419 if (Words.size() == 3 && Words[0] == "xchgl" && Words[1] == "%eax" &&
420 Words[2] == "%edx") {
421 return LowerToBSwap(CI);
422 }
423 }
424 }
425 }
426 break;
427 }
428 return false;
429}
430
431// Instantiate default implementation.
432TEMPLATE_INSTANTIATION(class X86TargetAsmInfo<TargetAsmInfo>);