r300/compiler: add a function to query program stats (alu, tex, temps..)
authorMarek Olšák <maraeo@gmail.com>
Tue, 7 Dec 2010 22:34:21 +0000 (23:34 +0100)
committerMarek Olšák <maraeo@gmail.com>
Wed, 8 Dec 2010 03:39:50 +0000 (04:39 +0100)
src/mesa/drivers/dri/r300/compiler/radeon_compiler.c
src/mesa/drivers/dri/r300/compiler/radeon_compiler.h

index b306bd03ae991ddae0ea17506fbb399aaf694ef9..7cd86fb3ed4a4edc1f07341866e52e5534808fae 100644 (file)
@@ -357,44 +357,54 @@ void rc_transform_fragment_face(struct radeon_compiler *c, unsigned face)
 static void reg_count_callback(void * userdata, struct rc_instruction * inst,
                rc_register_file file, unsigned int index, unsigned int mask)
 {
-       unsigned int * max_reg = userdata;
+       int *max_reg = userdata;
        if (file == RC_FILE_TEMPORARY)
-               index > *max_reg ? *max_reg = index : 0;
+               (int)index > *max_reg ? *max_reg = index : 0;
 }
 
-static void print_stats(struct radeon_compiler * c)
+void rc_get_stats(struct radeon_compiler *c, struct rc_program_stats *s)
 {
+       int max_reg = -1;
        struct rc_instruction * tmp;
-       unsigned max_reg, insts, fc, tex, alpha, rgb, presub;
-       max_reg = insts = fc = tex = alpha = rgb = presub = 0;
+       memset(s, 0, sizeof(*s));
+
        for(tmp = c->Program.Instructions.Next; tmp != &c->Program.Instructions;
                                                        tmp = tmp->Next){
                const struct rc_opcode_info * info;
                rc_for_all_reads_mask(tmp, reg_count_callback, &max_reg);
                if (tmp->Type == RC_INSTRUCTION_NORMAL) {
                        if (tmp->U.I.PreSub.Opcode != RC_PRESUB_NONE)
-                               presub++;
+                               s->num_presub_ops++;
                        info = rc_get_opcode_info(tmp->U.I.Opcode);
                } else {
                        if (tmp->U.P.RGB.Src[RC_PAIR_PRESUB_SRC].Used)
-                               presub++;
+                               s->num_presub_ops++;
                        if (tmp->U.P.Alpha.Src[RC_PAIR_PRESUB_SRC].Used)
-                               presub++;
+                               s->num_presub_ops++;
                        /* Assuming alpha will never be a flow control or
                         * a tex instruction. */
                        if (tmp->U.P.Alpha.Opcode != RC_OPCODE_NOP)
-                               alpha++;
+                               s->num_alpha_insts++;
                        if (tmp->U.P.RGB.Opcode != RC_OPCODE_NOP)
-                               rgb++;
+                               s->num_rgb_insts++;
                        info = rc_get_opcode_info(tmp->U.P.RGB.Opcode);
                }
                if (info->IsFlowControl)
-                       fc++;
+                       s->num_fc_insts++;
                if (info->HasTexture)
-                       tex++;
-               insts++;
+                       s->num_tex_insts++;
+               s->num_insts++;
        }
-       if (insts < 4)
+       s->num_temp_regs = max_reg + 1;
+}
+
+static void print_stats(struct radeon_compiler * c)
+{
+       struct rc_program_stats s;
+
+       rc_get_stats(c, &s);
+
+       if (s.num_insts < 4)
                return;
        fprintf(stderr,"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
                       "~%4u Instructions\n"
@@ -405,7 +415,9 @@ static void print_stats(struct radeon_compiler * c)
                       "~%4u Presub Operations\n"
                       "~%4u Temporary Registers\n"
                       "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n",
-                      insts, rgb, alpha, fc, tex, presub, max_reg + 1);
+                      s.num_insts, s.num_rgb_insts, s.num_alpha_insts,
+                      s.num_fc_insts, s.num_tex_insts, s.num_presub_ops,
+                      s.num_temp_regs);
 }
 
 /* Executes a list of compiler passes given in the parameter 'list'. */
index 31fd469a04f8ec8fb55448f1b5358a904c5c88c2..2aa797801035f3121e9c547ba84646aba244cf60 100644 (file)
@@ -140,6 +140,18 @@ struct radeon_compiler_pass {
        void *user;             /* Optional parameter which is passed to the run function. */
 };
 
+struct rc_program_stats {
+       unsigned num_insts;
+       unsigned num_fc_insts;
+       unsigned num_tex_insts;
+       unsigned num_rgb_insts;
+       unsigned num_alpha_insts;
+       unsigned num_presub_ops;
+       unsigned num_temp_regs;
+};
+
+void rc_get_stats(struct radeon_compiler *c, struct rc_program_stats *s);
+
 /* Executes a list of compiler passes given in the parameter 'list'. */
 void rc_run_compiler(struct radeon_compiler *c, struct radeon_compiler_pass *list,
                     const char *shader_name);