pco: support dce for vregs

Signed-off-by: Simon Perretta <simon.perretta@imgtec.com>
Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36412>
This commit is contained in:
Simon Perretta 2025-02-18 12:08:55 +00:00 committed by Marge Bot
parent 801215d03e
commit bd274e27be
3 changed files with 39 additions and 12 deletions

View file

@ -304,6 +304,8 @@ ForEachMacros: [
'pco_foreach_phase_in_igrp_rev',
'pco_foreach_phase_rev',
'pco_foreach_phi_src_in_instr',
'pco_foreach_vreg_if_in_func',
'pco_foreach_vreg_ssa_if_in_func',
'pvr_foreach_supported_tex_format',
'pvr_foreach_supported_tex_format_',
'pvr_foreach_supported_tex_format_compressed',

View file

@ -550,6 +550,16 @@ PCO_DEFINE_CAST(pco_cf_node_as_func,
pif = pco_next_if(pif)) \
if (pco_ref_is_ssa(pif->cond) && pco_ref_get_bits(pif->cond) == 1)
#define pco_foreach_vreg_if_in_func(pif, func) \
for (pco_if *pif = pco_func_first_if(func); pif != NULL; \
pif = pco_next_if(pif)) \
if (pco_ref_is_vreg(pif->cond))
#define pco_foreach_vreg_ssa_if_in_func(pif, func) \
for (pco_if *pif = pco_func_first_if(func); pif != NULL; \
pif = pco_next_if(pif)) \
if (pco_ref_is_vreg(pif->cond) || pco_ref_is_ssa(pif->cond))
#define pco_foreach_if_in_func_from(pif, from) \
for (pco_if *pif = pco_next_if(from); pif != NULL; pif = pco_next_if(pif))

View file

@ -573,41 +573,56 @@ bool pco_dce(pco_shader *shader)
{
bool progress = false;
BITSET_WORD *ssa_used;
BITSET_WORD *vreg_used;
pco_foreach_func_in_shader (func, shader) {
ssa_used = rzalloc_array_size(NULL,
sizeof(*ssa_used),
BITSET_WORDS(func->next_ssa));
/* Collect used SSA sources. */
vreg_used = rzalloc_array_size(NULL,
sizeof(*vreg_used),
BITSET_WORDS(func->next_vreg));
/* Collect used SSA/vreg sources. */
pco_foreach_instr_in_func (instr, func) {
pco_foreach_instr_src_ssa (psrc, instr) {
BITSET_SET(ssa_used, psrc->val);
pco_foreach_instr_src_vreg_ssa (psrc, instr) {
if (pco_ref_is_ssa(*psrc))
BITSET_SET(ssa_used, psrc->val);
else
BITSET_SET(vreg_used, psrc->val);
}
}
pco_foreach_ssa_if_in_func (pif, func) {
BITSET_SET(ssa_used, pif->cond.val);
pco_foreach_vreg_ssa_if_in_func (pif, func) {
if (pco_ref_is_ssa(pif->cond))
BITSET_SET(ssa_used, pif->cond.val);
else
BITSET_SET(vreg_used, pif->cond.val);
}
/* Remove instructions with unused SSA destinations (if they also have no
* side-effects).
/* Remove instructions with unused SSA/vreg destinations (if they also
* have no side-effects).
*/
pco_foreach_instr_in_func_safe (instr, func) {
bool has_ssa_dests = false;
bool has_dce_dests = false;
bool dests_used = false;
pco_foreach_instr_dest_ssa (pdest, instr) {
has_ssa_dests = true;
dests_used |= BITSET_TEST(ssa_used, pdest->val);
pco_foreach_instr_dest_vreg_ssa (pdest, instr) {
has_dce_dests = true;
if (pco_ref_is_ssa(*pdest))
dests_used |= BITSET_TEST(ssa_used, pdest->val);
else
dests_used |= BITSET_TEST(vreg_used, pdest->val);
}
if (has_ssa_dests && !dests_used && !instr_has_side_effects(instr)) {
if (has_dce_dests && !dests_used && !instr_has_side_effects(instr)) {
pco_instr_delete(instr);
progress = true;
}
}
ralloc_free(vreg_used);
ralloc_free(ssa_used);
}