1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2016-2017 Broadcom
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21bf215546Sopenharmony_ci * IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#include "broadcom/common/v3d_device_info.h"
25bf215546Sopenharmony_ci#include "v3d_compiler.h"
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci/* Prints a human-readable description of the uniform reference. */
28bf215546Sopenharmony_civoid
29bf215546Sopenharmony_civir_dump_uniform(enum quniform_contents contents,
30bf215546Sopenharmony_ci                 uint32_t data)
31bf215546Sopenharmony_ci{
32bf215546Sopenharmony_ci        static const char *quniform_names[] = {
33bf215546Sopenharmony_ci                [QUNIFORM_LINE_WIDTH] = "line_width",
34bf215546Sopenharmony_ci                [QUNIFORM_AA_LINE_WIDTH] = "aa_line_width",
35bf215546Sopenharmony_ci                [QUNIFORM_VIEWPORT_X_SCALE] = "vp_x_scale",
36bf215546Sopenharmony_ci                [QUNIFORM_VIEWPORT_Y_SCALE] = "vp_y_scale",
37bf215546Sopenharmony_ci                [QUNIFORM_VIEWPORT_Z_OFFSET] = "vp_z_offset",
38bf215546Sopenharmony_ci                [QUNIFORM_VIEWPORT_Z_SCALE] = "vp_z_scale",
39bf215546Sopenharmony_ci                [QUNIFORM_SHARED_OFFSET] = "shared_offset",
40bf215546Sopenharmony_ci        };
41bf215546Sopenharmony_ci
42bf215546Sopenharmony_ci        switch (contents) {
43bf215546Sopenharmony_ci        case QUNIFORM_CONSTANT:
44bf215546Sopenharmony_ci                fprintf(stderr, "0x%08x / %f", data, uif(data));
45bf215546Sopenharmony_ci                break;
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci        case QUNIFORM_UNIFORM:
48bf215546Sopenharmony_ci                fprintf(stderr, "push[%d]", data);
49bf215546Sopenharmony_ci                break;
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci        case QUNIFORM_TEXTURE_CONFIG_P1:
52bf215546Sopenharmony_ci                fprintf(stderr, "tex[%d].p1", data);
53bf215546Sopenharmony_ci                break;
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_ci        case QUNIFORM_TMU_CONFIG_P0:
56bf215546Sopenharmony_ci                fprintf(stderr, "tex[%d].p0 | 0x%x",
57bf215546Sopenharmony_ci                        v3d_unit_data_get_unit(data),
58bf215546Sopenharmony_ci                        v3d_unit_data_get_offset(data));
59bf215546Sopenharmony_ci                break;
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_ci        case QUNIFORM_TMU_CONFIG_P1:
62bf215546Sopenharmony_ci                fprintf(stderr, "tex[%d].p1 | 0x%x",
63bf215546Sopenharmony_ci                        v3d_unit_data_get_unit(data),
64bf215546Sopenharmony_ci                        v3d_unit_data_get_offset(data));
65bf215546Sopenharmony_ci                break;
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ci        case QUNIFORM_IMAGE_TMU_CONFIG_P0:
68bf215546Sopenharmony_ci                fprintf(stderr, "img[%d].p0 | 0x%x",
69bf215546Sopenharmony_ci                        v3d_unit_data_get_unit(data),
70bf215546Sopenharmony_ci                        v3d_unit_data_get_offset(data));
71bf215546Sopenharmony_ci                break;
72bf215546Sopenharmony_ci
73bf215546Sopenharmony_ci        case QUNIFORM_TEXTURE_WIDTH:
74bf215546Sopenharmony_ci                fprintf(stderr, "tex[%d].width", data);
75bf215546Sopenharmony_ci                break;
76bf215546Sopenharmony_ci        case QUNIFORM_TEXTURE_HEIGHT:
77bf215546Sopenharmony_ci                fprintf(stderr, "tex[%d].height", data);
78bf215546Sopenharmony_ci                break;
79bf215546Sopenharmony_ci        case QUNIFORM_TEXTURE_DEPTH:
80bf215546Sopenharmony_ci                fprintf(stderr, "tex[%d].depth", data);
81bf215546Sopenharmony_ci                break;
82bf215546Sopenharmony_ci        case QUNIFORM_TEXTURE_ARRAY_SIZE:
83bf215546Sopenharmony_ci                fprintf(stderr, "tex[%d].array_size", data);
84bf215546Sopenharmony_ci                break;
85bf215546Sopenharmony_ci        case QUNIFORM_TEXTURE_LEVELS:
86bf215546Sopenharmony_ci                fprintf(stderr, "tex[%d].levels", data);
87bf215546Sopenharmony_ci                break;
88bf215546Sopenharmony_ci
89bf215546Sopenharmony_ci        case QUNIFORM_IMAGE_WIDTH:
90bf215546Sopenharmony_ci                fprintf(stderr, "img[%d].width", data);
91bf215546Sopenharmony_ci                break;
92bf215546Sopenharmony_ci        case QUNIFORM_IMAGE_HEIGHT:
93bf215546Sopenharmony_ci                fprintf(stderr, "img[%d].height", data);
94bf215546Sopenharmony_ci                break;
95bf215546Sopenharmony_ci        case QUNIFORM_IMAGE_DEPTH:
96bf215546Sopenharmony_ci                fprintf(stderr, "img[%d].depth", data);
97bf215546Sopenharmony_ci                break;
98bf215546Sopenharmony_ci        case QUNIFORM_IMAGE_ARRAY_SIZE:
99bf215546Sopenharmony_ci                fprintf(stderr, "img[%d].array_size", data);
100bf215546Sopenharmony_ci                break;
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ci        case QUNIFORM_SPILL_OFFSET:
103bf215546Sopenharmony_ci                fprintf(stderr, "spill_offset");
104bf215546Sopenharmony_ci                break;
105bf215546Sopenharmony_ci
106bf215546Sopenharmony_ci        case QUNIFORM_SPILL_SIZE_PER_THREAD:
107bf215546Sopenharmony_ci                fprintf(stderr, "spill_size_per_thread");
108bf215546Sopenharmony_ci                break;
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ci        case QUNIFORM_UBO_ADDR:
111bf215546Sopenharmony_ci                fprintf(stderr, "ubo[%d]+0x%x",
112bf215546Sopenharmony_ci                        v3d_unit_data_get_unit(data),
113bf215546Sopenharmony_ci                        v3d_unit_data_get_offset(data));
114bf215546Sopenharmony_ci                break;
115bf215546Sopenharmony_ci
116bf215546Sopenharmony_ci        case QUNIFORM_SSBO_OFFSET:
117bf215546Sopenharmony_ci                fprintf(stderr, "ssbo[%d]", data);
118bf215546Sopenharmony_ci                break;
119bf215546Sopenharmony_ci
120bf215546Sopenharmony_ci        case QUNIFORM_GET_SSBO_SIZE:
121bf215546Sopenharmony_ci                fprintf(stderr, "ssbo_size[%d]", data);
122bf215546Sopenharmony_ci                break;
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ci        case QUNIFORM_GET_UBO_SIZE:
125bf215546Sopenharmony_ci                fprintf(stderr, "ubo_size[%d]", data);
126bf215546Sopenharmony_ci                break;
127bf215546Sopenharmony_ci
128bf215546Sopenharmony_ci        case QUNIFORM_NUM_WORK_GROUPS:
129bf215546Sopenharmony_ci                fprintf(stderr, "num_wg.%c", data < 3 ? "xyz"[data] : '?');
130bf215546Sopenharmony_ci                break;
131bf215546Sopenharmony_ci
132bf215546Sopenharmony_ci        default:
133bf215546Sopenharmony_ci                if (quniform_contents_is_texture_p0(contents)) {
134bf215546Sopenharmony_ci                        fprintf(stderr, "tex[%d].p0: 0x%08x",
135bf215546Sopenharmony_ci                                contents - QUNIFORM_TEXTURE_CONFIG_P0_0,
136bf215546Sopenharmony_ci                                data);
137bf215546Sopenharmony_ci                } else if (contents < ARRAY_SIZE(quniform_names) &&
138bf215546Sopenharmony_ci                           quniform_names[contents]) {
139bf215546Sopenharmony_ci                        fprintf(stderr, "%s",
140bf215546Sopenharmony_ci                                quniform_names[contents]);
141bf215546Sopenharmony_ci                } else {
142bf215546Sopenharmony_ci                        fprintf(stderr, "%d / 0x%08x", contents, data);
143bf215546Sopenharmony_ci                }
144bf215546Sopenharmony_ci        }
145bf215546Sopenharmony_ci}
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_cistatic void
148bf215546Sopenharmony_civir_print_reg(struct v3d_compile *c, const struct qinst *inst,
149bf215546Sopenharmony_ci              struct qreg reg)
150bf215546Sopenharmony_ci{
151bf215546Sopenharmony_ci        switch (reg.file) {
152bf215546Sopenharmony_ci
153bf215546Sopenharmony_ci        case QFILE_NULL:
154bf215546Sopenharmony_ci                fprintf(stderr, "null");
155bf215546Sopenharmony_ci                break;
156bf215546Sopenharmony_ci
157bf215546Sopenharmony_ci        case QFILE_LOAD_IMM:
158bf215546Sopenharmony_ci                fprintf(stderr, "0x%08x (%f)", reg.index, uif(reg.index));
159bf215546Sopenharmony_ci                break;
160bf215546Sopenharmony_ci
161bf215546Sopenharmony_ci        case QFILE_REG:
162bf215546Sopenharmony_ci                fprintf(stderr, "rf%d", reg.index);
163bf215546Sopenharmony_ci                break;
164bf215546Sopenharmony_ci
165bf215546Sopenharmony_ci        case QFILE_MAGIC:
166bf215546Sopenharmony_ci                fprintf(stderr, "%s",
167bf215546Sopenharmony_ci                        v3d_qpu_magic_waddr_name(c->devinfo, reg.index));
168bf215546Sopenharmony_ci                break;
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci        case QFILE_SMALL_IMM: {
171bf215546Sopenharmony_ci                uint32_t unpacked;
172bf215546Sopenharmony_ci                bool ok = v3d_qpu_small_imm_unpack(c->devinfo,
173bf215546Sopenharmony_ci                                                   inst->qpu.raddr_b,
174bf215546Sopenharmony_ci                                                   &unpacked);
175bf215546Sopenharmony_ci                assert(ok); (void) ok;
176bf215546Sopenharmony_ci
177bf215546Sopenharmony_ci                int8_t *p = (int8_t *)&inst->qpu.raddr_b;
178bf215546Sopenharmony_ci                if (*p >= -16 && *p <= 15)
179bf215546Sopenharmony_ci                        fprintf(stderr, "%d", unpacked);
180bf215546Sopenharmony_ci                else
181bf215546Sopenharmony_ci                        fprintf(stderr, "%f", uif(unpacked));
182bf215546Sopenharmony_ci                break;
183bf215546Sopenharmony_ci        }
184bf215546Sopenharmony_ci
185bf215546Sopenharmony_ci        case QFILE_VPM:
186bf215546Sopenharmony_ci                fprintf(stderr, "vpm%d.%d",
187bf215546Sopenharmony_ci                        reg.index / 4, reg.index % 4);
188bf215546Sopenharmony_ci                break;
189bf215546Sopenharmony_ci
190bf215546Sopenharmony_ci        case QFILE_TEMP:
191bf215546Sopenharmony_ci                fprintf(stderr, "t%d", reg.index);
192bf215546Sopenharmony_ci                break;
193bf215546Sopenharmony_ci        }
194bf215546Sopenharmony_ci}
195bf215546Sopenharmony_ci
196bf215546Sopenharmony_cistatic void
197bf215546Sopenharmony_civir_dump_sig_addr(const struct v3d_device_info *devinfo,
198bf215546Sopenharmony_ci                  const struct v3d_qpu_instr *instr)
199bf215546Sopenharmony_ci{
200bf215546Sopenharmony_ci        if (devinfo->ver < 41)
201bf215546Sopenharmony_ci                return;
202bf215546Sopenharmony_ci
203bf215546Sopenharmony_ci        if (!instr->sig_magic)
204bf215546Sopenharmony_ci                fprintf(stderr, ".rf%d", instr->sig_addr);
205bf215546Sopenharmony_ci        else {
206bf215546Sopenharmony_ci                const char *name =
207bf215546Sopenharmony_ci                         v3d_qpu_magic_waddr_name(devinfo, instr->sig_addr);
208bf215546Sopenharmony_ci                if (name)
209bf215546Sopenharmony_ci                        fprintf(stderr, ".%s", name);
210bf215546Sopenharmony_ci                else
211bf215546Sopenharmony_ci                        fprintf(stderr, ".UNKNOWN%d", instr->sig_addr);
212bf215546Sopenharmony_ci        }
213bf215546Sopenharmony_ci}
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_cistatic void
216bf215546Sopenharmony_civir_dump_sig(struct v3d_compile *c, struct qinst *inst)
217bf215546Sopenharmony_ci{
218bf215546Sopenharmony_ci        struct v3d_qpu_sig *sig = &inst->qpu.sig;
219bf215546Sopenharmony_ci
220bf215546Sopenharmony_ci        if (sig->thrsw)
221bf215546Sopenharmony_ci                fprintf(stderr, "; thrsw");
222bf215546Sopenharmony_ci        if (sig->ldvary) {
223bf215546Sopenharmony_ci                fprintf(stderr, "; ldvary");
224bf215546Sopenharmony_ci                vir_dump_sig_addr(c->devinfo, &inst->qpu);
225bf215546Sopenharmony_ci        }
226bf215546Sopenharmony_ci        if (sig->ldvpm)
227bf215546Sopenharmony_ci                fprintf(stderr, "; ldvpm");
228bf215546Sopenharmony_ci        if (sig->ldtmu) {
229bf215546Sopenharmony_ci                fprintf(stderr, "; ldtmu");
230bf215546Sopenharmony_ci                vir_dump_sig_addr(c->devinfo, &inst->qpu);
231bf215546Sopenharmony_ci        }
232bf215546Sopenharmony_ci        if (sig->ldtlb) {
233bf215546Sopenharmony_ci                fprintf(stderr, "; ldtlb");
234bf215546Sopenharmony_ci                vir_dump_sig_addr(c->devinfo, &inst->qpu);
235bf215546Sopenharmony_ci        }
236bf215546Sopenharmony_ci        if (sig->ldtlbu) {
237bf215546Sopenharmony_ci                fprintf(stderr, "; ldtlbu");
238bf215546Sopenharmony_ci                vir_dump_sig_addr(c->devinfo, &inst->qpu);
239bf215546Sopenharmony_ci        }
240bf215546Sopenharmony_ci        if (sig->ldunif)
241bf215546Sopenharmony_ci                fprintf(stderr, "; ldunif");
242bf215546Sopenharmony_ci        if (sig->ldunifrf) {
243bf215546Sopenharmony_ci                fprintf(stderr, "; ldunifrf");
244bf215546Sopenharmony_ci                vir_dump_sig_addr(c->devinfo, &inst->qpu);
245bf215546Sopenharmony_ci        }
246bf215546Sopenharmony_ci        if (sig->ldunifa)
247bf215546Sopenharmony_ci                fprintf(stderr, "; ldunifa");
248bf215546Sopenharmony_ci        if (sig->ldunifarf) {
249bf215546Sopenharmony_ci                fprintf(stderr, "; ldunifarf");
250bf215546Sopenharmony_ci                vir_dump_sig_addr(c->devinfo, &inst->qpu);
251bf215546Sopenharmony_ci        }
252bf215546Sopenharmony_ci        if (sig->wrtmuc)
253bf215546Sopenharmony_ci                fprintf(stderr, "; wrtmuc");
254bf215546Sopenharmony_ci}
255bf215546Sopenharmony_ci
256bf215546Sopenharmony_cistatic void
257bf215546Sopenharmony_civir_dump_alu(struct v3d_compile *c, struct qinst *inst)
258bf215546Sopenharmony_ci{
259bf215546Sopenharmony_ci        struct v3d_qpu_instr *instr = &inst->qpu;
260bf215546Sopenharmony_ci        int nsrc = vir_get_nsrc(inst);
261bf215546Sopenharmony_ci        enum v3d_qpu_input_unpack unpack[2];
262bf215546Sopenharmony_ci
263bf215546Sopenharmony_ci        if (inst->qpu.alu.add.op != V3D_QPU_A_NOP) {
264bf215546Sopenharmony_ci                fprintf(stderr, "%s", v3d_qpu_add_op_name(instr->alu.add.op));
265bf215546Sopenharmony_ci                fprintf(stderr, "%s", v3d_qpu_cond_name(instr->flags.ac));
266bf215546Sopenharmony_ci                fprintf(stderr, "%s", v3d_qpu_pf_name(instr->flags.apf));
267bf215546Sopenharmony_ci                fprintf(stderr, "%s", v3d_qpu_uf_name(instr->flags.auf));
268bf215546Sopenharmony_ci                fprintf(stderr, " ");
269bf215546Sopenharmony_ci
270bf215546Sopenharmony_ci                vir_print_reg(c, inst, inst->dst);
271bf215546Sopenharmony_ci                fprintf(stderr, "%s", v3d_qpu_pack_name(instr->alu.add.output_pack));
272bf215546Sopenharmony_ci
273bf215546Sopenharmony_ci                unpack[0] = instr->alu.add.a_unpack;
274bf215546Sopenharmony_ci                unpack[1] = instr->alu.add.b_unpack;
275bf215546Sopenharmony_ci        } else {
276bf215546Sopenharmony_ci                fprintf(stderr, "%s", v3d_qpu_mul_op_name(instr->alu.mul.op));
277bf215546Sopenharmony_ci                fprintf(stderr, "%s", v3d_qpu_cond_name(instr->flags.mc));
278bf215546Sopenharmony_ci                fprintf(stderr, "%s", v3d_qpu_pf_name(instr->flags.mpf));
279bf215546Sopenharmony_ci                fprintf(stderr, "%s", v3d_qpu_uf_name(instr->flags.muf));
280bf215546Sopenharmony_ci                fprintf(stderr, " ");
281bf215546Sopenharmony_ci
282bf215546Sopenharmony_ci                vir_print_reg(c, inst, inst->dst);
283bf215546Sopenharmony_ci                fprintf(stderr, "%s", v3d_qpu_pack_name(instr->alu.mul.output_pack));
284bf215546Sopenharmony_ci
285bf215546Sopenharmony_ci                unpack[0] = instr->alu.mul.a_unpack;
286bf215546Sopenharmony_ci                unpack[1] = instr->alu.mul.b_unpack;
287bf215546Sopenharmony_ci        }
288bf215546Sopenharmony_ci
289bf215546Sopenharmony_ci        for (int i = 0; i < nsrc; i++) {
290bf215546Sopenharmony_ci                fprintf(stderr, ", ");
291bf215546Sopenharmony_ci                vir_print_reg(c, inst, inst->src[i]);
292bf215546Sopenharmony_ci                fprintf(stderr, "%s", v3d_qpu_unpack_name(unpack[i]));
293bf215546Sopenharmony_ci        }
294bf215546Sopenharmony_ci
295bf215546Sopenharmony_ci        vir_dump_sig(c, inst);
296bf215546Sopenharmony_ci}
297bf215546Sopenharmony_ci
298bf215546Sopenharmony_civoid
299bf215546Sopenharmony_civir_dump_inst(struct v3d_compile *c, struct qinst *inst)
300bf215546Sopenharmony_ci{
301bf215546Sopenharmony_ci        struct v3d_qpu_instr *instr = &inst->qpu;
302bf215546Sopenharmony_ci
303bf215546Sopenharmony_ci        switch (inst->qpu.type) {
304bf215546Sopenharmony_ci        case V3D_QPU_INSTR_TYPE_ALU:
305bf215546Sopenharmony_ci                vir_dump_alu(c, inst);
306bf215546Sopenharmony_ci                break;
307bf215546Sopenharmony_ci        case V3D_QPU_INSTR_TYPE_BRANCH:
308bf215546Sopenharmony_ci                fprintf(stderr, "b");
309bf215546Sopenharmony_ci                if (instr->branch.ub)
310bf215546Sopenharmony_ci                        fprintf(stderr, "u");
311bf215546Sopenharmony_ci
312bf215546Sopenharmony_ci                fprintf(stderr, "%s",
313bf215546Sopenharmony_ci                        v3d_qpu_branch_cond_name(instr->branch.cond));
314bf215546Sopenharmony_ci                fprintf(stderr, "%s", v3d_qpu_msfign_name(instr->branch.msfign));
315bf215546Sopenharmony_ci
316bf215546Sopenharmony_ci                switch (instr->branch.bdi) {
317bf215546Sopenharmony_ci                case V3D_QPU_BRANCH_DEST_ABS:
318bf215546Sopenharmony_ci                        fprintf(stderr, "  zero_addr+0x%08x", instr->branch.offset);
319bf215546Sopenharmony_ci                        break;
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci                case V3D_QPU_BRANCH_DEST_REL:
322bf215546Sopenharmony_ci                        fprintf(stderr, "  %d", instr->branch.offset);
323bf215546Sopenharmony_ci                        break;
324bf215546Sopenharmony_ci
325bf215546Sopenharmony_ci                case V3D_QPU_BRANCH_DEST_LINK_REG:
326bf215546Sopenharmony_ci                        fprintf(stderr, "  lri");
327bf215546Sopenharmony_ci                        break;
328bf215546Sopenharmony_ci
329bf215546Sopenharmony_ci                case V3D_QPU_BRANCH_DEST_REGFILE:
330bf215546Sopenharmony_ci                        fprintf(stderr, "  rf%d", instr->branch.raddr_a);
331bf215546Sopenharmony_ci                        break;
332bf215546Sopenharmony_ci                }
333bf215546Sopenharmony_ci
334bf215546Sopenharmony_ci                if (instr->branch.ub) {
335bf215546Sopenharmony_ci                        switch (instr->branch.bdu) {
336bf215546Sopenharmony_ci                        case V3D_QPU_BRANCH_DEST_ABS:
337bf215546Sopenharmony_ci                                fprintf(stderr, ", a:unif");
338bf215546Sopenharmony_ci                                break;
339bf215546Sopenharmony_ci
340bf215546Sopenharmony_ci                        case V3D_QPU_BRANCH_DEST_REL:
341bf215546Sopenharmony_ci                                fprintf(stderr, ", r:unif");
342bf215546Sopenharmony_ci                                break;
343bf215546Sopenharmony_ci
344bf215546Sopenharmony_ci                        case V3D_QPU_BRANCH_DEST_LINK_REG:
345bf215546Sopenharmony_ci                                fprintf(stderr, ", lri");
346bf215546Sopenharmony_ci                                break;
347bf215546Sopenharmony_ci
348bf215546Sopenharmony_ci                        case V3D_QPU_BRANCH_DEST_REGFILE:
349bf215546Sopenharmony_ci                                fprintf(stderr, ", rf%d", instr->branch.raddr_a);
350bf215546Sopenharmony_ci                                break;
351bf215546Sopenharmony_ci                        }
352bf215546Sopenharmony_ci                }
353bf215546Sopenharmony_ci                break;
354bf215546Sopenharmony_ci        }
355bf215546Sopenharmony_ci
356bf215546Sopenharmony_ci        if (vir_has_uniform(inst)) {
357bf215546Sopenharmony_ci                fprintf(stderr, " (");
358bf215546Sopenharmony_ci                vir_dump_uniform(c->uniform_contents[inst->uniform],
359bf215546Sopenharmony_ci                                 c->uniform_data[inst->uniform]);
360bf215546Sopenharmony_ci                fprintf(stderr, ")");
361bf215546Sopenharmony_ci        }
362bf215546Sopenharmony_ci}
363bf215546Sopenharmony_ci
364bf215546Sopenharmony_civoid
365bf215546Sopenharmony_civir_dump(struct v3d_compile *c)
366bf215546Sopenharmony_ci{
367bf215546Sopenharmony_ci        int ip = 0;
368bf215546Sopenharmony_ci        int pressure = 0;
369bf215546Sopenharmony_ci
370bf215546Sopenharmony_ci        vir_for_each_block(block, c) {
371bf215546Sopenharmony_ci                fprintf(stderr, "BLOCK %d:\n", block->index);
372bf215546Sopenharmony_ci                vir_for_each_inst(inst, block) {
373bf215546Sopenharmony_ci                        if (c->live_intervals_valid) {
374bf215546Sopenharmony_ci                                for (int i = 0; i < c->num_temps; i++) {
375bf215546Sopenharmony_ci                                        if (c->temp_start[i] == ip)
376bf215546Sopenharmony_ci                                                pressure++;
377bf215546Sopenharmony_ci                                }
378bf215546Sopenharmony_ci
379bf215546Sopenharmony_ci                                fprintf(stderr, "P%4d ", pressure);
380bf215546Sopenharmony_ci
381bf215546Sopenharmony_ci                                bool first = true;
382bf215546Sopenharmony_ci
383bf215546Sopenharmony_ci                                for (int i = 0; i < c->num_temps; i++) {
384bf215546Sopenharmony_ci                                        if (c->temp_start[i] != ip)
385bf215546Sopenharmony_ci                                                continue;
386bf215546Sopenharmony_ci
387bf215546Sopenharmony_ci                                        if (first) {
388bf215546Sopenharmony_ci                                                first = false;
389bf215546Sopenharmony_ci                                        } else {
390bf215546Sopenharmony_ci                                                fprintf(stderr, ", ");
391bf215546Sopenharmony_ci                                        }
392bf215546Sopenharmony_ci                                        if (BITSET_TEST(c->spillable, i))
393bf215546Sopenharmony_ci                                                fprintf(stderr, "S%4d", i);
394bf215546Sopenharmony_ci                                        else
395bf215546Sopenharmony_ci                                                fprintf(stderr, "U%4d", i);
396bf215546Sopenharmony_ci                                }
397bf215546Sopenharmony_ci
398bf215546Sopenharmony_ci                                if (first)
399bf215546Sopenharmony_ci                                        fprintf(stderr, "      ");
400bf215546Sopenharmony_ci                                else
401bf215546Sopenharmony_ci                                        fprintf(stderr, " ");
402bf215546Sopenharmony_ci                        }
403bf215546Sopenharmony_ci
404bf215546Sopenharmony_ci                        if (c->live_intervals_valid) {
405bf215546Sopenharmony_ci                                bool first = true;
406bf215546Sopenharmony_ci
407bf215546Sopenharmony_ci                                for (int i = 0; i < c->num_temps; i++) {
408bf215546Sopenharmony_ci                                        if (c->temp_end[i] != ip)
409bf215546Sopenharmony_ci                                                continue;
410bf215546Sopenharmony_ci
411bf215546Sopenharmony_ci                                        if (first) {
412bf215546Sopenharmony_ci                                                first = false;
413bf215546Sopenharmony_ci                                        } else {
414bf215546Sopenharmony_ci                                                fprintf(stderr, ", ");
415bf215546Sopenharmony_ci                                        }
416bf215546Sopenharmony_ci                                        fprintf(stderr, "E%4d", i);
417bf215546Sopenharmony_ci                                        pressure--;
418bf215546Sopenharmony_ci                                }
419bf215546Sopenharmony_ci
420bf215546Sopenharmony_ci                                if (first)
421bf215546Sopenharmony_ci                                        fprintf(stderr, "      ");
422bf215546Sopenharmony_ci                                else
423bf215546Sopenharmony_ci                                        fprintf(stderr, " ");
424bf215546Sopenharmony_ci                        }
425bf215546Sopenharmony_ci
426bf215546Sopenharmony_ci                        vir_dump_inst(c, inst);
427bf215546Sopenharmony_ci                        fprintf(stderr, "\n");
428bf215546Sopenharmony_ci                        ip++;
429bf215546Sopenharmony_ci                }
430bf215546Sopenharmony_ci                if (block->successors[1]) {
431bf215546Sopenharmony_ci                        fprintf(stderr, "-> BLOCK %d, %d\n",
432bf215546Sopenharmony_ci                                block->successors[0]->index,
433bf215546Sopenharmony_ci                                block->successors[1]->index);
434bf215546Sopenharmony_ci                } else if (block->successors[0]) {
435bf215546Sopenharmony_ci                        fprintf(stderr, "-> BLOCK %d\n",
436bf215546Sopenharmony_ci                                block->successors[0]->index);
437bf215546Sopenharmony_ci                }
438bf215546Sopenharmony_ci        }
439bf215546Sopenharmony_ci}
440