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_texture
,
114 ppir_node_type_const
,
116 ppir_node_type_store
,
117 ppir_node_type_load_texture
,
126 extern const ppir_op_info ppir_op_infos
[];
130 struct list_head pred_link
;
131 struct list_head succ_link
;
134 typedef struct ppir_node
{
135 struct list_head list
;
141 struct ppir_instr
*instr
;
143 struct ppir_block
*block
;
146 struct list_head succ_list
;
147 struct list_head pred_list
;
151 ppir_pipeline_reg_const0
,
152 ppir_pipeline_reg_const1
,
153 ppir_pipeline_reg_sampler
,
154 ppir_pipeline_reg_uniform
,
155 ppir_pipeline_reg_vmul
,
156 ppir_pipeline_reg_fmul
,
157 ppir_pipeline_reg_discard
, /* varying load */
160 typedef struct ppir_reg
{
161 struct list_head list
;
164 /* whether this reg has to start from the x component
165 * of a full physical reg, this is true for reg used
166 * in load/store instr which has no swizzle field
169 /* instr live range */
170 int live_in
, live_out
;
176 ppir_target_pipeline
,
177 ppir_target_register
,
180 typedef struct ppir_src
{
186 ppir_pipeline pipeline
;
190 bool absolute
, negate
;
195 ppir_outmod_clamp_fraction
,
196 ppir_outmod_clamp_positive
,
200 typedef struct ppir_dest
{
206 ppir_pipeline pipeline
;
209 ppir_outmod modifier
;
210 unsigned write_mask
: 4;
218 int shift
: 3; /* Only used for ppir_op_mul */
221 typedef struct ppir_const
{
253 } ppir_load_texture_node
;
255 enum ppir_instr_slot
{
256 PPIR_INSTR_SLOT_VARYING
,
257 PPIR_INSTR_SLOT_TEXLD
,
258 PPIR_INSTR_SLOT_UNIFORM
,
259 PPIR_INSTR_SLOT_ALU_VEC_MUL
,
260 PPIR_INSTR_SLOT_ALU_SCL_MUL
,
261 PPIR_INSTR_SLOT_ALU_VEC_ADD
,
262 PPIR_INSTR_SLOT_ALU_SCL_ADD
,
263 PPIR_INSTR_SLOT_ALU_COMBINE
,
264 PPIR_INSTR_SLOT_STORE_TEMP
,
267 PPIR_INSTR_SLOT_ALU_START
= PPIR_INSTR_SLOT_ALU_VEC_MUL
,
268 PPIR_INSTR_SLOT_ALU_END
= PPIR_INSTR_SLOT_ALU_COMBINE
,
271 typedef struct ppir_instr
{
272 struct list_head list
;
275 int seq
; /* command sequence after schedule */
277 ppir_node
*slots
[PPIR_INSTR_SLOT_NUM
];
278 ppir_const constant
[2];
282 struct list_head succ_list
;
283 struct list_head pred_list
;
285 int est
; /* earliest start time */
290 typedef struct ppir_block
{
291 struct list_head list
;
292 struct list_head node_list
;
293 struct list_head instr_list
;
294 struct ppir_compiler
*comp
;
297 int sched_instr_index
;
298 int sched_instr_base
;
302 struct lima_fs_shader_state
;
304 typedef struct ppir_compiler
{
305 struct list_head block_list
;
309 struct list_head reg_list
;
311 /* array for searching ssa/reg node */
312 ppir_node
**var_nodes
;
316 struct lima_fs_shader_state
*prog
;
319 int sched_instr_base
;
321 /* for regalloc spilling debug */
325 void *ppir_node_create(ppir_block
*block
, ppir_op op
, int index
, unsigned mask
);
326 void ppir_node_add_dep(ppir_node
*succ
, ppir_node
*pred
);
327 void ppir_node_remove_dep(ppir_dep
*dep
);
328 void ppir_node_delete(ppir_node
*node
);
329 void ppir_node_print_prog(ppir_compiler
*comp
);
330 void ppir_node_replace_child(ppir_node
*parent
, ppir_node
*old_child
, ppir_node
*new_child
);
331 void ppir_node_replace_all_succ(ppir_node
*dst
, ppir_node
*src
);
332 void ppir_node_replace_pred(ppir_dep
*dep
, ppir_node
*new_pred
);
334 static inline bool ppir_node_is_root(ppir_node
*node
)
336 return list_empty(&node
->succ_list
);
339 static inline bool ppir_node_is_leaf(ppir_node
*node
)
341 return list_empty(&node
->pred_list
);
344 static inline bool ppir_node_has_single_succ(ppir_node
*node
)
346 return list_is_singular(&node
->succ_list
);
349 static inline ppir_node
*ppir_node_first_succ(ppir_node
*node
)
351 return list_first_entry(&node
->succ_list
, ppir_dep
, succ_link
)->succ
;
354 static inline bool ppir_node_has_single_pred(ppir_node
*node
)
356 return list_is_singular(&node
->pred_list
);
359 static inline ppir_node
*ppir_node_first_pred(ppir_node
*node
)
361 return list_first_entry(&node
->pred_list
, ppir_dep
, pred_link
)->pred
;
364 #define ppir_node_foreach_succ(node, dep) \
365 list_for_each_entry(ppir_dep, dep, &node->succ_list, succ_link)
366 #define ppir_node_foreach_succ_safe(node, dep) \
367 list_for_each_entry_safe(ppir_dep, dep, &node->succ_list, succ_link)
368 #define ppir_node_foreach_pred(node, dep) \
369 list_for_each_entry(ppir_dep, dep, &node->pred_list, pred_link)
370 #define ppir_node_foreach_pred_safe(node, dep) \
371 list_for_each_entry_safe(ppir_dep, dep, &node->pred_list, pred_link)
373 #define ppir_node_to_alu(node) ((ppir_alu_node *)(node))
374 #define ppir_node_to_const(node) ((ppir_const_node *)(node))
375 #define ppir_node_to_load(node) ((ppir_load_node *)(node))
376 #define ppir_node_to_store(node) ((ppir_store_node *)(node))
377 #define ppir_node_to_load_texture(node) ((ppir_load_texture_node *)(node))
379 static inline ppir_dest
*ppir_node_get_dest(ppir_node
*node
)
381 switch (node
->type
) {
382 case ppir_node_type_alu
:
383 return &ppir_node_to_alu(node
)->dest
;
384 case ppir_node_type_load
:
385 return &ppir_node_to_load(node
)->dest
;
386 case ppir_node_type_const
:
387 return &ppir_node_to_const(node
)->dest
;
388 case ppir_node_type_load_texture
:
389 return &ppir_node_to_load_texture(node
)->dest
;
395 static inline void ppir_node_target_assign(ppir_src
*src
, ppir_dest
*dest
)
397 src
->type
= dest
->type
;
399 case ppir_target_ssa
:
400 src
->ssa
= &dest
->ssa
;
402 case ppir_target_register
:
403 src
->reg
= dest
->reg
;
405 case ppir_target_pipeline
:
406 src
->pipeline
= dest
->pipeline
;
411 static inline bool ppir_node_target_equal(ppir_src
*src
, ppir_dest
*dest
)
413 if (src
->type
!= dest
->type
||
414 (src
->type
== ppir_target_ssa
&& src
->ssa
!= &dest
->ssa
) ||
415 (src
->type
== ppir_target_register
&& src
->reg
!= dest
->reg
) ||
416 (src
->type
== ppir_target_pipeline
&& src
->pipeline
!= dest
->pipeline
))
422 static inline int ppir_target_get_src_reg_index(ppir_src
*src
)
425 case ppir_target_ssa
:
426 return src
->ssa
->index
;
427 case ppir_target_register
:
428 return src
->reg
->index
;
429 case ppir_target_pipeline
:
430 if (src
->pipeline
== ppir_pipeline_reg_discard
)
432 return (src
->pipeline
+ 12) * 4;
438 static inline int ppir_target_get_dest_reg_index(ppir_dest
*dest
)
440 switch (dest
->type
) {
441 case ppir_target_ssa
:
442 return dest
->ssa
.index
;
443 case ppir_target_register
:
444 return dest
->reg
->index
;
445 case ppir_target_pipeline
:
446 if (dest
->pipeline
== ppir_pipeline_reg_discard
)
448 return (dest
->pipeline
+ 12) * 4;
454 static inline bool ppir_target_is_scaler(ppir_dest
*dest
)
456 switch (dest
->type
) {
457 case ppir_target_ssa
:
458 return dest
->ssa
.num_components
== 1;
459 case ppir_target_register
:
460 /* only one bit in mask is set */
461 if ((dest
->write_mask
& 0x3) == 0x3 ||
462 (dest
->write_mask
& 0x5) == 0x5 ||
463 (dest
->write_mask
& 0x9) == 0x9 ||
464 (dest
->write_mask
& 0x6) == 0x6 ||
465 (dest
->write_mask
& 0xa) == 0xa ||
466 (dest
->write_mask
& 0xc) == 0xc)
470 case ppir_target_pipeline
:
471 if (dest
->pipeline
== ppir_pipeline_reg_fmul
)
480 ppir_instr
*ppir_instr_create(ppir_block
*block
);
481 bool ppir_instr_insert_node(ppir_instr
*instr
, ppir_node
*node
);
482 void ppir_instr_add_dep(ppir_instr
*succ
, ppir_instr
*pred
);
483 void ppir_instr_print_list(ppir_compiler
*comp
);
484 void ppir_instr_print_dep(ppir_compiler
*comp
);
485 void ppir_instr_insert_mul_node(ppir_node
*add
, ppir_node
*mul
);
487 #define ppir_instr_foreach_succ(instr, dep) \
488 list_for_each_entry(ppir_dep, dep, &instr->succ_list, succ_link)
489 #define ppir_instr_foreach_succ_safe(instr, dep) \
490 list_for_each_entry_safe(ppir_dep, dep, &instr->succ_list, succ_link)
491 #define ppir_instr_foreach_pred(instr, dep) \
492 list_for_each_entry(ppir_dep, dep, &instr->pred_list, pred_link)
493 #define ppir_instr_foreach_pred_safe(instr, dep) \
494 list_for_each_entry_safe(ppir_dep, dep, &instr->pred_list, pred_link)
496 static inline bool ppir_instr_is_root(ppir_instr
*instr
)
498 return list_empty(&instr
->succ_list
);
501 static inline bool ppir_instr_is_leaf(ppir_instr
*instr
)
503 return list_empty(&instr
->pred_list
);
506 bool ppir_lower_prog(ppir_compiler
*comp
);
507 bool ppir_node_to_instr(ppir_compiler
*comp
);
508 bool ppir_schedule_prog(ppir_compiler
*comp
);
509 bool ppir_regalloc_prog(ppir_compiler
*comp
);
510 bool ppir_codegen_prog(ppir_compiler
*comp
);