Don't issue a slew of warnings if a bogus cpu type is specified.

Issue #221.
This commit is contained in:
Matt Pharr
2012-04-03 06:13:28 -07:00
parent eb85da81e1
commit b813452d33
3 changed files with 39 additions and 16 deletions

View File

@@ -113,6 +113,14 @@ lGetSystemISA() {
} }
static const char *supportedCPUs[] = {
"atom", "penryn", "core2", "corei7",
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
"corei7-avx"
#endif
};
bool bool
Target::GetTarget(const char *arch, const char *cpu, const char *isa, Target::GetTarget(const char *arch, const char *cpu, const char *isa,
bool pic, Target *t) { bool pic, Target *t) {
@@ -121,13 +129,13 @@ Target::GetTarget(const char *arch, const char *cpu, const char *isa,
// If a CPU was specified explicitly, try to pick the best // If a CPU was specified explicitly, try to pick the best
// possible ISA based on that. // possible ISA based on that.
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn) #if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn)
if (!strcasecmp(cpu, "sandybridge") || if (!strcmp(cpu, "sandybridge") ||
!strcasecmp(cpu, "corei7-avx")) !strcmp(cpu, "corei7-avx"))
isa = "avx"; isa = "avx";
else else
#endif #endif
if (!strcasecmp(cpu, "corei7") || if (!strcmp(cpu, "corei7") ||
!strcasecmp(cpu, "penryn")) !strcmp(cpu, "penryn"))
isa = "sse4"; isa = "sse4";
else else
isa = "sse2"; isa = "sse2";
@@ -153,6 +161,22 @@ Target::GetTarget(const char *arch, const char *cpu, const char *isa,
cpu = "generic"; cpu = "generic";
} }
} }
else {
bool foundCPU = false;
for (int i = 0; i < int(sizeof(supportedCPUs) / sizeof(supportedCPUs[0]));
++i) {
if (!strcmp(cpu, supportedCPUs[i])) {
foundCPU = true;
break;
}
}
if (foundCPU == false) {
fprintf(stderr, "Error: CPU type \"%s\" unknown. Supported CPUs: "
"%s.\n", cpu, SupportedTargetCPUs().c_str());
return false;
}
}
t->cpu = cpu; t->cpu = cpu;
if (arch == NULL) if (arch == NULL)
@@ -309,17 +333,16 @@ Target::GetTarget(const char *arch, const char *cpu, const char *isa,
} }
const char * std::string
Target::SupportedTargetCPUs() { Target::SupportedTargetCPUs() {
return "atom, barcelona, core2, corei7, " std::string ret;
#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn) int count = sizeof(supportedCPUs) / sizeof(supportedCPUs[0]);
"corei7-avx, " for (int i = 0; i < count; ++i) {
#endif ret += supportedCPUs[i];
"istanbul, nocona, penryn, " if (i != count - 1)
#ifdef LLVM_2_9 ret += ", ";
"sandybridge, " }
#endif return ret;
"westmere";
} }

2
ispc.h
View File

@@ -164,7 +164,7 @@ struct Target {
/** Returns a comma-delimited string giving the names of the currently /** Returns a comma-delimited string giving the names of the currently
supported target CPUs. */ supported target CPUs. */
static const char *SupportedTargetCPUs(); static std::string SupportedTargetCPUs();
/** Returns a comma-delimited string giving the names of the currently /** Returns a comma-delimited string giving the names of the currently
supported target architectures. */ supported target architectures. */

View File

@@ -91,7 +91,7 @@ usage(int ret) {
Target::SupportedTargetArchs()); Target::SupportedTargetArchs());
printf(" [--c++-include-file=<name>]\t\tSpecify name of file to emit in #include statement in generated C++ code.\n"); printf(" [--c++-include-file=<name>]\t\tSpecify name of file to emit in #include statement in generated C++ code.\n");
printf(" [--cpu=<cpu>]\t\t\tSelect target CPU type\n"); printf(" [--cpu=<cpu>]\t\t\tSelect target CPU type\n");
printf(" <cpu>={%s}\n", Target::SupportedTargetCPUs()); printf(" <cpu>={%s}\n", Target::SupportedTargetCPUs().c_str());
printf(" [-D<foo>]\t\t\t\t#define given value when running preprocessor\n"); printf(" [-D<foo>]\t\t\t\t#define given value when running preprocessor\n");
printf(" [--emit-asm]\t\t\tGenerate assembly language file as output\n"); printf(" [--emit-asm]\t\t\tGenerate assembly language file as output\n");
#ifndef LLVM_2_9 #ifndef LLVM_2_9