blob: a14b365b61ec466d8513f56dc3014b54c4ad8d7c [file] [log] [blame]
Chris Lattner4d326fa2003-12-20 01:46:27 +00001//===-- 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 Lattnerd5e1d9d2004-07-11 04:02:06 +000022#include "llvm/Target/TargetMachineRegistry.h"
23#include <iostream>
Chris Lattner4d326fa2003-12-20 01:46:27 +000024using namespace llvm;
25
Chris Lattnerd5e1d9d2004-07-11 04:02:06 +000026static cl::opt<const TargetMachineRegistry::Entry*, false, TargetNameParser>
27MArch("march", cl::desc("Architecture to generate assembly for:"));
Chris Lattner4d326fa2003-12-20 01:46:27 +000028
29/// create - Create an return a new JIT compiler if there is one available
30/// for the current target. Otherwise, return null.
31///
Chris Lattner73011782003-12-28 09:44:37 +000032ExecutionEngine *JIT::create(ModuleProvider *MP, IntrinsicLowering *IL) {
Chris Lattnerd5e1d9d2004-07-11 04:02:06 +000033 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 Lattner4d326fa2003-12-20 01:46:27 +000041 }
Chris Lattner4d326fa2003-12-20 01:46:27 +000042
43 // Allocate a target...
Chris Lattnerd5e1d9d2004-07-11 04:02:06 +000044 TargetMachine *Target = MArch->CtorFn(*MP->getModule(), IL);
Chris Lattner4d326fa2003-12-20 01:46:27 +000045 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}