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/TargetMachineImpls.h"
23 #include "Support/CommandLine.h"
26 #if !defined(ENABLE_X86_JIT) && !defined(ENABLE_SPARC_JIT)
27 #define NO_JITS_ENABLED
31 enum ArchName { x86, SparcV9 };
33 #ifndef NO_JITS_ENABLED
35 Arch("march", cl::desc("Architecture to JIT to:"), cl::Prefix,
38 clEnumVal(x86, " IA-32 (Pentium and above)"),
40 #ifdef ENABLE_SPARC_JIT
41 clEnumValN(SparcV9, "sparcv9", " Sparc-V9"),
44 #if defined(ENABLE_X86_JIT)
46 #elif defined(ENABLE_SPARC_JIT)
50 #endif /* NO_JITS_ENABLED */
53 /// create - Create an return a new JIT compiler if there is one available
54 /// for the current target. Otherwise, return null.
56 ExecutionEngine *JIT::create(ModuleProvider *MP, IntrinsicLowering *IL) {
57 TargetMachine* (*TargetMachineAllocator)(const Module &,
58 IntrinsicLowering *IL) = 0;
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
68 TargetMachineAllocator = allocateX86TargetMachine;
71 #ifdef ENABLE_SPARC_JIT
73 TargetMachineAllocator = allocateSparcV9TargetMachine;
77 assert(0 && "-march flag not supported on this host!");
83 // Allocate a target...
84 TargetMachine *Target = TargetMachineAllocator(*MP->getModule(), IL);
85 assert(Target && "Could not allocate target machine!");
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);