1//===-- 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//===----------------------------------------------------------------------===// --- 52 unchanged lines hidden (view full) --- 61class X86ELFObjectWriter : public MCELFObjectTargetWriter { 62public: 63 X86ELFObjectWriter(bool is64Bit, uint8_t OSABI, uint16_t EMachine, 64 bool HasRelocationAddend, bool foobar) 65 : MCELFObjectTargetWriter(is64Bit, OSABI, EMachine, HasRelocationAddend) {} 66}; 67 68class X86AsmBackend : public MCAsmBackend { |
69 StringRef CPU; |
70public: |
71 X86AsmBackend(const Target &T, StringRef _CPU) 72 : MCAsmBackend(), CPU(_CPU) {} |
73 74 unsigned getNumFixupKinds() const { 75 return X86::NumTargetFixupKinds; 76 } 77 78 const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const { 79 const static MCFixupKindInfo Infos[X86::NumTargetFixupKinds] = { 80 { "reloc_riprel_4byte", 0, 4 * 8, MCFixupKindInfo::FKF_IsPCRel }, --- 220 unchanged lines hidden (view full) --- 301 // nopl 0L(%[re]ax,%[re]ax,1) 302 {0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, 303 // nopw 0L(%[re]ax,%[re]ax,1) 304 {0x66, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, 305 // nopw %cs:0L(%[re]ax,%[re]ax,1) 306 {0x66, 0x2e, 0x0f, 0x1f, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00}, 307 }; 308 |
309 // This CPU doesnt support long nops. If needed add more. 310 if (CPU == "geode") { 311 for (uint64_t i = 0; i < Count; ++i) 312 OW->Write8(0x90); 313 return true; 314 } 315 |
316 // Write an optimal sequence for the first 15 bytes. 317 const uint64_t OptimalCount = (Count < 16) ? Count : 15; 318 const uint64_t Prefixes = OptimalCount <= 10 ? 0 : OptimalCount - 10; 319 for (uint64_t i = 0, e = Prefixes; i != e; i++) 320 OW->Write8(0x66); 321 const uint64_t Rest = OptimalCount - Prefixes; 322 for (uint64_t i = 0, e = Rest; i != e; i++) 323 OW->Write8(Nops[Rest - 1][i]); --- 6 unchanged lines hidden (view full) --- 330} 331 332/* *** */ 333 334namespace { 335class ELFX86AsmBackend : public X86AsmBackend { 336public: 337 uint8_t OSABI; |
338 ELFX86AsmBackend(const Target &T, uint8_t _OSABI, StringRef CPU) 339 : X86AsmBackend(T, CPU), OSABI(_OSABI) { |
340 HasReliableSymbolDifference = true; 341 } 342 343 virtual bool doesSectionRequireSymbols(const MCSection &Section) const { 344 const MCSectionELF &ES = static_cast<const MCSectionELF&>(Section); 345 return ES.getFlags() & ELF::SHF_MERGE; 346 } 347}; 348 349class ELFX86_32AsmBackend : public ELFX86AsmBackend { 350public: |
351 ELFX86_32AsmBackend(const Target &T, uint8_t OSABI, StringRef CPU) 352 : ELFX86AsmBackend(T, OSABI, CPU) {} |
353 354 MCObjectWriter *createObjectWriter(raw_ostream &OS) const { 355 return createX86ELFObjectWriter(OS, /*Is64Bit*/ false, OSABI); 356 } 357}; 358 359class ELFX86_64AsmBackend : public ELFX86AsmBackend { 360public: |
361 ELFX86_64AsmBackend(const Target &T, uint8_t OSABI, StringRef CPU) 362 : ELFX86AsmBackend(T, OSABI, CPU) {} |
363 364 MCObjectWriter *createObjectWriter(raw_ostream &OS) const { 365 return createX86ELFObjectWriter(OS, /*Is64Bit*/ true, OSABI); 366 } 367}; 368 369class WindowsX86AsmBackend : public X86AsmBackend { 370 bool Is64Bit; 371 372public: |
373 WindowsX86AsmBackend(const Target &T, bool is64Bit, StringRef CPU) 374 : X86AsmBackend(T, CPU) |
375 , Is64Bit(is64Bit) { 376 } 377 378 MCObjectWriter *createObjectWriter(raw_ostream &OS) const { 379 return createX86WinCOFFObjectWriter(OS, Is64Bit); 380 } 381}; 382 383class DarwinX86AsmBackend : public X86AsmBackend { 384public: |
385 DarwinX86AsmBackend(const Target &T, StringRef CPU) 386 : X86AsmBackend(T, CPU) { } |
387}; 388 389class DarwinX86_32AsmBackend : public DarwinX86AsmBackend { 390public: |
391 DarwinX86_32AsmBackend(const Target &T, StringRef CPU) 392 : DarwinX86AsmBackend(T, CPU) {} |
393 394 MCObjectWriter *createObjectWriter(raw_ostream &OS) const { 395 return createX86MachObjectWriter(OS, /*Is64Bit=*/false, 396 object::mach::CTM_i386, 397 object::mach::CSX86_ALL); 398 } 399}; 400 401class DarwinX86_64AsmBackend : public DarwinX86AsmBackend { 402public: |
403 DarwinX86_64AsmBackend(const Target &T, StringRef CPU) 404 : DarwinX86AsmBackend(T, CPU) { |
405 HasReliableSymbolDifference = true; 406 } 407 408 MCObjectWriter *createObjectWriter(raw_ostream &OS) const { 409 return createX86MachObjectWriter(OS, /*Is64Bit=*/true, 410 object::mach::CTM_x86_64, 411 object::mach::CSX86_ALL); 412 } --- 29 unchanged lines hidden (view full) --- 442 case MCSectionMachO::S_INTERPOSING: 443 return false; 444 } 445 } 446}; 447 448} // end anonymous namespace 449 |
450MCAsmBackend *llvm::createX86_32AsmBackend(const Target &T, StringRef TT, StringRef CPU) { |
451 Triple TheTriple(TT); 452 453 if (TheTriple.isOSDarwin() || TheTriple.getEnvironment() == Triple::MachO) |
454 return new DarwinX86_32AsmBackend(T, CPU); |
455 456 if (TheTriple.isOSWindows()) |
457 return new WindowsX86AsmBackend(T, false, CPU); |
458 459 uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS()); |
460 return new ELFX86_32AsmBackend(T, OSABI, CPU); |
461} 462 |
463MCAsmBackend *llvm::createX86_64AsmBackend(const Target &T, StringRef TT, StringRef CPU) { |
464 Triple TheTriple(TT); 465 466 if (TheTriple.isOSDarwin() || TheTriple.getEnvironment() == Triple::MachO) |
467 return new DarwinX86_64AsmBackend(T, CPU); |
468 469 if (TheTriple.isOSWindows()) |
470 return new WindowsX86AsmBackend(T, true, CPU); |
471 472 uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS()); |
473 return new ELFX86_64AsmBackend(T, OSABI, CPU); |
474} |