From 3c2d4bf97fa96fe171883cd80e4ea93fc43563e6 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 3 Aug 2009 04:03:51 +0000 Subject: 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 --- tools/llc/llc.cpp | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) (limited to 'tools/llc/llc.cpp') diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 9f7f0a43f1..e346857514 100644 --- a/tools/llc/llc.cpp +++ b/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 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 - target(TheTarget->createTargetMachine(mod, FeaturesStr)); + target(TheTarget->createTargetMachine(mod, TheTriple.getTriple(), + FeaturesStr)); assert(target.get() && "Could not allocate target machine!"); TargetMachine &Target = *target.get(); -- cgit v1.2.3-70-g09d2