Daniel Dunbar | c984df8 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 1 | //===-- PowerPCTargetInfo.cpp - PowerPC Target Implementation -------------===// |
| 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 | //===----------------------------------------------------------------------===// |
| 9 | |
Daniel Dunbar | 4cb1e13 | 2009-07-18 23:03:22 +0000 | [diff] [blame] | 10 | #include "PPC.h" |
Daniel Dunbar | c984df8 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 11 | #include "llvm/Module.h" |
| 12 | #include "llvm/Target/TargetRegistry.h" |
| 13 | using namespace llvm; |
| 14 | |
Daniel Dunbar | 4cb1e13 | 2009-07-18 23:03:22 +0000 | [diff] [blame] | 15 | Target llvm::ThePPC32Target; |
Daniel Dunbar | c984df8 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 16 | |
| 17 | static unsigned PPC32_JITMatchQuality() { |
| 18 | #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) || defined(__PPC__) |
| 19 | if (sizeof(void*) == 4) |
| 20 | return 10; |
| 21 | #endif |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | static unsigned PPC32_TripleMatchQuality(const std::string &TT) { |
| 26 | // We strongly match "powerpc-*". |
| 27 | if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-") |
| 28 | return 20; |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | static unsigned PPC32_ModuleMatchQuality(const Module &M) { |
| 34 | // Check for a triple match. |
| 35 | if (unsigned Q = PPC32_TripleMatchQuality(M.getTargetTriple())) |
| 36 | return Q; |
| 37 | |
| 38 | // Otherwise if the target triple is non-empty, we don't match. |
| 39 | if (!M.getTargetTriple().empty()) return 0; |
| 40 | |
| 41 | if (M.getEndianness() == Module::BigEndian && |
| 42 | M.getPointerSize() == Module::Pointer64) |
| 43 | return 10; // Weak match |
| 44 | else if (M.getEndianness() != Module::AnyEndianness || |
| 45 | M.getPointerSize() != Module::AnyPointerSize) |
| 46 | return 0; // Match for some other target |
| 47 | |
| 48 | return PPC32_JITMatchQuality()/2; |
| 49 | } |
| 50 | |
Daniel Dunbar | 4cb1e13 | 2009-07-18 23:03:22 +0000 | [diff] [blame] | 51 | Target llvm::ThePPC64Target; |
Daniel Dunbar | c984df8 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 52 | |
| 53 | static unsigned PPC64_JITMatchQuality() { |
| 54 | #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) || defined(__PPC__) |
| 55 | if (sizeof(void*) == 8) |
| 56 | return 10; |
| 57 | #endif |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | static unsigned PPC64_TripleMatchQuality(const std::string &TT) { |
| 62 | // We strongly match "powerpc64-*". |
| 63 | if (TT.size() >= 10 && std::string(TT.begin(), TT.begin()+10) == "powerpc64-") |
| 64 | return 20; |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static unsigned PPC64_ModuleMatchQuality(const Module &M) { |
| 70 | // Check for a triple match. |
| 71 | if (unsigned Q = PPC64_TripleMatchQuality(M.getTargetTriple())) |
| 72 | return Q; |
| 73 | |
| 74 | // Otherwise if the target triple is non-empty, we don't match. |
| 75 | if (!M.getTargetTriple().empty()) return 0; |
| 76 | |
| 77 | if (M.getEndianness() == Module::BigEndian && |
| 78 | M.getPointerSize() == Module::Pointer64) |
| 79 | return 10; // Weak match |
| 80 | else if (M.getEndianness() != Module::AnyEndianness || |
| 81 | M.getPointerSize() != Module::AnyPointerSize) |
| 82 | return 0; // Match for some other target |
| 83 | |
| 84 | return PPC64_JITMatchQuality()/2; |
| 85 | } |
| 86 | |
| 87 | extern "C" void LLVMInitializePowerPCTargetInfo() { |
| 88 | TargetRegistry::RegisterTarget(ThePPC32Target, "ppc32", |
| 89 | "PowerPC 32", |
| 90 | &PPC32_TripleMatchQuality, |
| 91 | &PPC32_ModuleMatchQuality, |
| 92 | &PPC32_JITMatchQuality); |
| 93 | |
| 94 | TargetRegistry::RegisterTarget(ThePPC64Target, "ppc64", |
| 95 | "PowerPC 64", |
| 96 | &PPC64_TripleMatchQuality, |
| 97 | &PPC64_ModuleMatchQuality, |
| 98 | &PPC64_JITMatchQuality); |
| 99 | } |