[Beignet] [PATCH] GBE: filter the unsupported cl compile arguments out.

Zhigang Gong zhigang.gong at intel.com
Wed Nov 27 18:54:47 PST 2013


As the unsupported argument may trigger unexpected compilation
error, we just remove them from the arglist.

If latter clang's cl frontend supports these arguments, we need
to revisit here.

This patch also add a new environment variable
OCL_OUTPUT_BUILD_LOG.
If this variable is set to 1, GBE will print the compile log to
the standard error channel (llvm::errs()). By default, it is false
and GBE will not print any build log.

Signed-off-by: Zhigang Gong <zhigang.gong at intel.com>
---
 backend/src/backend/program.cpp |   20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 8e80bbb..788837f 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -464,6 +464,7 @@ namespace gbe {
     GBE_SAFE_DELETE(program);
   }
 
+  BVAR(OCL_OUTPUT_BUILD_LOG, false);
   static bool buildModuleFromSource(const char* input, const char* output, std::string options,
                                     size_t stringSize, char *err, size_t *errSize) {
     // Arguments to pass to the clang frontend
@@ -473,12 +474,14 @@ namespace gbe {
 
     vector<std::string> useless; //hold substrings to avoid c_str free
     size_t start = 0, end = 0;
-    /* clang unsupport options:
+    /* FIXME
+       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
     */
+    const std::string unsupportedOptions("-cl-denorms-are-zero, -cl-strict-aliasing,"
+                                         "-cl-no-signed-zeros, -cl-fp32-correctly-rounded-divide-sqrt");
     while (end != std::string::npos) {
       end = options.find(' ', start);
       std::string str = options.substr(start, end - start);
@@ -487,7 +490,7 @@ namespace gbe {
         continue;
       if(str == "-cl-opt-disable") bOpt = false;
       if(str == "-cl-fast-relaxed-math") bFastMath = true;
-      if(str == "-cl-denorms-are-zero")
+      if(unsupportedOptions.find(str) != std::string::npos)
         continue;
       useless.push_back(str);
       args.push_back(str.c_str());
@@ -582,12 +585,15 @@ namespace gbe {
     if (err != NULL) {
       GBE_ASSERT(errSize != NULL);
       *errSize = ErrorString.copy(err, stringSize - 1, 0);
-      ErrorString.clear();
-    } else {
+      llvm::errs() << ErrorString;
+    }
+
+    if (err == NULL || OCL_OUTPUT_BUILD_LOG) {
       // flush the error messages to the errs() if there is no
       // error string buffer.
       llvm::errs() << ErrorString;
     }
+    ErrorString.clear();
     if (!retVal)
       return false;
 
@@ -607,7 +613,9 @@ namespace gbe {
       size_t errLen;
       errLen = ErrorString.copy(err + *errSize, stringSize - *errSize - 1, 0);
       *errSize += errLen;
-    } else if (err == NULL) {
+    }
+
+    if (err == NULL || OCL_OUTPUT_BUILD_LOG) {
       // flush the error messages to the errs() if there is no
       // error string buffer.
       llvm::errs() << ErrorString;
-- 
1.7.9.5



More information about the Beignet mailing list