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"
101 ppir_op_load_fragcoord
,
102 ppir_op_load_pointcoord
,
103 ppir_op_load_frontface
,
104 ppir_op_load_texture
,
120 ppir_node_type_const
,
122 ppir_node_type_store
,
123 ppir_node_type_load_texture
,
124 ppir_node_type_discard
,
125 ppir_node_type_branch
,
134 extern const ppir_op_info ppir_op_infos
[];
138 struct list_head pred_link
;
139 struct list_head succ_link
;
142 typedef struct ppir_node
{
143 struct list_head list
;
149 struct ppir_instr
*instr
;
151 struct ppir_block
*block
;
154 struct list_head succ_list
;
155 struct list_head pred_list
;
159 ppir_pipeline_reg_const0
,
160 ppir_pipeline_reg_const1
,
161 ppir_pipeline_reg_sampler
,
162 ppir_pipeline_reg_uniform
,
163 ppir_pipeline_reg_vmul
,
164 ppir_pipeline_reg_fmul
,
165 ppir_pipeline_reg_discard
, /* varying load */
168 typedef struct ppir_reg
{
169 struct list_head list
;
172 /* whether this reg has to start from the x component
173 * of a full physical reg, this is true for reg used
174 * in load/store instr which has no swizzle field
177 /* instr live range */
178 int live_in
, live_out
;
184 ppir_target_pipeline
,
185 ppir_target_register
,
188 typedef struct ppir_src
{
194 ppir_pipeline pipeline
;
198 bool absolute
, negate
;
203 ppir_outmod_clamp_fraction
,
204 ppir_outmod_clamp_positive
,
208 typedef struct ppir_dest
{
214 ppir_pipeline pipeline
;
217 ppir_outmod modifier
;
218 unsigned write_mask
: 4;
226 int shift
: 3; /* Only used for ppir_op_mul */
229 typedef struct ppir_const
{
258 ppir_src src_coords
; /* not to be used after lowering */
261 } ppir_load_texture_node
;
267 enum ppir_instr_slot
{
268 PPIR_INSTR_SLOT_VARYING
,
269 PPIR_INSTR_SLOT_TEXLD
,
270 PPIR_INSTR_SLOT_UNIFORM
,
271 PPIR_INSTR_SLOT_ALU_VEC_MUL
,
272 PPIR_INSTR_SLOT_ALU_SCL_MUL
,
273 PPIR_INSTR_SLOT_ALU_VEC_ADD
,
274 PPIR_INSTR_SLOT_ALU_SCL_ADD
,
275 PPIR_INSTR_SLOT_ALU_COMBINE
,
276 PPIR_INSTR_SLOT_STORE_TEMP
,
277 PPIR_INSTR_SLOT_BRANCH
,
280 PPIR_INSTR_SLOT_ALU_START
= PPIR_INSTR_SLOT_ALU_VEC_MUL
,
281 PPIR_INSTR_SLOT_ALU_END
= PPIR_INSTR_SLOT_ALU_COMBINE
,
284 typedef struct ppir_instr
{
285 struct list_head list
;
288 int seq
; /* command sequence after schedule */
290 ppir_node
*slots
[PPIR_INSTR_SLOT_NUM
];
291 ppir_const constant
[2];
295 struct list_head succ_list
;
296 struct list_head pred_list
;
298 int est
; /* earliest start time */
305 typedef struct ppir_block
{
306 struct list_head list
;
307 struct list_head node_list
;
308 struct list_head instr_list
;
309 struct ppir_compiler
*comp
;
312 int sched_instr_index
;
313 int sched_instr_base
;
326 struct lima_fs_shader_state
;
328 typedef struct ppir_compiler
{
329 struct list_head block_list
;
333 struct list_head reg_list
;
335 /* array for searching ssa/reg node */
336 ppir_node
**var_nodes
;
340 struct lima_fs_shader_state
*prog
;
343 int sched_instr_base
;
345 /* for regalloc spilling debug */
348 ppir_block
*discard_block
;
351 void *ppir_node_create(ppir_block
*block
, ppir_op op
, int index
, unsigned mask
);
352 void ppir_node_add_dep(ppir_node
*succ
, ppir_node
*pred
);
353 void ppir_node_remove_dep(ppir_dep
*dep
);
354 void ppir_node_delete(ppir_node
*node
);
355 void ppir_node_print_prog(ppir_compiler
*comp
);
356 void ppir_node_replace_child(ppir_node
*parent
, ppir_node
*old_child
, ppir_node
*new_child
);
357 void ppir_node_replace_all_succ(ppir_node
*dst
, ppir_node
*src
);
358 void ppir_node_replace_pred(ppir_dep
*dep
, ppir_node
*new_pred
);
360 static inline bool ppir_node_is_root(ppir_node
*node
)
362 return list_empty(&node
->succ_list
);
365 static inline bool ppir_node_is_leaf(ppir_node
*node
)
367 return list_empty(&node
->pred_list
);
370 static inline bool ppir_node_has_single_succ(ppir_node
*node
)
372 return list_is_singular(&node
->succ_list
);
375 static inline ppir_node
*ppir_node_first_succ(ppir_node
*node
)
377 return list_first_entry(&node
->succ_list
, ppir_dep
, succ_link
)->succ
;
380 static inline bool ppir_node_has_single_pred(ppir_node
*node
)
382 return list_is_singular(&node
->pred_list
);
385 static inline ppir_node
*ppir_node_first_pred(ppir_node
*node
)
387 return list_first_entry(&node
->pred_list
, ppir_dep
, pred_link
)->pred
;
390 #define ppir_node_foreach_succ(node, dep) \
391 list_for_each_entry(ppir_dep, dep, &node->succ_list, succ_link)
392 #define ppir_node_foreach_succ_safe(node, dep) \
393 list_for_each_entry_safe(ppir_dep, dep, &node->succ_list, succ_link)
394 #define ppir_node_foreach_pred(node, dep) \
395 list_for_each_entry(ppir_dep, dep, &node->pred_list, pred_link)
396 #define ppir_node_foreach_pred_safe(node, dep) \
397 list_for_each_entry_safe(ppir_dep, dep, &node->pred_list, pred_link)
399 #define ppir_node_to_alu(node) ((ppir_alu_node *)(node))
400 #define ppir_node_to_const(node) ((ppir_const_node *)(node))
401 #define ppir_node_to_load(node) ((ppir_load_node *)(node))
402 #define ppir_node_to_store(node) ((ppir_store_node *)(node))
403 #define ppir_node_to_load_texture(node) ((ppir_load_texture_node *)(node))
404 #define ppir_node_to_discard(node) ((ppir_discard_node *)(node))
405 #define ppir_node_to_branch(node) ((ppir_branch_node *)(node))
407 static inline ppir_dest
*ppir_node_get_dest(ppir_node
*node
)
409 switch (node
->type
) {
410 case ppir_node_type_alu
:
411 return &ppir_node_to_alu(node
)->dest
;
412 case ppir_node_type_load
:
413 return &ppir_node_to_load(node
)->dest
;
414 case ppir_node_type_const
:
415 return &ppir_node_to_const(node
)->dest
;
416 case ppir_node_type_load_texture
:
417 return &ppir_node_to_load_texture(node
)->dest
;
423 static inline void ppir_node_target_assign(ppir_src
*src
, ppir_dest
*dest
)
425 src
->type
= dest
->type
;
427 case ppir_target_ssa
:
428 src
->ssa
= &dest
->ssa
;
430 case ppir_target_register
:
431 src
->reg
= dest
->reg
;
433 case ppir_target_pipeline
:
434 src
->pipeline
= dest
->pipeline
;
439 static inline bool ppir_node_target_equal(ppir_src
*src
, ppir_dest
*dest
)
441 if (src
->type
!= dest
->type
||
442 (src
->type
== ppir_target_ssa
&& src
->ssa
!= &dest
->ssa
) ||
443 (src
->type
== ppir_target_register
&& src
->reg
!= dest
->reg
) ||
444 (src
->type
== ppir_target_pipeline
&& src
->pipeline
!= dest
->pipeline
))
450 static inline int ppir_target_get_src_reg_index(ppir_src
*src
)
453 case ppir_target_ssa
:
454 return src
->ssa
->index
;
455 case ppir_target_register
:
456 return src
->reg
->index
;
457 case ppir_target_pipeline
:
458 if (src
->pipeline
== ppir_pipeline_reg_discard
)
460 return (src
->pipeline
+ 12) * 4;
466 static inline int ppir_target_get_dest_reg_index(ppir_dest
*dest
)
468 switch (dest
->type
) {
469 case ppir_target_ssa
:
470 return dest
->ssa
.index
;
471 case ppir_target_register
:
472 return dest
->reg
->index
;
473 case ppir_target_pipeline
:
474 if (dest
->pipeline
== ppir_pipeline_reg_discard
)
476 return (dest
->pipeline
+ 12) * 4;
482 static inline bool ppir_target_is_scaler(ppir_dest
*dest
)
484 switch (dest
->type
) {
485 case ppir_target_ssa
:
486 return dest
->ssa
.num_components
== 1;
487 case ppir_target_register
:
488 /* only one bit in mask is set */
489 if ((dest
->write_mask
& 0x3) == 0x3 ||
490 (dest
->write_mask
& 0x5) == 0x5 ||
491 (dest
->write_mask
& 0x9) == 0x9 ||
492 (dest
->write_mask
& 0x6) == 0x6 ||
493 (dest
->write_mask
& 0xa) == 0xa ||
494 (dest
->write_mask
& 0xc) == 0xc)
498 case ppir_target_pipeline
:
499 if (dest
->pipeline
== ppir_pipeline_reg_fmul
)
508 ppir_instr
*ppir_instr_create(ppir_block
*block
);
509 bool ppir_instr_insert_node(ppir_instr
*instr
, ppir_node
*node
);
510 void ppir_instr_add_dep(ppir_instr
*succ
, ppir_instr
*pred
);
511 void ppir_instr_print_list(ppir_compiler
*comp
);
512 void ppir_instr_print_dep(ppir_compiler
*comp
);
513 void ppir_instr_insert_mul_node(ppir_node
*add
, ppir_node
*mul
);
515 #define ppir_instr_foreach_succ(instr, dep) \
516 list_for_each_entry(ppir_dep, dep, &instr->succ_list, succ_link)
517 #define ppir_instr_foreach_succ_safe(instr, dep) \
518 list_for_each_entry_safe(ppir_dep, dep, &instr->succ_list, succ_link)
519 #define ppir_instr_foreach_pred(instr, dep) \
520 list_for_each_entry(ppir_dep, dep, &instr->pred_list, pred_link)
521 #define ppir_instr_foreach_pred_safe(instr, dep) \
522 list_for_each_entry_safe(ppir_dep, dep, &instr->pred_list, pred_link)
524 static inline bool ppir_instr_is_root(ppir_instr
*instr
)
526 return list_empty(&instr
->succ_list
);
529 static inline bool ppir_instr_is_leaf(ppir_instr
*instr
)
531 return list_empty(&instr
->pred_list
);
534 bool ppir_lower_prog(ppir_compiler
*comp
);
535 bool ppir_node_to_instr(ppir_compiler
*comp
);
536 bool ppir_schedule_prog(ppir_compiler
*comp
);
537 bool ppir_regalloc_prog(ppir_compiler
*comp
);
538 bool ppir_codegen_prog(ppir_compiler
*comp
);