blob: d709463a15f5bb58fea01ddcb6531089cb0cf0c2 [file] [log] [blame]
Daniel Dunbar0eb66992009-07-15 06:35:19 +00001//===-- 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
Daniel Dunbar0b0441e2009-07-18 23:03:22 +000010#include "ARM.h"
Daniel Dunbar0eb66992009-07-15 06:35:19 +000011#include "llvm/Module.h"
12#include "llvm/Target/TargetRegistry.h"
13using namespace llvm;
14
Daniel Dunbar0b0441e2009-07-18 23:03:22 +000015Target llvm::TheARMTarget;
Daniel Dunbar0eb66992009-07-15 06:35:19 +000016
17static unsigned ARM_JITMatchQuality() {
18#if defined(__arm__)
19 return 10;
20#endif
21 return 0;
22}
23
24static unsigned ARM_TripleMatchQuality(const std::string &TT) {
25 // Match arm-foo-bar, as well as things like armv5blah-*
26 if (TT.size() >= 4 &&
27 (TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv"))
28 return 20;
29
30 return 0;
31}
32
33static unsigned ARM_ModuleMatchQuality(const Module &M) {
34 // Check for a triple match.
35 if (unsigned Q = ARM_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::LittleEndian &&
42 M.getPointerSize() == Module::Pointer32)
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 ARM_JITMatchQuality()/2;
49}
50
Daniel Dunbar0b0441e2009-07-18 23:03:22 +000051Target llvm::TheThumbTarget;
Daniel Dunbar0eb66992009-07-15 06:35:19 +000052
53static unsigned Thumb_JITMatchQuality() {
54#if defined(__thumb__)
55 return 10;
56#endif
57 return 0;
58}
59
60static unsigned Thumb_TripleMatchQuality(const std::string &TT) {
61 // Match thumb-foo-bar, as well as things like thumbv5blah-*
62 if (TT.size() >= 6 &&
63 (TT.substr(0, 6) == "thumb-" || TT.substr(0, 6) == "thumbv"))
64 return 20;
65
66 return 0;
67}
68
69static unsigned Thumb_ModuleMatchQuality(const Module &M) {
70 // Check for a triple match.
71 if (unsigned Q = Thumb_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::LittleEndian &&
78 M.getPointerSize() == Module::Pointer32)
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 Thumb_JITMatchQuality()/2;
85}
86
87extern "C" void LLVMInitializeARMTargetInfo() {
88 TargetRegistry::RegisterTarget(TheARMTarget, "arm",
89 "ARM",
90 &ARM_TripleMatchQuality,
91 &ARM_ModuleMatchQuality,
92 &ARM_JITMatchQuality);
93
94 TargetRegistry::RegisterTarget(TheThumbTarget, "thumb",
95 "Thumb",
96 &Thumb_TripleMatchQuality,
97 &Thumb_ModuleMatchQuality,
98 &Thumb_JITMatchQuality);
99}