xref: /aosp_15_r20/external/mesa3d/src/panfrost/compiler/bi_print.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright (C) 2019 Connor Abbott <[email protected]>
3  * Copyright (C) 2019 Lyude Paul <[email protected]>
4  * Copyright (C) 2019 Ryan Houdek <[email protected]>
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 "bi_print_common.h"
28 #include "compiler.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:
35       return "idle";
36    case BIFROST_OP_READ:
37       return "read";
38    case BIFROST_OP_WRITE:
39       return "write";
40    case BIFROST_OP_WRITE_LO:
41       return "write lo";
42    case BIFROST_OP_WRITE_HI:
43       return "write hi";
44    default:
45       return "invalid";
46    }
47 }
48 
49 void
bi_print_slots(bi_registers * regs,FILE * fp)50 bi_print_slots(bi_registers *regs, FILE *fp)
51 {
52    for (unsigned i = 0; i < 2; ++i) {
53       if (regs->enabled[i])
54          fprintf(fp, "slot %u: %u\n", i, regs->slot[i]);
55    }
56 
57    if (regs->slot23.slot2) {
58       fprintf(fp, "slot 2 (%s%s): %u\n", bi_reg_op_name(regs->slot23.slot2),
59               regs->slot23.slot2 >= BIFROST_OP_WRITE ? " FMA" : "",
60               regs->slot[2]);
61    }
62 
63    if (regs->slot23.slot3) {
64       fprintf(fp, "slot 3 (%s %s): %u\n", bi_reg_op_name(regs->slot23.slot3),
65               regs->slot23.slot3_fma ? "FMA" : "ADD", regs->slot[3]);
66    }
67 }
68 
69 void
bi_print_tuple(bi_tuple * tuple,FILE * fp)70 bi_print_tuple(bi_tuple *tuple, FILE *fp)
71 {
72    bi_instr *ins[2] = {tuple->fma, tuple->add};
73 
74    for (unsigned i = 0; i < 2; ++i) {
75       fprintf(fp, (i == 0) ? "\t* " : "\t+ ");
76 
77       if (ins[i])
78          bi_print_instr(ins[i], fp);
79       else
80          fprintf(fp, "NOP\n");
81    }
82 }
83 
84 void
bi_print_clause(bi_clause * clause,FILE * fp)85 bi_print_clause(bi_clause *clause, FILE *fp)
86 {
87    fprintf(fp, "id(%u)", clause->scoreboard_id);
88 
89    if (clause->dependencies) {
90       fprintf(fp, " wait(");
91 
92       for (unsigned i = 0; i < 8; ++i) {
93          if (clause->dependencies & (1 << i))
94             fprintf(fp, "%u ", i);
95       }
96 
97       fprintf(fp, ")");
98    }
99 
100    fprintf(fp, " %s", bi_flow_control_name(clause->flow_control));
101 
102    if (!clause->next_clause_prefetch)
103       fprintf(fp, " no_prefetch");
104 
105    if (clause->staging_barrier)
106       fprintf(fp, " osrb");
107 
108    if (clause->td)
109       fprintf(fp, " td");
110 
111    if (clause->pcrel_idx != ~0)
112       fprintf(fp, " pcrel(%u)", clause->pcrel_idx);
113 
114    fprintf(fp, "\n");
115 
116    for (unsigned i = 0; i < clause->tuple_count; ++i)
117       bi_print_tuple(&clause->tuples[i], fp);
118 
119    if (clause->constant_count) {
120       for (unsigned i = 0; i < clause->constant_count; ++i)
121          fprintf(fp, "%" PRIx64 " ", clause->constants[i]);
122 
123       if (clause->branch_constant)
124          fprintf(fp, "*");
125 
126       fprintf(fp, "\n");
127    }
128 
129    fprintf(fp, "\n");
130 }
131 
132 static void
bi_print_scoreboard_line(unsigned slot,const char * name,uint64_t mask,FILE * fp)133 bi_print_scoreboard_line(unsigned slot, const char *name, uint64_t mask,
134                          FILE *fp)
135 {
136    if (!mask)
137       return;
138 
139    fprintf(fp, "slot %u %s:", slot, name);
140 
141    u_foreach_bit64(reg, mask)
142       fprintf(fp, " r%" PRId64, reg);
143 
144    fprintf(fp, "\n");
145 }
146 
147 static void
bi_print_scoreboard(struct bi_scoreboard_state * state,FILE * fp)148 bi_print_scoreboard(struct bi_scoreboard_state *state, FILE *fp)
149 {
150    for (unsigned i = 0; i < BI_NUM_SLOTS; ++i) {
151       bi_print_scoreboard_line(i, "reads", state->read[i], fp);
152       bi_print_scoreboard_line(i, "writes", state->write[i], fp);
153    }
154 }
155 
156 void
bi_print_block(bi_block * block,FILE * fp)157 bi_print_block(bi_block *block, FILE *fp)
158 {
159    if (block->scheduled) {
160       bi_print_scoreboard(&block->scoreboard_in, fp);
161       fprintf(fp, "\n");
162    }
163 
164    fprintf(fp, "block%u {\n", block->index);
165 
166    if (block->scheduled) {
167       bi_foreach_clause_in_block(block, clause)
168          bi_print_clause(clause, fp);
169    } else {
170       bi_foreach_instr_in_block(block, ins)
171          bi_print_instr((bi_instr *)ins, fp);
172    }
173 
174    fprintf(fp, "}");
175 
176    if (block->successors[0]) {
177       fprintf(fp, " -> ");
178 
179       bi_foreach_successor((block), succ)
180          fprintf(fp, "block%u ", succ->index);
181    }
182 
183    if (bi_num_predecessors(block)) {
184       fprintf(fp, " from");
185 
186       bi_foreach_predecessor(block, pred)
187          fprintf(fp, " block%u", (*pred)->index);
188    }
189 
190    if (block->scheduled) {
191       fprintf(fp, "\n");
192       bi_print_scoreboard(&block->scoreboard_out, fp);
193    }
194 
195    fprintf(fp, "\n\n");
196 }
197 
198 void
bi_print_shader(bi_context * ctx,FILE * fp)199 bi_print_shader(bi_context *ctx, FILE *fp)
200 {
201    bi_foreach_block(ctx, block)
202       bi_print_block(block, fp);
203 }
204