Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/freedreno/ir3/ir3_cp.c
4565 views
1
/*
2
* Copyright (C) 2014 Rob Clark <[email protected]>
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
* Authors:
24
* Rob Clark <[email protected]>
25
*/
26
27
#include <math.h>
28
#include "util/half_float.h"
29
#include "util/u_math.h"
30
31
#include "ir3.h"
32
#include "ir3_compiler.h"
33
#include "ir3_shader.h"
34
35
#define swap(a, b) \
36
do { \
37
__typeof(a) __tmp = (a); \
38
(a) = (b); \
39
(b) = __tmp; \
40
} while (0)
41
42
/*
43
* Copy Propagate:
44
*/
45
46
struct ir3_cp_ctx {
47
struct ir3 *shader;
48
struct ir3_shader_variant *so;
49
bool progress;
50
};
51
52
/* is it a type preserving mov, with ok flags?
53
*
54
* @instr: the mov to consider removing
55
* @dst_instr: the instruction consuming the mov (instr)
56
*
57
* TODO maybe drop allow_flags since this is only false when dst is
58
* NULL (ie. outputs)
59
*/
60
static bool
61
is_eligible_mov(struct ir3_instruction *instr,
62
struct ir3_instruction *dst_instr, bool allow_flags)
63
{
64
if (is_same_type_mov(instr)) {
65
struct ir3_register *dst = instr->dsts[0];
66
struct ir3_register *src = instr->srcs[0];
67
struct ir3_instruction *src_instr = ssa(src);
68
69
/* only if mov src is SSA (not const/immed): */
70
if (!src_instr)
71
return false;
72
73
/* no indirect: */
74
if (dst->flags & IR3_REG_RELATIV)
75
return false;
76
if (src->flags & IR3_REG_RELATIV)
77
return false;
78
79
if (src->flags & IR3_REG_ARRAY)
80
return false;
81
82
if (!allow_flags)
83
if (src->flags & (IR3_REG_FABS | IR3_REG_FNEG | IR3_REG_SABS |
84
IR3_REG_SNEG | IR3_REG_BNOT))
85
return false;
86
87
return true;
88
}
89
return false;
90
}
91
92
/* we can end up with extra cmps.s from frontend, which uses a
93
*
94
* cmps.s p0.x, cond, 0
95
*
96
* as a way to mov into the predicate register. But frequently 'cond'
97
* is itself a cmps.s/cmps.f/cmps.u. So detect this special case.
98
*/
99
static bool
100
is_foldable_double_cmp(struct ir3_instruction *cmp)
101
{
102
struct ir3_instruction *cond = ssa(cmp->srcs[0]);
103
return (cmp->dsts[0]->num == regid(REG_P0, 0)) && cond &&
104
(cmp->srcs[1]->flags & IR3_REG_IMMED) &&
105
(cmp->srcs[1]->iim_val == 0) &&
106
(cmp->cat2.condition == IR3_COND_NE) &&
107
(!cond->address || cond->address->def->instr->block == cmp->block);
108
}
109
110
/* propagate register flags from src to dst.. negates need special
111
* handling to cancel each other out.
112
*/
113
static void
114
combine_flags(unsigned *dstflags, struct ir3_instruction *src)
115
{
116
unsigned srcflags = src->srcs[0]->flags;
117
118
/* if what we are combining into already has (abs) flags,
119
* we can drop (neg) from src:
120
*/
121
if (*dstflags & IR3_REG_FABS)
122
srcflags &= ~IR3_REG_FNEG;
123
if (*dstflags & IR3_REG_SABS)
124
srcflags &= ~IR3_REG_SNEG;
125
126
if (srcflags & IR3_REG_FABS)
127
*dstflags |= IR3_REG_FABS;
128
if (srcflags & IR3_REG_SABS)
129
*dstflags |= IR3_REG_SABS;
130
if (srcflags & IR3_REG_FNEG)
131
*dstflags ^= IR3_REG_FNEG;
132
if (srcflags & IR3_REG_SNEG)
133
*dstflags ^= IR3_REG_SNEG;
134
if (srcflags & IR3_REG_BNOT)
135
*dstflags ^= IR3_REG_BNOT;
136
137
*dstflags &= ~IR3_REG_SSA;
138
*dstflags |= srcflags & IR3_REG_SSA;
139
*dstflags |= srcflags & IR3_REG_CONST;
140
*dstflags |= srcflags & IR3_REG_IMMED;
141
*dstflags |= srcflags & IR3_REG_RELATIV;
142
*dstflags |= srcflags & IR3_REG_ARRAY;
143
*dstflags |= srcflags & IR3_REG_SHARED;
144
145
/* if src of the src is boolean we can drop the (abs) since we know
146
* the source value is already a postitive integer. This cleans
147
* up the absnegs that get inserted when converting between nir and
148
* native boolean (see ir3_b2n/n2b)
149
*/
150
struct ir3_instruction *srcsrc = ssa(src->srcs[0]);
151
if (srcsrc && is_bool(srcsrc))
152
*dstflags &= ~IR3_REG_SABS;
153
}
154
155
/* Tries lowering an immediate register argument to a const buffer access by
156
* adding to the list of immediates to be pushed to the const buffer when
157
* switching to this shader.
158
*/
159
static bool
160
lower_immed(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr, unsigned n,
161
struct ir3_register *reg, unsigned new_flags)
162
{
163
if (!(new_flags & IR3_REG_IMMED))
164
return false;
165
166
new_flags &= ~IR3_REG_IMMED;
167
new_flags |= IR3_REG_CONST;
168
169
if (!ir3_valid_flags(instr, n, new_flags))
170
return false;
171
172
reg = ir3_reg_clone(ctx->shader, reg);
173
174
/* Half constant registers seems to handle only 32-bit values
175
* within floating-point opcodes. So convert back to 32-bit values.
176
*/
177
bool f_opcode =
178
(is_cat2_float(instr->opc) || is_cat3_float(instr->opc)) ? true : false;
179
if (f_opcode && (new_flags & IR3_REG_HALF))
180
reg->uim_val = fui(_mesa_half_to_float(reg->uim_val));
181
182
/* in some cases, there are restrictions on (abs)/(neg) plus const..
183
* so just evaluate those and clear the flags:
184
*/
185
if (new_flags & IR3_REG_SABS) {
186
reg->iim_val = abs(reg->iim_val);
187
new_flags &= ~IR3_REG_SABS;
188
}
189
190
if (new_flags & IR3_REG_FABS) {
191
reg->fim_val = fabs(reg->fim_val);
192
new_flags &= ~IR3_REG_FABS;
193
}
194
195
if (new_flags & IR3_REG_SNEG) {
196
reg->iim_val = -reg->iim_val;
197
new_flags &= ~IR3_REG_SNEG;
198
}
199
200
if (new_flags & IR3_REG_FNEG) {
201
reg->fim_val = -reg->fim_val;
202
new_flags &= ~IR3_REG_FNEG;
203
}
204
205
/* Reallocate for 4 more elements whenever it's necessary. Note that ir3
206
* printing relies on having groups of 4 dwords, so we fill the unused
207
* slots with a dummy value.
208
*/
209
struct ir3_const_state *const_state = ir3_const_state(ctx->so);
210
if (const_state->immediates_count == const_state->immediates_size) {
211
const_state->immediates = rerzalloc(
212
const_state, const_state->immediates,
213
__typeof__(const_state->immediates[0]), const_state->immediates_size,
214
const_state->immediates_size + 4);
215
const_state->immediates_size += 4;
216
217
for (int i = const_state->immediates_count;
218
i < const_state->immediates_size; i++)
219
const_state->immediates[i] = 0xd0d0d0d0;
220
}
221
222
int i;
223
for (i = 0; i < const_state->immediates_count; i++) {
224
if (const_state->immediates[i] == reg->uim_val)
225
break;
226
}
227
228
if (i == const_state->immediates_count) {
229
/* Add on a new immediate to be pushed, if we have space left in the
230
* constbuf.
231
*/
232
if (const_state->offsets.immediate + const_state->immediates_count / 4 >=
233
ir3_max_const(ctx->so))
234
return false;
235
236
const_state->immediates[i] = reg->uim_val;
237
const_state->immediates_count++;
238
}
239
240
reg->flags = new_flags;
241
reg->num = i + (4 * const_state->offsets.immediate);
242
243
instr->srcs[n] = reg;
244
245
return true;
246
}
247
248
static void
249
unuse(struct ir3_instruction *instr)
250
{
251
debug_assert(instr->use_count > 0);
252
253
if (--instr->use_count == 0) {
254
struct ir3_block *block = instr->block;
255
256
instr->barrier_class = 0;
257
instr->barrier_conflict = 0;
258
259
/* we don't want to remove anything in keeps (which could
260
* be things like array store's)
261
*/
262
for (unsigned i = 0; i < block->keeps_count; i++) {
263
debug_assert(block->keeps[i] != instr);
264
}
265
}
266
}
267
268
/**
269
* Handles the special case of the 2nd src (n == 1) to "normal" mad
270
* instructions, which cannot reference a constant. See if it is
271
* possible to swap the 1st and 2nd sources.
272
*/
273
static bool
274
try_swap_mad_two_srcs(struct ir3_instruction *instr, unsigned new_flags)
275
{
276
if (!is_mad(instr->opc))
277
return false;
278
279
/* NOTE: pre-swap first two src's before valid_flags(),
280
* which might try to dereference the n'th src:
281
*/
282
swap(instr->srcs[0], instr->srcs[1]);
283
284
/* cat3 doesn't encode immediate, but we can lower immediate
285
* to const if that helps:
286
*/
287
if (new_flags & IR3_REG_IMMED) {
288
new_flags &= ~IR3_REG_IMMED;
289
new_flags |= IR3_REG_CONST;
290
}
291
292
bool valid_swap =
293
/* can we propagate mov if we move 2nd src to first? */
294
ir3_valid_flags(instr, 0, new_flags) &&
295
/* and does first src fit in second slot? */
296
ir3_valid_flags(instr, 1, instr->srcs[1]->flags);
297
298
if (!valid_swap) {
299
/* put things back the way they were: */
300
swap(instr->srcs[0], instr->srcs[1]);
301
} /* otherwise leave things swapped */
302
303
return valid_swap;
304
}
305
306
/**
307
* Handle cp for a given src register. This additionally handles
308
* the cases of collapsing immedate/const (which replace the src
309
* register with a non-ssa src) or collapsing mov's from relative
310
* src (which needs to also fixup the address src reference by the
311
* instruction).
312
*/
313
static bool
314
reg_cp(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr,
315
struct ir3_register *reg, unsigned n)
316
{
317
struct ir3_instruction *src = ssa(reg);
318
319
/* Values that are uniform inside a loop can become divergent outside
320
* it if the loop has a divergent trip count. This means that we can't
321
* propagate a copy of a shared to non-shared register if it would
322
* make the shared reg's live range extend outside of its loop. Users
323
* outside the loop would see the value for the thread(s) that last
324
* exited the loop, rather than for their own thread.
325
*/
326
if ((src->dsts[0]->flags & IR3_REG_SHARED) &&
327
src->block->loop_id != instr->block->loop_id)
328
return false;
329
330
if (is_eligible_mov(src, instr, true)) {
331
/* simple case, no immed/const/relativ, only mov's w/ ssa src: */
332
struct ir3_register *src_reg = src->srcs[0];
333
unsigned new_flags = reg->flags;
334
335
combine_flags(&new_flags, src);
336
337
if (ir3_valid_flags(instr, n, new_flags)) {
338
if (new_flags & IR3_REG_ARRAY) {
339
debug_assert(!(reg->flags & IR3_REG_ARRAY));
340
reg->array = src_reg->array;
341
}
342
reg->flags = new_flags;
343
reg->def = src_reg->def;
344
345
instr->barrier_class |= src->barrier_class;
346
instr->barrier_conflict |= src->barrier_conflict;
347
348
unuse(src);
349
reg->def->instr->use_count++;
350
351
return true;
352
}
353
} else if ((is_same_type_mov(src) || is_const_mov(src)) &&
354
/* cannot collapse const/immed/etc into control flow: */
355
opc_cat(instr->opc) != 0) {
356
/* immed/const/etc cases, which require some special handling: */
357
struct ir3_register *src_reg = src->srcs[0];
358
unsigned new_flags = reg->flags;
359
360
if (src_reg->flags & IR3_REG_ARRAY)
361
return false;
362
363
combine_flags(&new_flags, src);
364
365
if (!ir3_valid_flags(instr, n, new_flags)) {
366
/* See if lowering an immediate to const would help. */
367
if (lower_immed(ctx, instr, n, src_reg, new_flags))
368
return true;
369
370
/* special case for "normal" mad instructions, we can
371
* try swapping the first two args if that fits better.
372
*
373
* the "plain" MAD's (ie. the ones that don't shift first
374
* src prior to multiply) can swap their first two srcs if
375
* src[0] is !CONST and src[1] is CONST:
376
*/
377
if ((n == 1) && try_swap_mad_two_srcs(instr, new_flags)) {
378
return true;
379
} else {
380
return false;
381
}
382
}
383
384
/* Here we handle the special case of mov from
385
* CONST and/or RELATIV. These need to be handled
386
* specially, because in the case of move from CONST
387
* there is no src ir3_instruction so we need to
388
* replace the ir3_register. And in the case of
389
* RELATIV we need to handle the address register
390
* dependency.
391
*/
392
if (src_reg->flags & IR3_REG_CONST) {
393
/* an instruction cannot reference two different
394
* address registers:
395
*/
396
if ((src_reg->flags & IR3_REG_RELATIV) &&
397
conflicts(instr->address, reg->def->instr->address))
398
return false;
399
400
/* This seems to be a hw bug, or something where the timings
401
* just somehow don't work out. This restriction may only
402
* apply if the first src is also CONST.
403
*/
404
if ((opc_cat(instr->opc) == 3) && (n == 2) &&
405
(src_reg->flags & IR3_REG_RELATIV) && (src_reg->array.offset == 0))
406
return false;
407
408
/* When narrowing constant from 32b to 16b, it seems
409
* to work only for float. So we should do this only with
410
* float opcodes.
411
*/
412
if (src->cat1.dst_type == TYPE_F16) {
413
/* TODO: should we have a way to tell phi/collect to use a
414
* float move so that this is legal?
415
*/
416
if (is_meta(instr))
417
return false;
418
if (instr->opc == OPC_MOV && !type_float(instr->cat1.src_type))
419
return false;
420
if (!is_cat2_float(instr->opc) && !is_cat3_float(instr->opc))
421
return false;
422
} else if (src->cat1.dst_type == TYPE_U16) {
423
if (is_meta(instr))
424
return true;
425
/* Since we set CONSTANT_DEMOTION_ENABLE, a float reference of
426
* what was a U16 value read from the constbuf would incorrectly
427
* do 32f->16f conversion, when we want to read a 16f value.
428
*/
429
if (is_cat2_float(instr->opc) || is_cat3_float(instr->opc))
430
return false;
431
}
432
433
src_reg = ir3_reg_clone(instr->block->shader, src_reg);
434
src_reg->flags = new_flags;
435
instr->srcs[n] = src_reg;
436
437
if (src_reg->flags & IR3_REG_RELATIV)
438
ir3_instr_set_address(instr, reg->def->instr->address->def->instr);
439
440
return true;
441
}
442
443
if (src_reg->flags & IR3_REG_IMMED) {
444
int32_t iim_val = src_reg->iim_val;
445
446
debug_assert((opc_cat(instr->opc) == 1) ||
447
(opc_cat(instr->opc) == 2) ||
448
(opc_cat(instr->opc) == 6) ||
449
is_meta(instr) ||
450
(is_mad(instr->opc) && (n == 0)));
451
452
if ((opc_cat(instr->opc) == 2) &&
453
!ir3_cat2_int(instr->opc)) {
454
iim_val = ir3_flut(src_reg);
455
if (iim_val < 0) {
456
/* Fall back to trying to load the immediate as a const: */
457
return lower_immed(ctx, instr, n, src_reg, new_flags);
458
}
459
}
460
461
if (new_flags & IR3_REG_SABS)
462
iim_val = abs(iim_val);
463
464
if (new_flags & IR3_REG_SNEG)
465
iim_val = -iim_val;
466
467
if (new_flags & IR3_REG_BNOT)
468
iim_val = ~iim_val;
469
470
/* other than category 1 (mov) we can only encode up to 10 bits: */
471
if (ir3_valid_flags(instr, n, new_flags) &&
472
((instr->opc == OPC_MOV) || is_meta(instr) ||
473
!((iim_val & ~0x3ff) && (-iim_val & ~0x3ff)))) {
474
new_flags &= ~(IR3_REG_SABS | IR3_REG_SNEG | IR3_REG_BNOT);
475
src_reg = ir3_reg_clone(instr->block->shader, src_reg);
476
src_reg->flags = new_flags;
477
src_reg->iim_val = iim_val;
478
instr->srcs[n] = src_reg;
479
480
return true;
481
} else {
482
/* Fall back to trying to load the immediate as a const: */
483
return lower_immed(ctx, instr, n, src_reg, new_flags);
484
}
485
}
486
}
487
488
return false;
489
}
490
491
/* Handle special case of eliminating output mov, and similar cases where
492
* there isn't a normal "consuming" instruction. In this case we cannot
493
* collapse flags (ie. output mov from const, or w/ abs/neg flags, cannot
494
* be eliminated)
495
*/
496
static struct ir3_instruction *
497
eliminate_output_mov(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr)
498
{
499
if (is_eligible_mov(instr, NULL, false)) {
500
struct ir3_register *reg = instr->srcs[0];
501
if (!(reg->flags & IR3_REG_ARRAY)) {
502
struct ir3_instruction *src_instr = ssa(reg);
503
debug_assert(src_instr);
504
ctx->progress = true;
505
return src_instr;
506
}
507
}
508
return instr;
509
}
510
511
/**
512
* Find instruction src's which are mov's that can be collapsed, replacing
513
* the mov dst with the mov src
514
*/
515
static void
516
instr_cp(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr)
517
{
518
if (instr->srcs_count == 0)
519
return;
520
521
if (ir3_instr_check_mark(instr))
522
return;
523
524
/* walk down the graph from each src: */
525
bool progress;
526
do {
527
progress = false;
528
foreach_src_n (reg, n, instr) {
529
struct ir3_instruction *src = ssa(reg);
530
531
if (!src)
532
continue;
533
534
instr_cp(ctx, src);
535
536
/* TODO non-indirect access we could figure out which register
537
* we actually want and allow cp..
538
*/
539
if (reg->flags & IR3_REG_ARRAY)
540
continue;
541
542
/* Don't CP absneg into meta instructions, that won't end well: */
543
if (is_meta(instr) && (src->opc != OPC_MOV))
544
continue;
545
546
/* Don't CP mova and mova1 into their users */
547
if (writes_addr0(src) || writes_addr1(src))
548
continue;
549
550
progress |= reg_cp(ctx, instr, reg, n);
551
ctx->progress |= progress;
552
}
553
} while (progress);
554
555
/* After folding a mov's source we may wind up with a type-converting mov
556
* of an immediate. This happens e.g. with texture descriptors, since we
557
* narrow the descriptor (which may be a constant) to a half-reg in ir3.
558
* By converting the immediate in-place to the destination type, we can
559
* turn the mov into a same-type mov so that it can be further propagated.
560
*/
561
if (instr->opc == OPC_MOV && (instr->srcs[0]->flags & IR3_REG_IMMED) &&
562
instr->cat1.src_type != instr->cat1.dst_type &&
563
/* Only do uint types for now, until we generate other types of
564
* mov's during instruction selection.
565
*/
566
full_type(instr->cat1.src_type) == TYPE_U32 &&
567
full_type(instr->cat1.dst_type) == TYPE_U32) {
568
uint32_t uimm = instr->srcs[0]->uim_val;
569
if (instr->cat1.dst_type == TYPE_U16)
570
uimm &= 0xffff;
571
instr->srcs[0]->uim_val = uimm;
572
if (instr->dsts[0]->flags & IR3_REG_HALF)
573
instr->srcs[0]->flags |= IR3_REG_HALF;
574
else
575
instr->srcs[0]->flags &= ~IR3_REG_HALF;
576
instr->cat1.src_type = instr->cat1.dst_type;
577
ctx->progress = true;
578
}
579
580
/* Re-write the instruction writing predicate register to get rid
581
* of the double cmps.
582
*/
583
if ((instr->opc == OPC_CMPS_S) && is_foldable_double_cmp(instr)) {
584
struct ir3_instruction *cond = ssa(instr->srcs[0]);
585
switch (cond->opc) {
586
case OPC_CMPS_S:
587
case OPC_CMPS_F:
588
case OPC_CMPS_U:
589
instr->opc = cond->opc;
590
instr->flags = cond->flags;
591
instr->cat2 = cond->cat2;
592
if (cond->address)
593
ir3_instr_set_address(instr, cond->address->def->instr);
594
instr->srcs[0] = ir3_reg_clone(ctx->shader, cond->srcs[0]);
595
instr->srcs[1] = ir3_reg_clone(ctx->shader, cond->srcs[1]);
596
instr->barrier_class |= cond->barrier_class;
597
instr->barrier_conflict |= cond->barrier_conflict;
598
unuse(cond);
599
ctx->progress = true;
600
break;
601
default:
602
break;
603
}
604
}
605
606
/* Handle converting a sam.s2en (taking samp/tex idx params via register)
607
* into a normal sam (encoding immediate samp/tex idx) if they are
608
* immediate. This saves some instructions and regs in the common case
609
* where we know samp/tex at compile time. This needs to be done in the
610
* frontend for bindless tex, though, so don't replicate it here.
611
*/
612
if (is_tex(instr) && (instr->flags & IR3_INSTR_S2EN) &&
613
!(instr->flags & IR3_INSTR_B) &&
614
!(ir3_shader_debug & IR3_DBG_FORCES2EN)) {
615
/* The first src will be a collect, if both of it's
616
* two sources are mov from imm, then we can
617
*/
618
struct ir3_instruction *samp_tex = ssa(instr->srcs[0]);
619
620
debug_assert(samp_tex->opc == OPC_META_COLLECT);
621
622
struct ir3_register *samp = samp_tex->srcs[0];
623
struct ir3_register *tex = samp_tex->srcs[1];
624
625
if ((samp->flags & IR3_REG_IMMED) && (tex->flags & IR3_REG_IMMED)) {
626
instr->flags &= ~IR3_INSTR_S2EN;
627
instr->cat5.samp = samp->iim_val;
628
instr->cat5.tex = tex->iim_val;
629
630
/* shuffle around the regs to remove the first src: */
631
instr->srcs_count--;
632
for (unsigned i = 0; i < instr->srcs_count; i++) {
633
instr->srcs[i] = instr->srcs[i + 1];
634
}
635
636
ctx->progress = true;
637
}
638
}
639
}
640
641
bool
642
ir3_cp(struct ir3 *ir, struct ir3_shader_variant *so)
643
{
644
struct ir3_cp_ctx ctx = {
645
.shader = ir,
646
.so = so,
647
};
648
649
/* This is a bit annoying, and probably wouldn't be necessary if we
650
* tracked a reverse link from producing instruction to consumer.
651
* But we need to know when we've eliminated the last consumer of
652
* a mov, so we need to do a pass to first count consumers of a
653
* mov.
654
*/
655
foreach_block (block, &ir->block_list) {
656
foreach_instr (instr, &block->instr_list) {
657
658
/* by the way, we don't account for false-dep's, so the CP
659
* pass should always happen before false-dep's are inserted
660
*/
661
debug_assert(instr->deps_count == 0);
662
663
foreach_ssa_src (src, instr) {
664
src->use_count++;
665
}
666
}
667
}
668
669
ir3_clear_mark(ir);
670
671
foreach_block (block, &ir->block_list) {
672
if (block->condition) {
673
instr_cp(&ctx, block->condition);
674
block->condition = eliminate_output_mov(&ctx, block->condition);
675
}
676
677
for (unsigned i = 0; i < block->keeps_count; i++) {
678
instr_cp(&ctx, block->keeps[i]);
679
block->keeps[i] = eliminate_output_mov(&ctx, block->keeps[i]);
680
}
681
}
682
683
return ctx.progress;
684
}
685
686