LLVM API Documentation
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/SubtargetFeature.h" 00019 #include "llvm/Target/TargetMachine.h" 00020 #include "llvm/Target/TargetMachineRegistry.h" 00021 #include <iostream> 00022 using namespace llvm; 00023 00024 static cl::opt<const TargetMachineRegistry::Entry*, false, TargetNameParser> 00025 MArch("march", cl::desc("Architecture to generate assembly for:")); 00026 00027 static cl::opt<std::string> 00028 MCPU("mcpu", 00029 cl::desc("Target a specific cpu type (-mcpu=help for details)"), 00030 cl::value_desc("cpu-name"), 00031 cl::init("")); 00032 00033 static cl::list<std::string> 00034 MAttrs("mattr", 00035 cl::CommaSeparated, 00036 cl::desc("Target specific attributes (-mattr=help for details)"), 00037 cl::value_desc("a1,+a2,-a3,...")); 00038 00039 /// create - Create an return a new JIT compiler if there is one available 00040 /// for the current target. Otherwise, return null. 00041 /// 00042 ExecutionEngine *JIT::create(ModuleProvider *MP) { 00043 if (MArch == 0) { 00044 std::string Error; 00045 MArch = TargetMachineRegistry::getClosestTargetForJIT(Error); 00046 if (MArch == 0) return 0; 00047 } else if (MArch->JITMatchQualityFn() == 0) { 00048 std::cerr << "WARNING: This target JIT is not designed for the host you are" 00049 << " running. If bad things happen, please choose a different " 00050 << "-march switch.\n"; 00051 } 00052 00053 // Package up features to be passed to target/subtarget 00054 std::string FeaturesStr; 00055 if (MCPU.size() || MAttrs.size()) { 00056 SubtargetFeatures Features; 00057 Features.setCPU(MCPU); 00058 for (unsigned i = 0; i != MAttrs.size(); ++i) 00059 Features.AddFeature(MAttrs[i]); 00060 FeaturesStr = Features.getString(); 00061 } 00062 00063 // Allocate a target... 00064 TargetMachine *Target = MArch->CtorFn(*MP->getModule(), FeaturesStr); 00065 assert(Target && "Could not allocate target machine!"); 00066 00067 // If the target supports JIT code generation, return a new JIT now. 00068 if (TargetJITInfo *TJ = Target->getJITInfo()) 00069 return new JIT(MP, *Target, *TJ); 00070 return 0; 00071 }