Yikes. This requires checking apple gcc version.
[oota-llvm.git] / lib / ExecutionEngine / JIT / TargetSelect.cpp
1 //===-- TargetSelect.cpp - Target Chooser Code ----------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This just asks the TargetMachineRegistry for the appropriate JIT to use, and
11 // allows the user to specify a specific one on the commandline with -march=x.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "JIT.h"
16 #include "llvm/Module.h"
17 #include "llvm/ModuleProvider.h"
18 #include "llvm/Target/SubtargetFeature.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include "llvm/Target/TargetMachineRegistry.h"
21 #include <iostream>
22 using namespace llvm;
23
24 static cl::opt<const TargetMachineRegistry::Entry*, false, TargetNameParser>
25 MArch("march", cl::desc("Architecture to generate assembly for:"));
26
27 static cl::opt<std::string>
28 MCPU("mcpu", 
29   cl::desc("Target a specific cpu type (-mcpu=help for details)"),
30   cl::value_desc("cpu-name"),
31   cl::init(""));
32
33 static cl::list<std::string>
34 MAttrs("mattr", 
35   cl::CommaSeparated,
36   cl::desc("Target specific attributes (-mattr=help for details)"),
37   cl::value_desc("a1,+a2,-a3,..."));
38
39 /// create - Create an return a new JIT compiler if there is one available
40 /// for the current target.  Otherwise, return null.
41 ///
42 ExecutionEngine *JIT::create(ModuleProvider *MP) {
43   if (MArch == 0) {
44     std::string Error;
45     MArch = TargetMachineRegistry::getClosestTargetForJIT(Error);
46     if (MArch == 0) return 0;
47   } else if (MArch->JITMatchQualityFn() == 0) {
48     std::cerr << "WARNING: This target JIT is not designed for the host you are"
49               << " running.  If bad things happen, please choose a different "
50               << "-march switch.\n";
51   }
52
53   // Package up features to be passed to target/subtarget
54   std::string FeaturesStr;
55   if (MCPU.size() || MAttrs.size()) {
56     SubtargetFeatures Features;
57     Features.setCPU(MCPU);
58     for (unsigned i = 0; i != MAttrs.size(); ++i)
59       Features.AddFeature(MAttrs[i]);
60     FeaturesStr = Features.getString();
61   }
62
63   // Allocate a target...
64   TargetMachine *Target = MArch->CtorFn(*MP->getModule(), FeaturesStr);
65   assert(Target && "Could not allocate target machine!");
66
67   // If the target supports JIT code generation, return a new JIT now.
68   if (TargetJITInfo *TJ = Target->getJITInfo())
69     return new JIT(MP, *Target, *TJ);
70   return 0;
71 }