lima/ppir: add dummy op
authorVasily Khoruzhick <anarsoul@gmail.com>
Mon, 19 Aug 2019 06:03:57 +0000 (23:03 -0700)
committerVasily Khoruzhick <anarsoul@gmail.com>
Sat, 24 Aug 2019 01:19:47 +0000 (18:19 -0700)
We can get following from NIR:

(1) r1 = r2
(2) r2 = ssa1

Note that r2 is read before it's assigned, so there's no node for
it in comp->var_nodes. We need to create a dummy node in this case
which sole purpose is to hold ppir_dest with reg in it.

Tested-by: Andreas Baierl <ichgeh@imkreisrum.de>
Reviewed-by: Qiang Yu <yuq825@gmail.com>
Reviewed-by: Erico Nunes <nunes.erico@gmail.com>
Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
src/gallium/drivers/lima/ir/pp/nir.c
src/gallium/drivers/lima/ir/pp/node.c
src/gallium/drivers/lima/ir/pp/ppir.h

index 669e5fb4101ab1c0442948156e0f487a8d47786d..2375710f8151c86607b199c8711864573f11704f 100644 (file)
@@ -53,16 +53,16 @@ static void *ppir_node_create_ssa(ppir_block *block, ppir_op op, nir_ssa_def *ss
 }
 
 static void *ppir_node_create_reg(ppir_block *block, ppir_op op,
-                                  nir_reg_dest *reg, unsigned mask)
+                                  nir_register *reg, unsigned mask)
 {
-   ppir_node *node = ppir_node_create(block, op, reg->reg->index, mask);
+   ppir_node *node = ppir_node_create(block, op, reg->index, mask);
    if (!node)
       return NULL;
 
    ppir_dest *dest = ppir_node_get_dest(node);
 
    list_for_each_entry(ppir_reg, r, &block->comp->reg_list, list) {
-      if (r->index == reg->reg->index) {
+      if (r->index == reg->index) {
          dest->reg = r;
          break;
       }
@@ -87,7 +87,7 @@ static void *ppir_node_create_dest(ppir_block *block, ppir_op op,
       if (dest->is_ssa)
          return ppir_node_create_ssa(block, op, &dest->ssa);
       else
-         return ppir_node_create_reg(block, op, &dest->reg, mask);
+         return ppir_node_create_reg(block, op, dest->reg.reg, mask);
    }
 
    return ppir_node_create(block, op, index, 0);
@@ -125,7 +125,15 @@ static void ppir_node_add_src(ppir_compiler *comp, ppir_node *node,
       while (mask) {
          int swizzle = ps->swizzle[u_bit_scan(&mask)];
          child = comp->var_nodes[(reg->index << 2) + comp->reg_base + swizzle];
-         ppir_node_add_dep(node, child);
+         /* Reg is read before it was written, create a dummy node for it */
+         if (!child) {
+            child = ppir_node_create_reg(node->block, ppir_op_dummy, reg,
+               u_bit_consecutive(0, 4));
+            comp->var_nodes[(reg->index << 2) + comp->reg_base + swizzle] = child;
+         }
+         /* Don't add dummies or recursive deps for ops like r1 = r1 + ssa1 */
+         if (child && node != child && child->op != ppir_op_dummy)
+            ppir_node_add_dep(node, child);
       }
    }
 
index 1d4a0c9117421621acbabc190b00ab22a3ca4eb4..37dd65823fad194b8b25175fca9fb4c8695230fc 100644 (file)
@@ -331,6 +331,12 @@ const ppir_op_info ppir_op_infos[] = {
          PPIR_INSTR_SLOT_BRANCH, PPIR_INSTR_SLOT_END
       },
    },
+   [ppir_op_dummy] = {
+      .name = "dummy",
+      .type = ppir_node_type_alu,
+      .slots = (int []) {
+      },
+   },
 };
 
 void *ppir_node_create(ppir_block *block, ppir_op op, int index, unsigned mask)
index bcea3b1dad0a0ac794b3fd5ed56649d57bc3f597..3e852f27ebe73f1a74eb72ff271fac0261887a43 100644 (file)
@@ -113,6 +113,8 @@ typedef enum {
    ppir_op_discard,
    ppir_op_branch,
 
+   ppir_op_dummy,
+
    ppir_op_num,
 } ppir_op;