Adds “emit_emplace” to emit an instruction that is constructed inplace
with the parameters given. This will be used instead of the pattern of
doing emit(instruction(…)) because that ends up calling emit(const
instruction&) which implies doing a copy.

The “emplace” terminology comes from std::vector::emplace_back which
does a very similar thing.
---

Sorry if this email ends up getting sent twice. It didn’t seem to work
the first time.

 src/intel/compiler/brw_fs_builder.h   | 14 ++++++++++++++
 src/intel/compiler/brw_vec4_builder.h | 14 ++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/src/intel/compiler/brw_fs_builder.h 
b/src/intel/compiler/brw_fs_builder.h
index 87394bc..90d8285 100644
--- a/src/intel/compiler/brw_fs_builder.h
+++ b/src/intel/compiler/brw_fs_builder.h
@@ -25,6 +25,7 @@
 #ifndef BRW_FS_BUILDER_H
 #define BRW_FS_BUILDER_H
 
+#include <utility>
 #include "brw_ir_fs.h"
 #include "brw_shader.h"
 
@@ -256,6 +257,19 @@ namespace brw {
       }
 
       /**
+       * Insert an instruction by constructing it directly inplace. This uses
+       * perfect forwarding magic from C++11 to forward the arguments to the
+       * constructor.
+       */
+      template<typename... Args>
+      instruction *
+      emit_emplace(Args&&... args) const
+      {
+         return emit(new(shader->mem_ctx)
+                     instruction(std::forward<Args>(args)...));
+      }
+
+      /**
        * Create and insert a nullary control instruction into the program.
        */
       instruction *
diff --git a/src/intel/compiler/brw_vec4_builder.h 
b/src/intel/compiler/brw_vec4_builder.h
index 4c3efe8..413b27c 100644
--- a/src/intel/compiler/brw_vec4_builder.h
+++ b/src/intel/compiler/brw_vec4_builder.h
@@ -25,6 +25,7 @@
 #ifndef BRW_VEC4_BUILDER_H
 #define BRW_VEC4_BUILDER_H
 
+#include <utility>
 #include "brw_ir_vec4.h"
 #include "brw_ir_allocator.h"
 
@@ -221,6 +222,19 @@ namespace brw {
       }
 
       /**
+       * Insert an instruction by constructing it directly inplace. This uses
+       * perfect forwarding magic from C++11 to forward the arguments to the
+       * constructor.
+       */
+      template<typename... Args>
+      instruction *
+      emit_emplace(Args&&... args) const
+      {
+         return emit(new(shader->mem_ctx)
+                     instruction(std::forward<Args>(args)...));
+      }
+
+      /**
        * Create and insert a nullary control instruction into the program.
        */
       instruction *
-- 
2.9.5


.
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to