From b813452d33792caea23a3d2c7c4a2ee213a0cedd Mon Sep 17 00:00:00 2001 From: Matt Pharr Date: Tue, 3 Apr 2012 06:13:28 -0700 Subject: [PATCH] Don't issue a slew of warnings if a bogus cpu type is specified. Issue #221. --- ispc.cpp | 51 +++++++++++++++++++++++++++++++++++++-------------- ispc.h | 2 +- main.cpp | 2 +- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/ispc.cpp b/ispc.cpp index 9eb808dc..4e39c0b2 100644 --- a/ispc.cpp +++ b/ispc.cpp @@ -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 Target::GetTarget(const char *arch, const char *cpu, const char *isa, 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 // possible ISA based on that. #if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn) - if (!strcasecmp(cpu, "sandybridge") || - !strcasecmp(cpu, "corei7-avx")) + if (!strcmp(cpu, "sandybridge") || + !strcmp(cpu, "corei7-avx")) isa = "avx"; else #endif - if (!strcasecmp(cpu, "corei7") || - !strcasecmp(cpu, "penryn")) + if (!strcmp(cpu, "corei7") || + !strcmp(cpu, "penryn")) isa = "sse4"; else isa = "sse2"; @@ -153,6 +161,22 @@ Target::GetTarget(const char *arch, const char *cpu, const char *isa, 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; if (arch == NULL) @@ -309,17 +333,16 @@ Target::GetTarget(const char *arch, const char *cpu, const char *isa, } -const char * +std::string Target::SupportedTargetCPUs() { - return "atom, barcelona, core2, corei7, " -#if defined(LLVM_3_0) || defined(LLVM_3_0svn) || defined(LLVM_3_1svn) - "corei7-avx, " -#endif - "istanbul, nocona, penryn, " -#ifdef LLVM_2_9 - "sandybridge, " -#endif - "westmere"; + std::string ret; + int count = sizeof(supportedCPUs) / sizeof(supportedCPUs[0]); + for (int i = 0; i < count; ++i) { + ret += supportedCPUs[i]; + if (i != count - 1) + ret += ", "; + } + return ret; } diff --git a/ispc.h b/ispc.h index 360b7d99..fb334141 100644 --- a/ispc.h +++ b/ispc.h @@ -164,7 +164,7 @@ struct Target { /** Returns a comma-delimited string giving the names of the currently supported target CPUs. */ - static const char *SupportedTargetCPUs(); + static std::string SupportedTargetCPUs(); /** Returns a comma-delimited string giving the names of the currently supported target architectures. */ diff --git a/main.cpp b/main.cpp index b29a9f0f..8c231b60 100644 --- a/main.cpp +++ b/main.cpp @@ -91,7 +91,7 @@ usage(int ret) { Target::SupportedTargetArchs()); printf(" [--c++-include-file=]\t\tSpecify name of file to emit in #include statement in generated C++ code.\n"); printf(" [--cpu=]\t\t\tSelect target CPU type\n"); - printf(" ={%s}\n", Target::SupportedTargetCPUs()); + printf(" ={%s}\n", Target::SupportedTargetCPUs().c_str()); printf(" [-D]\t\t\t\t#define given value when running preprocessor\n"); printf(" [--emit-asm]\t\t\tGenerate assembly language file as output\n"); #ifndef LLVM_2_9