blob: 244d2f16a9b73df8a67a9e0967f06867c851f686 [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 Wendlingb6be1392009-07-13 18:48:39 +000096
97 // Leopard and earlier put exception tables in __DATA. Greater than Leopard
98 // put them in __TEXT.
99 if (Subtarget->getDarwinVers() < 10)
100 DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
101 else
102 DwarfExceptionSection = ".section __TEXT,__gcc_except_tab";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000103}
104
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000105unsigned
106X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
107 bool Global) const {
108 if (Reason == DwarfEncoding::Functions && Global)
109 return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
110 else if (Reason == DwarfEncoding::CodeLabels || !Global)
111 return DW_EH_PE_pcrel;
112 else
113 return DW_EH_PE_absptr;
114}
115
Rafael Espindola2f6fea92008-12-19 10:55:56 +0000116const char *
117X86DarwinTargetAsmInfo::getEHGlobalPrefix() const
118{
119 const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
120 if (Subtarget->getDarwinVers() > 9)
121 return PrivateGlobalPrefix;
122 else
123 return "";
124}
125
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000126X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000127 X86TargetAsmInfo<ELFTargetAsmInfo>(TM) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000128
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000129 CStringSection = ".rodata.str";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000130 PrivateGlobalPrefix = ".L";
131 WeakRefDirective = "\t.weak\t";
132 SetDirective = "\t.set\t";
133 PCSymbol = ".";
134
135 // Set up DWARF directives
136 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
137
138 // Debug Information
139 AbsoluteDebugSectionOffsets = true;
140 SupportsDebugInformation = true;
141 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
142 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
143 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
144 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
145 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
146 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
147 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
148 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
149 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
150 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000151 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000152
153 // Exceptions handling
Anton Korobeynikovc4da15a2008-09-08 21:13:08 +0000154 SupportsExceptionHandling = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000155 AbsoluteEHSectionOffsets = false;
156 DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
157 DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
158
159 // On Linux we must declare when we can use a non-executable stack.
Dan Gohman8f092252008-11-03 18:22:42 +0000160 if (TM.getSubtarget<X86Subtarget>().isLinux())
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000161 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
162}
163
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000164unsigned
165X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
166 bool Global) const {
Dan Gohman8f092252008-11-03 18:22:42 +0000167 CodeModel::Model CM = TM.getCodeModel();
168 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000169
Dan Gohman8f092252008-11-03 18:22:42 +0000170 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000171 unsigned Format = 0;
172
173 if (!is64Bit)
174 // 32 bit targets always encode pointers as 4 bytes
175 Format = DW_EH_PE_sdata4;
176 else {
177 // 64 bit targets encode pointers in 4 bytes iff:
178 // - code model is small OR
179 // - code model is medium and we're emitting externally visible symbols
180 // or any code symbols
181 if (CM == CodeModel::Small ||
182 (CM == CodeModel::Medium && (Global ||
183 Reason != DwarfEncoding::Data)))
184 Format = DW_EH_PE_sdata4;
185 else
186 Format = DW_EH_PE_sdata8;
187 }
188
189 if (Global)
190 Format |= DW_EH_PE_indirect;
191
192 return (Format | DW_EH_PE_pcrel);
193 } else {
194 if (is64Bit &&
195 (CM == CodeModel::Small ||
196 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
197 return DW_EH_PE_udata4;
198 else
199 return DW_EH_PE_absptr;
200 }
201}
202
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000203X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000204 X86GenericTargetAsmInfo(TM) {
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000205
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000206 GlobalPrefix = "_";
207 LCOMMDirective = "\t.lcomm\t";
208 COMMDirectiveTakesAlignment = false;
209 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +0000210 HasSingleParameterDotFile = false;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000211 StaticCtorsSection = "\t.section .ctors,\"aw\"";
212 StaticDtorsSection = "\t.section .dtors,\"aw\"";
213 HiddenDirective = NULL;
214 PrivateGlobalPrefix = "L"; // Prefix for private global symbols
215 WeakRefDirective = "\t.weak\t";
216 SetDirective = "\t.set\t";
217
218 // Set up DWARF directives
219 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
220 AbsoluteDebugSectionOffsets = true;
221 AbsoluteEHSectionOffsets = false;
222 SupportsDebugInformation = true;
223 DwarfSectionOffsetDirective = "\t.secrel32\t";
224 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\"";
225 DwarfInfoSection = "\t.section\t.debug_info,\"dr\"";
226 DwarfLineSection = "\t.section\t.debug_line,\"dr\"";
227 DwarfFrameSection = "\t.section\t.debug_frame,\"dr\"";
228 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
229 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
230 DwarfStrSection = "\t.section\t.debug_str,\"dr\"";
231 DwarfLocSection = "\t.section\t.debug_loc,\"dr\"";
232 DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
233 DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\"";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000234 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000235}
236
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000237unsigned
238X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
239 bool Global) const {
Dan Gohman8f092252008-11-03 18:22:42 +0000240 CodeModel::Model CM = TM.getCodeModel();
241 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000242
Dan Gohman8f092252008-11-03 18:22:42 +0000243 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000244 unsigned Format = 0;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000245
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000246 if (!is64Bit)
247 // 32 bit targets always encode pointers as 4 bytes
248 Format = DW_EH_PE_sdata4;
249 else {
250 // 64 bit targets encode pointers in 4 bytes iff:
251 // - code model is small OR
252 // - code model is medium and we're emitting externally visible symbols
253 // or any code symbols
254 if (CM == CodeModel::Small ||
255 (CM == CodeModel::Medium && (Global ||
256 Reason != DwarfEncoding::Data)))
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000257 Format = DW_EH_PE_sdata4;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000258 else
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000259 Format = DW_EH_PE_sdata8;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000260 }
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000261
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000262 if (Global)
263 Format |= DW_EH_PE_indirect;
264
265 return (Format | DW_EH_PE_pcrel);
266 } else {
267 if (is64Bit &&
268 (CM == CodeModel::Small ||
269 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
270 return DW_EH_PE_udata4;
271 else
272 return DW_EH_PE_absptr;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000273 }
274}
275
Anton Korobeynikovb9a02fc2008-07-09 13:21:29 +0000276std::string
277X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
278 SectionKind::Kind kind) const {
279 switch (kind) {
280 case SectionKind::Text:
281 return ".text$linkonce" + GV->getName();
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000282 case SectionKind::Data:
283 case SectionKind::BSS:
284 case SectionKind::ThreadData:
285 case SectionKind::ThreadBSS:
286 return ".data$linkonce" + GV->getName();
Anton Korobeynikovb9a02fc2008-07-09 13:21:29 +0000287 case SectionKind::ROData:
288 case SectionKind::RODataMergeConst:
289 case SectionKind::RODataMergeStr:
290 return ".rdata$linkonce" + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000291 default:
Torok Edwinc25e7582009-07-11 20:10:48 +0000292 LLVM_UNREACHABLE("Unknown section kind");
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000293 }
Devang Patel8a84e442009-01-05 17:31:22 +0000294 return NULL;
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000295}
296
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000297std::string X86COFFTargetAsmInfo::printSectionFlags(unsigned flags) const {
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000298 std::string Flags = ",\"";
299
300 if (flags & SectionFlags::Code)
301 Flags += 'x';
302 if (flags & SectionFlags::Writeable)
303 Flags += 'w';
304
305 Flags += "\"";
306
307 return Flags;
308}
309
310X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000311 X86GenericTargetAsmInfo(TM) {
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000312 GlobalPrefix = "_";
313 CommentString = ";";
314
Eli Friedmanaace4b12009-06-19 04:48:38 +0000315 InlineAsmStart = "; InlineAsm Start";
316 InlineAsmEnd = "; InlineAsm End";
317
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000318 PrivateGlobalPrefix = "$";
Eli Friedmanaace4b12009-06-19 04:48:38 +0000319 AlignDirective = "\tALIGN\t";
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000320 ZeroDirective = "\tdb\t";
321 ZeroDirectiveSuffix = " dup(0)";
322 AsciiDirective = "\tdb\t";
323 AscizDirective = 0;
324 Data8bitsDirective = "\tdb\t";
325 Data16bitsDirective = "\tdw\t";
326 Data32bitsDirective = "\tdd\t";
327 Data64bitsDirective = "\tdq\t";
328 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +0000329 HasSingleParameterDotFile = false;
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000330
Eli Friedmanaace4b12009-06-19 04:48:38 +0000331 AlignmentIsInBytes = true;
332
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000333 TextSection = getUnnamedSection("_text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000334 DataSection = getUnnamedSection("_data", SectionFlags::Writeable);
335
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000336 JumpTableDataSection = NULL;
337 SwitchToSectionDirective = "";
Eli Friedmanaace4b12009-06-19 04:48:38 +0000338 TextSectionStartSuffix = "\tSEGMENT PARA 'CODE'";
339 DataSectionStartSuffix = "\tSEGMENT PARA 'DATA'";
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000340 SectionEndDirectiveSuffix = "\tends\n";
341}
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000342
343template <class BaseTAI>
344bool X86TargetAsmInfo<BaseTAI>::LowerToBSwap(CallInst *CI) const {
345 // FIXME: this should verify that we are targetting a 486 or better. If not,
346 // we will turn this bswap into something that will be lowered to logical ops
347 // instead of emitting the bswap asm. For now, we don't support 486 or lower
348 // so don't worry about this.
349
350 // Verify this is a simple bswap.
351 if (CI->getNumOperands() != 2 ||
352 CI->getType() != CI->getOperand(1)->getType() ||
353 !CI->getType()->isInteger())
354 return false;
355
356 const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
357 if (!Ty || Ty->getBitWidth() % 16 != 0)
358 return false;
359
360 // Okay, we can do this xform, do so now.
361 const Type *Tys[] = { Ty };
362 Module *M = CI->getParent()->getParent()->getParent();
363 Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
364
365 Value *Op = CI->getOperand(1);
366 Op = CallInst::Create(Int, Op, CI->getName(), CI);
367
368 CI->replaceAllUsesWith(Op);
369 CI->eraseFromParent();
370 return true;
371}
372
373template <class BaseTAI>
374bool X86TargetAsmInfo<BaseTAI>::ExpandInlineAsm(CallInst *CI) const {
375 InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue());
376 std::vector<InlineAsm::ConstraintInfo> Constraints = IA->ParseConstraints();
377
378 std::string AsmStr = IA->getAsmString();
379
380 // TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a"
381 std::vector<std::string> AsmPieces;
382 SplitString(AsmStr, AsmPieces, "\n"); // ; as separator?
383
384 switch (AsmPieces.size()) {
385 default: return false;
386 case 1:
387 AsmStr = AsmPieces[0];
388 AsmPieces.clear();
389 SplitString(AsmStr, AsmPieces, " \t"); // Split with whitespace.
390
391 // bswap $0
392 if (AsmPieces.size() == 2 &&
Dan Gohman96264472009-03-17 02:45:40 +0000393 (AsmPieces[0] == "bswap" ||
394 AsmPieces[0] == "bswapq" ||
395 AsmPieces[0] == "bswapl") &&
396 (AsmPieces[1] == "$0" ||
397 AsmPieces[1] == "${0:q}")) {
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000398 // No need to check constraints, nothing other than the equivalent of
399 // "=r,0" would be valid here.
400 return LowerToBSwap(CI);
401 }
Dan Gohmandbf5f252009-01-21 23:40:54 +0000402 // rorw $$8, ${0:w} --> llvm.bswap.i16
403 if (CI->getType() == Type::Int16Ty &&
404 AsmPieces.size() == 3 &&
405 AsmPieces[0] == "rorw" &&
406 AsmPieces[1] == "$$8," &&
407 AsmPieces[2] == "${0:w}" &&
408 IA->getConstraintString() == "=r,0,~{dirflag},~{fpsr},~{flags},~{cc}") {
409 return LowerToBSwap(CI);
410 }
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000411 break;
412 case 3:
413 if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 &&
414 Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" &&
415 Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") {
416 // bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64
417 std::vector<std::string> Words;
418 SplitString(AsmPieces[0], Words, " \t");
419 if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%eax") {
420 Words.clear();
421 SplitString(AsmPieces[1], Words, " \t");
422 if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%edx") {
423 Words.clear();
424 SplitString(AsmPieces[2], Words, " \t,");
425 if (Words.size() == 3 && Words[0] == "xchgl" && Words[1] == "%eax" &&
426 Words[2] == "%edx") {
427 return LowerToBSwap(CI);
428 }
429 }
430 }
431 }
432 break;
433 }
434 return false;
435}
436
437// Instantiate default implementation.
438TEMPLATE_INSTANTIATION(class X86TargetAsmInfo<TargetAsmInfo>);