Set a preprocessor #define based on the target ISA.

For example, ISPC_TARGET_SSE4 is #defined for the sse4 targets, etc.
This commit is contained in:
Matt Pharr
2011-10-15 11:56:18 -07:00
parent c21e704a5c
commit 1ab05c0351
2 changed files with 35 additions and 6 deletions

View File

@@ -909,12 +909,27 @@ Module::execPreprocessor(const char* infilename, llvm::raw_string_ostream* ostre
clang::PreprocessorOptions &opts = inst.getPreprocessorOpts();
//Add defs for ISPC and PI
// Add defs for ISPC and PI
opts.addMacroDef("ISPC");
opts.addMacroDef("PI=3.1415926535");
// Add #define for current compilation target
switch (g->target.isa) {
case Target::SSE2:
opts.addMacroDef("ISPC_TARGET_SSE2");
break;
case Target::SSE4:
opts.addMacroDef("ISPC_TARGET_SSE4");
break;
case Target::AVX:
opts.addMacroDef("ISPC_TARGET_AVX");
break;
default:
FATAL("Unhandled target ISA in preprocessor symbol definition");
}
for (unsigned int i = 0; i < g->cppArgs.size(); ++i) {
// Sanity Check, should really begin with -D
// Sanity check--should really begin with -D
if (g->cppArgs[i].substr(0,2) == "-D") {
opts.addMacroDef(g->cppArgs[i].substr(2));
}