blob: 6201002d7d055cf11fa1032521c1bfe69591a0e2 [file] [log] [blame]
Daniel Dunbarc984df82009-07-15 06:35:19 +00001//===-- X86TargetInfo.cpp - X86 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 Dunbaredcb5402009-07-18 23:22:46 +000010#include "X86.h"
Daniel Dunbarc984df82009-07-15 06:35:19 +000011#include "llvm/Module.h"
12#include "llvm/Target/TargetRegistry.h"
13using namespace llvm;
14
Daniel Dunbar4cb1e132009-07-18 23:03:22 +000015Target llvm::TheX86_32Target;
Daniel Dunbarc984df82009-07-15 06:35:19 +000016
Daniel Dunbarc984df82009-07-15 06:35:19 +000017static unsigned X86_32_TripleMatchQuality(const std::string &TT) {
18 // We strongly match "i[3-9]86-*".
19 if (TT.size() >= 5 && TT[0] == 'i' && TT[2] == '8' && TT[3] == '6' &&
20 TT[4] == '-' && TT[1] - '3' < 6)
21 return 20;
22
23 return 0;
24}
25
26static unsigned X86_32_ModuleMatchQuality(const Module &M) {
27 // Check for a triple match.
28 if (unsigned Q = X86_32_TripleMatchQuality(M.getTargetTriple()))
29 return Q;
30
31 // If the target triple is something non-X86, 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 Dunbard6fd3772009-07-25 10:09:50 +000041 return 0;
Daniel Dunbarc984df82009-07-15 06:35:19 +000042}
43
Daniel Dunbar4cb1e132009-07-18 23:03:22 +000044Target llvm::TheX86_64Target;
Daniel Dunbarc984df82009-07-15 06:35:19 +000045
Daniel Dunbarc984df82009-07-15 06:35:19 +000046static unsigned X86_64_TripleMatchQuality(const std::string &TT) {
47 // We strongly match "x86_64-*".
48 if (TT.size() >= 7 && TT[0] == 'x' && TT[1] == '8' && TT[2] == '6' &&
49 TT[3] == '_' && TT[4] == '6' && TT[5] == '4' && TT[6] == '-')
50 return 20;
51
52 return 0;
53}
54
55static unsigned X86_64_ModuleMatchQuality(const Module &M) {
56 // Check for a triple match.
57 if (unsigned Q = X86_64_TripleMatchQuality(M.getTargetTriple()))
58 return Q;
59
60 // If the target triple is something non-X86-64, we don't match.
61 if (!M.getTargetTriple().empty()) return 0;
62
63 if (M.getEndianness() == Module::LittleEndian &&
64 M.getPointerSize() == Module::Pointer64)
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 Dunbard6fd3772009-07-25 10:09:50 +000070 return 0;
Daniel Dunbarc984df82009-07-15 06:35:19 +000071}
72
73extern "C" void LLVMInitializeX86TargetInfo() {
74 TargetRegistry::RegisterTarget(TheX86_32Target, "x86",
75 "32-bit X86: Pentium-Pro and above",
76 &X86_32_TripleMatchQuality,
77 &X86_32_ModuleMatchQuality,
Daniel Dunbard6fd3772009-07-25 10:09:50 +000078 /*HasJIT=*/true);
Daniel Dunbarc984df82009-07-15 06:35:19 +000079
80 TargetRegistry::RegisterTarget(TheX86_64Target, "x86-64",
81 "64-bit X86: EM64T and AMD64",
82 &X86_64_TripleMatchQuality,
83 &X86_64_ModuleMatchQuality,
Daniel Dunbard6fd3772009-07-25 10:09:50 +000084 /*HasJIT=*/true);
Daniel Dunbarc984df82009-07-15 06:35:19 +000085}