2 * Copyright (c) 2017 Lima Project
3 * Copyright (c) 2013 Connor Abbott
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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 THE
18 * 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
25 #ifndef LIMA_IR_PP_PPIR_H
26 #define LIMA_IR_PP_PPIR_H
28 #include "util/u_math.h"
29 #include "util/list.h"
31 #include "ir/lima_ir.h"
100 ppir_op_load_varying
,
102 ppir_op_load_fragcoord
,
103 ppir_op_load_pointcoord
,
104 ppir_op_load_frontface
,
105 ppir_op_load_texture
,
121 ppir_node_type_const
,
123 ppir_node_type_store
,
124 ppir_node_type_load_texture
,
125 ppir_node_type_discard
,
126 ppir_node_type_branch
,
135 extern const ppir_op_info ppir_op_infos
[];
139 struct list_head pred_link
;
140 struct list_head succ_link
;
143 typedef struct ppir_node
{
144 struct list_head list
;
150 struct ppir_instr
*instr
;
152 struct ppir_block
*block
;
155 struct list_head succ_list
;
156 struct list_head pred_list
;
160 ppir_pipeline_reg_const0
,
161 ppir_pipeline_reg_const1
,
162 ppir_pipeline_reg_sampler
,
163 ppir_pipeline_reg_uniform
,
164 ppir_pipeline_reg_vmul
,
165 ppir_pipeline_reg_fmul
,
166 ppir_pipeline_reg_discard
, /* varying load */
169 typedef struct ppir_reg
{
170 struct list_head list
;
173 /* whether this reg has to start from the x component
174 * of a full physical reg, this is true for reg used
175 * in load/store instr which has no swizzle field
178 /* instr live range */
179 int live_in
, live_out
;
185 ppir_target_pipeline
,
186 ppir_target_register
,
189 typedef struct ppir_src
{
196 ppir_pipeline pipeline
;
200 bool absolute
, negate
;
205 ppir_outmod_clamp_fraction
,
206 ppir_outmod_clamp_positive
,
210 typedef struct ppir_dest
{
216 ppir_pipeline pipeline
;
219 ppir_outmod modifier
;
220 unsigned write_mask
: 4;
228 int shift
: 3; /* Only used for ppir_op_mul */
231 typedef struct ppir_const
{
260 ppir_src src_coords
; /* not to be used after lowering */
263 } ppir_load_texture_node
;
269 enum ppir_instr_slot
{
270 PPIR_INSTR_SLOT_VARYING
,
271 PPIR_INSTR_SLOT_TEXLD
,
272 PPIR_INSTR_SLOT_UNIFORM
,
273 PPIR_INSTR_SLOT_ALU_VEC_MUL
,
274 PPIR_INSTR_SLOT_ALU_SCL_MUL
,
275 PPIR_INSTR_SLOT_ALU_VEC_ADD
,
276 PPIR_INSTR_SLOT_ALU_SCL_ADD
,
277 PPIR_INSTR_SLOT_ALU_COMBINE
,
278 PPIR_INSTR_SLOT_STORE_TEMP
,
279 PPIR_INSTR_SLOT_BRANCH
,
282 PPIR_INSTR_SLOT_ALU_START
= PPIR_INSTR_SLOT_ALU_VEC_MUL
,
283 PPIR_INSTR_SLOT_ALU_END
= PPIR_INSTR_SLOT_ALU_COMBINE
,
286 typedef struct ppir_instr
{
287 struct list_head list
;
290 int seq
; /* command sequence after schedule */
292 ppir_node
*slots
[PPIR_INSTR_SLOT_NUM
];
293 ppir_const constant
[2];
297 struct list_head succ_list
;
298 struct list_head pred_list
;
300 int est
; /* earliest start time */
307 typedef struct ppir_block
{
308 struct list_head list
;
309 struct list_head node_list
;
310 struct list_head instr_list
;
311 struct ppir_compiler
*comp
;
314 int sched_instr_index
;
315 int sched_instr_base
;
328 struct lima_fs_shader_state
;
330 typedef struct ppir_compiler
{
331 struct list_head block_list
;
335 struct list_head reg_list
;
337 /* array for searching ssa/reg node */
338 ppir_node
**var_nodes
;
342 struct lima_fs_shader_state
*prog
;
345 int sched_instr_base
;
347 /* for regalloc spilling debug */
355 ppir_block
*discard_block
;
358 void *ppir_node_create(ppir_block
*block
, ppir_op op
, int index
, unsigned mask
);
359 void ppir_node_add_dep(ppir_node
*succ
, ppir_node
*pred
);
360 void ppir_node_remove_dep(ppir_dep
*dep
);
361 void ppir_node_delete(ppir_node
*node
);
362 void ppir_node_print_prog(ppir_compiler
*comp
);
363 void ppir_node_replace_child(ppir_node
*parent
, ppir_node
*old_child
, ppir_node
*new_child
);
364 void ppir_node_replace_all_succ(ppir_node
*dst
, ppir_node
*src
);
365 void ppir_node_replace_pred(ppir_dep
*dep
, ppir_node
*new_pred
);
367 static inline bool ppir_node_is_root(ppir_node
*node
)
369 return list_empty(&node
->succ_list
);
372 static inline bool ppir_node_is_leaf(ppir_node
*node
)
374 return list_empty(&node
->pred_list
);
377 static inline bool ppir_node_has_single_succ(ppir_node
*node
)
379 return list_is_singular(&node
->succ_list
);
382 static inline ppir_node
*ppir_node_first_succ(ppir_node
*node
)
384 return list_first_entry(&node
->succ_list
, ppir_dep
, succ_link
)->succ
;
387 static inline bool ppir_node_has_single_pred(ppir_node
*node
)
389 return list_is_singular(&node
->pred_list
);
392 static inline ppir_node
*ppir_node_first_pred(ppir_node
*node
)
394 return list_first_entry(&node
->pred_list
, ppir_dep
, pred_link
)->pred
;
397 #define ppir_node_foreach_succ(node, dep) \
398 list_for_each_entry(ppir_dep, dep, &node->succ_list, succ_link)
399 #define ppir_node_foreach_succ_safe(node, dep) \
400 list_for_each_entry_safe(ppir_dep, dep, &node->succ_list, succ_link)
401 #define ppir_node_foreach_pred(node, dep) \
402 list_for_each_entry(ppir_dep, dep, &node->pred_list, pred_link)
403 #define ppir_node_foreach_pred_safe(node, dep) \
404 list_for_each_entry_safe(ppir_dep, dep, &node->pred_list, pred_link)
406 #define ppir_node_to_alu(node) ((ppir_alu_node *)(node))
407 #define ppir_node_to_const(node) ((ppir_const_node *)(node))
408 #define ppir_node_to_load(node) ((ppir_load_node *)(node))
409 #define ppir_node_to_store(node) ((ppir_store_node *)(node))
410 #define ppir_node_to_load_texture(node) ((ppir_load_texture_node *)(node))
411 #define ppir_node_to_discard(node) ((ppir_discard_node *)(node))
412 #define ppir_node_to_branch(node) ((ppir_branch_node *)(node))
414 static inline ppir_dest
*ppir_node_get_dest(ppir_node
*node
)
416 switch (node
->type
) {
417 case ppir_node_type_alu
:
418 return &ppir_node_to_alu(node
)->dest
;
419 case ppir_node_type_load
:
420 return &ppir_node_to_load(node
)->dest
;
421 case ppir_node_type_const
:
422 return &ppir_node_to_const(node
)->dest
;
423 case ppir_node_type_load_texture
:
424 return &ppir_node_to_load_texture(node
)->dest
;
430 static inline int ppir_node_get_src_num(ppir_node
*node
)
432 switch (node
->type
) {
433 case ppir_node_type_alu
:
434 return ppir_node_to_alu(node
)->num_src
;
435 case ppir_node_type_branch
:
437 case ppir_node_type_load_texture
:
438 case ppir_node_type_load
:
439 case ppir_node_type_store
:
448 static inline ppir_src
*ppir_node_get_src(ppir_node
*node
, int idx
)
450 if (idx
< 0 || idx
>= ppir_node_get_src_num(node
))
453 switch (node
->type
) {
454 case ppir_node_type_alu
:
455 return &ppir_node_to_alu(node
)->src
[idx
];
456 case ppir_node_type_branch
:
457 return &ppir_node_to_branch(node
)->src
[idx
];
458 case ppir_node_type_load_texture
:
459 return &ppir_node_to_load_texture(node
)->src_coords
;
460 case ppir_node_type_load
:
461 return &ppir_node_to_load(node
)->src
;
462 case ppir_node_type_store
:
463 return &ppir_node_to_store(node
)->src
;
471 static inline void ppir_node_target_assign(ppir_src
*src
, ppir_node
*node
)
473 ppir_dest
*dest
= ppir_node_get_dest(node
);
474 src
->type
= dest
->type
;
476 case ppir_target_ssa
:
477 src
->ssa
= &dest
->ssa
;
480 case ppir_target_register
:
481 src
->reg
= dest
->reg
;
482 /* Registers can be assigned from multiple nodes, so don't keep
483 * pointer to the node here
487 case ppir_target_pipeline
:
488 src
->pipeline
= dest
->pipeline
;
494 static inline bool ppir_node_target_equal(ppir_src
*src
, ppir_dest
*dest
)
496 if (src
->type
!= dest
->type
||
497 (src
->type
== ppir_target_ssa
&& src
->ssa
!= &dest
->ssa
) ||
498 (src
->type
== ppir_target_register
&& src
->reg
!= dest
->reg
) ||
499 (src
->type
== ppir_target_pipeline
&& src
->pipeline
!= dest
->pipeline
))
505 static inline int ppir_target_get_src_reg_index(ppir_src
*src
)
508 case ppir_target_ssa
:
509 return src
->ssa
->index
;
510 case ppir_target_register
:
511 return src
->reg
->index
;
512 case ppir_target_pipeline
:
513 if (src
->pipeline
== ppir_pipeline_reg_discard
)
515 return (src
->pipeline
+ 12) * 4;
521 static inline int ppir_target_get_dest_reg_index(ppir_dest
*dest
)
523 switch (dest
->type
) {
524 case ppir_target_ssa
:
525 return dest
->ssa
.index
;
526 case ppir_target_register
:
527 return dest
->reg
->index
;
528 case ppir_target_pipeline
:
529 if (dest
->pipeline
== ppir_pipeline_reg_discard
)
531 return (dest
->pipeline
+ 12) * 4;
537 static inline bool ppir_target_is_scaler(ppir_dest
*dest
)
539 switch (dest
->type
) {
540 case ppir_target_ssa
:
541 return dest
->ssa
.num_components
== 1;
542 case ppir_target_register
:
543 /* only one bit in mask is set */
544 if ((dest
->write_mask
& 0x3) == 0x3 ||
545 (dest
->write_mask
& 0x5) == 0x5 ||
546 (dest
->write_mask
& 0x9) == 0x9 ||
547 (dest
->write_mask
& 0x6) == 0x6 ||
548 (dest
->write_mask
& 0xa) == 0xa ||
549 (dest
->write_mask
& 0xc) == 0xc)
553 case ppir_target_pipeline
:
554 if (dest
->pipeline
== ppir_pipeline_reg_fmul
)
563 ppir_instr
*ppir_instr_create(ppir_block
*block
);
564 bool ppir_instr_insert_node(ppir_instr
*instr
, ppir_node
*node
);
565 void ppir_instr_add_dep(ppir_instr
*succ
, ppir_instr
*pred
);
566 void ppir_instr_print_list(ppir_compiler
*comp
);
567 void ppir_instr_print_dep(ppir_compiler
*comp
);
568 void ppir_instr_insert_mul_node(ppir_node
*add
, ppir_node
*mul
);
570 #define ppir_instr_foreach_succ(instr, dep) \
571 list_for_each_entry(ppir_dep, dep, &instr->succ_list, succ_link)
572 #define ppir_instr_foreach_succ_safe(instr, dep) \
573 list_for_each_entry_safe(ppir_dep, dep, &instr->succ_list, succ_link)
574 #define ppir_instr_foreach_pred(instr, dep) \
575 list_for_each_entry(ppir_dep, dep, &instr->pred_list, pred_link)
576 #define ppir_instr_foreach_pred_safe(instr, dep) \
577 list_for_each_entry_safe(ppir_dep, dep, &instr->pred_list, pred_link)
579 static inline bool ppir_instr_is_root(ppir_instr
*instr
)
581 return list_empty(&instr
->succ_list
);
584 static inline bool ppir_instr_is_leaf(ppir_instr
*instr
)
586 return list_empty(&instr
->pred_list
);
589 bool ppir_lower_prog(ppir_compiler
*comp
);
590 bool ppir_node_to_instr(ppir_compiler
*comp
);
591 bool ppir_schedule_prog(ppir_compiler
*comp
);
592 bool ppir_regalloc_prog(ppir_compiler
*comp
);
593 bool ppir_codegen_prog(ppir_compiler
*comp
);