blob: 3d25dad2d647500e3fb0f07409770b607243ecc2 [file] [log] [blame]
Daniel Dunbar56e29472009-07-15 06:35:19 +00001//===-- 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
Daniel Dunbar67038c12009-07-18 23:03:22 +000010#include "PPC.h"
Daniel Dunbar56e29472009-07-15 06:35:19 +000011#include "llvm/Module.h"
12#include "llvm/Target/TargetRegistry.h"
13using namespace llvm;
14
Daniel Dunbar67038c12009-07-18 23:03:22 +000015Target llvm::ThePPC32Target;
Daniel Dunbar56e29472009-07-15 06:35:19 +000016
Daniel Dunbar56e29472009-07-15 06:35:19 +000017static unsigned PPC32_TripleMatchQuality(const std::string &TT) {
18 // We strongly match "powerpc-*".
19 if (TT.size() >= 8 && std::string(TT.begin(), TT.begin()+8) == "powerpc-")
20 return 20;
21
22 return 0;
23}
24
25static unsigned PPC32_ModuleMatchQuality(const Module &M) {
26 // Check for a triple match.
27 if (unsigned Q = PPC32_TripleMatchQuality(M.getTargetTriple()))
28 return Q;
29
30 // Otherwise if the target triple is non-empty, we don't match.
31 if (!M.getTargetTriple().empty()) return 0;
32
33 if (M.getEndianness() == Module::BigEndian &&
34 M.getPointerSize() == Module::Pointer64)
35 return 10; // Weak match
36 else if (M.getEndianness() != Module::AnyEndianness ||
37 M.getPointerSize() != Module::AnyPointerSize)
38 return 0; // Match for some other target
39
Daniel Dunbar691a4782009-07-25 10:09:50 +000040 return 0;
Daniel Dunbar56e29472009-07-15 06:35:19 +000041}
42
Daniel Dunbar67038c12009-07-18 23:03:22 +000043Target llvm::ThePPC64Target;
Daniel Dunbar56e29472009-07-15 06:35:19 +000044
Daniel Dunbar56e29472009-07-15 06:35:19 +000045static unsigned PPC64_TripleMatchQuality(const std::string &TT) {
46 // We strongly match "powerpc64-*".
47 if (TT.size() >= 10 && std::string(TT.begin(), TT.begin()+10) == "powerpc64-")
48 return 20;
49
50 return 0;
51}
52
53static unsigned PPC64_ModuleMatchQuality(const Module &M) {
54 // Check for a triple match.
55 if (unsigned Q = PPC64_TripleMatchQuality(M.getTargetTriple()))
56 return Q;
57
58 // Otherwise if the target triple is non-empty, we don't match.
59 if (!M.getTargetTriple().empty()) return 0;
60
61 if (M.getEndianness() == Module::BigEndian &&
62 M.getPointerSize() == Module::Pointer64)
63 return 10; // Weak match
64 else if (M.getEndianness() != Module::AnyEndianness ||
65 M.getPointerSize() != Module::AnyPointerSize)
66 return 0; // Match for some other target
67
Daniel Dunbar691a4782009-07-25 10:09:50 +000068 return 0;
Daniel Dunbar56e29472009-07-15 06:35:19 +000069}
70
71extern "C" void LLVMInitializePowerPCTargetInfo() {
72 TargetRegistry::RegisterTarget(ThePPC32Target, "ppc32",
73 "PowerPC 32",
74 &PPC32_TripleMatchQuality,
75 &PPC32_ModuleMatchQuality,
Daniel Dunbar691a4782009-07-25 10:09:50 +000076 /*HasJIT=*/true);
Daniel Dunbar56e29472009-07-15 06:35:19 +000077
78 TargetRegistry::RegisterTarget(ThePPC64Target, "ppc64",
79 "PowerPC 64",
80 &PPC64_TripleMatchQuality,
81 &PPC64_ModuleMatchQuality,
Daniel Dunbar691a4782009-07-25 10:09:50 +000082 /*HasJIT=*/true);
Daniel Dunbar56e29472009-07-15 06:35:19 +000083}