pan/midgard: Optimize branches with inverted arguments
[mesa.git] / src / panfrost / midgard / compiler.h
1 /*
2 * Copyright (C) 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 #ifndef _MDG_COMPILER_H
25 #define _MDG_COMPILER_H
26
27 #include "midgard.h"
28 #include "helpers.h"
29 #include "midgard_compile.h"
30 #include "lcra.h"
31
32 #include "util/hash_table.h"
33 #include "util/u_dynarray.h"
34 #include "util/set.h"
35 #include "util/list.h"
36
37 #include "main/mtypes.h"
38 #include "compiler/nir_types.h"
39 #include "compiler/nir/nir.h"
40
41 /* Forward declare */
42 struct midgard_block;
43
44 /* Target types. Defaults to TARGET_GOTO (the type corresponding directly to
45 * the hardware), hence why that must be zero. TARGET_DISCARD signals this
46 * instruction is actually a discard op. */
47
48 #define TARGET_GOTO 0
49 #define TARGET_BREAK 1
50 #define TARGET_CONTINUE 2
51 #define TARGET_DISCARD 3
52
53 typedef struct midgard_branch {
54 /* If conditional, the condition is specified in r31.w */
55 bool conditional;
56
57 /* For conditionals, if this is true, we branch on FALSE. If false, we branch on TRUE. */
58 bool invert_conditional;
59
60 /* Branch targets: the start of a block, the start of a loop (continue), the end of a loop (break). Value is one of TARGET_ */
61 unsigned target_type;
62
63 /* The actual target */
64 union {
65 int target_block;
66 int target_break;
67 int target_continue;
68 };
69 } midgard_branch;
70
71 /* Generic in-memory data type repesenting a single logical instruction, rather
72 * than a single instruction group. This is the preferred form for code gen.
73 * Multiple midgard_insturctions will later be combined during scheduling,
74 * though this is not represented in this structure. Its format bridges
75 * the low-level binary representation with the higher level semantic meaning.
76 *
77 * Notably, it allows registers to be specified as block local SSA, for code
78 * emitted before the register allocation pass.
79 */
80
81 #define MIR_SRC_COUNT 4
82 #define MIR_VEC_COMPONENTS 16
83
84 typedef struct midgard_instruction {
85 /* Must be first for casting */
86 struct list_head link;
87
88 unsigned type; /* ALU, load/store, texture */
89
90 /* Instruction arguments represented as block-local SSA
91 * indices, rather than registers. ~0 means unused. */
92 unsigned src[MIR_SRC_COUNT];
93 unsigned dest;
94
95 /* vec16 swizzle, unpacked, per source */
96 unsigned swizzle[MIR_SRC_COUNT][MIR_VEC_COMPONENTS];
97
98 /* Special fields for an ALU instruction */
99 midgard_reg_info registers;
100
101 /* I.e. (1 << alu_bit) */
102 int unit;
103
104 bool has_constants;
105 uint32_t constants[4];
106 uint16_t inline_constant;
107 bool has_blend_constant;
108 bool has_inline_constant;
109
110 bool compact_branch;
111 bool writeout;
112
113 /* Kind of a hack, but hint against aggressive DCE */
114 bool dont_eliminate;
115
116 /* Masks in a saneish format. One bit per channel, not packed fancy.
117 * Use this instead of the op specific ones, and switch over at emit
118 * time */
119
120 uint16_t mask;
121
122 /* For ALU ops only: set to true to invert (bitwise NOT) the
123 * destination of an integer-out op. Not implemented in hardware but
124 * allows more optimizations */
125
126 bool invert;
127
128 /* Hint for the register allocator not to spill the destination written
129 * from this instruction (because it is a spill/unspill node itself).
130 * Bitmask of spilled classes */
131
132 unsigned no_spill;
133
134 /* Generic hint for intra-pass use */
135 bool hint;
136
137 /* During scheduling, the backwards dependency graph
138 * (DAG). nr_dependencies is the number of unscheduled
139 * instructions that must still be scheduled after
140 * (before) this instruction. dependents are which
141 * instructions need to be scheduled before (after) this
142 * instruction. */
143
144 unsigned nr_dependencies;
145 BITSET_WORD *dependents;
146
147 /* For load/store ops.. force 64-bit destination */
148 bool load_64;
149
150 union {
151 midgard_load_store_word load_store;
152 midgard_vector_alu alu;
153 midgard_texture_word texture;
154 midgard_branch_extended branch_extended;
155 uint16_t br_compact;
156
157 /* General branch, rather than packed br_compact. Higher level
158 * than the other components */
159 midgard_branch branch;
160 };
161 } midgard_instruction;
162
163 typedef struct midgard_block {
164 /* Link to next block. Must be first for mir_get_block */
165 struct list_head link;
166
167 /* List of midgard_instructions emitted for the current block */
168 struct list_head instructions;
169
170 /* Index of the block in source order */
171 unsigned source_id;
172
173 bool is_scheduled;
174
175 /* List of midgard_bundles emitted (after the scheduler has run) */
176 struct util_dynarray bundles;
177
178 /* Number of quadwords _actually_ emitted, as determined after scheduling */
179 unsigned quadword_count;
180
181 /* Succeeding blocks. The compiler should not necessarily rely on
182 * source-order traversal */
183 struct midgard_block *successors[2];
184 unsigned nr_successors;
185
186 struct set *predecessors;
187
188 /* The successors pointer form a graph, and in the case of
189 * complex control flow, this graph has a cycles. To aid
190 * traversal during liveness analysis, we have a visited?
191 * boolean for passes to use as they see fit, provided they
192 * clean up later */
193 bool visited;
194
195 /* In liveness analysis, these are live masks (per-component) for
196 * indices for the block. Scalar compilers have the luxury of using
197 * simple bit fields, but for us, liveness is a vector idea. */
198 uint16_t *live_in;
199 uint16_t *live_out;
200
201 /* Indicates this is a fixed-function fragment epilogue block */
202 bool epilogue;
203 } midgard_block;
204
205 typedef struct midgard_bundle {
206 /* Tag for the overall bundle */
207 int tag;
208
209 /* Instructions contained by the bundle. instruction_count <= 6 (vmul,
210 * sadd, vadd, smul, vlut, branch) */
211 int instruction_count;
212 midgard_instruction *instructions[6];
213
214 /* Bundle-wide ALU configuration */
215 int padding;
216 int control;
217 bool has_embedded_constants;
218 float constants[4];
219 bool has_blend_constant;
220 } midgard_bundle;
221
222 typedef struct compiler_context {
223 nir_shader *nir;
224 gl_shader_stage stage;
225
226 /* Is internally a blend shader? Depends on stage == FRAGMENT */
227 bool is_blend;
228
229 /* Render target number for a keyed blend shader. Depends on is_blend */
230 unsigned blend_rt;
231
232 /* Tracking for blend constant patching */
233 int blend_constant_offset;
234
235 /* Number of bytes used for Thread Local Storage */
236 unsigned tls_size;
237
238 /* Count of spills and fills for shaderdb */
239 unsigned spills;
240 unsigned fills;
241
242 /* Current NIR function */
243 nir_function *func;
244
245 /* Allocated compiler temporary counter */
246 unsigned temp_alloc;
247
248 /* Unordered list of midgard_blocks */
249 int block_count;
250 struct list_head blocks;
251
252 /* TODO merge with block_count? */
253 unsigned block_source_count;
254
255 /* List of midgard_instructions emitted for the current block */
256 midgard_block *current_block;
257
258 /* If there is a preset after block, use this, otherwise emit_block will create one if NULL */
259 midgard_block *after_block;
260
261 /* The current "depth" of the loop, for disambiguating breaks/continues
262 * when using nested loops */
263 int current_loop_depth;
264
265 /* Total number of loops for shader-db */
266 unsigned loop_count;
267
268 /* Constants which have been loaded, for later inlining */
269 struct hash_table_u64 *ssa_constants;
270
271 /* Mapping of hashes computed from NIR indices to the sequential temp indices ultimately used in MIR */
272 struct hash_table_u64 *hash_to_temp;
273 int temp_count;
274 int max_hash;
275
276 /* Just the count of the max register used. Higher count => higher
277 * register pressure */
278 int work_registers;
279
280 /* Used for cont/last hinting. Increase when a tex op is added.
281 * Decrease when a tex op is removed. */
282 int texture_op_count;
283
284 /* The number of uniforms allowable for the fast path */
285 int uniform_cutoff;
286
287 /* Count of instructions emitted from NIR overall, across all blocks */
288 int instruction_count;
289
290 /* Alpha ref value passed in */
291 float alpha_ref;
292
293 unsigned quadword_count;
294
295 /* The mapping of sysvals to uniforms, the count, and the off-by-one inverse */
296 unsigned sysvals[MAX_SYSVAL_COUNT];
297 unsigned sysval_count;
298 struct hash_table_u64 *sysval_to_id;
299
300 /* Bitmask of valid metadata */
301 unsigned metadata;
302
303 /* Model-specific quirk set */
304 uint32_t quirks;
305 } compiler_context;
306
307 /* Per-block live_in/live_out */
308 #define MIDGARD_METADATA_LIVENESS (1 << 0)
309
310 /* Helpers for manipulating the above structures (forming the driver IR) */
311
312 /* Append instruction to end of current block */
313
314 static inline midgard_instruction *
315 mir_upload_ins(struct compiler_context *ctx, struct midgard_instruction ins)
316 {
317 midgard_instruction *heap = ralloc(ctx, struct midgard_instruction);
318 memcpy(heap, &ins, sizeof(ins));
319 return heap;
320 }
321
322 static inline midgard_instruction *
323 emit_mir_instruction(struct compiler_context *ctx, struct midgard_instruction ins)
324 {
325 midgard_instruction *u = mir_upload_ins(ctx, ins);
326 list_addtail(&u->link, &ctx->current_block->instructions);
327 return u;
328 }
329
330 static inline struct midgard_instruction *
331 mir_insert_instruction_before(struct compiler_context *ctx,
332 struct midgard_instruction *tag,
333 struct midgard_instruction ins)
334 {
335 struct midgard_instruction *u = mir_upload_ins(ctx, ins);
336 list_addtail(&u->link, &tag->link);
337 return u;
338 }
339
340 static inline void
341 mir_remove_instruction(struct midgard_instruction *ins)
342 {
343 list_del(&ins->link);
344 }
345
346 static inline midgard_instruction*
347 mir_prev_op(struct midgard_instruction *ins)
348 {
349 return list_last_entry(&(ins->link), midgard_instruction, link);
350 }
351
352 static inline midgard_instruction*
353 mir_next_op(struct midgard_instruction *ins)
354 {
355 return list_first_entry(&(ins->link), midgard_instruction, link);
356 }
357
358 #define mir_foreach_block(ctx, v) \
359 list_for_each_entry(struct midgard_block, v, &ctx->blocks, link)
360
361 #define mir_foreach_block_from(ctx, from, v) \
362 list_for_each_entry_from(struct midgard_block, v, from, &ctx->blocks, link)
363
364 #define mir_foreach_instr(ctx, v) \
365 list_for_each_entry(struct midgard_instruction, v, &ctx->current_block->instructions, link)
366
367 #define mir_foreach_instr_safe(ctx, v) \
368 list_for_each_entry_safe(struct midgard_instruction, v, &ctx->current_block->instructions, link)
369
370 #define mir_foreach_instr_in_block(block, v) \
371 list_for_each_entry(struct midgard_instruction, v, &block->instructions, link)
372 #define mir_foreach_instr_in_block_rev(block, v) \
373 list_for_each_entry_rev(struct midgard_instruction, v, &block->instructions, link)
374
375 #define mir_foreach_instr_in_block_safe(block, v) \
376 list_for_each_entry_safe(struct midgard_instruction, v, &block->instructions, link)
377
378 #define mir_foreach_instr_in_block_safe_rev(block, v) \
379 list_for_each_entry_safe_rev(struct midgard_instruction, v, &block->instructions, link)
380
381 #define mir_foreach_instr_in_block_from(block, v, from) \
382 list_for_each_entry_from(struct midgard_instruction, v, from, &block->instructions, link)
383
384 #define mir_foreach_instr_in_block_from_rev(block, v, from) \
385 list_for_each_entry_from_rev(struct midgard_instruction, v, from, &block->instructions, link)
386
387 #define mir_foreach_bundle_in_block(block, v) \
388 util_dynarray_foreach(&block->bundles, midgard_bundle, v)
389
390 #define mir_foreach_bundle_in_block_rev(block, v) \
391 util_dynarray_foreach_reverse(&block->bundles, midgard_bundle, v)
392
393 #define mir_foreach_instr_in_block_scheduled_rev(block, v) \
394 midgard_instruction* v; \
395 signed i = 0; \
396 mir_foreach_bundle_in_block_rev(block, _bundle) \
397 for (i = (_bundle->instruction_count - 1), v = _bundle->instructions[i]; \
398 i >= 0; \
399 --i, v = (i >= 0) ? _bundle->instructions[i] : NULL) \
400
401 #define mir_foreach_instr_global(ctx, v) \
402 mir_foreach_block(ctx, v_block) \
403 mir_foreach_instr_in_block(v_block, v)
404
405 #define mir_foreach_instr_global_safe(ctx, v) \
406 mir_foreach_block(ctx, v_block) \
407 mir_foreach_instr_in_block_safe(v_block, v)
408
409 #define mir_foreach_successor(blk, v) \
410 struct midgard_block *v; \
411 struct midgard_block **_v; \
412 for (_v = &blk->successors[0], \
413 v = *_v; \
414 v != NULL && _v < &blk->successors[2]; \
415 _v++, v = *_v) \
416
417 /* Based on set_foreach, expanded with automatic type casts */
418
419 #define mir_foreach_predecessor(blk, v) \
420 struct set_entry *_entry_##v; \
421 struct midgard_block *v; \
422 for (_entry_##v = _mesa_set_next_entry(blk->predecessors, NULL), \
423 v = (struct midgard_block *) (_entry_##v ? _entry_##v->key : NULL); \
424 _entry_##v != NULL; \
425 _entry_##v = _mesa_set_next_entry(blk->predecessors, _entry_##v), \
426 v = (struct midgard_block *) (_entry_##v ? _entry_##v->key : NULL))
427
428 #define mir_foreach_src(ins, v) \
429 for (unsigned v = 0; v < ARRAY_SIZE(ins->src); ++v)
430
431 static inline midgard_instruction *
432 mir_last_in_block(struct midgard_block *block)
433 {
434 return list_last_entry(&block->instructions, struct midgard_instruction, link);
435 }
436
437 static inline midgard_block *
438 mir_get_block(compiler_context *ctx, int idx)
439 {
440 struct list_head *lst = &ctx->blocks;
441
442 while ((idx--) + 1)
443 lst = lst->next;
444
445 return (struct midgard_block *) lst;
446 }
447
448 static inline midgard_block *
449 mir_exit_block(struct compiler_context *ctx)
450 {
451 midgard_block *last = list_last_entry(&ctx->blocks,
452 struct midgard_block, link);
453
454 /* The last block must be empty logically but contains branch writeout
455 * for fragment shaders */
456
457 assert(last->nr_successors == 0);
458
459 return last;
460 }
461
462 static inline bool
463 mir_is_alu_bundle(midgard_bundle *bundle)
464 {
465 return IS_ALU(bundle->tag);
466 }
467
468 /* Registers/SSA are distinguish in the backend by the bottom-most bit */
469
470 #define IS_REG (1)
471
472 static inline unsigned
473 make_compiler_temp(compiler_context *ctx)
474 {
475 return (ctx->func->impl->ssa_alloc + ctx->temp_alloc++) << 1;
476 }
477
478 static inline unsigned
479 make_compiler_temp_reg(compiler_context *ctx)
480 {
481 return ((ctx->func->impl->reg_alloc + ctx->temp_alloc++) << 1) | IS_REG;
482 }
483
484 static inline unsigned
485 nir_src_index(compiler_context *ctx, nir_src *src)
486 {
487 if (src->is_ssa)
488 return (src->ssa->index << 1) | 0;
489 else {
490 assert(!src->reg.indirect);
491 return (src->reg.reg->index << 1) | IS_REG;
492 }
493 }
494
495 static inline unsigned
496 nir_alu_src_index(compiler_context *ctx, nir_alu_src *src)
497 {
498 return nir_src_index(ctx, &src->src);
499 }
500
501 static inline unsigned
502 nir_dest_index(compiler_context *ctx, nir_dest *dst)
503 {
504 if (dst->is_ssa)
505 return (dst->ssa.index << 1) | 0;
506 else {
507 assert(!dst->reg.indirect);
508 return (dst->reg.reg->index << 1) | IS_REG;
509 }
510 }
511
512
513
514 /* MIR manipulation */
515
516 void mir_rewrite_index(compiler_context *ctx, unsigned old, unsigned new);
517 void mir_rewrite_index_src(compiler_context *ctx, unsigned old, unsigned new);
518 void mir_rewrite_index_dst(compiler_context *ctx, unsigned old, unsigned new);
519 void mir_rewrite_index_dst_single(midgard_instruction *ins, unsigned old, unsigned new);
520 void mir_rewrite_index_src_single(midgard_instruction *ins, unsigned old, unsigned new);
521 void mir_rewrite_index_src_swizzle(compiler_context *ctx, unsigned old, unsigned new, unsigned *swizzle);
522 bool mir_single_use(compiler_context *ctx, unsigned value);
523 bool mir_special_index(compiler_context *ctx, unsigned idx);
524 unsigned mir_use_count(compiler_context *ctx, unsigned value);
525 bool mir_is_written_before(compiler_context *ctx, midgard_instruction *ins, unsigned node);
526 uint16_t mir_bytemask_of_read_components(midgard_instruction *ins, unsigned node);
527 midgard_reg_mode mir_typesize(midgard_instruction *ins);
528 midgard_reg_mode mir_srcsize(midgard_instruction *ins, unsigned i);
529 unsigned mir_bytes_for_mode(midgard_reg_mode mode);
530 midgard_reg_mode mir_mode_for_destsize(unsigned size);
531 uint16_t mir_from_bytemask(uint16_t bytemask, midgard_reg_mode mode);
532 uint16_t mir_to_bytemask(midgard_reg_mode mode, unsigned mask);
533 uint16_t mir_bytemask(midgard_instruction *ins);
534 uint16_t mir_round_bytemask_down(uint16_t mask, midgard_reg_mode mode);
535 void mir_set_bytemask(midgard_instruction *ins, uint16_t bytemask);
536 unsigned mir_upper_override(midgard_instruction *ins);
537
538 /* MIR printing */
539
540 void mir_print_instruction(midgard_instruction *ins);
541 void mir_print_bundle(midgard_bundle *ctx);
542 void mir_print_block(midgard_block *block);
543 void mir_print_shader(compiler_context *ctx);
544 bool mir_nontrivial_source2_mod(midgard_instruction *ins);
545 bool mir_nontrivial_source2_mod_simple(midgard_instruction *ins);
546 bool mir_nontrivial_outmod(midgard_instruction *ins);
547
548 void mir_insert_instruction_before_scheduled(compiler_context *ctx, midgard_block *block, midgard_instruction *tag, midgard_instruction ins);
549 void mir_insert_instruction_after_scheduled(compiler_context *ctx, midgard_block *block, midgard_instruction *tag, midgard_instruction ins);
550 void mir_flip(midgard_instruction *ins);
551 void mir_compute_temp_count(compiler_context *ctx);
552
553 /* 'Intrinsic' move for aliasing */
554
555 static inline midgard_instruction
556 v_mov(unsigned src, unsigned dest)
557 {
558 midgard_instruction ins = {
559 .type = TAG_ALU_4,
560 .mask = 0xF,
561 .src = { ~0, src, ~0, ~0 },
562 .swizzle = SWIZZLE_IDENTITY,
563 .dest = dest,
564 .alu = {
565 .op = midgard_alu_op_imov,
566 .reg_mode = midgard_reg_mode_32,
567 .dest_override = midgard_dest_override_none,
568 .outmod = midgard_outmod_int_wrap
569 },
570 };
571
572 return ins;
573 }
574
575 /* Broad types of register classes so we can handle special
576 * registers */
577
578 #define REG_CLASS_WORK 0
579 #define REG_CLASS_LDST 1
580 #define REG_CLASS_TEXR 3
581 #define REG_CLASS_TEXW 4
582
583 /* Like a move, but to thread local storage! */
584
585 static inline midgard_instruction
586 v_load_store_scratch(
587 unsigned srcdest,
588 unsigned index,
589 bool is_store,
590 unsigned mask)
591 {
592 /* We index by 32-bit vec4s */
593 unsigned byte = (index * 4 * 4);
594
595 midgard_instruction ins = {
596 .type = TAG_LOAD_STORE_4,
597 .mask = mask,
598 .dest = ~0,
599 .src = { ~0, ~0, ~0, ~0 },
600 .swizzle = SWIZZLE_IDENTITY_4,
601 .load_store = {
602 .op = is_store ? midgard_op_st_int4 : midgard_op_ld_int4,
603
604 /* For register spilling - to thread local storage */
605 .arg_1 = 0xEA,
606 .arg_2 = 0x1E,
607 },
608
609 /* If we spill an unspill, RA goes into an infinite loop */
610 .no_spill = (1 << REG_CLASS_WORK)
611 };
612
613 ins.constants[0] = byte;
614
615 if (is_store) {
616 ins.src[0] = srcdest;
617
618 /* Ensure we are tightly swizzled so liveness analysis is
619 * correct */
620
621 for (unsigned i = 0; i < 4; ++i) {
622 if (!(mask & (1 << i)))
623 ins.swizzle[0][i] = COMPONENT_X;
624 }
625 } else
626 ins.dest = srcdest;
627
628 return ins;
629 }
630
631 static inline bool
632 mir_has_arg(midgard_instruction *ins, unsigned arg)
633 {
634 if (!ins)
635 return false;
636
637 for (unsigned i = 0; i < ARRAY_SIZE(ins->src); ++i) {
638 if (ins->src[i] == arg)
639 return true;
640 }
641
642 return false;
643 }
644
645 /* Scheduling */
646
647 void schedule_program(compiler_context *ctx);
648
649 void mir_ra(compiler_context *ctx);
650 void mir_squeeze_index(compiler_context *ctx);
651 void mir_lower_special_reads(compiler_context *ctx);
652 void mir_liveness_ins_update(uint16_t *live, midgard_instruction *ins, unsigned max);
653 void mir_compute_liveness(compiler_context *ctx);
654 void mir_invalidate_liveness(compiler_context *ctx);
655 bool mir_is_live_after(compiler_context *ctx, midgard_block *block, midgard_instruction *start, int src);
656
657 void mir_create_pipeline_registers(compiler_context *ctx);
658 void midgard_promote_uniforms(compiler_context *ctx);
659
660 midgard_instruction *
661 emit_ubo_read(
662 compiler_context *ctx,
663 nir_instr *instr,
664 unsigned dest,
665 unsigned offset,
666 nir_src *indirect_offset,
667 unsigned index);
668
669 void
670 emit_sysval_read(compiler_context *ctx, nir_instr *instr, signed dest_override, unsigned nr_components);
671
672 void
673 midgard_emit_derivatives(compiler_context *ctx, nir_alu_instr *instr);
674
675 void
676 midgard_lower_derivatives(compiler_context *ctx, midgard_block *block);
677
678 bool mir_op_computes_derivatives(gl_shader_stage stage, unsigned op);
679
680 /* Final emission */
681
682 void emit_binary_bundle(
683 compiler_context *ctx,
684 midgard_bundle *bundle,
685 struct util_dynarray *emission,
686 int next_tag);
687
688 bool
689 nir_undef_to_zero(nir_shader *shader);
690
691 void midgard_nir_lod_errata(nir_shader *shader);
692
693 /* Optimizations */
694
695 bool midgard_opt_copy_prop(compiler_context *ctx, midgard_block *block);
696 bool midgard_opt_combine_projection(compiler_context *ctx, midgard_block *block);
697 bool midgard_opt_varying_projection(compiler_context *ctx, midgard_block *block);
698 bool midgard_opt_dead_code_eliminate(compiler_context *ctx, midgard_block *block);
699 bool midgard_opt_dead_move_eliminate(compiler_context *ctx, midgard_block *block);
700
701 void midgard_lower_invert(compiler_context *ctx, midgard_block *block);
702 bool midgard_opt_not_propagate(compiler_context *ctx, midgard_block *block);
703 bool midgard_opt_fuse_src_invert(compiler_context *ctx, midgard_block *block);
704 bool midgard_opt_fuse_dest_invert(compiler_context *ctx, midgard_block *block);
705 bool midgard_opt_csel_invert(compiler_context *ctx, midgard_block *block);
706 bool midgard_opt_promote_fmov(compiler_context *ctx, midgard_block *block);
707 bool midgard_opt_drop_cmp_invert(compiler_context *ctx, midgard_block *block);
708 bool midgard_opt_invert_branch(compiler_context *ctx, midgard_block *block);
709
710 #endif