blob: 0c474e122810cf689ed5e66dd41f46bfe3ee0520 [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"
24
Jim Laskey8e8de8f2006-09-07 22:05:02 +000025using namespace llvm;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000026using namespace llvm::dwarf;
Jim Laskey8e8de8f2006-09-07 22:05:02 +000027
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000028const char *const llvm::x86_asm_table[] = {
29 "{si}", "S",
30 "{di}", "D",
31 "{ax}", "a",
32 "{cx}", "c",
33 "{memory}", "memory",
34 "{flags}", "",
35 "{dirflag}", "",
36 "{fpsr}", "",
37 "{cc}", "cc",
38 0,0};
Andrew Lenharth6c0695f2006-11-28 19:52:49 +000039
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000040X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000041 X86TargetAsmInfo<DarwinTargetAsmInfo>(TM) {
Dan Gohman8f092252008-11-03 18:22:42 +000042 const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
Anton Korobeynikov16b7f512008-08-08 18:25:52 +000043 bool is64Bit = Subtarget->is64Bit();
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000044
45 AlignmentIsInBytes = false;
46 TextAlignFillValue = 0x90;
47 GlobalPrefix = "_";
48 if (!is64Bit)
49 Data64bitsDirective = 0; // we can't emit a 64-bit unit
50 ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
51 PrivateGlobalPrefix = "L"; // Marker for constant pool idxs
Dale Johannesenb2dfb892008-09-09 01:21:22 +000052 LessPrivateGlobalPrefix = "l"; // Marker for some ObjC metadata
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000053 BSSSection = 0; // no BSS section.
54 ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
Dan Gohman8f092252008-11-03 18:22:42 +000055 if (TM.getRelocationModel() != Reloc::Static)
Anton Korobeynikov7705ea32008-07-09 21:54:26 +000056 ConstantPoolSection = "\t.const_data";
57 else
58 ConstantPoolSection = "\t.const\n";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000059 JumpTableDataSection = "\t.const\n";
60 CStringSection = "\t.cstring";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000061 // FIXME: Why don't always use this section?
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000062 if (is64Bit) {
Anton Korobeynikov64818732008-09-24 22:18:54 +000063 SixteenByteConstantSection = getUnnamedSection("\t.literal16\n",
64 SectionFlags::Mergeable);
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000065 }
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000066 LCOMMDirective = "\t.lcomm\t";
67 SwitchToSectionDirective = "\t.section ";
68 StringConstantPrefix = "\1LC";
Anton Korobeynikov16b7f512008-08-08 18:25:52 +000069 // Leopard and above support aligned common symbols.
70 COMMDirectiveTakesAlignment = (Subtarget->getDarwinVers() >= 9);
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000071 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +000072 HasSingleParameterDotFile = false;
Bill Wendling722f5f12008-12-24 08:05:17 +000073 NonLocalEHFrameLabel = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000074 if (TM.getRelocationModel() == Reloc::Static) {
75 StaticCtorsSection = ".constructor";
76 StaticDtorsSection = ".destructor";
77 } else {
78 StaticCtorsSection = ".mod_init_func";
79 StaticDtorsSection = ".mod_term_func";
80 }
81 if (is64Bit) {
82 PersonalityPrefix = "";
83 PersonalitySuffix = "+4@GOTPCREL";
84 } else {
85 PersonalityPrefix = "L";
86 PersonalitySuffix = "$non_lazy_ptr";
87 }
88 NeedsIndirectEncoding = true;
89 InlineAsmStart = "## InlineAsm Start";
90 InlineAsmEnd = "## InlineAsm End";
91 CommentString = "##";
92 SetDirective = "\t.set";
93 PCSymbol = ".";
94 UsedDirective = "\t.no_dead_strip\t";
95 WeakDefDirective = "\t.weak_definition ";
96 WeakRefDirective = "\t.weak_reference ";
97 HiddenDirective = "\t.private_extern ";
98 ProtectedDirective = "\t.globl\t";
99
100 // In non-PIC modes, emit a special label before jump tables so that the
101 // linker can perform more accurate dead code stripping.
Evan Chengb13bafe2009-06-18 20:37:15 +0000102 // Emit a local label that is preserved until the linker runs.
103 // We do not check the relocation model here since it can be overridden
104 // later.
105 JumpTableSpecialLabelPrefix = "l";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000106
107 SupportsDebugInformation = true;
108 NeedsSet = true;
109 DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
110 DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
111 DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
112 DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
113 DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
114 DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
Devang Patel0f7fef32009-04-13 17:02:03 +0000115 DwarfDebugInlineSection = ".section __DWARF,__debug_inlined,regular,debug";
116 DwarfUsesInlineInfoSection = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000117 DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
118 DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
119 DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
120 DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
121 DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
122
123 // Exceptions handling
124 SupportsExceptionHandling = true;
125 GlobalEHDirective = "\t.globl\t";
126 SupportsWeakOmittedEHFrame = false;
127 AbsoluteEHSectionOffsets = false;
128 DwarfEHFrameSection =
129 ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
130 DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
131}
132
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000133unsigned
134X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
135 bool Global) const {
136 if (Reason == DwarfEncoding::Functions && Global)
137 return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
138 else if (Reason == DwarfEncoding::CodeLabels || !Global)
139 return DW_EH_PE_pcrel;
140 else
141 return DW_EH_PE_absptr;
142}
143
Rafael Espindola2f6fea92008-12-19 10:55:56 +0000144const char *
145X86DarwinTargetAsmInfo::getEHGlobalPrefix() const
146{
147 const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
148 if (Subtarget->getDarwinVers() > 9)
149 return PrivateGlobalPrefix;
150 else
151 return "";
152}
153
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000154X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000155 X86TargetAsmInfo<ELFTargetAsmInfo>(TM) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000156
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000157 CStringSection = ".rodata.str";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000158 PrivateGlobalPrefix = ".L";
159 WeakRefDirective = "\t.weak\t";
160 SetDirective = "\t.set\t";
161 PCSymbol = ".";
162
163 // Set up DWARF directives
164 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
165
166 // Debug Information
167 AbsoluteDebugSectionOffsets = true;
168 SupportsDebugInformation = true;
169 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
170 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
171 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
172 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
173 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
174 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
175 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
176 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
177 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
178 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
179 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
180
181 // Exceptions handling
Anton Korobeynikovc4da15a2008-09-08 21:13:08 +0000182 SupportsExceptionHandling = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000183 AbsoluteEHSectionOffsets = false;
184 DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
185 DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
186
187 // On Linux we must declare when we can use a non-executable stack.
Dan Gohman8f092252008-11-03 18:22:42 +0000188 if (TM.getSubtarget<X86Subtarget>().isLinux())
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000189 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
190}
191
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000192unsigned
193X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
194 bool Global) const {
Dan Gohman8f092252008-11-03 18:22:42 +0000195 CodeModel::Model CM = TM.getCodeModel();
196 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000197
Dan Gohman8f092252008-11-03 18:22:42 +0000198 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000199 unsigned Format = 0;
200
201 if (!is64Bit)
202 // 32 bit targets always encode pointers as 4 bytes
203 Format = DW_EH_PE_sdata4;
204 else {
205 // 64 bit targets encode pointers in 4 bytes iff:
206 // - code model is small OR
207 // - code model is medium and we're emitting externally visible symbols
208 // or any code symbols
209 if (CM == CodeModel::Small ||
210 (CM == CodeModel::Medium && (Global ||
211 Reason != DwarfEncoding::Data)))
212 Format = DW_EH_PE_sdata4;
213 else
214 Format = DW_EH_PE_sdata8;
215 }
216
217 if (Global)
218 Format |= DW_EH_PE_indirect;
219
220 return (Format | DW_EH_PE_pcrel);
221 } else {
222 if (is64Bit &&
223 (CM == CodeModel::Small ||
224 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
225 return DW_EH_PE_udata4;
226 else
227 return DW_EH_PE_absptr;
228 }
229}
230
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000231X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000232 X86GenericTargetAsmInfo(TM) {
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000233
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000234 GlobalPrefix = "_";
235 LCOMMDirective = "\t.lcomm\t";
236 COMMDirectiveTakesAlignment = false;
237 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +0000238 HasSingleParameterDotFile = false;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000239 StaticCtorsSection = "\t.section .ctors,\"aw\"";
240 StaticDtorsSection = "\t.section .dtors,\"aw\"";
241 HiddenDirective = NULL;
242 PrivateGlobalPrefix = "L"; // Prefix for private global symbols
243 WeakRefDirective = "\t.weak\t";
244 SetDirective = "\t.set\t";
245
246 // Set up DWARF directives
247 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
248 AbsoluteDebugSectionOffsets = true;
249 AbsoluteEHSectionOffsets = false;
250 SupportsDebugInformation = true;
251 DwarfSectionOffsetDirective = "\t.secrel32\t";
252 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\"";
253 DwarfInfoSection = "\t.section\t.debug_info,\"dr\"";
254 DwarfLineSection = "\t.section\t.debug_line,\"dr\"";
255 DwarfFrameSection = "\t.section\t.debug_frame,\"dr\"";
256 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
257 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
258 DwarfStrSection = "\t.section\t.debug_str,\"dr\"";
259 DwarfLocSection = "\t.section\t.debug_loc,\"dr\"";
260 DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
261 DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\"";
262 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
263}
264
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000265unsigned
266X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
267 bool Global) const {
Dan Gohman8f092252008-11-03 18:22:42 +0000268 CodeModel::Model CM = TM.getCodeModel();
269 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000270
Dan Gohman8f092252008-11-03 18:22:42 +0000271 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000272 unsigned Format = 0;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000273
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000274 if (!is64Bit)
275 // 32 bit targets always encode pointers as 4 bytes
276 Format = DW_EH_PE_sdata4;
277 else {
278 // 64 bit targets encode pointers in 4 bytes iff:
279 // - code model is small OR
280 // - code model is medium and we're emitting externally visible symbols
281 // or any code symbols
282 if (CM == CodeModel::Small ||
283 (CM == CodeModel::Medium && (Global ||
284 Reason != DwarfEncoding::Data)))
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000285 Format = DW_EH_PE_sdata4;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000286 else
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000287 Format = DW_EH_PE_sdata8;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000288 }
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000289
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000290 if (Global)
291 Format |= DW_EH_PE_indirect;
292
293 return (Format | DW_EH_PE_pcrel);
294 } else {
295 if (is64Bit &&
296 (CM == CodeModel::Small ||
297 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
298 return DW_EH_PE_udata4;
299 else
300 return DW_EH_PE_absptr;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000301 }
302}
303
Anton Korobeynikovb9a02fc2008-07-09 13:21:29 +0000304std::string
305X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
306 SectionKind::Kind kind) const {
307 switch (kind) {
308 case SectionKind::Text:
309 return ".text$linkonce" + GV->getName();
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000310 case SectionKind::Data:
311 case SectionKind::BSS:
312 case SectionKind::ThreadData:
313 case SectionKind::ThreadBSS:
314 return ".data$linkonce" + GV->getName();
Anton Korobeynikovb9a02fc2008-07-09 13:21:29 +0000315 case SectionKind::ROData:
316 case SectionKind::RODataMergeConst:
317 case SectionKind::RODataMergeStr:
318 return ".rdata$linkonce" + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000319 default:
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000320 assert(0 && "Unknown section kind");
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000321 }
Devang Patel8a84e442009-01-05 17:31:22 +0000322 return NULL;
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000323}
324
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000325std::string X86COFFTargetAsmInfo::printSectionFlags(unsigned flags) const {
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000326 std::string Flags = ",\"";
327
328 if (flags & SectionFlags::Code)
329 Flags += 'x';
330 if (flags & SectionFlags::Writeable)
331 Flags += 'w';
332
333 Flags += "\"";
334
335 return Flags;
336}
337
338X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000339 X86GenericTargetAsmInfo(TM) {
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000340 GlobalPrefix = "_";
341 CommentString = ";";
342
343 PrivateGlobalPrefix = "$";
344 AlignDirective = "\talign\t";
345 ZeroDirective = "\tdb\t";
346 ZeroDirectiveSuffix = " dup(0)";
347 AsciiDirective = "\tdb\t";
348 AscizDirective = 0;
349 Data8bitsDirective = "\tdb\t";
350 Data16bitsDirective = "\tdw\t";
351 Data32bitsDirective = "\tdd\t";
352 Data64bitsDirective = "\tdq\t";
353 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +0000354 HasSingleParameterDotFile = false;
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000355
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000356 TextSection = getUnnamedSection("_text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000357 DataSection = getUnnamedSection("_data", SectionFlags::Writeable);
358
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000359 JumpTableDataSection = NULL;
360 SwitchToSectionDirective = "";
361 TextSectionStartSuffix = "\tsegment 'CODE'";
362 DataSectionStartSuffix = "\tsegment 'DATA'";
363 SectionEndDirectiveSuffix = "\tends\n";
364}
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000365
366template <class BaseTAI>
367bool X86TargetAsmInfo<BaseTAI>::LowerToBSwap(CallInst *CI) const {
368 // FIXME: this should verify that we are targetting a 486 or better. If not,
369 // we will turn this bswap into something that will be lowered to logical ops
370 // instead of emitting the bswap asm. For now, we don't support 486 or lower
371 // so don't worry about this.
372
373 // Verify this is a simple bswap.
374 if (CI->getNumOperands() != 2 ||
375 CI->getType() != CI->getOperand(1)->getType() ||
376 !CI->getType()->isInteger())
377 return false;
378
379 const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
380 if (!Ty || Ty->getBitWidth() % 16 != 0)
381 return false;
382
383 // Okay, we can do this xform, do so now.
384 const Type *Tys[] = { Ty };
385 Module *M = CI->getParent()->getParent()->getParent();
386 Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
387
388 Value *Op = CI->getOperand(1);
389 Op = CallInst::Create(Int, Op, CI->getName(), CI);
390
391 CI->replaceAllUsesWith(Op);
392 CI->eraseFromParent();
393 return true;
394}
395
396template <class BaseTAI>
397bool X86TargetAsmInfo<BaseTAI>::ExpandInlineAsm(CallInst *CI) const {
398 InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue());
399 std::vector<InlineAsm::ConstraintInfo> Constraints = IA->ParseConstraints();
400
401 std::string AsmStr = IA->getAsmString();
402
403 // TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a"
404 std::vector<std::string> AsmPieces;
405 SplitString(AsmStr, AsmPieces, "\n"); // ; as separator?
406
407 switch (AsmPieces.size()) {
408 default: return false;
409 case 1:
410 AsmStr = AsmPieces[0];
411 AsmPieces.clear();
412 SplitString(AsmStr, AsmPieces, " \t"); // Split with whitespace.
413
414 // bswap $0
415 if (AsmPieces.size() == 2 &&
Dan Gohman96264472009-03-17 02:45:40 +0000416 (AsmPieces[0] == "bswap" ||
417 AsmPieces[0] == "bswapq" ||
418 AsmPieces[0] == "bswapl") &&
419 (AsmPieces[1] == "$0" ||
420 AsmPieces[1] == "${0:q}")) {
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000421 // No need to check constraints, nothing other than the equivalent of
422 // "=r,0" would be valid here.
423 return LowerToBSwap(CI);
424 }
Dan Gohmandbf5f252009-01-21 23:40:54 +0000425 // rorw $$8, ${0:w} --> llvm.bswap.i16
426 if (CI->getType() == Type::Int16Ty &&
427 AsmPieces.size() == 3 &&
428 AsmPieces[0] == "rorw" &&
429 AsmPieces[1] == "$$8," &&
430 AsmPieces[2] == "${0:w}" &&
431 IA->getConstraintString() == "=r,0,~{dirflag},~{fpsr},~{flags},~{cc}") {
432 return LowerToBSwap(CI);
433 }
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000434 break;
435 case 3:
436 if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 &&
437 Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" &&
438 Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") {
439 // bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64
440 std::vector<std::string> Words;
441 SplitString(AsmPieces[0], Words, " \t");
442 if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%eax") {
443 Words.clear();
444 SplitString(AsmPieces[1], Words, " \t");
445 if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%edx") {
446 Words.clear();
447 SplitString(AsmPieces[2], Words, " \t,");
448 if (Words.size() == 3 && Words[0] == "xchgl" && Words[1] == "%eax" &&
449 Words[2] == "%edx") {
450 return LowerToBSwap(CI);
451 }
452 }
453 }
454 }
455 break;
456 }
457 return false;
458}
459
460// Instantiate default implementation.
461TEMPLATE_INSTANTIATION(class X86TargetAsmInfo<TargetAsmInfo>);