Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 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 file contains the hideously gross code that is currently used to select |
| 11 | // a particular TargetMachine for the JIT to use. This should obviously be |
| 12 | // improved in the future, probably by having the TargetMachines register |
| 13 | // themselves with the runtime, and then have them choose themselves if they |
| 14 | // match the current machine. |
| 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| 18 | #include "JIT.h" |
| 19 | #include "llvm/Module.h" |
| 20 | #include "llvm/ModuleProvider.h" |
| 21 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | d5e1d9d | 2004-07-11 04:02:06 +0000 | [diff] [blame^] | 22 | #include "llvm/Target/TargetMachineRegistry.h" |
| 23 | #include <iostream> |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 24 | using namespace llvm; |
| 25 | |
Chris Lattner | d5e1d9d | 2004-07-11 04:02:06 +0000 | [diff] [blame^] | 26 | static cl::opt<const TargetMachineRegistry::Entry*, false, TargetNameParser> |
| 27 | MArch("march", cl::desc("Architecture to generate assembly for:")); |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 28 | |
| 29 | /// create - Create an return a new JIT compiler if there is one available |
| 30 | /// for the current target. Otherwise, return null. |
| 31 | /// |
Chris Lattner | 7301178 | 2003-12-28 09:44:37 +0000 | [diff] [blame] | 32 | ExecutionEngine *JIT::create(ModuleProvider *MP, IntrinsicLowering *IL) { |
Chris Lattner | d5e1d9d | 2004-07-11 04:02:06 +0000 | [diff] [blame^] | 33 | if (MArch == 0) { |
| 34 | std::string Error; |
| 35 | MArch = TargetMachineRegistry::getClosestTargetForJIT(Error); |
| 36 | if (MArch == 0) return 0; |
| 37 | } else if (MArch->JITMatchQualityFn() == 0) { |
| 38 | std::cerr << "WARNING: This target JIT is not designed for the host you are" |
| 39 | << " running. If bad things happen, please choose a different " |
| 40 | << "-march switch.\n"; |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 41 | } |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 42 | |
| 43 | // Allocate a target... |
Chris Lattner | d5e1d9d | 2004-07-11 04:02:06 +0000 | [diff] [blame^] | 44 | TargetMachine *Target = MArch->CtorFn(*MP->getModule(), IL); |
Chris Lattner | 4d326fa | 2003-12-20 01:46:27 +0000 | [diff] [blame] | 45 | assert(Target && "Could not allocate target machine!"); |
| 46 | |
| 47 | // If the target supports JIT code generation, return a new JIT now. |
| 48 | if (TargetJITInfo *TJ = Target->getJITInfo()) |
| 49 | return new JIT(MP, *Target, *TJ); |
| 50 | return 0; |
| 51 | } |