[Mesa-dev,38/47] clover: Move back to using build_error to signal compilation failure.

Submitted by Francisco Jerez on July 4, 2016, 12:51 a.m.

Details

Message ID 20160704005156.5703-39-currojerez@riseup.net
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Francisco Jerez July 4, 2016, 12:51 a.m.
This partially reverts 7e0180d57d330bd8d3047e841086712376b2a1cc.
Having two different exception subclasses for compilation and linking
makes it more difficult to share or move code between the two
codepaths, because the exact same function under the same error
condition would need to throw one exception or the other depending on
what top-level API is being implemented with it.  There is little
benefit anyway because clCompileProgram() and clLinkProgram() can tell
whether they are linking or compiling a program.

Reviewed-by: Serge Martin <edb+mesa@sigluy.net>
---
 src/gallium/state_trackers/clover/api/program.cpp         | 5 +++--
 src/gallium/state_trackers/clover/core/error.hpp          | 7 +++----
 src/gallium/state_trackers/clover/llvm/codegen/native.cpp | 8 ++++----
 src/gallium/state_trackers/clover/llvm/invocation.cpp     | 6 +++---
 src/gallium/state_trackers/clover/tgsi/compiler.cpp       | 8 ++++----
 5 files changed, 17 insertions(+), 17 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp
index 27ca2ef..ff199ab 100644
--- a/src/gallium/state_trackers/clover/api/program.cpp
+++ b/src/gallium/state_trackers/clover/api/program.cpp
@@ -186,8 +186,6 @@  clBuildProgram(cl_program d_prog, cl_uint num_devs,
 } catch (error &e) {
    if (e.get() == CL_INVALID_COMPILER_OPTIONS)
       return CL_INVALID_BUILD_OPTIONS;
-   if (e.get() == CL_COMPILE_PROGRAM_FAILURE)
-      return CL_BUILD_PROGRAM_FAILURE;
    return e.get();
 }
 
@@ -227,6 +225,9 @@  clCompileProgram(cl_program d_prog, cl_uint num_devs,
    prog.build(devs, opts, headers);
    return CL_SUCCESS;
 
+} catch (build_error &e) {
+   return CL_COMPILE_PROGRAM_FAILURE;
+
 } catch (error &e) {
    return e.get();
 }
diff --git a/src/gallium/state_trackers/clover/core/error.hpp b/src/gallium/state_trackers/clover/core/error.hpp
index 59a5af4..3165402 100644
--- a/src/gallium/state_trackers/clover/core/error.hpp
+++ b/src/gallium/state_trackers/clover/core/error.hpp
@@ -65,11 +65,10 @@  namespace clover {
       cl_int code;
    };
 
-   class compile_error : public error {
+   class build_error : public error {
    public:
-      compile_error(const std::string &what = "") :
-         error(CL_COMPILE_PROGRAM_FAILURE, what) {
-      }
+      build_error(const std::string &what = "") :
+         error(CL_BUILD_PROGRAM_FAILURE, what) {}
    };
 
    template<typename O>
diff --git a/src/gallium/state_trackers/clover/llvm/codegen/native.cpp b/src/gallium/state_trackers/clover/llvm/codegen/native.cpp
index 4adb05f..b96236b 100644
--- a/src/gallium/state_trackers/clover/llvm/codegen/native.cpp
+++ b/src/gallium/state_trackers/clover/llvm/codegen/native.cpp
@@ -98,7 +98,7 @@  namespace {
       const auto elf = elf::get(code);
       const auto symtab = elf::get_symbol_table(elf.get());
       if (!symtab)
-         fail(r_log, compile_error(), "Unable to find symbol table.");
+         fail(r_log, build_error(), "Unable to find symbol table.");
 
       return elf::get_symbol_offsets(elf.get(), symtab);
    }
@@ -110,7 +110,7 @@  namespace {
       std::string err;
       auto t = ::llvm::TargetRegistry::lookupTarget(target.triple, err);
       if (!t)
-         fail(r_log, compile_error(), err);
+         fail(r_log, build_error(), err);
 
       std::unique_ptr<TargetMachine> tm {
          t->createTargetMachine(target.triple, target.cpu, "", {},
@@ -118,7 +118,7 @@  namespace {
                                 ::llvm::CodeModel::Default,
                                 ::llvm::CodeGenOpt::Default) };
       if (!tm)
-         fail(r_log, compile_error(),
+         fail(r_log, build_error(),
               "Could not create TargetMachine: " + target.triple);
 
       ::llvm::SmallVector<char, 1024> data;
@@ -133,7 +133,7 @@  namespace {
             (ft == TargetMachine::CGFT_AssemblyFile);
 
          if (tm->addPassesToEmitFile(pm, fos, ft))
-            fail(r_log, compile_error(), "TargetMachine can't emit this file");
+            fail(r_log, build_error(), "TargetMachine can't emit this file");
 
          pm.run(mod);
       }
diff --git a/src/gallium/state_trackers/clover/llvm/invocation.cpp b/src/gallium/state_trackers/clover/llvm/invocation.cpp
index 40b00b7..db3b481 100644
--- a/src/gallium/state_trackers/clover/llvm/invocation.cpp
+++ b/src/gallium/state_trackers/clover/llvm/invocation.cpp
@@ -70,7 +70,7 @@  namespace {
          raw_string_ostream os { *reinterpret_cast<std::string *>(data) };
          ::llvm::DiagnosticPrinterRawOStream printer { os };
          di.print(printer);
-         throw compile_error();
+         throw build_error();
       }
    }
 
@@ -173,7 +173,7 @@  namespace {
       // Compile the code
       clang::EmitLLVMOnlyAction act(&ctx);
       if (!c.ExecuteAction(act))
-         throw compile_error();
+         throw build_error();
 
       return act.takeModule();
    }
@@ -241,7 +241,7 @@  namespace {
       for (auto &m : modules) {
          if (compat::link_in_module(*linker,
                                     parse_module_library(m, ctx, r_log)))
-            throw compile_error();
+            throw build_error();
       }
 
       return std::move(mod);
diff --git a/src/gallium/state_trackers/clover/tgsi/compiler.cpp b/src/gallium/state_trackers/clover/tgsi/compiler.cpp
index e385a07..9bbd454 100644
--- a/src/gallium/state_trackers/clover/tgsi/compiler.cpp
+++ b/src/gallium/state_trackers/clover/tgsi/compiler.cpp
@@ -48,7 +48,7 @@  namespace {
 
          if (!(ts >> offset)) {
             r_log = "invalid kernel start address";
-            throw compile_error();
+            throw build_error();
          }
 
          while (ts >> tok) {
@@ -72,7 +72,7 @@  namespace {
                args.push_back({ module::argument::sampler, 0 });
             else {
                r_log = "invalid kernel argument";
-               throw compile_error();
+               throw build_error();
             }
          }
 
@@ -86,7 +86,7 @@  namespace {
 
       if (!tgsi_text_translate(source, prog, ARRAY_SIZE(prog))) {
          r_log = "translate failed";
-         throw compile_error();
+         throw build_error();
       }
 
       unsigned sz = tgsi_num_tokens(prog) * sizeof(tgsi_token);
@@ -100,7 +100,7 @@  clover::tgsi::compile_program(const std::string &source, std::string &r_log) {
    const size_t body_pos = source.find("COMP\n");
    if (body_pos == std::string::npos) {
       r_log = "invalid source";
-      throw compile_error();
+      throw build_error();
    }
 
    const char *body = &source[body_pos];