[cfe-commits] r148839 - in /cfe/trunk/lib/Driver: Driver.cpp ToolChains.cpp
Chandler Carruth
chandlerc at gmail.com
Tue Jan 24 11:17:47 PST 2012
Author: chandlerc
Date: Tue Jan 24 13:17:46 2012
New Revision: 148839
URL: http://llvm.org/viewvc/llvm-project?rev=148839&view=rev
Log:
Start hoisting the logic for computing the target triple into its own
function. The logic for this, and I want to emphasize that this is the
logic for computing the *target* triple, is currently scattered
throughout various different HostInfo classes ToolChain factoring
functions. Best part, it is largely *duplicated* there. The goal is to
hoist all of that up to here where we can deal with it once, and in
a consistent manner.
Unfortunately, this uncovers more fun problems: the ToolChains assume
that the *actual* target triple is the one passed into them by these
factory functions, while the *host* triple is the one in the driver.
This already was a lie, and a damn lie, when the '-target' flag was
specified. It only really worked when the difference stemmed from '-m32'
and '-m64' flags. I'll have to fix that (and remove all the FIXMEs I've
introduced here to document the problem) before I can finish hoisting
the target-calculation logic.
It's bugs all the way down today it seems...
Modified:
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/lib/Driver/ToolChains.cpp
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=148839&r1=148838&r2=148839&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Jan 24 13:17:46 2012
@@ -237,6 +237,18 @@
return DAL;
}
+/// \brief Compute target triple from args.
+///
+/// This routine provides the logic to compute a target triple from various
+/// args passed to the driver and the default triple string.
+static llvm::Triple computeTargetTriple(StringRef DefaultTargetTriple,
+ const ArgList &Args) {
+ if (const Arg *A = Args.getLastArg(options::OPT_target))
+ DefaultTargetTriple = A->getValue(Args);
+
+ return llvm::Triple(llvm::Triple::normalize(DefaultTargetTriple));
+}
+
Compilation *Driver::BuildCompilation(ArrayRef<const char *> ArgList) {
llvm::PrettyStackTraceString CrashInfo("Compilation construction");
@@ -305,10 +317,6 @@
Cur = Split.second;
}
}
- // FIXME: We shouldn't overwrite the default host triple here, but we have
- // nowhere else to put this currently.
- if (const Arg *A = Args->getLastArg(options::OPT_target))
- DefaultTargetTriple = A->getValue(*Args);
if (const Arg *A = Args->getLastArg(options::OPT_ccc_install_dir))
Dir = InstalledDir = A->getValue(*Args);
for (arg_iterator it = Args->filtered_begin(options::OPT_B),
@@ -322,10 +330,8 @@
if (Args->hasArg(options::OPT_nostdlib))
UseStdLib = false;
- // Reset the target triple here as we may have adjusted the
- // DefaultTargetTriple string for flags above.
- // FIXME: Same fix is needed here when the above flag management is fixed.
- TargetTriple = llvm::Triple(llvm::Triple::normalize(DefaultTargetTriple));
+ // Recompute the target triple based on the args.
+ TargetTriple = computeTargetTriple(DefaultTargetTriple, *Args);
Host = GetHostInfo(TargetTriple);
// Perform the default argument translations.
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=148839&r1=148838&r2=148839&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Tue Jan 24 13:17:46 2012
@@ -1099,7 +1099,10 @@
/// Once constructed, a GCCInstallation is esentially immutable.
Generic_GCC::GCCInstallationDetector::GCCInstallationDetector(const Driver &D)
: IsValid(false),
- GccTriple(D.DefaultTargetTriple) {
+ // FIXME: GccTriple is using the target triple as both the target and host
+ // triple here. It also shouldn't be using the string representation, and
+ // should instead be using the Triple object.
+ GccTriple(D.TargetTriple.str()) {
// FIXME: Using CXX_INCLUDE_ROOT is here is a bit of a hack, but
// avoids adding yet another option to configure/cmake.
// It would probably be cleaner to break it in two variables
@@ -1137,7 +1140,8 @@
// Always include the default host triple as the final fallback if no
// specific triple is detected.
- CandidateTriples.push_back(D.DefaultTargetTriple);
+ // FIXME: This is using the Driver's target triple as the host triple!
+ CandidateTriples.push_back(D.TargetTriple.str());
// Compute the set of prefixes for our search.
SmallVector<std::string, 8> Prefixes(D.PrefixDirs.begin(),
@@ -1543,14 +1547,14 @@
// Determine if we are compiling 32-bit code on an x86_64 platform.
bool Lib32 = false;
+ // FIXME: This is using the Driver's target triple as the host triple!
if (Triple.getArch() == llvm::Triple::x86 &&
- llvm::Triple(getDriver().DefaultTargetTriple).getArch() ==
- llvm::Triple::x86_64)
+ getDriver().TargetTriple.getArch() == llvm::Triple::x86_64)
Lib32 = true;
+ // FIXME: This is using the Driver's target triple as the host triple!
if (Triple.getArch() == llvm::Triple::ppc &&
- llvm::Triple(getDriver().DefaultTargetTriple).getArch() ==
- llvm::Triple::ppc64)
+ getDriver().TargetTriple.getArch() == llvm::Triple::ppc64)
Lib32 = true;
if (Lib32) {
@@ -1894,8 +1898,8 @@
Linux::Linux(const HostInfo &Host, const llvm::Triple &Triple)
: Generic_ELF(Host, Triple) {
- llvm::Triple::ArchType Arch =
- llvm::Triple(getDriver().DefaultTargetTriple).getArch();
+ // FIXME: This is using the Driver's target triple to emulate the host triple!
+ llvm::Triple::ArchType Arch = getDriver().TargetTriple.getArch();
const std::string &SysRoot = getDriver().SysRoot;
// OpenSuse stores the linker with the compiler, add that to the search
@@ -2186,8 +2190,8 @@
// Check if the target architecture specific dirs need a suffix. Note that we
// only support the suffix-based bi-arch-like header scheme for host/target
// mismatches of just bit width.
- llvm::Triple::ArchType HostArch =
- llvm::Triple(getDriver().DefaultTargetTriple).getArch();
+ // FIXME: This is using the Driver's target triple to emulate the host triple!
+ llvm::Triple::ArchType HostArch = getDriver().TargetTriple.getArch();
llvm::Triple::ArchType TargetArch = TargetTriple.getArch();
StringRef Suffix;
if ((HostArch == llvm::Triple::x86 && TargetArch == llvm::Triple::x86_64) ||
More information about the cfe-commits
mailing list