[Beignet] [PATCH] Use the default clang build options defined in the CMakeList.txt.

Zhigang Gong zhigang.gong at linux.intel.com
Tue Jul 23 23:46:24 PDT 2013


Thus we can make sure that the default clang build options we use
to create the pch file at build time are the same as we build user
kernels.

Signed-off-by: Zhigang Gong <zhigang.gong at linux.intel.com>
---
 backend/src/CMakeLists.txt      |   16 ++++++++++------
 backend/src/GBEConfig.h.in      |    1 +
 backend/src/backend/program.cpp |   18 +-----------------
 3 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/backend/src/CMakeLists.txt b/backend/src/CMakeLists.txt
index b7b47ae..757c3bf 100644
--- a/backend/src/CMakeLists.txt
+++ b/backend/src/CMakeLists.txt
@@ -34,24 +34,28 @@ add_custom_command(
   COMMAND ${ocl_gen_blob_cmd} ${ocl_stdlib_tmpl_file} ${ocl_blob_file}
   DEPENDS ${ocl_gen_blob_cmd} ${ocl_stdlib_tmpl_file} ${ocl_vector_file} ${ocl_as_file} ${ocl_convert_file})
 
-
 set (pch_object ${ocl_blob_file}.pch)
+
+set (clang_default_opt -cc1 -x cl -fno-builtin)
+
 # generate pch object
 if (LLVM_VERSION_NODOT VERSION_GREATER 32)
-    set (clang_cmd -cc1 -x cl -triple spir -ffp-contract=off -emit-pch)
+    set (clang_default_opt ${clang_default_opt}  -triple spir -ffp-contract=off)
 else (LLVM_VERSION_NODOT VERSION_GREATER 32)
     if (LLVM_VERSION_NODOT VERSION_GREATER 31)
-        set (clang_cmd -cc1 -x cl -triple nvptx -ffp-contract=off -emit-pch)
+        set (clang_default_opt ${clang_default_opt}  -triple nvptx -ffp-contract=off)
     else (LLVM_VERSION_NODOT VERSION_GREATER 31)
-        set (clang_cmd -cc1 -x cl -triple ptx32 -emit-pch)
+        set (clang_default_opt ${clang_default_opt}  -triple ptx32)
     endif (LLVM_VERSION_NODOT VERSION_GREATER 31)
 endif (LLVM_VERSION_NODOT VERSION_GREATER 32)
-set (clang_cmd ${clang_cmd} -fno-builtin)
+
+string (REPLACE ";" " " CLANG_DEFAULT_OPT " ${clang_default_opt} ")
+set (clang_pch_opt ${clang_default_opt} -emit-pch)
 
 add_custom_command(
      OUTPUT ${pch_object}
      COMMAND rm -f ${pch_object}
-     COMMAND clang ${clang_cmd} ${ocl_blob_file} -o ${pch_object}
+     COMMAND clang ${clang_pch_opt} ${ocl_blob_file} -o ${pch_object}
      DEPENDS ${ocl_blob_file}
      )
 
diff --git a/backend/src/GBEConfig.h.in b/backend/src/GBEConfig.h.in
index 74bef3f..de36474 100644
--- a/backend/src/GBEConfig.h.in
+++ b/backend/src/GBEConfig.h.in
@@ -2,3 +2,4 @@
 #define LIBGBE_VERSION_MAJOR @LIBGBE_VERSION_MAJOR@
 #define LIBGBE_VERSION_MINOR @LIBGBE_VERSION_MINOR@
 #define PCH_OBJECT_DIR "@PCH_OBJECT_DIR@"
+#define CLANG_DEFAULT_OPT "@CLANG_DEFAULT_OPT@"
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 20bdcec..7880096 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -141,6 +141,7 @@ namespace gbe {
        all support options, refer to clang/include/clang/Driver/Options.inc
        Maybe can filter these options to avoid warning
     */
+    options += CLANG_DEFAULT_OPT;
     while (end != std::string::npos) {
       end = options.find(' ', start);
       std::string str = options.substr(start, end - start);
@@ -153,33 +154,16 @@ namespace gbe {
     }
 
     args.push_back("-emit-llvm");
-    // XXX we haven't implement those builtin functions,
-    // so disable it currently.
-    args.push_back("-fno-builtin");
     if(bOpt)  args.push_back("-O3");
-#if LLVM_VERSION_MINOR <= 2
-    args.push_back("-triple");
-    args.push_back("nvptx");
-#else
-    args.push_back("-x");
-    args.push_back("cl");
-    args.push_back("-triple");
-    args.push_back("spir");
-#endif /* LLVM_VERSION_MINOR <= 2 */
     args.push_back(input);
 
     // The compiler invocation needs a DiagnosticsEngine so it can report problems
 #if LLVM_VERSION_MINOR <= 1
-    args.push_back("-triple");
-    args.push_back("ptx32");
-
     clang::TextDiagnosticPrinter *DiagClient =
                              new clang::TextDiagnosticPrinter(llvm::errs(), clang::DiagnosticOptions());
     llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID(new clang::DiagnosticIDs());
     clang::DiagnosticsEngine Diags(DiagID, DiagClient);
 #else
-    args.push_back("-ffp-contract=off");
-
     llvm::IntrusiveRefCntPtr<clang::DiagnosticOptions> DiagOpts = new clang::DiagnosticOptions();
     clang::TextDiagnosticPrinter *DiagClient =
                              new clang::TextDiagnosticPrinter(llvm::errs(), &*DiagOpts);
-- 
1.7.9.5



More information about the Beignet mailing list