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_texture
,
119 ppir_node_type_const
,
121 ppir_node_type_store
,
122 ppir_node_type_load_texture
,
123 ppir_node_type_discard
,
124 ppir_node_type_branch
,
133 extern const ppir_op_info ppir_op_infos
[];
137 struct list_head pred_link
;
138 struct list_head succ_link
;
141 typedef struct ppir_node
{
142 struct list_head list
;
148 struct ppir_instr
*instr
;
150 struct ppir_block
*block
;
153 struct list_head succ_list
;
154 struct list_head pred_list
;
158 ppir_pipeline_reg_const0
,
159 ppir_pipeline_reg_const1
,
160 ppir_pipeline_reg_sampler
,
161 ppir_pipeline_reg_uniform
,
162 ppir_pipeline_reg_vmul
,
163 ppir_pipeline_reg_fmul
,
164 ppir_pipeline_reg_discard
, /* varying load */
167 typedef struct ppir_reg
{
168 struct list_head list
;
171 /* whether this reg has to start from the x component
172 * of a full physical reg, this is true for reg used
173 * in load/store instr which has no swizzle field
176 /* instr live range */
177 int live_in
, live_out
;
183 ppir_target_pipeline
,
184 ppir_target_register
,
187 typedef struct ppir_src
{
193 ppir_pipeline pipeline
;
197 bool absolute
, negate
;
202 ppir_outmod_clamp_fraction
,
203 ppir_outmod_clamp_positive
,
207 typedef struct ppir_dest
{
213 ppir_pipeline pipeline
;
216 ppir_outmod modifier
;
217 unsigned write_mask
: 4;
225 int shift
: 3; /* Only used for ppir_op_mul */
228 typedef struct ppir_const
{
260 } ppir_load_texture_node
;
266 enum ppir_instr_slot
{
267 PPIR_INSTR_SLOT_VARYING
,
268 PPIR_INSTR_SLOT_TEXLD
,
269 PPIR_INSTR_SLOT_UNIFORM
,
270 PPIR_INSTR_SLOT_ALU_VEC_MUL
,
271 PPIR_INSTR_SLOT_ALU_SCL_MUL
,
272 PPIR_INSTR_SLOT_ALU_VEC_ADD
,
273 PPIR_INSTR_SLOT_ALU_SCL_ADD
,
274 PPIR_INSTR_SLOT_ALU_COMBINE
,
275 PPIR_INSTR_SLOT_STORE_TEMP
,
276 PPIR_INSTR_SLOT_BRANCH
,
279 PPIR_INSTR_SLOT_ALU_START
= PPIR_INSTR_SLOT_ALU_VEC_MUL
,
280 PPIR_INSTR_SLOT_ALU_END
= PPIR_INSTR_SLOT_ALU_COMBINE
,
283 typedef struct ppir_instr
{
284 struct list_head list
;
287 int seq
; /* command sequence after schedule */
289 ppir_node
*slots
[PPIR_INSTR_SLOT_NUM
];
290 ppir_const constant
[2];
294 struct list_head succ_list
;
295 struct list_head pred_list
;
297 int est
; /* earliest start time */
303 typedef struct ppir_block
{
304 struct list_head list
;
305 struct list_head node_list
;
306 struct list_head instr_list
;
307 struct ppir_compiler
*comp
;
310 int sched_instr_index
;
311 int sched_instr_base
;
324 struct lima_fs_shader_state
;
326 typedef struct ppir_compiler
{
327 struct list_head block_list
;
331 struct list_head reg_list
;
333 /* array for searching ssa/reg node */
334 ppir_node
**var_nodes
;
338 struct lima_fs_shader_state
*prog
;
341 int sched_instr_base
;
343 /* for regalloc spilling debug */
346 ppir_block
*discard_block
;
349 void *ppir_node_create(ppir_block
*block
, ppir_op op
, int index
, unsigned mask
);
350 void ppir_node_add_dep(ppir_node
*succ
, ppir_node
*pred
);
351 void ppir_node_remove_dep(ppir_dep
*dep
);
352 void ppir_node_delete(ppir_node
*node
);
353 void ppir_node_print_prog(ppir_compiler
*comp
);
354 void ppir_node_replace_child(ppir_node
*parent
, ppir_node
*old_child
, ppir_node
*new_child
);
355 void ppir_node_replace_all_succ(ppir_node
*dst
, ppir_node
*src
);
356 void ppir_node_replace_pred(ppir_dep
*dep
, ppir_node
*new_pred
);
358 static inline bool ppir_node_is_root(ppir_node
*node
)
360 return list_empty(&node
->succ_list
);
363 static inline bool ppir_node_is_leaf(ppir_node
*node
)
365 return list_empty(&node
->pred_list
);
368 static inline bool ppir_node_has_single_succ(ppir_node
*node
)
370 return list_is_singular(&node
->succ_list
);
373 static inline ppir_node
*ppir_node_first_succ(ppir_node
*node
)
375 return list_first_entry(&node
->succ_list
, ppir_dep
, succ_link
)->succ
;
378 static inline bool ppir_node_has_single_pred(ppir_node
*node
)
380 return list_is_singular(&node
->pred_list
);
383 static inline ppir_node
*ppir_node_first_pred(ppir_node
*node
)
385 return list_first_entry(&node
->pred_list
, ppir_dep
, pred_link
)->pred
;
388 #define ppir_node_foreach_succ(node, dep) \
389 list_for_each_entry(ppir_dep, dep, &node->succ_list, succ_link)
390 #define ppir_node_foreach_succ_safe(node, dep) \
391 list_for_each_entry_safe(ppir_dep, dep, &node->succ_list, succ_link)
392 #define ppir_node_foreach_pred(node, dep) \
393 list_for_each_entry(ppir_dep, dep, &node->pred_list, pred_link)
394 #define ppir_node_foreach_pred_safe(node, dep) \
395 list_for_each_entry_safe(ppir_dep, dep, &node->pred_list, pred_link)
397 #define ppir_node_to_alu(node) ((ppir_alu_node *)(node))
398 #define ppir_node_to_const(node) ((ppir_const_node *)(node))
399 #define ppir_node_to_load(node) ((ppir_load_node *)(node))
400 #define ppir_node_to_store(node) ((ppir_store_node *)(node))
401 #define ppir_node_to_load_texture(node) ((ppir_load_texture_node *)(node))
402 #define ppir_node_to_discard(node) ((ppir_discard_node *)(node))
403 #define ppir_node_to_branch(node) ((ppir_branch_node *)(node))
405 static inline ppir_dest
*ppir_node_get_dest(ppir_node
*node
)
407 switch (node
->type
) {
408 case ppir_node_type_alu
:
409 return &ppir_node_to_alu(node
)->dest
;
410 case ppir_node_type_load
:
411 return &ppir_node_to_load(node
)->dest
;
412 case ppir_node_type_const
:
413 return &ppir_node_to_const(node
)->dest
;
414 case ppir_node_type_load_texture
:
415 return &ppir_node_to_load_texture(node
)->dest
;
421 static inline void ppir_node_target_assign(ppir_src
*src
, ppir_dest
*dest
)
423 src
->type
= dest
->type
;
425 case ppir_target_ssa
:
426 src
->ssa
= &dest
->ssa
;
428 case ppir_target_register
:
429 src
->reg
= dest
->reg
;
431 case ppir_target_pipeline
:
432 src
->pipeline
= dest
->pipeline
;
437 static inline bool ppir_node_target_equal(ppir_src
*src
, ppir_dest
*dest
)
439 if (src
->type
!= dest
->type
||
440 (src
->type
== ppir_target_ssa
&& src
->ssa
!= &dest
->ssa
) ||
441 (src
->type
== ppir_target_register
&& src
->reg
!= dest
->reg
) ||
442 (src
->type
== ppir_target_pipeline
&& src
->pipeline
!= dest
->pipeline
))
448 static inline int ppir_target_get_src_reg_index(ppir_src
*src
)
451 case ppir_target_ssa
:
452 return src
->ssa
->index
;
453 case ppir_target_register
:
454 return src
->reg
->index
;
455 case ppir_target_pipeline
:
456 if (src
->pipeline
== ppir_pipeline_reg_discard
)
458 return (src
->pipeline
+ 12) * 4;
464 static inline int ppir_target_get_dest_reg_index(ppir_dest
*dest
)
466 switch (dest
->type
) {
467 case ppir_target_ssa
:
468 return dest
->ssa
.index
;
469 case ppir_target_register
:
470 return dest
->reg
->index
;
471 case ppir_target_pipeline
:
472 if (dest
->pipeline
== ppir_pipeline_reg_discard
)
474 return (dest
->pipeline
+ 12) * 4;
480 static inline bool ppir_target_is_scaler(ppir_dest
*dest
)
482 switch (dest
->type
) {
483 case ppir_target_ssa
:
484 return dest
->ssa
.num_components
== 1;
485 case ppir_target_register
:
486 /* only one bit in mask is set */
487 if ((dest
->write_mask
& 0x3) == 0x3 ||
488 (dest
->write_mask
& 0x5) == 0x5 ||
489 (dest
->write_mask
& 0x9) == 0x9 ||
490 (dest
->write_mask
& 0x6) == 0x6 ||
491 (dest
->write_mask
& 0xa) == 0xa ||
492 (dest
->write_mask
& 0xc) == 0xc)
496 case ppir_target_pipeline
:
497 if (dest
->pipeline
== ppir_pipeline_reg_fmul
)
506 ppir_instr
*ppir_instr_create(ppir_block
*block
);
507 bool ppir_instr_insert_node(ppir_instr
*instr
, ppir_node
*node
);
508 void ppir_instr_add_dep(ppir_instr
*succ
, ppir_instr
*pred
);
509 void ppir_instr_print_list(ppir_compiler
*comp
);
510 void ppir_instr_print_dep(ppir_compiler
*comp
);
511 void ppir_instr_insert_mul_node(ppir_node
*add
, ppir_node
*mul
);
513 #define ppir_instr_foreach_succ(instr, dep) \
514 list_for_each_entry(ppir_dep, dep, &instr->succ_list, succ_link)
515 #define ppir_instr_foreach_succ_safe(instr, dep) \
516 list_for_each_entry_safe(ppir_dep, dep, &instr->succ_list, succ_link)
517 #define ppir_instr_foreach_pred(instr, dep) \
518 list_for_each_entry(ppir_dep, dep, &instr->pred_list, pred_link)
519 #define ppir_instr_foreach_pred_safe(instr, dep) \
520 list_for_each_entry_safe(ppir_dep, dep, &instr->pred_list, pred_link)
522 static inline bool ppir_instr_is_root(ppir_instr
*instr
)
524 return list_empty(&instr
->succ_list
);
527 static inline bool ppir_instr_is_leaf(ppir_instr
*instr
)
529 return list_empty(&instr
->pred_list
);
532 bool ppir_lower_prog(ppir_compiler
*comp
);
533 bool ppir_node_to_instr(ppir_compiler
*comp
);
534 bool ppir_schedule_prog(ppir_compiler
*comp
);
535 bool ppir_regalloc_prog(ppir_compiler
*comp
);
536 bool ppir_codegen_prog(ppir_compiler
*comp
);