PowerPCTargetInfo.cpp revision 4cb1e13769856716261a4d315f8202bd918502c3
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 10#include "PPC.h" 11#include "llvm/Module.h" 12#include "llvm/Target/TargetRegistry.h" 13using namespace llvm; 14 15Target llvm::ThePPC32Target; 16 17static 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 25static 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 33static 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 51Target llvm::ThePPC64Target; 52 53static 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 61static 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 69static 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 87extern "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} 100