blob: 0540862870377dd47d0d15445e89b5dd7a8f20d6 [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"
22#include "llvm/Target/TargetMachineImpls.h"
23#include "Support/CommandLine.h"
24using namespace llvm;
25
26#if !defined(ENABLE_X86_JIT) && !defined(ENABLE_SPARC_JIT)
27#define NO_JITS_ENABLED
28#endif
29
30namespace {
31 enum ArchName { x86, Sparc };
32
33#ifndef NO_JITS_ENABLED
34 cl::opt<ArchName>
35 Arch("march", cl::desc("Architecture to JIT to:"), cl::Prefix,
36 cl::values(
37#ifdef ENABLE_X86_JIT
38 clEnumVal(x86, " IA-32 (Pentium and above)"),
39#endif
40#ifdef ENABLE_SPARC_JIT
41 clEnumValN(Sparc, "sparc", " Sparc-V9"),
42#endif
43 0),
44#if defined(ENABLE_X86_JIT)
45 cl::init(x86)
46#elif defined(ENABLE_SPARC_JIT)
47 cl::init(Sparc)
48#endif
49 );
50#endif /* NO_JITS_ENABLED */
51}
52
53/// create - Create an return a new JIT compiler if there is one available
54/// for the current target. Otherwise, return null.
55///
Chris Lattner73011782003-12-28 09:44:37 +000056ExecutionEngine *JIT::create(ModuleProvider *MP, IntrinsicLowering *IL) {
57 TargetMachine* (*TargetMachineAllocator)(const Module &,
58 IntrinsicLowering *IL) = 0;
Chris Lattner4d326fa2003-12-20 01:46:27 +000059
60 // Allow a command-line switch to override what *should* be the default target
61 // machine for this platform. This allows for debugging a Sparc JIT on X86 --
62 // our X86 machines are much faster at recompiling LLVM and linking LLI.
63#ifndef NO_JITS_ENABLED
64
65 switch (Arch) {
66#ifdef ENABLE_X86_JIT
67 case x86:
68 TargetMachineAllocator = allocateX86TargetMachine;
69 break;
70#endif
71#ifdef ENABLE_SPARC_JIT
72 case Sparc:
73 TargetMachineAllocator = allocateSparcTargetMachine;
74 break;
75#endif
76 default:
77 assert(0 && "-march flag not supported on this host!");
78 }
79#else
80 return 0;
81#endif
82
83 // Allocate a target...
Chris Lattner73011782003-12-28 09:44:37 +000084 TargetMachine *Target = TargetMachineAllocator(*MP->getModule(), IL);
Chris Lattner4d326fa2003-12-20 01:46:27 +000085 assert(Target && "Could not allocate target machine!");
86
87 // If the target supports JIT code generation, return a new JIT now.
88 if (TargetJITInfo *TJ = Target->getJITInfo())
89 return new JIT(MP, *Target, *TJ);
90 return 0;
91}
92
93