summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine/JIT/TargetSelect.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2009-09-02 00:19:03 +0000
committerEvan Cheng <evan.cheng@apple.com>2009-09-02 00:19:03 +0000
commit10a5dabfd54a8fd85eb365178b711622f4743618 (patch)
treeb1c2b6054cadaf5ccacd025b74418bc0d71432c3 /llvm/lib/ExecutionEngine/JIT/TargetSelect.cpp
parent34455c9c652ed4d1728889142b70e4985d3a17de (diff)
downloadbcm5719-llvm-10a5dabfd54a8fd85eb365178b711622f4743618.tar.gz
bcm5719-llvm-10a5dabfd54a8fd85eb365178b711622f4743618.zip
Fix PR4845: r77946 completely broke x86_64 Darwin (or any situation where the
desired triplet is a sub-target, e.g. thumbv7 vs. arm host). Reverting the patch isn't quite right either since the previous behavior does not allow the triplet to be overridden with -march. llvm-svn: 80742
Diffstat (limited to 'llvm/lib/ExecutionEngine/JIT/TargetSelect.cpp')
-rw-r--r--llvm/lib/ExecutionEngine/JIT/TargetSelect.cpp42
1 files changed, 32 insertions, 10 deletions
diff --git a/llvm/lib/ExecutionEngine/JIT/TargetSelect.cpp b/llvm/lib/ExecutionEngine/JIT/TargetSelect.cpp
index c2d5a1403e4..2c105416cc7 100644
--- a/llvm/lib/ExecutionEngine/JIT/TargetSelect.cpp
+++ b/llvm/lib/ExecutionEngine/JIT/TargetSelect.cpp
@@ -43,19 +43,41 @@ 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) {
- Triple TheTriple(sys::getHostTriple());
+ Module &Mod = *MP->getModule();
+
+ Triple TheTriple(Mod.getTargetTriple());
+ if (TheTriple.getTriple().empty())
+ TheTriple.setTriple(sys::getHostTriple());
// Adjust the triple to match what the user requested.
- if (!MArch.empty())
- TheTriple.setArch(Triple::getArchTypeForLLVMName(MArch));
+ const Target *TheTarget = 0;
+ if (!MArch.empty()) {
+ for (TargetRegistry::iterator it = TargetRegistry::begin(),
+ ie = TargetRegistry::end(); it != ie; ++it) {
+ if (MArch == it->getName()) {
+ TheTarget = &*it;
+ break;
+ }
+ }
+
+ if (!TheTarget) {
+ errs() << "JIT: error: invalid target '" << MArch << "'.\n";
+ return 0;
+ }
- std::string Error;
- const Target *TheTarget =
- TargetRegistry::lookupTarget(TheTriple.getTriple(), Error);
- if (TheTarget == 0) {
- if (ErrorStr)
- *ErrorStr = Error;
- return 0;
+ // Adjust the triple to match (if known), otherwise stick with the
+ // module/host triple.
+ Triple::ArchType Type = Triple::getArchTypeForLLVMName(MArch);
+ if (Type != Triple::UnknownArch)
+ TheTriple.setArch(Type);
+ } else {
+ std::string Error;
+ TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(), Error);
+ if (TheTarget == 0) {
+ if (ErrorStr)
+ *ErrorStr = Error;
+ return 0;
+ }
}
if (!TheTarget->hasJIT()) {
OpenPOWER on IntegriCloud