Daniel Dunbar | 56e2947 | 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 | 67038c1 | 2009-07-18 23:03:22 +0000 | [diff] [blame] | 10 | #include "PPC.h" |
Daniel Dunbar | 56e2947 | 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 | 67038c1 | 2009-07-18 23:03:22 +0000 | [diff] [blame] | 15 | Target llvm::ThePPC32Target; |
Daniel Dunbar | 56e2947 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 16 | |
Daniel Dunbar | 56e2947 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 17 | static unsigned PPC32_TripleMatchQuality(const std::string &TT) { |
| 18 | // We strongly match "powerpc-*". |
| 19 | if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-") |
| 20 | return 20; |
| 21 | |
| 22 | return 0; |
| 23 | } |
| 24 | |
| 25 | static unsigned PPC32_ModuleMatchQuality(const Module &M) { |
| 26 | // Check for a triple match. |
| 27 | if (unsigned Q = PPC32_TripleMatchQuality(M.getTargetTriple())) |
| 28 | return Q; |
| 29 | |
| 30 | // Otherwise if the target triple is non-empty, we don't match. |
| 31 | if (!M.getTargetTriple().empty()) return 0; |
| 32 | |
| 33 | if (M.getEndianness() == Module::BigEndian && |
| 34 | M.getPointerSize() == Module::Pointer64) |
| 35 | return 10; // Weak match |
| 36 | else if (M.getEndianness() != Module::AnyEndianness || |
| 37 | M.getPointerSize() != Module::AnyPointerSize) |
| 38 | return 0; // Match for some other target |
| 39 | |
Daniel Dunbar | 691a478 | 2009-07-25 10:09:50 +0000 | [diff] [blame^] | 40 | return 0; |
Daniel Dunbar | 56e2947 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Daniel Dunbar | 67038c1 | 2009-07-18 23:03:22 +0000 | [diff] [blame] | 43 | Target llvm::ThePPC64Target; |
Daniel Dunbar | 56e2947 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 44 | |
Daniel Dunbar | 56e2947 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 45 | static unsigned PPC64_TripleMatchQuality(const std::string &TT) { |
| 46 | // We strongly match "powerpc64-*". |
| 47 | if (TT.size() >= 10 && std::string(TT.begin(), TT.begin()+10) == "powerpc64-") |
| 48 | return 20; |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static unsigned PPC64_ModuleMatchQuality(const Module &M) { |
| 54 | // Check for a triple match. |
| 55 | if (unsigned Q = PPC64_TripleMatchQuality(M.getTargetTriple())) |
| 56 | return Q; |
| 57 | |
| 58 | // Otherwise if the target triple is non-empty, we don't match. |
| 59 | if (!M.getTargetTriple().empty()) return 0; |
| 60 | |
| 61 | if (M.getEndianness() == Module::BigEndian && |
| 62 | M.getPointerSize() == Module::Pointer64) |
| 63 | return 10; // Weak match |
| 64 | else if (M.getEndianness() != Module::AnyEndianness || |
| 65 | M.getPointerSize() != Module::AnyPointerSize) |
| 66 | return 0; // Match for some other target |
| 67 | |
Daniel Dunbar | 691a478 | 2009-07-25 10:09:50 +0000 | [diff] [blame^] | 68 | return 0; |
Daniel Dunbar | 56e2947 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | extern "C" void LLVMInitializePowerPCTargetInfo() { |
| 72 | TargetRegistry::RegisterTarget(ThePPC32Target, "ppc32", |
| 73 | "PowerPC 32", |
| 74 | &PPC32_TripleMatchQuality, |
| 75 | &PPC32_ModuleMatchQuality, |
Daniel Dunbar | 691a478 | 2009-07-25 10:09:50 +0000 | [diff] [blame^] | 76 | /*HasJIT=*/true); |
Daniel Dunbar | 56e2947 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 77 | |
| 78 | TargetRegistry::RegisterTarget(ThePPC64Target, "ppc64", |
| 79 | "PowerPC 64", |
| 80 | &PPC64_TripleMatchQuality, |
| 81 | &PPC64_ModuleMatchQuality, |
Daniel Dunbar | 691a478 | 2009-07-25 10:09:50 +0000 | [diff] [blame^] | 82 | /*HasJIT=*/true); |
Daniel Dunbar | 56e2947 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 83 | } |