1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
/* -*- mode: C; c-file-style: "k&r"; tab-width 4; indent-tabs-mode: t; -*- */
/*
* Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Authors:
* Rob Clark <robclark@freedesktop.org>
*/
#include <stdarg.h>
#include <stdio.h>
#include "ir3.h"
#define PTRID(x) ((unsigned long)(x))
static void print_instr_name(struct ir3_instruction *instr)
{
#ifdef DEBUG
printf("%04u:", instr->serialno);
#endif
printf("%03u: ", instr->depth);
if (instr->flags & IR3_INSTR_SY)
printf("(sy)");
if (instr->flags & IR3_INSTR_SS)
printf("(ss)");
if (is_meta(instr)) {
switch(instr->opc) {
case OPC_META_PHI:
printf("Φ");
break;
default:
/* shouldn't hit here.. just for debugging: */
switch (instr->opc) {
case OPC_META_INPUT: printf("_meta:in"); break;
case OPC_META_OUTPUT: printf("_meta:out"); break;
case OPC_META_FO: printf("_meta:fo"); break;
case OPC_META_FI: printf("_meta:fi"); break;
case OPC_META_FLOW: printf("_meta:flow"); break;
default: printf("_meta:%d", instr->opc); break;
}
break;
}
} else if (instr->category == 1) {
static const char *type[] = {
[TYPE_F16] = "f16",
[TYPE_F32] = "f32",
[TYPE_U16] = "u16",
[TYPE_U32] = "u32",
[TYPE_S16] = "s16",
[TYPE_S32] = "s32",
[TYPE_U8] = "u8",
[TYPE_S8] = "s8",
};
if (instr->cat1.src_type == instr->cat1.dst_type)
printf("mov");
else
printf("cov");
printf(".%s%s", type[instr->cat1.src_type], type[instr->cat1.dst_type]);
} else {
printf("%s", ir3_instr_name(instr));
if (instr->flags & IR3_INSTR_3D)
printf(".3d");
if (instr->flags & IR3_INSTR_A)
printf(".a");
if (instr->flags & IR3_INSTR_O)
printf(".o");
if (instr->flags & IR3_INSTR_P)
printf(".p");
if (instr->flags & IR3_INSTR_S)
printf(".s");
if (instr->flags & IR3_INSTR_S2EN)
printf(".s2en");
}
}
static void print_reg_name(struct ir3_register *reg, bool followssa)
{
if ((reg->flags & (IR3_REG_FABS | IR3_REG_SABS)) &&
(reg->flags & (IR3_REG_FNEG | IR3_REG_SNEG | IR3_REG_BNOT)))
printf("(absneg)");
else if (reg->flags & (IR3_REG_FNEG | IR3_REG_SNEG | IR3_REG_BNOT))
printf("(neg)");
else if (reg->flags & (IR3_REG_FABS | IR3_REG_SABS))
printf("(abs)");
if (reg->flags & IR3_REG_IMMED) {
printf("imm[%f,%d,0x%x]", reg->fim_val, reg->iim_val, reg->iim_val);
} else if (reg->flags & IR3_REG_SSA) {
printf("_");
if (followssa) {
printf("[");
print_instr_name(reg->instr);
printf("]");
}
} else if (reg->flags & IR3_REG_RELATIV) {
if (reg->flags & IR3_REG_HALF)
printf("h");
if (reg->flags & IR3_REG_CONST)
printf("c<a0.x + %u>", reg->num);
else
printf("\x1b[0;31mr<a0.x + %u>\x1b[0m (%u)", reg->num, reg->size);
} else {
if (reg->flags & IR3_REG_HALF)
printf("h");
if (reg->flags & IR3_REG_CONST)
printf("c%u.%c", reg_num(reg), "xyzw"[reg_comp(reg)]);
else
printf("\x1b[0;31mr%u.%c\x1b[0m", reg_num(reg), "xyzw"[reg_comp(reg)]);
}
}
static void
tab(int lvl)
{
for (int i = 0; i < lvl; i++)
printf("\t");
}
static void
print_instr(struct ir3_instruction *instr, int lvl)
{
unsigned i;
tab(lvl);
print_instr_name(instr);
for (i = 0; i < instr->regs_count; i++) {
struct ir3_register *reg = instr->regs[i];
printf(i ? ", " : " ");
print_reg_name(reg, !!i);
}
if (instr->address) {
printf(", address=_");
printf("[");
print_instr_name(instr->address);
printf("]");
}
if (instr->fanin) {
printf(", fanin=_");
printf("[");
print_instr_name(instr->fanin);
printf("]");
}
if (is_meta(instr)) {
if (instr->opc == OPC_META_FO) {
printf(", off=%d", instr->fo.off);
} else if ((instr->opc == OPC_META_FI) && instr->fi.aid) {
printf(", aid=%d", instr->fi.aid);
}
}
printf("\n");
}
void ir3_print_instr(struct ir3_instruction *instr)
{
print_instr(instr, 0);
}
static void
print_block(struct ir3_block *block, int lvl)
{
tab(lvl); printf("block {\n");
list_for_each_entry (struct ir3_instruction, instr, &block->instr_list, node) {
print_instr(instr, lvl+1);
}
tab(lvl); printf("}\n");
}
void
ir3_print(struct ir3 *ir)
{
struct ir3_block *block = ir->block;
print_block(block, 0);
for (unsigned i = 0; i < block->noutputs; i++) {
if (!block->outputs[i])
continue;
printf("out%d: ", i);
print_instr(block->outputs[i], 0);
}
}
|