Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 1 | //===-- TargetSelect.cpp - Target Chooser Code ----------------------------===// |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 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. |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Chris Lattner | beff74f | 2004-07-11 08:24:02 +0000 | [diff] [blame] | 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. |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "JIT.h" |
| 16 | #include "llvm/Module.h" |
| 17 | #include "llvm/ModuleProvider.h" |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 18 | #include "llvm/Target/SubtargetFeature.h" |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | d5e1d9d | 2004-07-11 04:02:06 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetMachineRegistry.h" |
| 21 | #include <iostream> |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 22 | using namespace llvm; |
| 23 | |
Chris Lattner | d5e1d9d | 2004-07-11 04:02:06 +0000 | [diff] [blame] | 24 | static cl::opt<const TargetMachineRegistry::Entry*, false, TargetNameParser> |
| 25 | MArch("march", cl::desc("Architecture to generate assembly for:")); |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 26 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 27 | static cl::opt<std::string> |
| 28 | MCPU("mcpu", |
Chris Lattner | 667eeca | 2005-10-23 22:39:01 +0000 | [diff] [blame] | 29 | cl::desc("Target a specific cpu type (-mcpu=help for details)"), |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 30 | cl::value_desc("cpu-name"), |
| 31 | cl::init("")); |
| 32 | |
| 33 | static cl::list<std::string> |
| 34 | MAttrs("mattr", |
| 35 | cl::CommaSeparated, |
Chris Lattner | 667eeca | 2005-10-23 22:39:01 +0000 | [diff] [blame] | 36 | cl::desc("Target specific attributes (-mattr=help for details)"), |
| 37 | cl::value_desc("a1,+a2,-a3,...")); |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 38 | |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 39 | /// create - Create an return a new JIT compiler if there is one available |
| 40 | /// for the current target. Otherwise, return null. |
| 41 | /// |
Chris Lattner | 726c1ef | 2006-03-23 05:22:51 +0000 | [diff] [blame] | 42 | ExecutionEngine *JIT::create(ModuleProvider *MP) { |
Chris Lattner | d5e1d9d | 2004-07-11 04:02:06 +0000 | [diff] [blame] | 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"; |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 51 | } |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 52 | |
Jim Laskey | b1e1180 | 2005-09-01 21:38:21 +0000 | [diff] [blame] | 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 | |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 63 | // Allocate a target... |
Chris Lattner | ef98691 | 2006-03-23 05:28:02 +0000 | [diff] [blame] | 64 | TargetMachine *Target = MArch->CtorFn(*MP->getModule(), FeaturesStr); |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 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 | } |