llvm.org GIT mirror llvm / d6fd377
Simplify JIT target selection. - Instead of requiring targets to define a JIT quality match function, we just have them specify if they support a JIT. - Target selection for the JIT just gets the host triple and looks for the best target which matches the triple and has a JIT. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77060 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 11 years ago
17 changed file(s) with 58 addition(s) and 156 deletion(s). Raw diff Collapse all Expand all
6767 /// of a module.
6868 ModuleMatchQualityFnTy ModuleMatchQualityFn;
6969
70 /// JITMatchQualityFn - The target function for rating the match quality
71 /// with the host.
72 JITMatchQualityFnTy JITMatchQualityFn;
73
7470 /// Name - The target name.
7571 const char *Name;
7672
7773 /// ShortDesc - A short description of the target.
7874 const char *ShortDesc;
75
76 /// HasJIT - Whether this target supports the JIT.
77 bool HasJIT;
7978
8079 /// TargetMachineCtorFn - Construction function for this target's
8180 /// TargetMachine, if registered.
9998 /// getShortDescription - Get a short description of the target.
10099 const char *getShortDescription() const { return ShortDesc; }
101100
102 /// getJITMatchQuality - Get the quality of this targets match for use as a
103 /// JIT.
104 unsigned getJITMatchQuality() const { return JITMatchQualityFn(); }
101 bool hasJIT() const { return HasJIT; }
105102
106103 /// hasTargetMachine - Check if this target supports code generation.
107104 bool hasTargetMachine() const { return TargetMachineCtorFn != 0; }
223220 /// this target.
224221 /// @param MQualityFn - The module match quality computation function for
225222 /// this target.
226 /// @param JITMatchQualityFn - The JIT match quality computation function
227 /// for this target.
223 /// @param HasJIT - Whether the target supports JIT code
224 /// generation.
228225 static void RegisterTarget(Target &T,
229226 const char *Name,
230227 const char *ShortDesc,
231228 Target::TripleMatchQualityFnTy TQualityFn,
232229 Target::ModuleMatchQualityFnTy MQualityFn,
233 Target::JITMatchQualityFnTy JITQualityFn);
230 bool HasJIT = false);
234231
235232 /// RegisterTargetMachine - Register a TargetMachine implementation for the
236233 /// given target.
291288 ///
292289 /// namespace {
293290 /// struct FooInfo {
291 /// static const bool HasJIT = ...;
292 ///
294293 /// static unsigned getJITMatchQuality() { ... }
295294 /// static unsigned getTripleMatchQuality(const std::string &) { ... }
296295 /// static unsigned getModuleMatchQuality(const Module &) { ... }
306305 TargetRegistry::RegisterTarget(T, Name, Desc,
307306 &TargetInfoImpl::getTripleMatchQuality,
308307 &TargetInfoImpl::getModuleMatchQuality,
309 &TargetInfoImpl::getJITMatchQuality);
308 TargetInfoImpl::HasJIT);
310309 }
311310 };
312311
6464 return 0;
6565 }
6666
67 if (TheTarget->getJITMatchQuality() == 0) {
67 if (!TheTarget->hasJIT()) {
6868 cerr << "WARNING: This target JIT is not designed for the host you are"
6969 << " running. If bad things happen, please choose a different "
7070 << "-march switch.\n";
77 //===----------------------------------------------------------------------===//
88
99 #include "llvm/Target/TargetRegistry.h"
10 #include "llvm/System/Host.h"
1011 #include
1112 using namespace llvm;
1213
7677 }
7778 }
7879
80 // FIXME: This is a hack to ignore super weak matches like msil, etc. and look
81 // by host instead. They will be found again via the triple.
82 if (Best && BestQuality == 1)
83 Best = EquallyBest = 0;
84
85 // If that failed, try looking up the host triple.
86 if (!Best)
87 Best = getClosestStaticTargetForTriple(sys::getHostTriple(), Error);
88
7989 if (!Best) {
8090 Error = "No available targets are compatible with this module";
81 return 0;
91 return Best;
8292 }
8393
8494 // Otherwise, take the best target, but make sure we don't have two equally
94104
95105 const Target *
96106 TargetRegistry::getClosestTargetForJIT(std::string &Error) {
107 std::string Triple = sys::getHostTriple();
108
97109 // Provide special warning when no targets are initialized.
98110 if (begin() == end()) {
99111 Error = "No JIT is available for this host (no targets are registered)";
103115 const Target *Best = 0, *EquallyBest = 0;
104116 unsigned BestQuality = 0;
105117 for (iterator it = begin(), ie = end(); it != ie; ++it) {
106 if (unsigned Qual = it->JITMatchQualityFn()) {
118 if (!it->hasJIT())
119 continue;
120
121 if (unsigned Qual = it->TripleMatchQualityFn(Triple)) {
107122 if (!Best || Qual > BestQuality) {
108123 Best = &*it;
109124 EquallyBest = 0;
127142 const char *ShortDesc,
128143 Target::TripleMatchQualityFnTy TQualityFn,
129144 Target::ModuleMatchQualityFnTy MQualityFn,
130 Target::JITMatchQualityFnTy JITQualityFn) {
131 assert(Name && ShortDesc && TQualityFn && MQualityFn && JITQualityFn &&
145 bool HasJIT) {
146 assert(Name && ShortDesc && TQualityFn && MQualityFn &&
132147 "Missing required target information!");
133148
134149 // Check if this target has already been initialized, we allow this as a
144159 T.ShortDesc = ShortDesc;
145160 T.TripleMatchQualityFn = TQualityFn;
146161 T.ModuleMatchQualityFn = MQualityFn;
147 T.JITMatchQualityFn = JITQualityFn;
162 T.HasJIT = HasJIT;
148163 }
149164
1212 using namespace llvm;
1313
1414 Target llvm::TheARMTarget;
15
16 static unsigned ARM_JITMatchQuality() {
17 #if defined(__arm__)
18 return 10;
19 #endif
20 return 0;
21 }
2215
2316 static unsigned ARM_TripleMatchQuality(const std::string &TT) {
2417 // Match arm-foo-bar, as well as things like armv5blah-*
4437 M.getPointerSize() != Module::AnyPointerSize)
4538 return 0; // Match for some other target
4639
47 return ARM_JITMatchQuality()/2;
40 return 0;
4841 }
4942
5043 Target llvm::TheThumbTarget;
51
52 static unsigned Thumb_JITMatchQuality() {
53 #if defined(__thumb__)
54 return 10;
55 #endif
56 return 0;
57 }
5844
5945 static unsigned Thumb_TripleMatchQuality(const std::string &TT) {
6046 // Match thumb-foo-bar, as well as things like thumbv5blah-*
8066 M.getPointerSize() != Module::AnyPointerSize)
8167 return 0; // Match for some other target
8268
83 return Thumb_JITMatchQuality()/2;
69 return 0;
8470 }
8571
8672 extern "C" void LLVMInitializeARMTargetInfo() {
8874 "ARM",
8975 &ARM_TripleMatchQuality,
9076 &ARM_ModuleMatchQuality,
91 &ARM_JITMatchQuality);
77 /*HasJIT=*/true);
9278
9379 TargetRegistry::RegisterTarget(TheThumbTarget, "thumb",
9480 "Thumb",
9581 &Thumb_TripleMatchQuality,
9682 &Thumb_ModuleMatchQuality,
97 &Thumb_JITMatchQuality);
83 /*HasJIT=*/true);
9884 }
1212 using namespace llvm;
1313
1414 llvm::Target llvm::TheAlphaTarget;
15
16 static unsigned Alpha_JITMatchQuality() {
17 #ifdef __alpha
18 return 10;
19 #else
20 return 0;
21 #endif
22 }
2315
2416 static unsigned Alpha_TripleMatchQuality(const std::string &TT) {
2517 // We strongly match "alpha*".
4537 M.getPointerSize() != Module::AnyPointerSize)
4638 return 0; // Match for some other target
4739
48 return Alpha_JITMatchQuality()/2;
40 return 0;
4941 }
5042
5143 extern "C" void LLVMInitializeAlphaTargetInfo() {
5345 "Alpha [experimental]",
5446 &Alpha_TripleMatchQuality,
5547 &Alpha_ModuleMatchQuality,
56 &Alpha_JITMatchQuality);
48 /*HasJIT=*/true);
5749 }
1212 using namespace llvm;
1313
1414 Target llvm::TheCBackendTarget;
15
16 static unsigned CBackend_JITMatchQuality() {
17 return 0;
18 }
1915
2016 static unsigned CBackend_TripleMatchQuality(const std::string &TT) {
2117 // This class always works, but must be requested explicitly on
3329 TargetRegistry::RegisterTarget(TheCBackendTarget, "c",
3430 "C backend",
3531 &CBackend_TripleMatchQuality,
36 &CBackend_ModuleMatchQuality,
37 &CBackend_JITMatchQuality);
32 &CBackend_ModuleMatchQuality);
3833 }
1212 using namespace llvm;
1313
1414 Target llvm::TheCellSPUTarget;
15
16 static unsigned CellSPU_JITMatchQuality() {
17 return 0;
18 }
1915
2016 static unsigned CellSPU_TripleMatchQuality(const std::string &TT) {
2117 // We strongly match "spu-*" or "cellspu-*".
4339 TargetRegistry::RegisterTarget(TheCellSPUTarget, "cellspu",
4440 "STI CBEA Cell SPU [experimental]",
4541 &CellSPU_TripleMatchQuality,
46 &CellSPU_ModuleMatchQuality,
47 &CellSPU_JITMatchQuality);
42 &CellSPU_ModuleMatchQuality);
4843 }
1313
1414 Target llvm::TheCppBackendTarget;
1515
16 static unsigned CppBackend_JITMatchQuality() {
17 return 0;
18 }
19
2016 static unsigned CppBackend_TripleMatchQuality(const std::string &TT) {
2117 // This class always works, but shouldn't be the default in most cases.
2218 return 1;
3127 TargetRegistry::RegisterTarget(TheCppBackendTarget, "cpp",
3228 "C++ backend",
3329 &CppBackend_TripleMatchQuality,
34 &CppBackend_ModuleMatchQuality,
35 &CppBackend_JITMatchQuality);
30 &CppBackend_ModuleMatchQuality);
3631 }
1313
1414 Target llvm::TheMSILTarget;
1515
16 static unsigned MSIL_JITMatchQuality() {
17 return 0;
18 }
19
2016 static unsigned MSIL_TripleMatchQuality(const std::string &TT) {
2117 // This class always works, but shouldn't be the default in most cases.
2218 return 1;
3127 TargetRegistry::RegisterTarget(TheMSILTarget, "msil",
3228 "MSIL backend",
3329 &MSIL_TripleMatchQuality,
34 &MSIL_ModuleMatchQuality,
35 &MSIL_JITMatchQuality);
30 &MSIL_ModuleMatchQuality);
3631 }
1212 using namespace llvm;
1313
1414 Target llvm::TheMSP430Target;
15
16 static unsigned MSP430_JITMatchQuality() {
17 return 0;
18 }
1915
2016 static unsigned MSP430_TripleMatchQuality(const std::string &TT) {
2117 // We strongly match msp430
4137 TargetRegistry::RegisterTarget(TheMSP430Target, "msp430",
4238 "MSP430 [experimental]",
4339 &MSP430_TripleMatchQuality,
44 &MSP430_ModuleMatchQuality,
45 &MSP430_JITMatchQuality);
40 &MSP430_ModuleMatchQuality);
4641 }
1212 using namespace llvm;
1313
1414 Target llvm::TheMipsTarget;
15
16 static unsigned Mips_JITMatchQuality() {
17 return 0;
18 }
1915
2016 static unsigned Mips_TripleMatchQuality(const std::string &TT) {
2117 // We strongly match "mips*-*".
4137 }
4238
4339 Target llvm::TheMipselTarget;
44
45 static unsigned Mipsel_JITMatchQuality() {
46 return 0;
47 }
4840
4941 static unsigned Mipsel_TripleMatchQuality(const std::string &TT) {
5042 // We strongly match "mips*el-*".
7668 TargetRegistry::RegisterTarget(TheMipsTarget, "mips",
7769 "Mips",
7870 &Mips_TripleMatchQuality,
79 &Mips_ModuleMatchQuality,
80 &Mips_JITMatchQuality);
71 &Mips_ModuleMatchQuality);
8172
8273 TargetRegistry::RegisterTarget(TheMipselTarget, "mipsel",
8374 "Mipsel",
8475 &Mipsel_TripleMatchQuality,
85 &Mipsel_ModuleMatchQuality,
86 &Mipsel_JITMatchQuality);
76 &Mipsel_ModuleMatchQuality);
8777 }
1313
1414 Target llvm::ThePIC16Target;
1515
16 static unsigned PIC16_JITMatchQuality() {
17 return 0;
18 }
19
2016 static unsigned PIC16_TripleMatchQuality(const std::string &TT) {
2117 return 0;
2218 }
2622 }
2723
2824 Target llvm::TheCooperTarget;
29
30 static unsigned Cooper_JITMatchQuality() {
31 return 0;
32 }
3325
3426 static unsigned Cooper_TripleMatchQuality(const std::string &TT) {
3527 return 0;
4335 TargetRegistry::RegisterTarget(ThePIC16Target, "pic16",
4436 "PIC16 14-bit [experimental]",
4537 &PIC16_TripleMatchQuality,
46 &PIC16_ModuleMatchQuality,
47 &PIC16_JITMatchQuality);
38 &PIC16_ModuleMatchQuality);
4839
4940 TargetRegistry::RegisterTarget(TheCooperTarget, "cooper",
5041 "PIC16 Cooper [experimental]",
5142 &Cooper_TripleMatchQuality,
52 &Cooper_ModuleMatchQuality,
53 &Cooper_JITMatchQuality);
43 &Cooper_ModuleMatchQuality);
5444 }
1212 using namespace llvm;
1313
1414 Target llvm::ThePPC32Target;
15
16 static unsigned PPC32_JITMatchQuality() {
17 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) || defined(__PPC__)
18 if (sizeof(void*) == 4)
19 return 10;
20 #endif
21 return 0;
22 }
2315
2416 static unsigned PPC32_TripleMatchQuality(const std::string &TT) {
2517 // We strongly match "powerpc-*".
4436 M.getPointerSize() != Module::AnyPointerSize)
4537 return 0; // Match for some other target
4638
47 return PPC32_JITMatchQuality()/2;
39 return 0;
4840 }
4941
5042 Target llvm::ThePPC64Target;
51
52 static unsigned PPC64_JITMatchQuality() {
53 #if defined(__POWERPC__) || defined (__ppc__) || defined(_POWER) || defined(__PPC__)
54 if (sizeof(void*) == 8)
55 return 10;
56 #endif
57 return 0;
58 }
5943
6044 static unsigned PPC64_TripleMatchQuality(const std::string &TT) {
6145 // We strongly match "powerpc64-*".
8064 M.getPointerSize() != Module::AnyPointerSize)
8165 return 0; // Match for some other target
8266
83 return PPC64_JITMatchQuality()/2;
67 return 0;
8468 }
8569
8670 extern "C" void LLVMInitializePowerPCTargetInfo() {
8872 "PowerPC 32",
8973 &PPC32_TripleMatchQuality,
9074 &PPC32_ModuleMatchQuality,
91 &PPC32_JITMatchQuality);
75 /*HasJIT=*/true);
9276
9377 TargetRegistry::RegisterTarget(ThePPC64Target, "ppc64",
9478 "PowerPC 64",
9579 &PPC64_TripleMatchQuality,
9680 &PPC64_ModuleMatchQuality,
97 &PPC64_JITMatchQuality);
81 /*HasJIT=*/true);
9882 }
1212 using namespace llvm;
1313
1414 Target llvm::TheSparcTarget;
15
16 static unsigned Sparc_JITMatchQuality() {
17 return 0;
18 }
1915
2016 static unsigned Sparc_TripleMatchQuality(const std::string &TT) {
2117 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "sparc-")
5652 TargetRegistry::RegisterTarget(TheSparcTarget, "sparc",
5753 "Sparc",
5854 &Sparc_TripleMatchQuality,
59 &Sparc_ModuleMatchQuality,
60 &Sparc_JITMatchQuality);
55 &Sparc_ModuleMatchQuality);
6156 }
None //===-- SystemZTargetInfo.cpp - SystemZ Target Implementation -----------------===//
0 //===-- SystemZTargetInfo.cpp - SystemZ Target Implementation -------------===//
11 //
22 // The LLVM Compiler Infrastructure
33 //
1212 using namespace llvm;
1313
1414 Target llvm::TheSystemZTarget;
15
16 static unsigned SystemZ_JITMatchQuality() {
17 return 0;
18 }
1915
2016 static unsigned SystemZ_TripleMatchQuality(const std::string &TT) {
2117 // We strongly match s390x
3935 TargetRegistry::RegisterTarget(TheSystemZTarget, "systemz",
4036 "SystemZ",
4137 &SystemZ_TripleMatchQuality,
42 &SystemZ_ModuleMatchQuality,
43 &SystemZ_JITMatchQuality);
38 &SystemZ_ModuleMatchQuality);
4439 }
1212 using namespace llvm;
1313
1414 Target llvm::TheX86_32Target;
15
16 static unsigned X86_32_JITMatchQuality() {
17 #if defined(i386) || defined(__i386__) || defined(__x86__) || defined(_M_IX86)
18 return 10;
19 #endif
20 return 0;
21 }
2215
2316 static unsigned X86_32_TripleMatchQuality(const std::string &TT) {
2417 // We strongly match "i[3-9]86-*".
4437 M.getPointerSize() != Module::AnyPointerSize)
4538 return 0; // Match for some other target
4639
47 return X86_32_JITMatchQuality()/2;
40 return 0;
4841 }
4942
5043 Target llvm::TheX86_64Target;
51
52 static unsigned X86_64_JITMatchQuality() {
53 #if defined(__x86_64__) || defined(_M_AMD64)
54 return 10;
55 #endif
56 return 0;
57 }
5844
5945 static unsigned X86_64_TripleMatchQuality(const std::string &TT) {
6046 // We strongly match "x86_64-*".
8066 M.getPointerSize() != Module::AnyPointerSize)
8167 return 0; // Match for some other target
8268
83 return X86_64_JITMatchQuality()/2;
69 return 0;
8470 }
8571
8672 extern "C" void LLVMInitializeX86TargetInfo() {
8874 "32-bit X86: Pentium-Pro and above",
8975 &X86_32_TripleMatchQuality,
9076 &X86_32_ModuleMatchQuality,
91 &X86_32_JITMatchQuality);
77 /*HasJIT=*/true);
9278
9379 TargetRegistry::RegisterTarget(TheX86_64Target, "x86-64",
9480 "64-bit X86: EM64T and AMD64",
9581 &X86_64_TripleMatchQuality,
9682 &X86_64_ModuleMatchQuality,
97 &X86_64_JITMatchQuality);
83 /*HasJIT=*/true);
9884 }
1212 using namespace llvm;
1313
1414 Target llvm::TheXCoreTarget;
15
16 static unsigned XCore_JITMatchQuality() {
17 return 0;
18 }
1915
2016 static unsigned XCore_TripleMatchQuality(const std::string &TT) {
2117 if (TT.size() >= 6 && std::string(TT.begin(), TT.begin()+6) == "xcore-")
3733 TargetRegistry::RegisterTarget(TheXCoreTarget, "xcore",
3834 "XCore",
3935 &XCore_TripleMatchQuality,
40 &XCore_ModuleMatchQuality,
41 &XCore_JITMatchQuality);
36 &XCore_ModuleMatchQuality);
4237 }