ARMTargetInfo.cpp revision 0eb6699b8f19fc450c7ce61c7ac0638753f92f9c
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 10#include "llvm/Module.h" 11#include "llvm/Target/TargetRegistry.h" 12using namespace llvm; 13 14Target TheARMTarget; 15 16static unsigned ARM_JITMatchQuality() { 17#if defined(__arm__) 18 return 10; 19#endif 20 return 0; 21} 22 23static unsigned ARM_TripleMatchQuality(const std::string &TT) { 24 // Match arm-foo-bar, as well as things like armv5blah-* 25 if (TT.size() >= 4 && 26 (TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv")) 27 return 20; 28 29 return 0; 30} 31 32static unsigned ARM_ModuleMatchQuality(const Module &M) { 33 // Check for a triple match. 34 if (unsigned Q = ARM_TripleMatchQuality(M.getTargetTriple())) 35 return Q; 36 37 // Otherwise if the target triple is non-empty, we don't match. 38 if (!M.getTargetTriple().empty()) return 0; 39 40 if (M.getEndianness() == Module::LittleEndian && 41 M.getPointerSize() == Module::Pointer32) 42 return 10; // Weak match 43 else if (M.getEndianness() != Module::AnyEndianness || 44 M.getPointerSize() != Module::AnyPointerSize) 45 return 0; // Match for some other target 46 47 return ARM_JITMatchQuality()/2; 48} 49 50Target TheThumbTarget; 51 52static unsigned Thumb_JITMatchQuality() { 53#if defined(__thumb__) 54 return 10; 55#endif 56 return 0; 57} 58 59static unsigned Thumb_TripleMatchQuality(const std::string &TT) { 60 // Match thumb-foo-bar, as well as things like thumbv5blah-* 61 if (TT.size() >= 6 && 62 (TT.substr(0, 6) == "thumb-" || TT.substr(0, 6) == "thumbv")) 63 return 20; 64 65 return 0; 66} 67 68static unsigned Thumb_ModuleMatchQuality(const Module &M) { 69 // Check for a triple match. 70 if (unsigned Q = Thumb_TripleMatchQuality(M.getTargetTriple())) 71 return Q; 72 73 // Otherwise if the target triple is non-empty, we don't match. 74 if (!M.getTargetTriple().empty()) return 0; 75 76 if (M.getEndianness() == Module::LittleEndian && 77 M.getPointerSize() == Module::Pointer32) 78 return 10; // Weak match 79 else if (M.getEndianness() != Module::AnyEndianness || 80 M.getPointerSize() != Module::AnyPointerSize) 81 return 0; // Match for some other target 82 83 return Thumb_JITMatchQuality()/2; 84} 85 86extern "C" void LLVMInitializeARMTargetInfo() { 87 TargetRegistry::RegisterTarget(TheARMTarget, "arm", 88 "ARM", 89 &ARM_TripleMatchQuality, 90 &ARM_ModuleMatchQuality, 91 &ARM_JITMatchQuality); 92 93 TargetRegistry::RegisterTarget(TheThumbTarget, "thumb", 94 "Thumb", 95 &Thumb_TripleMatchQuality, 96 &Thumb_ModuleMatchQuality, 97 &Thumb_JITMatchQuality); 98} 99