1 //===-- PowerPCTargetInfo.cpp - PowerPC Target Implementation -------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Module.h"
11 #include "llvm/Target/TargetRegistry.h"
14 Target ThePPC32Target;
16 static unsigned PPC32_JITMatchQuality() {
17 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) || defined(__PPC__)
18 if (sizeof(void*) == 4)
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-")
32 static unsigned PPC32_ModuleMatchQuality(const Module &M) {
33 // Check for a triple match.
34 if (unsigned Q = PPC32_TripleMatchQuality(M.getTargetTriple()))
37 // Otherwise if the target triple is non-empty, we don't match.
38 if (!M.getTargetTriple().empty()) return 0;
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
47 return PPC32_JITMatchQuality()/2;
50 Target ThePPC64Target;
52 static unsigned PPC64_JITMatchQuality() {
53 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) || defined(__PPC__)
54 if (sizeof(void*) == 8)
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-")
68 static unsigned PPC64_ModuleMatchQuality(const Module &M) {
69 // Check for a triple match.
70 if (unsigned Q = PPC64_TripleMatchQuality(M.getTargetTriple()))
73 // Otherwise if the target triple is non-empty, we don't match.
74 if (!M.getTargetTriple().empty()) return 0;
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
83 return PPC64_JITMatchQuality()/2;
86 extern "C" void LLVMInitializePowerPCTargetInfo() {
87 TargetRegistry::RegisterTarget(ThePPC32Target, "ppc32",
89 &PPC32_TripleMatchQuality,
90 &PPC32_ModuleMatchQuality,
91 &PPC32_JITMatchQuality);
93 TargetRegistry::RegisterTarget(ThePPC64Target, "ppc64",
95 &PPC64_TripleMatchQuality,
96 &PPC64_ModuleMatchQuality,
97 &PPC64_JITMatchQuality);