diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ExecutionEngine/JIT/TargetSelect.cpp | 52 | ||||
-rw-r--r-- | lib/Support/Triple.cpp | 35 | ||||
-rw-r--r-- | lib/Target/CBackend/CBackend.cpp | 17 |
3 files changed, 70 insertions, 34 deletions
diff --git a/lib/ExecutionEngine/JIT/TargetSelect.cpp b/lib/ExecutionEngine/JIT/TargetSelect.cpp index 84b745b3f9..55ff44121d 100644 --- a/lib/ExecutionEngine/JIT/TargetSelect.cpp +++ b/lib/ExecutionEngine/JIT/TargetSelect.cpp @@ -16,8 +16,10 @@ #include "JIT.h" #include "llvm/Module.h" #include "llvm/ModuleProvider.h" +#include "llvm/ADT/Triple.h" #include "llvm/Support/CommandLine.h" -#include "llvm/Support/Streams.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/System/Host.h" #include "llvm/Target/SubtargetFeature.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetRegistry.h" @@ -41,35 +43,28 @@ MAttrs("mattr", /// selectTarget - Pick a target either via -march or by guessing the native /// arch. Add any CPU features specified via -mcpu or -mattr. TargetMachine *JIT::selectTarget(ModuleProvider *MP, std::string *ErrorStr) { - const Target *TheTarget = 0; - if (MArch.empty()) { - std::string Error; - TheTarget = TargetRegistry::getClosestTargetForJIT(Error); - if (TheTarget == 0) { - if (ErrorStr) - *ErrorStr = Error; - return 0; - } - } else { - for (TargetRegistry::iterator it = TargetRegistry::begin(), - ie = TargetRegistry::end(); it != ie; ++it) { - if (MArch == it->getName()) { - TheTarget = &*it; - break; - } - } - - if (TheTarget == 0) { - if (ErrorStr) - *ErrorStr = std::string("invalid target '" + MArch + "'.\n"); - return 0; - } + Triple TheTriple(sys::getHostTriple()); - if (!TheTarget->hasJIT()) { - cerr << "WARNING: This target JIT is not designed for the host you are" + // Adjust the triple to match what the user requested. + if (!MArch.empty()) + TheTriple.setArch(Triple::getArchTypeForLLVMName(MArch)); + + std::string Error; + const Target *TheTarget = + TargetRegistry::lookupTarget(TheTriple.getTriple(), + /*FallbackToHost=*/false, + /*RequireJIT=*/false, + Error); + if (TheTarget == 0) { + if (ErrorStr) + *ErrorStr = Error; + return 0; + } + + if (!TheTarget->hasJIT()) { + errs() << "WARNING: This target JIT is not designed for the host you are" << " running. If bad things happen, please choose a different " << "-march switch.\n"; - } } // Package up features to be passed to target/subtarget @@ -84,7 +79,8 @@ TargetMachine *JIT::selectTarget(ModuleProvider *MP, std::string *ErrorStr) { // Allocate a target... TargetMachine *Target = - TheTarget->createTargetMachine(*MP->getModule(), FeaturesStr); + TheTarget->createTargetMachine(*MP->getModule(), TheTriple.getTriple(), + FeaturesStr); assert(Target && "Could not allocate target machine!"); return Target; } diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp index 391c98656d..1cdaac0c2b 100644 --- a/lib/Support/Triple.cpp +++ b/lib/Support/Triple.cpp @@ -71,6 +71,41 @@ const char *Triple::getOSTypeName(OSType Kind) { return "<invalid>"; } +Triple::ArchType Triple::getArchTypeForLLVMName(const StringRef &Name) { + if (Name == "alpha") + return alpha; + if (Name == "arm") + return arm; + if (Name == "bfin") + return bfin; + if (Name == "cellspu") + return cellspu; + if (Name == "mips") + return mips; + if (Name == "mipsel") + return mipsel; + if (Name == "msp430") + return msp430; + if (Name == "ppc64") + return ppc64; + if (Name == "ppc") + return ppc; + if (Name == "sparc") + return sparc; + if (Name == "systemz") + return systemz; + if (Name == "thumb") + return thumb; + if (Name == "x86") + return x86; + if (Name == "x86_64") + return x86_64; + if (Name == "xcore") + return xcore; + + return UnknownArch; +} + // void Triple::Parse() const { diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp index 84f7c11e5d..c014006f54 100644 --- a/lib/Target/CBackend/CBackend.cpp +++ b/lib/Target/CBackend/CBackend.cpp @@ -24,6 +24,8 @@ #include "llvm/Intrinsics.h" #include "llvm/IntrinsicInst.h" #include "llvm/InlineAsm.h" +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Analysis/ConstantsScanner.h" #include "llvm/Analysis/FindUsedTypes.h" #include "llvm/Analysis/LoopInfo.h" @@ -41,9 +43,7 @@ #include "llvm/Support/InstVisitor.h" #include "llvm/Support/Mangler.h" #include "llvm/Support/MathExtras.h" -#include "llvm/ADT/StringExtras.h" -#include "llvm/ADT/STLExtras.h" -#include "llvm/Support/MathExtras.h" +#include "llvm/System/Host.h" #include "llvm/Config/config.h" #include <algorithm> #include <sstream> @@ -3181,16 +3181,21 @@ std::string CWriter::InterpretASMConstraint(InlineAsm::ConstraintInfo& c) { // Grab the translation table from TargetAsmInfo if it exists. if (!TAsm) { + std::string Triple = TheModule->getTargetTriple(); + if (Triple.empty()) + Triple = llvm::sys::getHostTriple(); + std::string E; const Target *Match = - TargetRegistry::lookupTarget(TheModule->getTargetTriple(), - /*FallbackToHost=*/true, + TargetRegistry::lookupTarget(Triple, + /*FallbackToHost=*/false, /*RequireJIT=*/false, E); if (Match) { // Per platform Target Machines don't exist, so create it; // this must be done only once. - const TargetMachine* TM = Match->createTargetMachine(*TheModule, ""); + const TargetMachine* TM = Match->createTargetMachine(*TheModule, Triple, + ""); TAsm = TM->getTargetAsmInfo(); } } |