diff --git a/src/imagination/pco/pco_internal.h b/src/imagination/pco/pco_internal.h index 8016ef0a031..d6fca168a5b 100644 --- a/src/imagination/pco/pco_internal.h +++ b/src/imagination/pco/pco_internal.h @@ -24,6 +24,7 @@ #include "util/hash_table.h" #include "util/macros.h" #include "util/list.h" +#include "util/u_debug.h" #include "util/u_dynarray.h" #include "util/u_math.h" @@ -2150,6 +2151,32 @@ static inline pco_instr *find_parent_instr_from(pco_ref src, pco_instr *from) return NULL; } +static inline bool pco_should_skip_pass(const char *pass) +{ + return comma_separated_list_contains(pco_skip_passes, pass); +} + +#define PCO_PASS(progress, shader, pass, ...) \ + do { \ + if (pco_should_skip_pass(#pass)) { \ + fprintf(stdout, "Skipping pass '%s'\n", #pass); \ + break; \ + } \ + \ + if (pass(shader, ##__VA_ARGS__)) { \ + UNUSED bool _; \ + progress = true; \ + \ + if (PCO_DEBUG(REINDEX)) \ + pco_index(shader, false); \ + \ + pco_validate_shader(shader, "after " #pass); \ + \ + if (pco_should_print_shader_pass(shader)) \ + pco_print_shader(shader, stdout, "after " #pass); \ + } \ + } while (0) + /* Common hw constants. */ /** Integer/float zero. */ diff --git a/src/imagination/pco/pco_ir.c b/src/imagination/pco/pco_ir.c index 7b2dfe70795..3c42b79138e 100644 --- a/src/imagination/pco/pco_ir.c +++ b/src/imagination/pco/pco_ir.c @@ -12,37 +12,10 @@ #include "pco.h" #include "pco_internal.h" -#include "util/u_debug.h" #include #include -static inline bool pco_should_skip_pass(const char *pass) -{ - return comma_separated_list_contains(pco_skip_passes, pass); -} - -#define PCO_PASS(progress, shader, pass, ...) \ - do { \ - if (pco_should_skip_pass(#pass)) { \ - fprintf(stdout, "Skipping pass '%s'\n", #pass); \ - break; \ - } \ - \ - if (pass(shader, ##__VA_ARGS__)) { \ - UNUSED bool _; \ - progress = true; \ - \ - if (PCO_DEBUG(REINDEX)) \ - pco_index(shader, false); \ - \ - pco_validate_shader(shader, "after " #pass); \ - \ - if (pco_should_print_shader_pass(shader)) \ - pco_print_shader(shader, stdout, "after " #pass); \ - } \ - } while (0) - /** * \brief Runs passes on a PCO shader. * diff --git a/src/imagination/pco/pco_opt.c b/src/imagination/pco/pco_opt.c index 9d4d2903524..71a4a3cfb69 100644 --- a/src/imagination/pco/pco_opt.c +++ b/src/imagination/pco/pco_opt.c @@ -44,7 +44,8 @@ struct pco_opt_ctx { * \param[in,out] ctx Shared optimization context. * \return True if any instructions were modified. */ -static inline bool prep_mods(pco_shader *shader, struct pco_opt_ctx *ctx) +static inline bool pco_opt_prep_mods(pco_shader *shader, + struct pco_opt_ctx *ctx) { bool progress = false; @@ -161,7 +162,8 @@ static inline bool prep_mods(pco_shader *shader, struct pco_opt_ctx *ctx) * \param[in,out] ctx Shared optimization context. * \return True if any instructions were modified. */ -static inline bool lower_mods(pco_shader *shader, struct pco_opt_ctx *ctx) +static inline bool pco_opt_lower_mods(pco_shader *shader, + struct pco_opt_ctx *ctx) { bool progress = false; @@ -276,7 +278,7 @@ static inline bool try_back_prop_instr(struct pco_use *uses, pco_instr *instr) * \param[in,out] shader PCO shader. * \return True if any back-propagations were performed. */ -static inline bool back_prop(pco_shader *shader) +static inline bool pco_opt_back_prop(pco_shader *shader) { bool progress = false; struct pco_use *uses; @@ -400,7 +402,7 @@ static inline bool try_fwd_prop_instr(pco_instr **writes, pco_instr *instr) * \param[in,out] shader PCO shader. * \return True if any forward-propagations were performed. */ -static inline bool fwd_prop(pco_shader *shader) +static inline bool pco_opt_fwd_prop(pco_shader *shader) { bool progress = false; pco_instr **writes; @@ -464,7 +466,7 @@ static inline bool try_prop_hw_comp(pco_ref src, pco_ref repl, pco_instr *from) * \param[in,out] shader PCO shader. * \return True if any hw reg propagations were performed. */ -static inline bool prop_hw_comps(pco_shader *shader) +static inline bool pco_opt_prop_hw_comps(pco_shader *shader) { bool progress = false; pco_foreach_func_in_shader (func, shader) { @@ -506,17 +508,17 @@ bool pco_opt(pco_shader *shader) bool progress = false; struct pco_opt_ctx ctx = { .mem_ctx = ralloc_context(NULL) }; - progress |= prep_mods(shader, &ctx); - progress |= back_prop(shader); - progress |= fwd_prop(shader); + PCO_PASS(progress, shader, pco_opt_prep_mods, &ctx); + PCO_PASS(progress, shader, pco_opt_back_prop); + PCO_PASS(progress, shader, pco_opt_fwd_prop); /* TODO: Track whether there are any comp instructions referencing hw - * registers resulting from the previous passes, and only run prop_hw_comps - * if this is the case. + * registers resulting from the previous passes, and only run + * pco_opt_prop_hw_comps if this is the case. */ - progress |= prop_hw_comps(shader); - progress |= lower_mods(shader, &ctx); + PCO_PASS(progress, shader, pco_opt_prop_hw_comps); + PCO_PASS(progress, shader, pco_opt_lower_mods, &ctx); ralloc_free(ctx.mem_ctx); return progress; }