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