[llvm-branch-commits] [llvm-branch] r81023 - /llvm/branches/release_26/lib/ExecutionEngine/JIT/TargetSelect.cpp
Tanya Lattner
tonic at nondot.org
Fri Sep 4 11:42:46 PDT 2009
Author: tbrethou
Date: Fri Sep 4 13:42:45 2009
New Revision: 81023
URL: http://llvm.org/viewvc/llvm-project?rev=81023&view=rev
Log:
Merge 80742 from mainline.
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.
Modified:
llvm/branches/release_26/lib/ExecutionEngine/JIT/TargetSelect.cpp
Modified: llvm/branches/release_26/lib/ExecutionEngine/JIT/TargetSelect.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_26/lib/ExecutionEngine/JIT/TargetSelect.cpp?rev=81023&r1=81022&r2=81023&view=diff
==============================================================================
--- llvm/branches/release_26/lib/ExecutionEngine/JIT/TargetSelect.cpp (original)
+++ llvm/branches/release_26/lib/ExecutionEngine/JIT/TargetSelect.cpp Fri Sep 4 13:42:45 2009
@@ -43,19 +43,41 @@
/// 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()) {
More information about the llvm-branch-commits
mailing list