clover/llvm: Use device in llvm compilation instead of copying fields
authorAaron Watry <awatry@gmail.com>
Sat, 10 Feb 2018 20:03:13 +0000 (14:03 -0600)
committerAaron Watry <awatry@gmail.com>
Tue, 6 Mar 2018 02:09:46 +0000 (20:09 -0600)
Copying the individual fields from the device when compiling/linking
will lead to an unnecessarily large number of fields getting passed
around.

v3: Rebase on current master
v2: Use device in function args before making additional changes in
    following patches

Signed-off-by: Aaron Watry <awatry@gmail.com>
Reviewed-by: Jan Vesely <jan.vesely@rutgers.edu>
Reviewed-by: Pierre Moreau <pierre.morrow@free.fr>
Reviewed-by: Francisco Jerez <currojerez@riseup.net>
src/gallium/state_trackers/clover/core/program.cpp
src/gallium/state_trackers/clover/llvm/invocation.cpp
src/gallium/state_trackers/clover/llvm/invocation.hpp

index ae4b50a8797a985696ccde1b15593d4bf4665a22..4e74fccd9731d447b837db4c6d14397dddfe066a 100644 (file)
@@ -53,8 +53,8 @@ program::compile(const ref_vector<device> &devs, const std::string &opts,
          try {
             const module m = (dev.ir_format() == PIPE_SHADER_IR_TGSI ?
                               tgsi::compile_program(_source, log) :
-                              llvm::compile_program(_source, headers,
-                                                    dev.ir_target(), opts, log));
+                              llvm::compile_program(_source, headers, dev,
+                                                    opts, log));
             _builds[&dev] = { m, opts, log };
          } catch (...) {
             _builds[&dev] = { module(), opts, log };
@@ -78,8 +78,7 @@ program::link(const ref_vector<device> &devs, const std::string &opts,
       try {
          const module m = (dev.ir_format() == PIPE_SHADER_IR_TGSI ?
                            tgsi::link_program(ms) :
-                           llvm::link_program(ms, dev.ir_format(),
-                                              dev.ir_target(), opts, log));
+                           llvm::link_program(ms, dev, opts, log));
          _builds[&dev] = { m, opts, log };
       } catch (...) {
          _builds[&dev] = { module(), opts, log };
index e4ca5fa444249a181a873b8f7695ff58a024d519..c8c0311a3a0e9e0e7331de530f609ddee4d6451a 100644 (file)
@@ -201,17 +201,17 @@ namespace {
 module
 clover::llvm::compile_program(const std::string &source,
                               const header_map &headers,
-                              const std::string &target,
+                              const device &dev,
                               const std::string &opts,
                               std::string &r_log) {
    if (has_flag(debug::clc))
       debug::log(".cl", "// Options: " + opts + '\n' + source);
 
    auto ctx = create_context(r_log);
-   auto c = create_compiler_instance(target, tokenize(opts + " input.cl"),
-                                     r_log);
-   auto mod = compile(*ctx, *c, "input.cl", source, headers, target, opts,
-                      r_log);
+   auto c = create_compiler_instance(dev.ir_target(),
+                                     tokenize(opts + " input.cl"), r_log);
+   auto mod = compile(*ctx, *c, "input.cl", source, headers, dev.ir_target(),
+                      opts, r_log);
 
    if (has_flag(debug::llvm))
       debug::log(".ll", print_module_bitcode(*mod));
@@ -269,14 +269,14 @@ namespace {
 
 module
 clover::llvm::link_program(const std::vector<module> &modules,
-                           enum pipe_shader_ir ir, const std::string &target,
+                           const device &dev,
                            const std::string &opts, std::string &r_log) {
    std::vector<std::string> options = tokenize(opts + " input.cl");
    const bool create_library = count("-create-library", options);
    erase_if(equals("-create-library"), options);
 
    auto ctx = create_context(r_log);
-   auto c = create_compiler_instance(target, options, r_log);
+   auto c = create_compiler_instance(dev.ir_target(), options, r_log);
    auto mod = link(*ctx, *c, modules, r_log);
 
    optimize(*mod, c->getCodeGenOpts().OptimizationLevel, !create_library);
@@ -291,11 +291,11 @@ clover::llvm::link_program(const std::vector<module> &modules,
    if (create_library) {
       return build_module_library(*mod, module::section::text_library);
 
-   } else if (ir == PIPE_SHADER_IR_NATIVE) {
+   } else if (dev.ir_format() == PIPE_SHADER_IR_NATIVE) {
       if (has_flag(debug::native))
-         debug::log(id +  ".asm", print_module_native(*mod, target));
+         debug::log(id +  ".asm", print_module_native(*mod, dev.ir_target()));
 
-      return build_module_native(*mod, target, *c, r_log);
+      return build_module_native(*mod, dev.ir_target(), *c, r_log);
 
    } else {
       unreachable("Unsupported IR.");
index 5b3530c382938f0010ae94b61c5dd75d7addf3a7..ff9caa457cad5ebf11828a8fa86dd3d010d0b0fd 100644 (file)
@@ -32,13 +32,12 @@ namespace clover {
    namespace llvm {
       module compile_program(const std::string &source,
                              const header_map &headers,
-                             const std::string &target,
+                             const device &device,
                              const std::string &opts,
                              std::string &r_log);
 
       module link_program(const std::vector<module> &modules,
-                          enum pipe_shader_ir ir,
-                          const std::string &target,
+                          const device &device,
                           const std::string &opts,
                           std::string &r_log);
    }