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_texture
,
115 ppir_node_type_const
,
117 ppir_node_type_store
,
118 ppir_node_type_load_texture
,
127 extern const ppir_op_info ppir_op_infos
[];
131 struct list_head pred_link
;
132 struct list_head succ_link
;
135 typedef struct ppir_node
{
136 struct list_head list
;
142 struct ppir_instr
*instr
;
144 struct ppir_block
*block
;
147 struct list_head succ_list
;
148 struct list_head pred_list
;
152 ppir_pipeline_reg_const0
,
153 ppir_pipeline_reg_const1
,
154 ppir_pipeline_reg_sampler
,
155 ppir_pipeline_reg_uniform
,
156 ppir_pipeline_reg_vmul
,
157 ppir_pipeline_reg_fmul
,
158 ppir_pipeline_reg_discard
, /* varying load */
161 typedef struct ppir_reg
{
162 struct list_head list
;
165 /* whether this reg has to start from the x component
166 * of a full physical reg, this is true for reg used
167 * in load/store instr which has no swizzle field
170 /* instr live range */
171 int live_in
, live_out
;
177 ppir_target_pipeline
,
178 ppir_target_register
,
181 typedef struct ppir_src
{
187 ppir_pipeline pipeline
;
191 bool absolute
, negate
;
196 ppir_outmod_clamp_fraction
,
197 ppir_outmod_clamp_positive
,
201 typedef struct ppir_dest
{
207 ppir_pipeline pipeline
;
210 ppir_outmod modifier
;
211 unsigned write_mask
: 4;
219 int shift
: 3; /* Only used for ppir_op_mul */
222 typedef struct ppir_const
{
254 } ppir_load_texture_node
;
256 enum ppir_instr_slot
{
257 PPIR_INSTR_SLOT_VARYING
,
258 PPIR_INSTR_SLOT_TEXLD
,
259 PPIR_INSTR_SLOT_UNIFORM
,
260 PPIR_INSTR_SLOT_ALU_VEC_MUL
,
261 PPIR_INSTR_SLOT_ALU_SCL_MUL
,
262 PPIR_INSTR_SLOT_ALU_VEC_ADD
,
263 PPIR_INSTR_SLOT_ALU_SCL_ADD
,
264 PPIR_INSTR_SLOT_ALU_COMBINE
,
265 PPIR_INSTR_SLOT_STORE_TEMP
,
268 PPIR_INSTR_SLOT_ALU_START
= PPIR_INSTR_SLOT_ALU_VEC_MUL
,
269 PPIR_INSTR_SLOT_ALU_END
= PPIR_INSTR_SLOT_ALU_COMBINE
,
272 typedef struct ppir_instr
{
273 struct list_head list
;
276 int seq
; /* command sequence after schedule */
278 ppir_node
*slots
[PPIR_INSTR_SLOT_NUM
];
279 ppir_const constant
[2];
283 struct list_head succ_list
;
284 struct list_head pred_list
;
286 int est
; /* earliest start time */
291 typedef struct ppir_block
{
292 struct list_head list
;
293 struct list_head node_list
;
294 struct list_head instr_list
;
295 struct ppir_compiler
*comp
;
298 int sched_instr_index
;
299 int sched_instr_base
;
303 struct lima_fs_shader_state
;
305 typedef struct ppir_compiler
{
306 struct list_head block_list
;
310 struct list_head reg_list
;
312 /* array for searching ssa/reg node */
313 ppir_node
**var_nodes
;
317 struct lima_fs_shader_state
*prog
;
320 int sched_instr_base
;
322 /* for regalloc spilling debug */
326 void *ppir_node_create(ppir_block
*block
, ppir_op op
, int index
, unsigned mask
);
327 void ppir_node_add_dep(ppir_node
*succ
, ppir_node
*pred
);
328 void ppir_node_remove_dep(ppir_dep
*dep
);
329 void ppir_node_delete(ppir_node
*node
);
330 void ppir_node_print_prog(ppir_compiler
*comp
);
331 void ppir_node_replace_child(ppir_node
*parent
, ppir_node
*old_child
, ppir_node
*new_child
);
332 void ppir_node_replace_all_succ(ppir_node
*dst
, ppir_node
*src
);
333 void ppir_node_replace_pred(ppir_dep
*dep
, ppir_node
*new_pred
);
335 static inline bool ppir_node_is_root(ppir_node
*node
)
337 return list_empty(&node
->succ_list
);
340 static inline bool ppir_node_is_leaf(ppir_node
*node
)
342 return list_empty(&node
->pred_list
);
345 static inline bool ppir_node_has_single_succ(ppir_node
*node
)
347 return list_is_singular(&node
->succ_list
);
350 static inline ppir_node
*ppir_node_first_succ(ppir_node
*node
)
352 return list_first_entry(&node
->succ_list
, ppir_dep
, succ_link
)->succ
;
355 static inline bool ppir_node_has_single_pred(ppir_node
*node
)
357 return list_is_singular(&node
->pred_list
);
360 static inline ppir_node
*ppir_node_first_pred(ppir_node
*node
)
362 return list_first_entry(&node
->pred_list
, ppir_dep
, pred_link
)->pred
;
365 #define ppir_node_foreach_succ(node, dep) \
366 list_for_each_entry(ppir_dep, dep, &node->succ_list, succ_link)
367 #define ppir_node_foreach_succ_safe(node, dep) \
368 list_for_each_entry_safe(ppir_dep, dep, &node->succ_list, succ_link)
369 #define ppir_node_foreach_pred(node, dep) \
370 list_for_each_entry(ppir_dep, dep, &node->pred_list, pred_link)
371 #define ppir_node_foreach_pred_safe(node, dep) \
372 list_for_each_entry_safe(ppir_dep, dep, &node->pred_list, pred_link)
374 #define ppir_node_to_alu(node) ((ppir_alu_node *)(node))
375 #define ppir_node_to_const(node) ((ppir_const_node *)(node))
376 #define ppir_node_to_load(node) ((ppir_load_node *)(node))
377 #define ppir_node_to_store(node) ((ppir_store_node *)(node))
378 #define ppir_node_to_load_texture(node) ((ppir_load_texture_node *)(node))
380 static inline ppir_dest
*ppir_node_get_dest(ppir_node
*node
)
382 switch (node
->type
) {
383 case ppir_node_type_alu
:
384 return &ppir_node_to_alu(node
)->dest
;
385 case ppir_node_type_load
:
386 return &ppir_node_to_load(node
)->dest
;
387 case ppir_node_type_const
:
388 return &ppir_node_to_const(node
)->dest
;
389 case ppir_node_type_load_texture
:
390 return &ppir_node_to_load_texture(node
)->dest
;
396 static inline void ppir_node_target_assign(ppir_src
*src
, ppir_dest
*dest
)
398 src
->type
= dest
->type
;
400 case ppir_target_ssa
:
401 src
->ssa
= &dest
->ssa
;
403 case ppir_target_register
:
404 src
->reg
= dest
->reg
;
406 case ppir_target_pipeline
:
407 src
->pipeline
= dest
->pipeline
;
412 static inline bool ppir_node_target_equal(ppir_src
*src
, ppir_dest
*dest
)
414 if (src
->type
!= dest
->type
||
415 (src
->type
== ppir_target_ssa
&& src
->ssa
!= &dest
->ssa
) ||
416 (src
->type
== ppir_target_register
&& src
->reg
!= dest
->reg
) ||
417 (src
->type
== ppir_target_pipeline
&& src
->pipeline
!= dest
->pipeline
))
423 static inline int ppir_target_get_src_reg_index(ppir_src
*src
)
426 case ppir_target_ssa
:
427 return src
->ssa
->index
;
428 case ppir_target_register
:
429 return src
->reg
->index
;
430 case ppir_target_pipeline
:
431 if (src
->pipeline
== ppir_pipeline_reg_discard
)
433 return (src
->pipeline
+ 12) * 4;
439 static inline int ppir_target_get_dest_reg_index(ppir_dest
*dest
)
441 switch (dest
->type
) {
442 case ppir_target_ssa
:
443 return dest
->ssa
.index
;
444 case ppir_target_register
:
445 return dest
->reg
->index
;
446 case ppir_target_pipeline
:
447 if (dest
->pipeline
== ppir_pipeline_reg_discard
)
449 return (dest
->pipeline
+ 12) * 4;
455 static inline bool ppir_target_is_scaler(ppir_dest
*dest
)
457 switch (dest
->type
) {
458 case ppir_target_ssa
:
459 return dest
->ssa
.num_components
== 1;
460 case ppir_target_register
:
461 /* only one bit in mask is set */
462 if ((dest
->write_mask
& 0x3) == 0x3 ||
463 (dest
->write_mask
& 0x5) == 0x5 ||
464 (dest
->write_mask
& 0x9) == 0x9 ||
465 (dest
->write_mask
& 0x6) == 0x6 ||
466 (dest
->write_mask
& 0xa) == 0xa ||
467 (dest
->write_mask
& 0xc) == 0xc)
471 case ppir_target_pipeline
:
472 if (dest
->pipeline
== ppir_pipeline_reg_fmul
)
481 ppir_instr
*ppir_instr_create(ppir_block
*block
);
482 bool ppir_instr_insert_node(ppir_instr
*instr
, ppir_node
*node
);
483 void ppir_instr_add_dep(ppir_instr
*succ
, ppir_instr
*pred
);
484 void ppir_instr_print_list(ppir_compiler
*comp
);
485 void ppir_instr_print_dep(ppir_compiler
*comp
);
486 void ppir_instr_insert_mul_node(ppir_node
*add
, ppir_node
*mul
);
488 #define ppir_instr_foreach_succ(instr, dep) \
489 list_for_each_entry(ppir_dep, dep, &instr->succ_list, succ_link)
490 #define ppir_instr_foreach_succ_safe(instr, dep) \
491 list_for_each_entry_safe(ppir_dep, dep, &instr->succ_list, succ_link)
492 #define ppir_instr_foreach_pred(instr, dep) \
493 list_for_each_entry(ppir_dep, dep, &instr->pred_list, pred_link)
494 #define ppir_instr_foreach_pred_safe(instr, dep) \
495 list_for_each_entry_safe(ppir_dep, dep, &instr->pred_list, pred_link)
497 static inline bool ppir_instr_is_root(ppir_instr
*instr
)
499 return list_empty(&instr
->succ_list
);
502 static inline bool ppir_instr_is_leaf(ppir_instr
*instr
)
504 return list_empty(&instr
->pred_list
);
507 bool ppir_lower_prog(ppir_compiler
*comp
);
508 bool ppir_node_to_instr(ppir_compiler
*comp
);
509 bool ppir_schedule_prog(ppir_compiler
*comp
);
510 bool ppir_regalloc_prog(ppir_compiler
*comp
);
511 bool ppir_codegen_prog(ppir_compiler
*comp
);