summaryrefslogtreecommitdiffstats
path: root/llvm/tools
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools')
-rw-r--r--llvm/tools/llc/llc.cpp52
-rw-r--r--llvm/tools/lto/LTOCodeGenerator.cpp14
-rw-r--r--llvm/tools/lto/LTOModule.cpp14
3 files changed, 52 insertions, 28 deletions
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index 9f7f0a43f15..e3468575142 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -13,21 +13,20 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/Bitcode/ReaderWriter.h"
-#include "llvm/CodeGen/FileWriters.h"
-#include "llvm/CodeGen/LinkAllCodegenComponents.h"
-#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
-#include "llvm/CodeGen/ObjectCodeEmitter.h"
-#include "llvm/Target/SubtargetFeature.h"
-#include "llvm/Target/TargetData.h"
-#include "llvm/Target/TargetMachine.h"
-#include "llvm/Target/TargetRegistry.h"
-#include "llvm/Transforms/Scalar.h"
#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/ModuleProvider.h"
#include "llvm/PassManager.h"
#include "llvm/Pass.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/Analysis/Verifier.h"
+#include "llvm/Bitcode/ReaderWriter.h"
+#include "llvm/CodeGen/FileWriters.h"
+#include "llvm/CodeGen/LinkAllAsmWriterComponents.h"
+#include "llvm/CodeGen/LinkAllCodegenComponents.h"
+#include "llvm/CodeGen/ObjectCodeEmitter.h"
+#include "llvm/Config/config.h"
+#include "llvm/LinkAllVMCore.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/FormattedStream.h"
@@ -35,11 +34,14 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/PrettyStackTrace.h"
-#include "llvm/Analysis/Verifier.h"
+#include "llvm/System/Host.h"
#include "llvm/System/Signals.h"
-#include "llvm/Config/config.h"
-#include "llvm/LinkAllVMCore.h"
+#include "llvm/Target/SubtargetFeature.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetRegistry.h"
#include "llvm/Target/TargetSelect.h"
+#include "llvm/Transforms/Scalar.h"
#include <memory>
using namespace llvm;
@@ -234,8 +236,13 @@ int main(int argc, char **argv) {
if (!TargetTriple.empty())
mod.setTargetTriple(TargetTriple);
- // Allocate target machine. First, check whether the user has
- // explicitly specified an architecture to compile for.
+ Triple TheTriple(mod.getTargetTriple());
+ if (TheTriple.getTriple().empty())
+ TheTriple.setTriple(sys::getHostTriple());
+
+ // Allocate target machine. First, check whether the user has explicitly
+ // specified an architecture to compile for. If so we have to look it up by
+ // name, because it might be a backend that has no mapping to a target triple.
const Target *TheTarget = 0;
if (!MArch.empty()) {
for (TargetRegistry::iterator it = TargetRegistry::begin(),
@@ -249,11 +256,17 @@ int main(int argc, char **argv) {
if (!TheTarget) {
errs() << argv[0] << ": error: invalid target '" << MArch << "'.\n";
return 1;
- }
+ }
+
+ // 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 Err;
- TheTarget = TargetRegistry::lookupTarget(mod.getTargetTriple(),
- /*FallbackToHost=*/true,
+ TheTarget = TargetRegistry::lookupTarget(TheTriple.getTriple(),
+ /*FallbackToHost=*/false,
/*RequireJIT=*/false,
Err);
if (TheTarget == 0) {
@@ -275,7 +288,8 @@ int main(int argc, char **argv) {
}
std::auto_ptr<TargetMachine>
- target(TheTarget->createTargetMachine(mod, FeaturesStr));
+ target(TheTarget->createTargetMachine(mod, TheTriple.getTriple(),
+ FeaturesStr));
assert(target.get() && "Could not allocate target machine!");
TargetMachine &Target = *target.get();
diff --git a/llvm/tools/lto/LTOCodeGenerator.cpp b/llvm/tools/lto/LTOCodeGenerator.cpp
index a5023fb2f4f..ac7af13cb80 100644
--- a/llvm/tools/lto/LTOCodeGenerator.cpp
+++ b/llvm/tools/lto/LTOCodeGenerator.cpp
@@ -35,6 +35,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/StandardPasses.h"
#include "llvm/Support/SystemUtils.h"
+#include "llvm/System/Host.h"
#include "llvm/System/Signals.h"
#include "llvm/Target/SubtargetFeature.h"
#include "llvm/Target/TargetOptions.h"
@@ -326,11 +327,15 @@ bool LTOCodeGenerator::assemble(const std::string& asmPath,
bool LTOCodeGenerator::determineTarget(std::string& errMsg)
{
if ( _target == NULL ) {
+ std::string Triple = _linker.getModule()->getTargetTriple();
+ if (Triple.empty())
+ Triple = sys::getHostTriple();
+
// create target machine from info for merged modules
Module* mergedModule = _linker.getModule();
const Target *march =
- TargetRegistry::lookupTarget(mergedModule->getTargetTriple(),
- /*FallbackToHost=*/true,
+ TargetRegistry::lookupTarget(Triple,
+ /*FallbackToHost=*/false,
/*RequireJIT=*/false,
errMsg);
if ( march == NULL )
@@ -351,9 +356,8 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg)
}
// construct LTModule, hand over ownership of module and target
- std::string FeatureStr =
- getFeatureString(_linker.getModule()->getTargetTriple().c_str());
- _target = march->createTargetMachine(*mergedModule, FeatureStr.c_str());
+ std::string FeatureStr = getFeatureString(Triple.c_str());
+ _target = march->createTargetMachine(*mergedModule, Triple, FeatureStr);
}
return false;
}
diff --git a/llvm/tools/lto/LTOModule.cpp b/llvm/tools/lto/LTOModule.cpp
index 4a2c5ad1dc3..9a8b155275f 100644
--- a/llvm/tools/lto/LTOModule.cpp
+++ b/llvm/tools/lto/LTOModule.cpp
@@ -24,6 +24,7 @@
#include "llvm/Support/Mangler.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/MathExtras.h"
+#include "llvm/System/Host.h"
#include "llvm/System/Path.h"
#include "llvm/System/Process.h"
#include "llvm/Target/SubtargetFeature.h"
@@ -149,17 +150,22 @@ LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer,
OwningPtr<Module> m(ParseBitcodeFile(buffer, getGlobalContext(), &errMsg));
if ( !m )
return NULL;
+
+ std::string Triple = m->getTargetTriple();
+ if (Triple.empty())
+ Triple = sys::getHostTriple();
+
// find machine architecture for this module
- const Target* march = TargetRegistry::lookupTarget(m->getTargetTriple(),
- /*FallbackToHost=*/true,
+ const Target* march = TargetRegistry::lookupTarget(Triple,
+ /*FallbackToHost=*/false,
/*RequireJIT=*/false,
errMsg);
if ( march == NULL )
return NULL;
// construct LTModule, hand over ownership of module and target
- std::string FeatureStr = getFeatureString(m->getTargetTriple().c_str());
- TargetMachine* target = march->createTargetMachine(*m, FeatureStr);
+ std::string FeatureStr = getFeatureString(Triple.c_str());
+ TargetMachine* target = march->createTargetMachine(*m, Triple, FeatureStr);
return new LTOModule(m.take(), target);
}
OpenPOWER on IntegriCloud