Add TargetInfo libraries for all targets.
[oota-llvm.git] / lib / Target / PowerPC / TargetInfo / PowerPCTargetInfo.cpp
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 "llvm/Module.h"
11 #include "llvm/Target/TargetRegistry.h"
12 using namespace llvm;
13
14 Target ThePPC32Target;
15
16 static unsigned PPC32_JITMatchQuality() {
17 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) || defined(__PPC__)
18   if (sizeof(void*) == 4)
19     return 10;
20 #endif
21   return 0;
22 }
23
24 static unsigned PPC32_TripleMatchQuality(const std::string &TT) {
25   // We strongly match "powerpc-*".
26   if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
27     return 20;
28
29   return 0;
30 }
31
32 static unsigned PPC32_ModuleMatchQuality(const Module &M) {
33   // Check for a triple match.
34   if (unsigned Q = PPC32_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::BigEndian &&
41       M.getPointerSize() == Module::Pointer64)
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 PPC32_JITMatchQuality()/2;
48 }
49
50 Target ThePPC64Target;
51
52 static unsigned PPC64_JITMatchQuality() {
53 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) || defined(__PPC__)
54   if (sizeof(void*) == 8)
55     return 10;
56 #endif
57   return 0;
58 }
59
60 static unsigned PPC64_TripleMatchQuality(const std::string &TT) {
61   // We strongly match "powerpc64-*".
62   if (TT.size() >= 10 && std::string(TT.begin(), TT.begin()+10) == "powerpc64-")
63     return 20;
64
65   return 0;
66 }
67
68 static unsigned PPC64_ModuleMatchQuality(const Module &M) {
69   // Check for a triple match.
70   if (unsigned Q = PPC64_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::BigEndian &&
77       M.getPointerSize() == Module::Pointer64)
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 PPC64_JITMatchQuality()/2;
84 }
85
86 extern "C" void LLVMInitializePowerPCTargetInfo() { 
87   TargetRegistry::RegisterTarget(ThePPC32Target, "ppc32",
88                                   "PowerPC 32",
89                                   &PPC32_TripleMatchQuality,
90                                   &PPC32_ModuleMatchQuality,
91                                   &PPC32_JITMatchQuality);
92
93   TargetRegistry::RegisterTarget(ThePPC64Target, "ppc64",
94                                   "PowerPC 64",
95                                   &PPC64_TripleMatchQuality,
96                                   &PPC64_ModuleMatchQuality,
97                                   &PPC64_JITMatchQuality);
98 }