Daniel Dunbar | 0eb6699 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 1 | //===-- ARMTargetInfo.cpp - ARM 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 | 0b0441e | 2009-07-18 23:03:22 +0000 | [diff] [blame^] | 10 | #include "ARM.h" |
Daniel Dunbar | 0eb6699 | 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 | 0b0441e | 2009-07-18 23:03:22 +0000 | [diff] [blame^] | 15 | Target llvm::TheARMTarget; |
Daniel Dunbar | 0eb6699 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 16 | |
| 17 | static unsigned ARM_JITMatchQuality() { |
| 18 | #if defined(__arm__) |
| 19 | return 10; |
| 20 | #endif |
| 21 | return 0; |
| 22 | } |
| 23 | |
| 24 | static unsigned ARM_TripleMatchQuality(const std::string &TT) { |
| 25 | // Match arm-foo-bar, as well as things like armv5blah-* |
| 26 | if (TT.size() >= 4 && |
| 27 | (TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv")) |
| 28 | return 20; |
| 29 | |
| 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | static unsigned ARM_ModuleMatchQuality(const Module &M) { |
| 34 | // Check for a triple match. |
| 35 | if (unsigned Q = ARM_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::LittleEndian && |
| 42 | M.getPointerSize() == Module::Pointer32) |
| 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 ARM_JITMatchQuality()/2; |
| 49 | } |
| 50 | |
Daniel Dunbar | 0b0441e | 2009-07-18 23:03:22 +0000 | [diff] [blame^] | 51 | Target llvm::TheThumbTarget; |
Daniel Dunbar | 0eb6699 | 2009-07-15 06:35:19 +0000 | [diff] [blame] | 52 | |
| 53 | static unsigned Thumb_JITMatchQuality() { |
| 54 | #if defined(__thumb__) |
| 55 | return 10; |
| 56 | #endif |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | static unsigned Thumb_TripleMatchQuality(const std::string &TT) { |
| 61 | // Match thumb-foo-bar, as well as things like thumbv5blah-* |
| 62 | if (TT.size() >= 6 && |
| 63 | (TT.substr(0, 6) == "thumb-" || TT.substr(0, 6) == "thumbv")) |
| 64 | return 20; |
| 65 | |
| 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static unsigned Thumb_ModuleMatchQuality(const Module &M) { |
| 70 | // Check for a triple match. |
| 71 | if (unsigned Q = Thumb_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::LittleEndian && |
| 78 | M.getPointerSize() == Module::Pointer32) |
| 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 Thumb_JITMatchQuality()/2; |
| 85 | } |
| 86 | |
| 87 | extern "C" void LLVMInitializeARMTargetInfo() { |
| 88 | TargetRegistry::RegisterTarget(TheARMTarget, "arm", |
| 89 | "ARM", |
| 90 | &ARM_TripleMatchQuality, |
| 91 | &ARM_ModuleMatchQuality, |
| 92 | &ARM_JITMatchQuality); |
| 93 | |
| 94 | TargetRegistry::RegisterTarget(TheThumbTarget, "thumb", |
| 95 | "Thumb", |
| 96 | &Thumb_TripleMatchQuality, |
| 97 | &Thumb_ModuleMatchQuality, |
| 98 | &Thumb_JITMatchQuality); |
| 99 | } |