From 225a9c990aa592cdee5b3a0047756dbea59b3c43 Mon Sep 17 00:00:00 2001 From: Yang Rong Date: Wed, 29 May 2013 11:20:47 +0800 Subject: [PATCH] Pass user options to clang. clang do not support all options in opencl. clang unsupport options: -cl-denorms-are-zero, -cl-strict-aliasing -cl-no-signed-zeros, -cl-fp32-correctly-rounded-divide-sqrt all support options, refer to clang/include/clang/Driver/Options.inc Can ignore these options to avoid warning. Signed-off-by: Yang Rong Reviewed-by: Zhigang Gong --- backend/src/backend/program.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp index 6816a13..c95fb4a 100644 --- a/backend/src/backend/program.cpp +++ b/backend/src/backend/program.cpp @@ -121,11 +121,32 @@ namespace gbe { GBE_SAFE_DELETE(program); } - static void buildModuleFromSource(const char* input, const char* output) { + static void buildModuleFromSource(const char* input, const char* output, std::string options) { // Arguments to pass to the clang frontend vector args; + bool bOpt = true; + + vector useless; //hold substrings to avoid c_str free + uint32_t start = 0, end = 0; + /* clang unsupport options: + -cl-denorms-are-zero, -cl-strict-aliasing + -cl-no-signed-zeros, -cl-fp32-correctly-rounded-divide-sqrt + all support options, refer to clang/include/clang/Driver/Options.inc + Maybe can filter these options to avoid warning + */ + while (end != std::string::npos) { + end = options.find(' ', start); + std::string str = options.substr(start, end - start); + if(str.size() == 0) + continue; + if(str == "-cl-opt-disable") bOpt = false; + useless.push_back(str); + args.push_back(str.c_str()); + start = end + 1; + } + args.push_back("-emit-llvm"); - args.push_back("-O3"); + if(bOpt) args.push_back("-O3"); args.push_back("-triple"); args.push_back("nvptx"); args.push_back(input); @@ -206,7 +227,7 @@ namespace gbe { fwrite(source, strlen(source), 1, clFile); fclose(clFile); - buildModuleFromSource(clName.c_str(), llName.c_str()); + buildModuleFromSource(clName.c_str(), llName.c_str(), options ? options : ""); remove(clName.c_str()); // Now build the program from llvm -- 2.7.4