aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler/nir/nir_algebraic.py
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2018-11-07 14:32:19 -0600
committerJason Ekstrand <[email protected]>2018-12-05 15:02:54 -0600
commit4925290ab1771d075c994ac23e0c0a3c19d3a50e (patch)
treefe8539bf9d6932743d93fdf958528b6dd93a8b1e /src/compiler/nir/nir_algebraic.py
parentd6aac618fb489fdaf11670489567cc95ea891c86 (diff)
nir/algebraic: Refactor codegen a bit
Instead of using an OrderedDict, just have a (necessarily sorted) array of transforms and a set of opcodes. Reviewed-by: Connor Abbott <[email protected]>
Diffstat (limited to 'src/compiler/nir/nir_algebraic.py')
-rw-r--r--src/compiler/nir/nir_algebraic.py21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py
index d75a7ce27c9..b90264b282e 100644
--- a/src/compiler/nir/nir_algebraic.py
+++ b/src/compiler/nir/nir_algebraic.py
@@ -25,7 +25,7 @@
from __future__ import print_function
import ast
-from collections import OrderedDict
+from collections import defaultdict
import itertools
import struct
import sys
@@ -622,12 +622,12 @@ struct transform {
#endif
-% for (opcode, xform_list) in xform_dict.items():
-% for xform in xform_list:
+% for xform in xforms:
${xform.search.render()}
${xform.replace.render()}
% endfor
+% for (opcode, xform_list) in sorted(opcode_xforms.items()):
static const struct transform ${pass_name}_${opcode}_xforms[] = {
% for xform in xform_list:
{ &${xform.search.name}, ${xform.replace.c_ptr}, ${xform.condition_index} },
@@ -650,7 +650,7 @@ ${pass_name}_block(nir_builder *build, nir_block *block,
continue;
switch (alu->op) {
- % for opcode in xform_dict.keys():
+ % for opcode in sorted(opcode_xforms.keys()):
case nir_op_${opcode}:
for (unsigned i = 0; i < ARRAY_SIZE(${pass_name}_${opcode}_xforms); i++) {
const struct transform *xform = &${pass_name}_${opcode}_xforms[i];
@@ -713,7 +713,8 @@ ${pass_name}(nir_shader *shader)
class AlgebraicPass(object):
def __init__(self, pass_name, transforms):
- self.xform_dict = OrderedDict()
+ self.xforms = []
+ self.opcode_xforms = defaultdict(lambda : [])
self.pass_name = pass_name
error = False
@@ -730,15 +731,15 @@ class AlgebraicPass(object):
error = True
continue
- if xform.search.opcode not in self.xform_dict:
- self.xform_dict[xform.search.opcode] = []
-
- self.xform_dict[xform.search.opcode].append(xform)
+ self.xforms.append(xform)
+ self.opcode_xforms[xform.search.opcode].append(xform)
if error:
sys.exit(1)
+
def render(self):
return _algebraic_pass_template.render(pass_name=self.pass_name,
- xform_dict=self.xform_dict,
+ xforms=self.xforms,
+ opcode_xforms=self.opcode_xforms,
condition_list=condition_list)