[Mesa-dev] [PATCH 09/15] glsl/standalone: Optimize add-of-neg to subtract
Ian Romanick
idr at freedesktop.org
Thu Sep 15 22:12:42 UTC 2016
From: Ian Romanick <ian.d.romanick at intel.com>
This just makes the output of the standalone compiler a little more
compact.
Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
src/compiler/glsl/standalone.cpp | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/src/compiler/glsl/standalone.cpp b/src/compiler/glsl/standalone.cpp
index 6b1c2ce..c4b6854 100644
--- a/src/compiler/glsl/standalone.cpp
+++ b/src/compiler/glsl/standalone.cpp
@@ -38,6 +38,37 @@
#include "standalone.h"
#include "util/string_to_uint_map.h"
+class add_neg_to_sub_visitor : public ir_hierarchical_visitor {
+public:
+ add_neg_to_sub_visitor()
+ {
+ /* empty */
+ }
+
+ ir_visitor_status visit_leave(ir_expression *ir)
+ {
+ if (ir->operation != ir_binop_add)
+ return visit_continue;
+
+ for (unsigned i = 0; i < 2; i++) {
+ ir_expression *const op = ir->operands[i]->as_expression();
+
+ if (op != NULL && op->operation == ir_unop_neg) {
+ ir->operation = ir_binop_sub;
+
+ /* This ensures that -a + b becomes b - a. */
+ if (i == 0)
+ ir->operands[0] = ir->operands[1];
+
+ ir->operands[i] = op->operands[0];
+ break;
+ }
+ }
+
+ return visit_continue;
+ }
+};
+
static const struct standalone_options *options;
static void
@@ -437,6 +468,9 @@ standalone_compile_shader(const struct standalone_options *_options,
if (!shader)
continue;
+ add_neg_to_sub_visitor v;
+ visit_list_elements(&v, shader->ir);
+
shader->Program = rzalloc(shader, gl_program);
init_gl_program(shader->Program, shader->Stage);
}
--
2.5.5
More information about the mesa-dev
mailing list