Remove attribution from file headers, per discussion on llvmdev.
[oota-llvm.git] / lib / ExecutionEngine / JIT / TargetSelect.cpp
1 //===-- TargetSelect.cpp - Target Chooser Code ----------------------------===//
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 //
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 using namespace llvm;
22
23 static cl::opt<const TargetMachineRegistry::entry*, false,
24                TargetMachineRegistry::Parser>
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 /// createInternal - Create an return a new JIT compiler if there is one
40 /// available for the current target.  Otherwise, return null.
41 ///
42 ExecutionEngine *JIT::createJIT(ModuleProvider *MP, std::string *ErrorStr,
43                                 JITMemoryManager *JMM) {
44   const TargetMachineRegistry::entry *TheArch = MArch;
45   if (TheArch == 0) {
46     std::string Error;
47     TheArch = TargetMachineRegistry::getClosestTargetForJIT(Error);
48     if (TheArch == 0) {
49       if (ErrorStr)
50         *ErrorStr = Error;
51       return 0;
52     }
53   } else if (TheArch->JITMatchQualityFn() == 0) {
54     cerr << "WARNING: This target JIT is not designed for the host you are"
55          << " running.  If bad things happen, please choose a different "
56          << "-march switch.\n";
57   }
58
59   // Package up features to be passed to target/subtarget
60   std::string FeaturesStr;
61   if (MCPU.size() || MAttrs.size()) {
62     SubtargetFeatures Features;
63     Features.setCPU(MCPU);
64     for (unsigned i = 0; i != MAttrs.size(); ++i)
65       Features.AddFeature(MAttrs[i]);
66     FeaturesStr = Features.getString();
67   }
68
69   // Allocate a target...
70   TargetMachine *Target = TheArch->CtorFn(*MP->getModule(), FeaturesStr);
71   assert(Target && "Could not allocate target machine!");
72
73   // If the target supports JIT code generation, return a new JIT now.
74   if (TargetJITInfo *TJ = Target->getJITInfo())
75     return new JIT(MP, *Target, *TJ, JMM);
76
77   if (ErrorStr)
78     *ErrorStr = "target does not support JIT code generation";
79   return 0;
80 }