pan/midgard: Add units for more instructions
[mesa.git] / src / panfrost / midgard / midgard_print.c
1 /*
2 * Copyright (C) 2018-2019 Alyssa Rosenzweig <alyssa@rosenzweig.io>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
24 #include "compiler.h"
25 #include "helpers.h"
26 #include "midgard_ops.h"
27
28 /* Pretty printer for Midgard IR, for use debugging compiler-internal
29 * passes like register allocation. The output superficially resembles
30 * Midgard assembly, with the exception that unit information and such is
31 * (normally) omitted, and generic indices are usually used instead of
32 * registers */
33
34 static void
35 mir_print_source(int source)
36 {
37 if (source >= SSA_FIXED_MINIMUM) {
38 /* Specific register */
39 int reg = SSA_REG_FROM_FIXED(source);
40
41 /* TODO: Moving threshold */
42 if (reg > 16 && reg < 24)
43 printf("u%d", 23 - reg);
44 else
45 printf("r%d", reg);
46 } else {
47 printf("%d", source);
48 }
49 }
50
51 void
52 mir_print_instruction(midgard_instruction *ins)
53 {
54 printf("\t");
55
56 switch (ins->type) {
57 case TAG_ALU_4: {
58 midgard_alu_op op = ins->alu.op;
59 const char *name = alu_opcode_props[op].name;
60
61 if (ins->unit)
62 printf("%d.", ins->unit);
63
64 printf("%s", name ? name : "??");
65 break;
66 }
67
68 case TAG_LOAD_STORE_4: {
69 midgard_load_store_op op = ins->load_store.op;
70 const char *name = load_store_opcode_names[op];
71
72 assert(name);
73 printf("%s", name);
74 break;
75 }
76
77 case TAG_TEXTURE_4: {
78 printf("texture");
79 break;
80 }
81
82 default:
83 assert(0);
84 }
85
86 ssa_args *args = &ins->ssa_args;
87
88 printf(" %d, ", args->dest);
89
90 mir_print_source(args->src0);
91 printf(", ");
92
93 if (args->inline_constant)
94 printf("#%d", ins->inline_constant);
95 else
96 mir_print_source(args->src1);
97
98 if (ins->has_constants)
99 printf(" <%f, %f, %f, %f>", ins->constants[0], ins->constants[1], ins->constants[2], ins->constants[3]);
100
101 printf("\n");
102 }
103
104 /* Dumps MIR for a block or entire shader respective */
105
106 void
107 mir_print_block(midgard_block *block)
108 {
109 printf("%p: {\n", block);
110
111 mir_foreach_instr_in_block(block, ins) {
112 mir_print_instruction(ins);
113 }
114
115 printf("}");
116
117 if (block->nr_successors) {
118 printf(" -> ");
119 for (unsigned i = 0; i < block->nr_successors; ++i) {
120 printf("%p%s", block->successors[i],
121 (i + 1) != block->nr_successors ? ", " : "");
122 }
123 }
124
125 printf("\n\n");
126 }
127
128 void
129 mir_print_shader(compiler_context *ctx)
130 {
131 mir_foreach_block(ctx, block) {
132 mir_print_block(block);
133 }
134 }
135
136 void
137 mir_print_bundle(midgard_bundle *bundle)
138 {
139 printf("[\n");
140
141 for (unsigned i = 0; i < bundle->instruction_count; ++i) {
142 midgard_instruction *ins = bundle->instructions[i];
143 mir_print_instruction(ins);
144 }
145
146 printf("]\n");
147 }