From: Ian Romanick <ian.d.roman...@intel.com> This just makes the output of the standalone compiler a little more compact.
Signed-off-by: Ian Romanick <ian.d.roman...@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 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev