aboutsummaryrefslogtreecommitdiff
path: root/lib/ExecutionEngine/JIT/TargetSelect.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-08-03 04:03:51 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-08-03 04:03:51 +0000
commit3c2d4bf97fa96fe171883cd80e4ea93fc43563e6 (patch)
tree736e1e2b833b3475c24a0569a546870cf25dd5fb /lib/ExecutionEngine/JIT/TargetSelect.cpp
parent0c794b87253bcd597f87960632f8654a151f37ec (diff)
Pass target triple string in to TargetMachine constructor.
This is not just a matter of passing in the target triple from the module; currently backends are making decisions based on the build and host architecture. The goal is to migrate to making these decisions based off of the triple (in conjunction with the feature string). Thus most clients pass in the target triple, or the host triple if that is empty. This has one important change in the way behavior of the JIT and llc. For the JIT, it was previously selecting the Target based on the host (naturally), but it was setting the target machine features based on the triple from the module. Now it is setting the target machine features based on the triple of the host. For LLC, -march was previously only used to select the target, the target machine features were initialized from the module's triple (which may have been empty). Now the target triple is taken from the module, or the host's triple is used if that is empty. Then the triple is adjusted to match -march. The take away is that -march for llc is now used in conjunction with the host triple to initialize the subtarget. If users want more deterministic behavior from llc, they should use -mtriple, or set the triple in the input module. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77946 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine/JIT/TargetSelect.cpp')
-rw-r--r--lib/ExecutionEngine/JIT/TargetSelect.cpp52
1 files changed, 24 insertions, 28 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;
}