Fix ShouldUseClangCompiler to use llvm::Triple.

- -1 FIXME, and fixes 'clang -arch armv4t ...', for example.

llvm-svn: 81276
This commit is contained in:
Daniel Dunbar 2009-09-08 23:36:55 +00:00
parent f26a7ab377
commit 953b8d1f15
4 changed files with 32 additions and 37 deletions

View File

@ -15,6 +15,7 @@
#include "clang/Driver/Phases.h" #include "clang/Driver/Phases.h"
#include "clang/Driver/Util.h" #include "clang/Driver/Util.h"
#include "llvm/ADT/Triple.h"
#include "llvm/System/Path.h" // FIXME: Kill when CompilationInfo #include "llvm/System/Path.h" // FIXME: Kill when CompilationInfo
// lands. // lands.
#include <list> #include <list>
@ -102,7 +103,7 @@ public:
private: private:
/// Only use clang for the given architectures (only used when /// Only use clang for the given architectures (only used when
/// non-empty). /// non-empty).
std::set<std::string> CCCClangArchs; std::set<llvm::Triple::ArchType> CCCClangArchs;
/// Certain options suppress the 'no input files' warning. /// Certain options suppress the 'no input files' warning.
bool SuppressMissingInputWarning : 1; bool SuppressMissingInputWarning : 1;
@ -260,7 +261,7 @@ public:
/// ShouldUseClangCompilar - Should the clang compiler be used to /// ShouldUseClangCompilar - Should the clang compiler be used to
/// handle this action. /// handle this action.
bool ShouldUseClangCompiler(const Compilation &C, const JobAction &JA, bool ShouldUseClangCompiler(const Compilation &C, const JobAction &JA,
const std::string &ArchName) const; const llvm::Triple &ArchName) const;
/// @} /// @}

View File

@ -60,12 +60,9 @@ Driver::Driver(const char *_Name, const char *_Dir,
{ {
#ifdef USE_PRODUCTION_CLANG #ifdef USE_PRODUCTION_CLANG
// In a "production" build, only use clang on architectures we expect to work. // In a "production" build, only use clang on architectures we expect to work.
CCCClangArchs.insert("i386"); CCCClangArchs.insert(llvm::Triple::x86);
CCCClangArchs.insert("x86_64"); CCCClangArchs.insert(llvm::Triple::x86_64);
CCCClangArchs.insert("arm"); CCCClangArchs.insert(llvm::Triple::arm);
CCCClangArchs.insert("armv5");
CCCClangArchs.insert("armv6");
CCCClangArchs.insert("armv7");
#endif #endif
} }
@ -169,23 +166,27 @@ Compilation *Driver::BuildCompilation(int argc, const char **argv) {
CCCUseClangCPP = false; CCCUseClangCPP = false;
} else if (!strcmp(Opt, "clang-archs")) { } else if (!strcmp(Opt, "clang-archs")) {
assert(Start+1 < End && "FIXME: -ccc- argument handling."); assert(Start+1 < End && "FIXME: -ccc- argument handling.");
const char *Cur = *++Start; llvm::StringRef Cur = *++Start;
CCCClangArchs.clear(); CCCClangArchs.clear();
for (;;) { while (!Cur.empty()) {
const char *Next = strchr(Cur, ','); std::pair<llvm::StringRef, llvm::StringRef> Split = Cur.split(',');
if (Next) { if (!Split.first.empty()) {
if (Cur != Next) llvm::Triple::ArchType Arch =
CCCClangArchs.insert(std::string(Cur, Next)); llvm::Triple(Split.first, "", "").getArch();
Cur = Next + 1;
} else { if (Arch == llvm::Triple::UnknownArch) {
if (*Cur != '\0') // FIXME: Error handling.
CCCClangArchs.insert(std::string(Cur)); llvm::errs() << "invalid arch name: " << Split.first << "\n";
break; exit(1);
}
} }
CCCClangArchs.insert(Arch);
}
Cur = Split.second;
}
} else if (!strcmp(Opt, "host-triple")) { } else if (!strcmp(Opt, "host-triple")) {
assert(Start+1 < End && "FIXME: -ccc- argument handling."); assert(Start+1 < End && "FIXME: -ccc- argument handling.");
HostTriple = *++Start; HostTriple = *++Start;
@ -1262,14 +1263,7 @@ const HostInfo *Driver::GetHostInfo(const char *TripleStr) const {
} }
bool Driver::ShouldUseClangCompiler(const Compilation &C, const JobAction &JA, bool Driver::ShouldUseClangCompiler(const Compilation &C, const JobAction &JA,
const std::string &ArchNameStr) const { const llvm::Triple &Triple) const {
// FIXME: Remove this hack.
const char *ArchName = ArchNameStr.c_str();
if (ArchNameStr == "powerpc")
ArchName = "ppc";
else if (ArchNameStr == "powerpc64")
ArchName = "ppc64";
// Check if user requested no clang, or clang doesn't understand this type (we // Check if user requested no clang, or clang doesn't understand this type (we
// only handle single inputs for now). // only handle single inputs for now).
if (!CCCUseClang || JA.size() != 1 || if (!CCCUseClang || JA.size() != 1 ||
@ -1297,8 +1291,8 @@ bool Driver::ShouldUseClangCompiler(const Compilation &C, const JobAction &JA,
// Finally, don't use clang if this isn't one of the user specified archs to // Finally, don't use clang if this isn't one of the user specified archs to
// build. // build.
if (!CCCClangArchs.empty() && !CCCClangArchs.count(ArchName)) { if (!CCCClangArchs.empty() && !CCCClangArchs.count(Triple.getArch())) {
Diag(clang::diag::warn_drv_not_using_clang_arch) << ArchName; Diag(clang::diag::warn_drv_not_using_clang_arch) << Triple.getArchName();
return false; return false;
} }

View File

@ -103,7 +103,7 @@ Darwin::~Darwin() {
Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const { Tool &Darwin::SelectTool(const Compilation &C, const JobAction &JA) const {
Action::ActionClass Key; Action::ActionClass Key;
if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Key = Action::AnalyzeJobClass; Key = Action::AnalyzeJobClass;
else else
Key = JA.getKind(); Key = JA.getKind();
@ -338,7 +338,7 @@ Generic_GCC::~Generic_GCC() {
Tool &Generic_GCC::SelectTool(const Compilation &C, Tool &Generic_GCC::SelectTool(const Compilation &C,
const JobAction &JA) const { const JobAction &JA) const {
Action::ActionClass Key; Action::ActionClass Key;
if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Key = Action::AnalyzeJobClass; Key = Action::AnalyzeJobClass;
else else
Key = JA.getKind(); Key = JA.getKind();
@ -404,7 +404,7 @@ OpenBSD::OpenBSD(const HostInfo &Host, const llvm::Triple& Triple)
Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const { Tool &OpenBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
Action::ActionClass Key; Action::ActionClass Key;
if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Key = Action::AnalyzeJobClass; Key = Action::AnalyzeJobClass;
else else
Key = JA.getKind(); Key = JA.getKind();
@ -439,7 +439,7 @@ FreeBSD::FreeBSD(const HostInfo &Host, const llvm::Triple& Triple, bool Lib32)
Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const { Tool &FreeBSD::SelectTool(const Compilation &C, const JobAction &JA) const {
Action::ActionClass Key; Action::ActionClass Key;
if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Key = Action::AnalyzeJobClass; Key = Action::AnalyzeJobClass;
else else
Key = JA.getKind(); Key = JA.getKind();
@ -480,7 +480,7 @@ AuroraUX::AuroraUX(const HostInfo &Host, const llvm::Triple& Triple)
Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const { Tool &AuroraUX::SelectTool(const Compilation &C, const JobAction &JA) const {
Action::ActionClass Key; Action::ActionClass Key;
if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Key = Action::AnalyzeJobClass; Key = Action::AnalyzeJobClass;
else else
Key = JA.getKind(); Key = JA.getKind();
@ -545,7 +545,7 @@ DragonFly::DragonFly(const HostInfo &Host, const llvm::Triple& Triple)
Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const { Tool &DragonFly::SelectTool(const Compilation &C, const JobAction &JA) const {
Action::ActionClass Key; Action::ActionClass Key;
if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getArchName())) if (getHost().getDriver().ShouldUseClangCompiler(C, JA, getTriple()))
Key = Action::AnalyzeJobClass; Key = Action::AnalyzeJobClass;
else else
Key = JA.getKind(); Key = JA.getKind();

View File

@ -39,7 +39,7 @@
// RUN: grep '"clang", inputs: \[".*\.i"\], output: (nothing)' %t && // RUN: grep '"clang", inputs: \[".*\.i"\], output: (nothing)' %t &&
// RUN: clang -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings -ccc-clang-archs i386 %s -S -arch ppc 2> %t && // RUN: clang -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings -ccc-clang-archs i386 %s -S -arch ppc 2> %t &&
// RUN: grep '"gcc::Compile", inputs: \[".*bindings.c"\], output: "bindings.s"' %t && // RUN: grep '"gcc::Compile", inputs: \[".*bindings.c"\], output: "bindings.s"' %t &&
// RUN: clang -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings -ccc-clang-archs ppc %s -S -arch ppc 2> %t && // RUN: clang -ccc-host-triple i386-apple-darwin9 -ccc-print-bindings -ccc-clang-archs powerpc %s -S -arch ppc 2> %t &&
// RUN: grep '"clang", inputs: \[".*bindings.c"\], output: "bindings.s"' %t && // RUN: grep '"clang", inputs: \[".*bindings.c"\], output: "bindings.s"' %t &&
// RUN: clang -ccc-host-triple powerpc-unknown-unknown -ccc-print-bindings -ccc-clang-archs "" %s -S 2> %t && // RUN: clang -ccc-host-triple powerpc-unknown-unknown -ccc-print-bindings -ccc-clang-archs "" %s -S 2> %t &&