• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 Connor Abbott <cwabbott0@gmail.com>
3  * Copyright (C) 2019 Lyude Paul <thatslyude@gmail.com>
4  * Copyright (C) 2019 Ryan Houdek <Sonicadvance1@gmail.com>
5  * Copyright (C) 2019-2020 Collabora, Ltd.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the next
15  * paragraph) shall be included in all copies or substantial portions of the
16  * Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
21  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24  * SOFTWARE.
25  */
26 
27 #include "compiler.h"
28 #include "bi_print_common.h"
29 
30 static const char *
bi_reg_op_name(enum bifrost_reg_op op)31 bi_reg_op_name(enum bifrost_reg_op op)
32 {
33         switch (op) {
34         case BIFROST_OP_IDLE: return "idle";
35         case BIFROST_OP_READ: return "read";
36         case BIFROST_OP_WRITE: return "write";
37         case BIFROST_OP_WRITE_LO: return "write lo";
38         case BIFROST_OP_WRITE_HI: return "write hi";
39         default: return "invalid";
40         }
41 }
42 
43 void
bi_print_slots(bi_registers * regs,FILE * fp)44 bi_print_slots(bi_registers *regs, FILE *fp)
45 {
46         for (unsigned i = 0; i < 2; ++i) {
47                 if (regs->enabled[i])
48                         fprintf(fp, "slot %u: %u\n", i, regs->slot[i]);
49         }
50 
51         if (regs->slot23.slot2) {
52                 fprintf(fp, "slot 2 (%s%s): %u\n",
53                                 bi_reg_op_name(regs->slot23.slot2),
54                                 regs->slot23.slot2 >= BIFROST_OP_WRITE ?
55                                         " FMA": "",
56                                 regs->slot[2]);
57         }
58 
59         if (regs->slot23.slot3) {
60                 fprintf(fp, "slot 3 (%s %s): %u\n",
61                                 bi_reg_op_name(regs->slot23.slot3),
62                                 regs->slot23.slot3_fma ? "FMA" : "ADD",
63                                 regs->slot[3]);
64         }
65 }
66 
67 void
bi_print_tuple(bi_tuple * tuple,FILE * fp)68 bi_print_tuple(bi_tuple *tuple, FILE *fp)
69 {
70         bi_instr *ins[2] = { tuple->fma, tuple->add };
71 
72         for (unsigned i = 0; i < 2; ++i) {
73                 fprintf(fp, (i == 0) ? "\t* " : "\t+ ");
74 
75                 if (ins[i])
76                         bi_print_instr(ins[i], fp);
77                 else
78                         fprintf(fp, "NOP\n");
79         }
80 }
81 
82 void
bi_print_clause(bi_clause * clause,FILE * fp)83 bi_print_clause(bi_clause *clause, FILE *fp)
84 {
85         fprintf(fp, "id(%u)", clause->scoreboard_id);
86 
87         if (clause->dependencies) {
88                 fprintf(fp, " wait(");
89 
90                 for (unsigned i = 0; i < 8; ++i) {
91                         if (clause->dependencies & (1 << i))
92                                 fprintf(fp, "%u ", i);
93                 }
94 
95                 fprintf(fp, ")");
96         }
97 
98         fprintf(fp, " %s", bi_flow_control_name(clause->flow_control));
99 
100         if (!clause->next_clause_prefetch)
101                fprintf(fp, " no_prefetch");
102 
103         if (clause->staging_barrier)
104                 fprintf(fp, " osrb");
105 
106         if (clause->td)
107                 fprintf(fp, " td");
108 
109         if (clause->pcrel_idx != ~0)
110                 fprintf(fp, " pcrel(%u)", clause->pcrel_idx);
111 
112         fprintf(fp, "\n");
113 
114         for (unsigned i = 0; i < clause->tuple_count; ++i)
115                 bi_print_tuple(&clause->tuples[i], fp);
116 
117         if (clause->constant_count) {
118                 for (unsigned i = 0; i < clause->constant_count; ++i)
119                         fprintf(fp, "%" PRIx64 " ", clause->constants[i]);
120 
121                 if (clause->branch_constant)
122                         fprintf(fp, "*");
123 
124                 fprintf(fp, "\n");
125         }
126 
127         fprintf(fp, "\n");
128 }
129 
130 static void
bi_print_scoreboard_line(unsigned slot,const char * name,uint64_t mask,FILE * fp)131 bi_print_scoreboard_line(unsigned slot, const char *name, uint64_t mask, FILE *fp)
132 {
133         if (!mask)
134                 return;
135 
136         fprintf(fp, "slot %u %s:", slot, name);
137 
138         u_foreach_bit64(reg, mask)
139                 fprintf(fp, " r%" PRId64, reg);
140 
141         fprintf(fp, "\n");
142 }
143 
144 static void
bi_print_scoreboard(struct bi_scoreboard_state * state,FILE * fp)145 bi_print_scoreboard(struct bi_scoreboard_state *state, FILE *fp)
146 {
147         for (unsigned i = 0; i < BI_NUM_SLOTS; ++i) {
148                 bi_print_scoreboard_line(i, "reads", state->read[i], fp);
149                 bi_print_scoreboard_line(i, "writes", state->write[i], fp);
150         }
151 }
152 
153 void
bi_print_block(bi_block * block,FILE * fp)154 bi_print_block(bi_block *block, FILE *fp)
155 {
156         if (block->scheduled) {
157                 bi_print_scoreboard(&block->scoreboard_in, fp);
158                 fprintf(fp, "\n");
159         }
160 
161         fprintf(fp, "block%u {\n", block->index);
162 
163         if (block->scheduled) {
164                 bi_foreach_clause_in_block(block, clause)
165                         bi_print_clause(clause, fp);
166         } else {
167                 bi_foreach_instr_in_block(block, ins)
168                         bi_print_instr((bi_instr *) ins, fp);
169         }
170 
171         fprintf(fp, "}");
172 
173         if (block->successors[0]) {
174                 fprintf(fp, " -> ");
175 
176                 bi_foreach_successor((block), succ)
177                         fprintf(fp, "block%u ", succ->index);
178         }
179 
180         if (bi_num_predecessors(block)) {
181                 fprintf(fp, " from");
182 
183                 bi_foreach_predecessor(block, pred)
184                         fprintf(fp, " block%u", (*pred)->index);
185         }
186 
187         if (block->scheduled) {
188                 fprintf(fp, "\n");
189                 bi_print_scoreboard(&block->scoreboard_out, fp);
190         }
191 
192         fprintf(fp, "\n\n");
193 }
194 
195 void
bi_print_shader(bi_context * ctx,FILE * fp)196 bi_print_shader(bi_context *ctx, FILE *fp)
197 {
198         bi_foreach_block(ctx, block)
199                 bi_print_block(block, fp);
200 }
201