blob: a9f99e0646e4eaea1d203ae0eb38a95520db0a06 [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
Daniel Dunbar0eb66992009-07-15 06:35:19 +000017static unsigned ARM_TripleMatchQuality(const std::string &TT) {
18 // Match arm-foo-bar, as well as things like armv5blah-*
19 if (TT.size() >= 4 &&
20 (TT.substr(0, 4) == "arm-" || TT.substr(0, 4) == "armv"))
21 return 20;
22
23 return 0;
24}
25
26static unsigned ARM_ModuleMatchQuality(const Module &M) {
27 // Check for a triple match.
28 if (unsigned Q = ARM_TripleMatchQuality(M.getTargetTriple()))
29 return Q;
30
31 // Otherwise if the target triple is non-empty, we don't match.
32 if (!M.getTargetTriple().empty()) return 0;
33
34 if (M.getEndianness() == Module::LittleEndian &&
35 M.getPointerSize() == Module::Pointer32)
36 return 10; // Weak match
37 else if (M.getEndianness() != Module::AnyEndianness ||
38 M.getPointerSize() != Module::AnyPointerSize)
39 return 0; // Match for some other target
40
Daniel Dunbar123157a2009-07-25 10:09:50 +000041 return 0;
Daniel Dunbar0eb66992009-07-15 06:35:19 +000042}
43
Daniel Dunbar0b0441e2009-07-18 23:03:22 +000044Target llvm::TheThumbTarget;
Daniel Dunbar0eb66992009-07-15 06:35:19 +000045
Daniel Dunbar0eb66992009-07-15 06:35:19 +000046static unsigned Thumb_TripleMatchQuality(const std::string &TT) {
47 // Match thumb-foo-bar, as well as things like thumbv5blah-*
48 if (TT.size() >= 6 &&
49 (TT.substr(0, 6) == "thumb-" || TT.substr(0, 6) == "thumbv"))
50 return 20;
51
52 return 0;
53}
54
55static unsigned Thumb_ModuleMatchQuality(const Module &M) {
56 // Check for a triple match.
57 if (unsigned Q = Thumb_TripleMatchQuality(M.getTargetTriple()))
58 return Q;
59
60 // Otherwise if the target triple is non-empty, we don't match.
61 if (!M.getTargetTriple().empty()) return 0;
62
63 if (M.getEndianness() == Module::LittleEndian &&
64 M.getPointerSize() == Module::Pointer32)
65 return 10; // Weak match
66 else if (M.getEndianness() != Module::AnyEndianness ||
67 M.getPointerSize() != Module::AnyPointerSize)
68 return 0; // Match for some other target
69
Daniel Dunbar123157a2009-07-25 10:09:50 +000070 return 0;
Daniel Dunbar0eb66992009-07-15 06:35:19 +000071}
72
73extern "C" void LLVMInitializeARMTargetInfo() {
74 TargetRegistry::RegisterTarget(TheARMTarget, "arm",
75 "ARM",
76 &ARM_TripleMatchQuality,
77 &ARM_ModuleMatchQuality,
Daniel Dunbar123157a2009-07-25 10:09:50 +000078 /*HasJIT=*/true);
Daniel Dunbar0eb66992009-07-15 06:35:19 +000079
80 TargetRegistry::RegisterTarget(TheThumbTarget, "thumb",
81 "Thumb",
82 &Thumb_TripleMatchQuality,
83 &Thumb_ModuleMatchQuality,
Daniel Dunbar123157a2009-07-25 10:09:50 +000084 /*HasJIT=*/true);
Daniel Dunbar0eb66992009-07-15 06:35:19 +000085}