blob: 851b4b4fb0959a974dec609eeadd07ddc131635c [file] [log] [blame]
Chris Lattner4d326fa2003-12-20 01:46:27 +00001//===-- TargetSelect.cpp - Target Chooser Code ----------------------------===//
Misha Brukmanf976c852005-04-21 22:55:34 +00002//
Chris Lattner4d326fa2003-12-20 01:46:27 +00003// 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 Brukmanf976c852005-04-21 22:55:34 +00007//
Chris Lattner4d326fa2003-12-20 01:46:27 +00008//===----------------------------------------------------------------------===//
9//
Chris Lattnerbeff74f2004-07-11 08:24:02 +000010// 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 Lattner4d326fa2003-12-20 01:46:27 +000012//
13//===----------------------------------------------------------------------===//
14
15#include "JIT.h"
16#include "llvm/Module.h"
17#include "llvm/ModuleProvider.h"
18#include "llvm/Target/TargetMachine.h"
Chris Lattnerd5e1d9d2004-07-11 04:02:06 +000019#include "llvm/Target/TargetMachineRegistry.h"
20#include <iostream>
Chris Lattner4d326fa2003-12-20 01:46:27 +000021using namespace llvm;
22
Chris Lattnerd5e1d9d2004-07-11 04:02:06 +000023static cl::opt<const TargetMachineRegistry::Entry*, false, TargetNameParser>
24MArch("march", cl::desc("Architecture to generate assembly for:"));
Chris Lattner4d326fa2003-12-20 01:46:27 +000025
26/// create - Create an return a new JIT compiler if there is one available
27/// for the current target. Otherwise, return null.
28///
Chris Lattner73011782003-12-28 09:44:37 +000029ExecutionEngine *JIT::create(ModuleProvider *MP, IntrinsicLowering *IL) {
Chris Lattnerd5e1d9d2004-07-11 04:02:06 +000030 if (MArch == 0) {
31 std::string Error;
32 MArch = TargetMachineRegistry::getClosestTargetForJIT(Error);
33 if (MArch == 0) return 0;
34 } else if (MArch->JITMatchQualityFn() == 0) {
35 std::cerr << "WARNING: This target JIT is not designed for the host you are"
36 << " running. If bad things happen, please choose a different "
37 << "-march switch.\n";
Chris Lattner4d326fa2003-12-20 01:46:27 +000038 }
Chris Lattner4d326fa2003-12-20 01:46:27 +000039
40 // Allocate a target...
Chris Lattnerd5e1d9d2004-07-11 04:02:06 +000041 TargetMachine *Target = MArch->CtorFn(*MP->getModule(), IL);
Chris Lattner4d326fa2003-12-20 01:46:27 +000042 assert(Target && "Could not allocate target machine!");
43
44 // If the target supports JIT code generation, return a new JIT now.
45 if (TargetJITInfo *TJ = Target->getJITInfo())
46 return new JIT(MP, *Target, *TJ);
47 return 0;
48}