[Mesa-dev] [PATCH 4/9] glsl: Make compare_ir sort expression operands for commutative operations
Petri Latvala
petri.latvala at intel.com
Tue Jul 29 02:36:34 PDT 2014
Sort expression operands when possible so that building expected IR
sexps doesn't need to know which ordering will be produced by an
optimization pass.
Signed-off-by: Petri Latvala <petri.latvala at intel.com>
---
src/glsl/tests/compare_ir | 4 ++--
src/glsl/tests/sexps.py | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/src/glsl/tests/compare_ir b/src/glsl/tests/compare_ir
index a40fc81..0b63fab 100755
--- a/src/glsl/tests/compare_ir
+++ b/src/glsl/tests/compare_ir
@@ -38,9 +38,9 @@ if len(sys.argv) != 3:
exit(1)
with open(sys.argv[1]) as f:
- ir1 = sort_decls(parse_sexp(f.read()))
+ ir1 = sort_decls(sort_commutatives(parse_sexp(f.read())))
with open(sys.argv[2]) as f:
- ir2 = sort_decls(parse_sexp(f.read()))
+ ir2 = sort_decls(sort_commutatives(parse_sexp(f.read())))
if ir1 == ir2:
exit(0)
diff --git a/src/glsl/tests/sexps.py b/src/glsl/tests/sexps.py
index a714af8..60c54bd 100644
--- a/src/glsl/tests/sexps.py
+++ b/src/glsl/tests/sexps.py
@@ -101,3 +101,40 @@ def sort_decls(sexp):
other_code.append(s)
return sorted(decls) + other_code
+commutatives = [
+ '+',
+ '*',
+ 'imul_high',
+ 'carry',
+ '==',
+ '!=',
+ 'all_equal',
+ 'any_nequal',
+ '&',
+ '^',
+ '|',
+ '&&',
+ '^^',
+ '||',
+ 'dot',
+ 'min',
+ 'max'
+ ]
+
+def sort_commutatives(sexp):
+ """Sort operands of expressions that are commutative in sexp.
+
+ This is used to work around the fact that optimization passes might
+ reorder operands.
+ """
+ if not isinstance(sexp, list): return sexp
+
+ code = []
+ for s in sexp:
+ sd = sort_commutatives(s)
+ # An expression is [expression, type, operation, operand1, ...]
+ if isinstance(sd, list) and len(sd) >= 3 and sd[0] == 'expression' and sd[2] in commutatives:
+ code.append(['expression', sd[1:2]] + sorted(sd[3:]))
+ else:
+ code.append(sd)
+ return code
--
2.0.1
More information about the mesa-dev
mailing list