LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

TargetSelect.cpp

Go to the documentation of this file.
00001 //===-- TargetSelect.cpp - Target Chooser Code ----------------------------===//
00002 // 
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file was developed by the LLVM research group and is distributed under
00006 // the University of Illinois Open Source License. See LICENSE.TXT for details.
00007 // 
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This just asks the TargetMachineRegistry for the appropriate JIT to use, and
00011 // allows the user to specify a specific one on the commandline with -march=x.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #include "JIT.h"
00016 #include "llvm/Module.h"
00017 #include "llvm/ModuleProvider.h"
00018 #include "llvm/Target/TargetMachine.h"
00019 #include "llvm/Target/TargetMachineRegistry.h"
00020 #include <iostream>
00021 using namespace llvm;
00022 
00023 static cl::opt<const TargetMachineRegistry::Entry*, false, TargetNameParser>
00024 MArch("march", cl::desc("Architecture to generate assembly for:"));
00025 
00026 /// create - Create an return a new JIT compiler if there is one available
00027 /// for the current target.  Otherwise, return null.
00028 ///
00029 ExecutionEngine *JIT::create(ModuleProvider *MP, IntrinsicLowering *IL) {
00030   if (MArch == 0) {
00031     std::string Error;
00032     MArch = TargetMachineRegistry::getClosestTargetForJIT(Error);
00033     if (MArch == 0) return 0;
00034   } else if (MArch->JITMatchQualityFn() == 0) {
00035     std::cerr << "WARNING: This target JIT is not designed for the host you are"
00036               << " running.  If bad things happen, please choose a different "
00037               << "-march switch.\n";
00038   }
00039 
00040   // Allocate a target...
00041   TargetMachine *Target = MArch->CtorFn(*MP->getModule(), IL);
00042   assert(Target && "Could not allocate target machine!");
00043 
00044   // If the target supports JIT code generation, return a new JIT now.
00045   if (TargetJITInfo *TJ = Target->getJITInfo())
00046     return new JIT(MP, *Target, *TJ);
00047   return 0;
00048 }