1 //===-- TargetSelect.cpp - Target Chooser Code ----------------------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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.
16 //===----------------------------------------------------------------------===//
19 #include "llvm/Module.h"
20 #include "llvm/ModuleProvider.h"
21 #include "llvm/Target/TargetMachine.h"
22 #include "llvm/Target/TargetMachineRegistry.h"
26 static cl::opt<const TargetMachineRegistry::Entry*, false, TargetNameParser>
27 MArch("march", cl::desc("Architecture to generate assembly for:"));
29 /// create - Create an return a new JIT compiler if there is one available
30 /// for the current target. Otherwise, return null.
32 ExecutionEngine *JIT::create(ModuleProvider *MP, IntrinsicLowering *IL) {
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";
43 // Allocate a target...
44 TargetMachine *Target = MArch->CtorFn(*MP->getModule(), IL);
45 assert(Target && "Could not allocate target machine!");
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);