vc4: Add a "qir_for_each_inst_inorder" macro and use it in many places.
authorEric Anholt <eric@anholt.net>
Fri, 8 Jul 2016 22:24:34 +0000 (15:24 -0700)
committerEric Anholt <eric@anholt.net>
Tue, 12 Jul 2016 22:47:25 +0000 (15:47 -0700)
We have the prior list_foreach() all over the code, but I need to move
where instructions live as part of adding support for control flow.  Start
by just converting to a helper iterator macro.  (The simpler
"qir_for_each_inst()" will be used for the for-each-inst-in-a-block
iterator macro later)

12 files changed:
src/gallium/drivers/vc4/vc4_opt_algebraic.c
src/gallium/drivers/vc4/vc4_opt_constant_folding.c
src/gallium/drivers/vc4/vc4_opt_copy_propagation.c
src/gallium/drivers/vc4/vc4_opt_small_immediates.c
src/gallium/drivers/vc4/vc4_opt_vpm.c
src/gallium/drivers/vc4/vc4_program.c
src/gallium/drivers/vc4/vc4_qir.h
src/gallium/drivers/vc4/vc4_qir_lower_uniforms.c
src/gallium/drivers/vc4/vc4_qir_validate.c
src/gallium/drivers/vc4/vc4_qpu_emit.c
src/gallium/drivers/vc4/vc4_register_allocate.c
src/gallium/drivers/vc4/vc4_reorder_uniforms.c

index b8ce377ff6b73ea94e3348a5fb656a18600890f0..01ad05d2759e96361e7d8cf49ecd6148fd3dc5b3 100644 (file)
@@ -143,7 +143,7 @@ qir_opt_algebraic(struct vc4_compile *c)
 {
         bool progress = false;
 
-        list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+        qir_for_each_inst_inorder(inst, c) {
                 switch (inst->op) {
                 case QOP_FMIN:
                         if (is_1f(c, inst->src[1]) &&
index 15ec9f0726071022dc6df204806da65ad9c0401b..7ff91615545411214b239097e26f43b890e5742a 100644 (file)
@@ -99,7 +99,7 @@ qir_opt_constant_folding(struct vc4_compile *c)
 {
         bool progress = false;
 
-        list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+        qir_for_each_inst_inorder(inst, c) {
                 if (constant_fold(c, inst))
                         progress = true;
         }
index 0eee5c34e1ddb455bf488e13f7f9d083513dd011..a180f040b54c92a30b0ef248404ca5280836658f 100644 (file)
@@ -40,7 +40,7 @@ qir_opt_copy_propagation(struct vc4_compile *c)
         bool progress = false;
         bool debug = false;
 
-        list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+        qir_for_each_inst_inorder(inst, c) {
                 int nsrc = qir_get_op_nsrc(inst->op);
                 for (int i = 0; i < nsrc; i++) {
                         if (inst->src[i].file != QFILE_TEMP)
index e61562171aae9a4ddcb247dfa9875cfd73bc4fc9..4c105f37344253dd0f6cafc4cbba730f4b6e4cc5 100644 (file)
@@ -38,7 +38,7 @@ qir_opt_small_immediates(struct vc4_compile *c)
 {
         bool progress = false;
 
-        list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+        qir_for_each_inst_inorder(inst, c) {
                 /* The small immediate value sits in the raddr B field, so we
                  * can't have 2 small immediates in one instruction (unless
                  * they're the same value, but that should be optimized away
index d31b673bd63f0dfbf2421244998a8078e4c7eb2b..e2249bd048eb1d512bb7f4f7463c9aefd363bbfc 100644 (file)
@@ -44,7 +44,7 @@ qir_opt_vpm(struct vc4_compile *c)
         uint32_t vpm_write_count = 0;
         memset(&use_count, 0, sizeof(use_count));
 
-        list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+        qir_for_each_inst_inorder(inst, c) {
                 switch (inst->dst.file) {
                 case QFILE_VPM:
                         vpm_writes[vpm_write_count++] = inst;
@@ -64,7 +64,7 @@ qir_opt_vpm(struct vc4_compile *c)
         /* For instructions reading from a temporary that contains a VPM read
          * result, try to move the instruction up in place of the VPM read.
          */
-        list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+        qir_for_each_inst_inorder(inst, c) {
                 if (!inst)
                         continue;
 
index 20e2850e625a3602cc9767fde29052cd35c57992..0a231b2f6e8be80a52038d7430b0933887727a8b 100644 (file)
@@ -2003,7 +2003,7 @@ vc4_get_compiled_shader(struct vc4_context *vc4, enum qstage stage,
                 bool input_live[c->num_input_slots];
 
                 memset(input_live, 0, sizeof(input_live));
-                list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+                qir_for_each_inst_inorder(inst, c) {
                         for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
                                 if (inst->src[i].file == QFILE_VARY)
                                         input_live[inst->src[i].index] = true;
index 2f4b71a3dfaa9e1b7aa9ae71e29dceec414e4580..315f403e43b07c63c9fa321a5331216739c6933b 100644 (file)
@@ -719,4 +719,7 @@ qir_LOAD_IMM(struct vc4_compile *c, uint32_t val)
                                         qir_reg(QFILE_LOAD_IMM, val), c->undef));
 }
 
+#define qir_for_each_inst_inorder(inst, c)                              \
+        list_for_each_entry(struct qinst, inst, &c->instructions, link)
+
 #endif /* VC4_QIR_H */
index 927268d71efe42c745d749a18fae83747c424f07..9f782dfc7df3c218e981014eb30a10b6c2dccebe 100644 (file)
@@ -118,7 +118,7 @@ qir_lower_uniforms(struct vc4_compile *c)
          * than one uniform referenced, and add those uniform values to the
          * ht.
          */
-        list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+        qir_for_each_inst_inorder(inst, c) {
                 uint32_t nsrc = qir_get_op_nsrc(inst->op);
 
                 if (qir_get_instruction_uniform_count(inst) <= 1)
@@ -154,7 +154,7 @@ qir_lower_uniforms(struct vc4_compile *c)
                 struct qinst *mov = qir_inst(QOP_MOV, temp, unif, c->undef);
                 list_add(&mov->link, &c->instructions);
                 c->defs[temp.index] = mov;
-                list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+                qir_for_each_inst_inorder(inst, c) {
                         uint32_t nsrc = qir_get_op_nsrc(inst->op);
 
                         uint32_t count = qir_get_instruction_uniform_count(inst);
index da6457c75b3b0b89f665183dbfc03d0d91242c8d..e8d4372f19f898b602706547980c69e6d3fa0e4e 100644 (file)
@@ -53,7 +53,7 @@ void qir_validate(struct vc4_compile *c)
                         fail_instr(c, def, "SSA def with condition");
         }
 
-        list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+        qir_for_each_inst_inorder(inst, c) {
                 switch (inst->dst.file) {
                 case QFILE_TEMP:
                         if (inst->dst.index >= c->num_temps)
index 794757e6d189e46a3e59dd6f22cc13e2dd65930a..1fd151acac281f811b25b7c2107d573e11af7be1 100644 (file)
@@ -213,7 +213,7 @@ vc4_generate_code(struct vc4_context *vc4, struct vc4_compile *c)
                 break;
         }
 
-        list_for_each_entry(struct qinst, qinst, &c->instructions, link) {
+        qir_for_each_inst_inorder(qinst, c) {
 #if 0
                 fprintf(stderr, "translating qinst to qpu: ");
                 qir_dump_inst(qinst);
index bca36c3e7f420a8a1b3bcaaedbddf428dcc860ad..bb5a396ca2da8db80b958dba532d838e7e9a5cfc 100644 (file)
@@ -198,7 +198,7 @@ vc4_register_allocate(struct vc4_context *vc4, struct vc4_compile *c)
         /* Compute the live ranges so we can figure out interference.
          */
         uint32_t ip = 0;
-        list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+        qir_for_each_inst_inorder(inst, c) {
                 if (inst->dst.file == QFILE_TEMP) {
                         def[inst->dst.index] = MIN2(ip, def[inst->dst.index]);
                         use[inst->dst.index] = ip;
@@ -242,7 +242,7 @@ vc4_register_allocate(struct vc4_context *vc4, struct vc4_compile *c)
                sizeof(class_bits));
 
         ip = 0;
-        list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+        qir_for_each_inst_inorder(inst, c) {
                 if (qir_writes_r4(inst)) {
                         /* This instruction writes r4 (and optionally moves
                          * its result to a temp), so nothing else can be
index 85a0c95e85155c214d44faf2e67de010c1c675b8..7d5076f429e6f66fd74fbcab33ce3dfb14a523cf 100644 (file)
@@ -43,7 +43,7 @@ qir_reorder_uniforms(struct vc4_compile *c)
         uint32_t uniform_index_size = 0;
         uint32_t next_uniform = 0;
 
-        list_for_each_entry(struct qinst, inst, &c->instructions, link) {
+        qir_for_each_inst_inorder(inst, c) {
                 uint32_t new = ~0;
 
                 for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {