pco: Switch back to util/list

Signed-off-by: Ella Stanforth <ella@igalia.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:
Ella Stanforth 2025-08-07 08:36:40 +01:00 committed by Marge Bot
parent 28bee9fbdd
commit 719ece42c0
9 changed files with 247 additions and 185 deletions

View file

@ -10,7 +10,6 @@
* \brief Main compiler interface. * \brief Main compiler interface.
*/ */
#include "compiler/list.h"
#include "compiler/glsl_types.h" #include "compiler/glsl_types.h"
#include "nir_serialize.h" #include "nir_serialize.h"
#include "pco.h" #include "pco.h"
@ -96,7 +95,7 @@ pco_shader *pco_shader_create(pco_ctx *ctx, nir_shader *nir, void *mem_ctx)
shader->name = ralloc_strdup(shader, nir->info.name); shader->name = ralloc_strdup(shader, nir->info.name);
shader->is_internal = nir->info.internal; shader->is_internal = nir->info.internal;
shader->is_grouped = false; shader->is_grouped = false;
exec_list_make_empty(&shader->funcs); list_inithead(&shader->funcs);
return shader; return shader;
} }
@ -134,15 +133,15 @@ pco_func *pco_func_create(pco_shader *shader,
*/ */
if (type == PCO_FUNC_TYPE_PREAMBLE) { if (type == PCO_FUNC_TYPE_PREAMBLE) {
assert(!preamble); assert(!preamble);
exec_list_push_head(&shader->funcs, &func->node); list_add(&func->link, &shader->funcs);
} else if (type == PCO_FUNC_TYPE_ENTRYPOINT) { } else if (type == PCO_FUNC_TYPE_ENTRYPOINT) {
assert(!pco_entrypoint(shader)); assert(!pco_entrypoint(shader));
if (!preamble) if (!preamble)
exec_list_push_head(&shader->funcs, &func->node); list_add(&func->link, &shader->funcs);
else else
exec_node_insert_after(&func->node, &preamble->node); list_add(&func->link, &preamble->link);
} else { } else {
exec_list_push_tail(&shader->funcs, &func->node); list_addtail(&func->link, &shader->funcs);
} }
init_cf_node(&func->cf_node, PCO_CF_NODE_TYPE_FUNC); init_cf_node(&func->cf_node, PCO_CF_NODE_TYPE_FUNC);
@ -150,7 +149,7 @@ pco_func *pco_func_create(pco_shader *shader,
func->type = type; func->type = type;
func->index = shader->next_func++; func->index = shader->next_func++;
exec_list_make_empty(&func->body); list_inithead(&func->body);
func->num_params = num_params; func->num_params = num_params;
if (num_params) { if (num_params) {
@ -177,7 +176,7 @@ pco_block *pco_block_create(pco_func *func)
init_cf_node(&block->cf_node, PCO_CF_NODE_TYPE_BLOCK); init_cf_node(&block->cf_node, PCO_CF_NODE_TYPE_BLOCK);
block->parent_func = func; block->parent_func = func;
exec_list_make_empty(&block->instrs); list_inithead(&block->instrs);
block->index = func->next_block++; block->index = func->next_block++;
return block; return block;
@ -195,11 +194,11 @@ pco_if *pco_if_create(pco_func *func)
init_cf_node(&pif->cf_node, PCO_CF_NODE_TYPE_IF); init_cf_node(&pif->cf_node, PCO_CF_NODE_TYPE_IF);
pif->parent_func = func; pif->parent_func = func;
exec_list_make_empty(&pif->prologue); list_inithead(&pif->prologue);
exec_list_make_empty(&pif->then_body); list_inithead(&pif->then_body);
exec_list_make_empty(&pif->interlogue); list_inithead(&pif->interlogue);
exec_list_make_empty(&pif->else_body); list_inithead(&pif->else_body);
exec_list_make_empty(&pif->epilogue); list_inithead(&pif->epilogue);
pif->index = func->next_if++; pif->index = func->next_if++;
return pif; return pif;
@ -217,10 +216,10 @@ pco_loop *pco_loop_create(pco_func *func)
init_cf_node(&loop->cf_node, PCO_CF_NODE_TYPE_LOOP); init_cf_node(&loop->cf_node, PCO_CF_NODE_TYPE_LOOP);
loop->parent_func = func; loop->parent_func = func;
exec_list_make_empty(&loop->prologue); list_inithead(&loop->prologue);
exec_list_make_empty(&loop->body); list_inithead(&loop->body);
exec_list_make_empty(&loop->interlogue); list_inithead(&loop->interlogue);
exec_list_make_empty(&loop->epilogue); list_inithead(&loop->epilogue);
loop->index = func->next_loop++; loop->index = func->next_loop++;
return loop; return loop;
@ -282,7 +281,7 @@ pco_igrp *pco_igrp_create(pco_func *func)
*/ */
void pco_instr_delete(pco_instr *instr) void pco_instr_delete(pco_instr *instr)
{ {
exec_node_remove(&instr->node); list_del(&instr->link);
ralloc_free(instr); ralloc_free(instr);
} }

View file

@ -13,9 +13,9 @@
* \\brief PCO builder header. * \\brief PCO builder header.
*/ */
#include "compiler/list.h"
#include "pco.h" #include "pco.h"
#include "pco_internal.h" #include "pco_internal.h"
#include "util/list.h"
#include "util/macros.h" #include "util/macros.h"
#include <stdbool.h> #include <stdbool.h>
@ -100,26 +100,25 @@ static inline pco_cursor pco_cursor_after_block(pco_block *block)
} }
/** /**
* \brief Returns a cursor set to before an exec_list. * \brief Returns a cursor set to before a list.
* *
* \param[in] exec_list The exec_list. * \param[in] list The list.
* \return The cursor. * \return The cursor.
*/ */
static inline pco_cursor static inline pco_cursor pco_cursor_before_list(struct list_head *list)
pco_cursor_before_exec_list(struct exec_list *exec_list)
{ {
return pco_cursor_before_cf_node(pco_cf_node_head(exec_list)); return pco_cursor_before_cf_node(pco_cf_node_head(list));
} }
/** /**
* \brief Returns a cursor set to after an exec_list. * \brief Returns a cursor set to after an exec_list.
* *
* \param[in] block The exec_list. * \param[in] list The list.
* \return The exec_list. * \return The list.
*/ */
static inline pco_cursor pco_cursor_after_exec_list(struct exec_list *exec_list) static inline pco_cursor pco_cursor_after_list(struct list_head *list)
{ {
return pco_cursor_after_cf_node(pco_cf_node_tail(exec_list)); return pco_cursor_after_cf_node(pco_cf_node_tail(list));
} }
/** /**
@ -413,14 +412,14 @@ static inline void pco_builder_insert_instr(pco_builder *b, pco_instr *instr)
if (cursor_instr) { if (cursor_instr) {
if (before) if (before)
exec_node_insert_node_before(&cursor_instr->node, &instr->node); list_add(&instr->link, cursor_instr->link.prev);
else else
exec_node_insert_after(&cursor_instr->node, &instr->node); list_add(&instr->link, &cursor_instr->link);
} else { } else {
if (before) if (before)
exec_list_push_head(&block->instrs, &instr->node); list_add(&instr->link, &block->instrs);
else else
exec_list_push_tail(&block->instrs, &instr->node); list_addtail(&instr->link, &block->instrs);
} }
b->cursor = pco_cursor_after_instr(instr); b->cursor = pco_cursor_after_instr(instr);
@ -442,14 +441,14 @@ static inline void pco_builder_insert_igrp(pco_builder *b, pco_igrp *igrp)
if (cursor_igrp) { if (cursor_igrp) {
if (before) if (before)
exec_node_insert_node_before(&cursor_igrp->node, &igrp->node); list_add(&igrp->link, cursor_igrp->link.prev);
else else
exec_node_insert_after(&cursor_igrp->node, &igrp->node); list_add(&igrp->link, &cursor_igrp->link);
} else { } else {
if (before) if (before)
exec_list_push_head(&block->instrs, &igrp->node); list_add(&igrp->link, &block->instrs);
else else
exec_list_push_tail(&block->instrs, &igrp->node); list_addtail(&igrp->link, &block->instrs);
} }
b->cursor = pco_cursor_after_igrp(igrp); b->cursor = pco_cursor_after_igrp(igrp);

View file

@ -10,11 +10,11 @@
* \brief PCO control-flow passes. * \brief PCO control-flow passes.
*/ */
#include "compiler/list.h"
#include "pco.h" #include "pco.h"
#include "pco_builder.h" #include "pco_builder.h"
#include "util/bitscan.h" #include "util/bitscan.h"
#include "util/bitset.h" #include "util/bitset.h"
#include "util/list.h"
#include "util/macros.h" #include "util/macros.h"
#include "util/ralloc.h" #include "util/ralloc.h"
#include "util/u_dynarray.h" #include "util/u_dynarray.h"
@ -42,7 +42,7 @@ static pco_ref emc_ref(pco_func *func, pco_builder *b)
static inline pco_block *cf_section_create(pco_func *func, static inline pco_block *cf_section_create(pco_func *func,
pco_cf_node *parent_cf_node, pco_cf_node *parent_cf_node,
struct exec_list *cf_node_list, struct list_head *cf_node_list,
enum pco_cf_node_flag flag) enum pco_cf_node_flag flag)
{ {
assert(flag == PCO_CF_NODE_FLAG_PROLOGUE || assert(flag == PCO_CF_NODE_FLAG_PROLOGUE ||
@ -52,14 +52,14 @@ static inline pco_block *cf_section_create(pco_func *func,
pco_block *block = pco_block_create(func); pco_block *block = pco_block_create(func);
block->cf_node.parent = parent_cf_node; block->cf_node.parent = parent_cf_node;
block->cf_node.flag = flag; block->cf_node.flag = flag;
exec_list_push_tail(cf_node_list, &block->cf_node.node); list_addtail(&block->cf_node.link, cf_node_list);
return block; return block;
} }
static inline bool body_has_non_preds(struct exec_list *body) static inline bool body_has_non_preds(struct list_head *body)
{ {
if (exec_list_is_empty(body)) if (list_is_empty(body))
return false; return false;
pco_block *block = pco_cf_node_as_block(pco_cf_node_head(body)); pco_block *block = pco_cf_node_as_block(pco_cf_node_head(body));
@ -95,10 +95,8 @@ static inline bool can_pred_exec(pco_if *pif)
return false; return false;
/* Skip if there is any nesting. */ /* Skip if there is any nesting. */
if (exec_list_length(&pif->then_body) > 1 || if (list_length(&pif->then_body) > 1 || list_length(&pif->else_body) > 1)
exec_list_length(&pif->else_body) > 1) {
return false; return false;
}
/* Skip if then/else blocks end with a branch, or contain non-predicatable /* Skip if then/else blocks end with a branch, or contain non-predicatable
* instructions. * instructions.
@ -113,10 +111,10 @@ static inline bool can_pred_exec(pco_if *pif)
return true; return true;
} }
static inline void set_body_exec_cnd(struct exec_list *body, static inline void set_body_exec_cnd(struct list_head *body,
enum pco_exec_cnd exec_cnd) enum pco_exec_cnd exec_cnd)
{ {
assert(!exec_list_is_empty(body)); assert(!list_is_empty(body));
pco_block *block = pco_cf_node_as_block(pco_cf_node_head(body)); pco_block *block = pco_cf_node_as_block(pco_cf_node_head(body));
pco_foreach_instr_in_block (instr, block) { pco_foreach_instr_in_block (instr, block) {
@ -223,18 +221,18 @@ lower_if_cond_exec(pco_if *pif, pco_func *func, bool has_else, bool invert_cond)
static inline void lower_if(pco_if *pif, pco_func *func) static inline void lower_if(pco_if *pif, pco_func *func)
{ {
assert(!pco_ref_is_null(pif->cond)); assert(!pco_ref_is_null(pif->cond));
assert(exec_list_is_empty(&pif->prologue)); assert(list_is_empty(&pif->prologue));
assert(exec_list_is_empty(&pif->interlogue)); assert(list_is_empty(&pif->interlogue));
assert(exec_list_is_empty(&pif->epilogue)); assert(list_is_empty(&pif->epilogue));
bool has_then = !exec_list_is_empty(&pif->then_body); bool has_then = !list_is_empty(&pif->then_body);
bool has_else = !exec_list_is_empty(&pif->else_body); bool has_else = !list_is_empty(&pif->else_body);
assert(has_then || has_else); assert(has_then || has_else);
/* If we only have an else body, invert the condition and bodies. */ /* If we only have an else body, invert the condition and bodies. */
bool invert_cond = false; bool invert_cond = false;
if (!has_then && has_else) { if (!has_then && has_else) {
struct exec_list temp; struct list_head temp;
memcpy(&temp, &pif->then_body, sizeof(pif->then_body)); memcpy(&temp, &pif->then_body, sizeof(pif->then_body));
memcpy(&pif->then_body, &pif->else_body, sizeof(pif->else_body)); memcpy(&pif->then_body, &pif->else_body, sizeof(pif->else_body));
memcpy(&pif->else_body, &pif->then_body, sizeof(pif->then_body)); memcpy(&pif->else_body, &pif->then_body, sizeof(pif->then_body));
@ -256,9 +254,9 @@ static inline void lower_if(pco_if *pif, pco_func *func)
static inline void lower_loop(pco_loop *loop, pco_func *func) static inline void lower_loop(pco_loop *loop, pco_func *func)
{ {
assert(exec_list_is_empty(&loop->prologue)); assert(list_is_empty(&loop->prologue));
assert(exec_list_is_empty(&loop->interlogue)); assert(list_is_empty(&loop->interlogue));
assert(exec_list_is_empty(&loop->epilogue)); assert(list_is_empty(&loop->epilogue));
pco_block *prologue = cf_section_create(func, pco_block *prologue = cf_section_create(func,
&loop->cf_node, &loop->cf_node,

View file

@ -10,7 +10,6 @@
* \brief PCO instruction grouping pass. * \brief PCO instruction grouping pass.
*/ */
#include "compiler/list.h"
#include "hwdef/rogue_hw_defs.h" #include "hwdef/rogue_hw_defs.h"
#include "pco.h" #include "pco.h"
#include "pco_builder.h" #include "pco_builder.h"

View file

@ -13,7 +13,6 @@
* \brief PCO internal header. * \brief PCO internal header.
*/ */
#include "compiler/list.h"
#include "compiler/spirv/nir_spirv.h" #include "compiler/spirv/nir_spirv.h"
#include "hwdef/rogue_hw_utils.h" #include "hwdef/rogue_hw_utils.h"
#include "pco.h" #include "pco.h"
@ -142,7 +141,7 @@ typedef struct _pco_phi_src {
/** PCO instruction group. */ /** PCO instruction group. */
typedef struct _pco_igrp { typedef struct _pco_igrp {
struct exec_node node; /** Node in pco_block::instrs. */ struct list_head link; /** Node in pco_block::instrs. */
pco_block *parent_block; /** Basic block containing the igrp. */ pco_block *parent_block; /** Basic block containing the igrp. */
pco_func *parent_func; /** Parent function. */ pco_func *parent_func; /** Parent function. */
@ -225,7 +224,7 @@ typedef struct _pco_igrp {
typedef struct _pco_instr { typedef struct _pco_instr {
union { union {
struct { struct {
struct exec_node node; /** Node in pco_block::instrs. */ struct list_head link; /** Node in pco_block::instrs. */
pco_block *parent_block; /** Basic block containing the instruction. */ pco_block *parent_block; /** Basic block containing the instruction. */
}; };
@ -278,7 +277,7 @@ enum pco_cf_node_flag {
/** PCO control-flow node. */ /** PCO control-flow node. */
typedef struct _pco_cf_node { typedef struct _pco_cf_node {
struct exec_node node; /** Node in lists of pco_cf_nodes. */ struct list_head link; /** Node in lists of pco_cf_nodes. */
enum pco_cf_node_type type; /** CF node type. */ enum pco_cf_node_type type; /** CF node type. */
struct _pco_cf_node *parent; /** Parent cf node. */ struct _pco_cf_node *parent; /** Parent cf node. */
enum pco_cf_node_flag flag; /** Implementation-defined flag. */ enum pco_cf_node_flag flag; /** Implementation-defined flag. */
@ -288,7 +287,7 @@ typedef struct _pco_cf_node {
typedef struct _pco_block { typedef struct _pco_block {
pco_cf_node cf_node; /** Control flow node. */ pco_cf_node cf_node; /** Control flow node. */
pco_func *parent_func; /** Parent function. */ pco_func *parent_func; /** Parent function. */
struct exec_list instrs; /** Instruction/group list. */ struct list_head instrs; /** Instruction/group list. */
unsigned index; /** Block index. */ unsigned index; /** Block index. */
} pco_block; } pco_block;
@ -298,11 +297,11 @@ typedef struct _pco_if {
pco_func *parent_func; /** Parent function. */ pco_func *parent_func; /** Parent function. */
pco_ref cond; /** If condition. */ pco_ref cond; /** If condition. */
bool pred_exec; /** Whether this if construct uses predicated execution. */ bool pred_exec; /** Whether this if construct uses predicated execution. */
struct exec_list prologue; /** List of pco_cf_nodes for if prologue. */ struct list_head prologue; /** List of pco_cf_nodes for if prologue. */
struct exec_list then_body; /** List of pco_cf_nodes for if body. */ struct list_head then_body; /** List of pco_cf_nodes for if body. */
struct exec_list interlogue; /** List of pco_cf_nodes for if interlogue. */ struct list_head interlogue; /** List of pco_cf_nodes for if interlogue. */
struct exec_list else_body; /** List of pco_cf_nodes for else body. */ struct list_head else_body; /** List of pco_cf_nodes for else body. */
struct exec_list epilogue; /** List of pco_cf_nodes for if epilogue. */ struct list_head epilogue; /** List of pco_cf_nodes for if epilogue. */
unsigned index; /** If index. */ unsigned index; /** If index. */
} pco_if; } pco_if;
@ -310,10 +309,10 @@ typedef struct _pco_if {
typedef struct _pco_loop { typedef struct _pco_loop {
pco_cf_node cf_node; /** CF node. */ pco_cf_node cf_node; /** CF node. */
pco_func *parent_func; /** Parent function. */ pco_func *parent_func; /** Parent function. */
struct exec_list prologue; /** List of pco_cf_nodes for loop prologue. */ struct list_head prologue; /** List of pco_cf_nodes for loop prologue. */
struct exec_list body; /** List of pco_cf_nodes for loop body. */ struct list_head body; /** List of pco_cf_nodes for loop body. */
struct exec_list interlogue; /** List of pco_cf_nodes for loop interlogue. */ struct list_head interlogue; /** List of pco_cf_nodes for loop interlogue. */
struct exec_list epilogue; /** List of pco_cf_nodes for loop epilogue. */ struct list_head epilogue; /** List of pco_cf_nodes for loop epilogue. */
unsigned index; /** Loop index. */ unsigned index; /** Loop index. */
} pco_loop; } pco_loop;
@ -328,7 +327,7 @@ typedef struct _pco_vec_info {
/** PCO function. */ /** PCO function. */
typedef struct _pco_func { typedef struct _pco_func {
struct exec_node node; /** Node in pco_shader::funcs. */ struct list_head link; /** Node in pco_shader::funcs. */
pco_cf_node cf_node; /** Control flow node. */ pco_cf_node cf_node; /** Control flow node. */
pco_shader *parent_shader; /** Shader containing the function. */ pco_shader *parent_shader; /** Shader containing the function. */
@ -337,7 +336,7 @@ typedef struct _pco_func {
unsigned index; /** Function index. */ unsigned index; /** Function index. */
const char *name; /** Function name. */ const char *name; /** Function name. */
struct exec_list body; /** List of pco_cf_nodes for function body. */ struct list_head body; /** List of pco_cf_nodes for function body. */
unsigned num_params; unsigned num_params;
pco_ref *params; pco_ref *params;
@ -370,7 +369,7 @@ typedef struct _pco_shader {
bool is_grouped; /** Whether the shader uses igrps. */ bool is_grouped; /** Whether the shader uses igrps. */
bool is_legalized; /** Whether the shader has been legalized. */ bool is_legalized; /** Whether the shader has been legalized. */
struct exec_list funcs; /** List of functions. */ struct list_head funcs; /** List of functions. */
unsigned next_func; /** Next function index. */ unsigned next_func; /** Next function index. */
pco_data data; /** Shader data. */ pco_data data; /** Shader data. */
@ -443,7 +442,7 @@ void pco_instr_delete(pco_instr *instr);
static inline out_type *name(const in_type *parent) \ static inline out_type *name(const in_type *parent) \
{ \ { \
assert(parent && parent->type_field == type_value); \ assert(parent && parent->type_field == type_value); \
return exec_node_data(out_type, parent, field); \ return list_entry(parent, out_type, field); \
} }
PCO_DEFINE_CAST(pco_cf_node_as_block, PCO_DEFINE_CAST(pco_cf_node_as_block,
@ -475,45 +474,45 @@ PCO_DEFINE_CAST(pco_cf_node_as_func,
/* Iterators. */ /* Iterators. */
#define pco_foreach_func_in_shader(func, shader) \ #define pco_foreach_func_in_shader(func, shader) \
foreach_list_typed (pco_func, func, node, &(shader)->funcs) list_for_each_entry (pco_func, func, &(shader)->funcs, link)
#define pco_foreach_func_in_shader_rev(func, shader) \ #define pco_foreach_func_in_shader_rev(func, shader) \
foreach_list_typed_reverse (pco_func, func, node, &(shader)->funcs) list_for_each_entry_rev (pco_func, func, &(shader)->funcs, link)
#define pco_foreach_cf_node_in_if_prologue(cf_node, _if) \ #define pco_foreach_cf_node_in_if_prologue(cf_node, _if) \
foreach_list_typed (pco_cf_node, cf_node, node, &(_if)->prologue) list_for_each_entry (pco_cf_node, cf_node, &(_if)->prologue, link)
#define pco_foreach_cf_node_in_if_then(cf_node, _if) \ #define pco_foreach_cf_node_in_if_then(cf_node, _if) \
foreach_list_typed (pco_cf_node, cf_node, node, &(_if)->then_body) list_for_each_entry (pco_cf_node, cf_node, &(_if)->then_body, link)
#define pco_foreach_cf_node_in_if_interlogue(cf_node, _if) \ #define pco_foreach_cf_node_in_if_interlogue(cf_node, _if) \
foreach_list_typed (pco_cf_node, cf_node, node, &(_if)->interlogue) list_for_each_entry (pco_cf_node, cf_node, &(_if)->interlogue, link)
#define pco_foreach_cf_node_in_if_else(cf_node, _if) \ #define pco_foreach_cf_node_in_if_else(cf_node, _if) \
foreach_list_typed (pco_cf_node, cf_node, node, &(_if)->else_body) list_for_each_entry (pco_cf_node, cf_node, &(_if)->else_body, link)
#define pco_foreach_cf_node_in_if_epilogue(cf_node, _if) \ #define pco_foreach_cf_node_in_if_epilogue(cf_node, _if) \
foreach_list_typed (pco_cf_node, cf_node, node, &(_if)->epilogue) list_for_each_entry (pco_cf_node, cf_node, &(_if)->epilogue, link)
#define pco_foreach_cf_node_in_loop_prologue(cf_node, loop) \ #define pco_foreach_cf_node_in_loop_prologue(cf_node, loop) \
foreach_list_typed (pco_cf_node, cf_node, node, &(loop)->prologue) list_for_each_entry (pco_cf_node, cf_node, &(loop)->prologue, link)
#define pco_foreach_cf_node_in_loop(cf_node, loop) \ #define pco_foreach_cf_node_in_loop(cf_node, loop) \
foreach_list_typed (pco_cf_node, cf_node, node, &(loop)->body) list_for_each_entry (pco_cf_node, cf_node, &(loop)->body, link)
#define pco_foreach_cf_node_in_loop_interlogue(cf_node, loop) \ #define pco_foreach_cf_node_in_loop_interlogue(cf_node, loop) \
foreach_list_typed (pco_cf_node, cf_node, node, &(loop)->interlogue) list_for_each_entry (pco_cf_node, cf_node, &(loop)->interlogue, link)
#define pco_foreach_cf_node_in_loop_epilogue(cf_node, loop) \ #define pco_foreach_cf_node_in_loop_epilogue(cf_node, loop) \
foreach_list_typed (pco_cf_node, cf_node, node, &(loop)->epilogue) list_for_each_entry (pco_cf_node, cf_node, &(loop)->epilogue, link)
#define pco_foreach_cf_node_in_func(cf_node, func) \ #define pco_foreach_cf_node_in_func(cf_node, func) \
foreach_list_typed (pco_cf_node, cf_node, node, &(func)->body) list_for_each_entry (pco_cf_node, cf_node, &(func)->body, link)
#define pco_foreach_cf_node_in_func_structured(cf_node, \ #define pco_foreach_cf_node_in_func_structured(cf_node, \
cf_node_completed, \ cf_node_completed, \
func) \ func) \
for (pco_cf_node *cf_node = pco_first_func_cf_node(func), \ for (pco_cf_node *cf_node = pco_cf_node_head(&(func)->body), \
*cf_node_completed = NULL; \ *cf_node_completed = NULL; \
cf_node != NULL; \ cf_node != NULL; \
cf_node = pco_next_cf_node(cf_node, &cf_node_completed)) cf_node = pco_next_cf_node(cf_node, &cf_node_completed))
@ -585,7 +584,7 @@ PCO_DEFINE_CAST(pco_cf_node_as_func,
loop = pco_prev_loop(loop)) loop = pco_prev_loop(loop))
#define pco_foreach_instr_in_block(instr, block) \ #define pco_foreach_instr_in_block(instr, block) \
foreach_list_typed (pco_instr, instr, node, &(block)->instrs) list_for_each_entry (pco_instr, instr, &(block)->instrs, link)
#define pco_foreach_instr_in_block_from(instr, block, from) \ #define pco_foreach_instr_in_block_from(instr, block, from) \
foreach_list_typed_from (pco_instr, instr, node, _, &from->node) foreach_list_typed_from (pco_instr, instr, node, _, &from->node)
@ -594,16 +593,16 @@ PCO_DEFINE_CAST(pco_cf_node_as_func,
foreach_list_typed_from_reverse (pco_instr, instr, node, _, &from->node) foreach_list_typed_from_reverse (pco_instr, instr, node, _, &from->node)
#define pco_foreach_instr_in_block_safe(instr, block) \ #define pco_foreach_instr_in_block_safe(instr, block) \
foreach_list_typed_safe (pco_instr, instr, node, &(block)->instrs) list_for_each_entry_safe (pco_instr, instr, &(block)->instrs, link)
#define pco_foreach_instr_in_block_rev(instr, block) \ #define pco_foreach_instr_in_block_rev(instr, block) \
foreach_list_typed_reverse (pco_instr, instr, node, &(block)->instrs) list_for_each_entry_rev (pco_instr, instr, &(block)->instrs, link)
#define pco_foreach_instr_in_block_safe_rev(instr, block) \ #define pco_foreach_instr_in_block_safe_rev(instr, block) \
foreach_list_typed_reverse_safe (pco_instr, instr, node, &(block)->instrs) list_for_each_entry_safe_rev (pco_instr, instr, &(block)->instrs, link)
#define pco_foreach_igrp_in_block(igrp, block) \ #define pco_foreach_igrp_in_block(igrp, block) \
foreach_list_typed (pco_igrp, igrp, node, &(block)->instrs) list_for_each_entry (pco_igrp, igrp, &(block)->instrs, link)
#define pco_foreach_phi_src_in_instr(phi_src, instr) \ #define pco_foreach_phi_src_in_instr(phi_src, instr) \
list_for_each_entry (pco_phi_src, phi_src, &(instr)->phi_srcs, link) list_for_each_entry (pco_phi_src, phi_src, &(instr)->phi_srcs, link)
@ -731,12 +730,8 @@ PCO_DEFINE_CAST(pco_cf_node_as_func,
pco_foreach_instr_src (psrc, instr) \ pco_foreach_instr_src (psrc, instr) \
if (pco_ref_is_hwreg(*psrc)) if (pco_ref_is_hwreg(*psrc))
#define pco_cf_node_head(list) exec_node_data_head(pco_cf_node, list, node) #define pco_cf_node_head(list) list_first_entry(list, pco_cf_node, link)
#define pco_cf_node_tail(list) exec_node_data_tail(pco_cf_node, list, node) #define pco_cf_node_tail(list) list_last_entry(list, pco_cf_node, link)
#define pco_cf_node_next(cf_node) \
exec_node_data_next(pco_cf_node, cf_node, node)
#define pco_cf_node_prev(cf_node) \
exec_node_data_prev(pco_cf_node, cf_node, node)
/** /**
* \brief Returns the preamble function of a PCO shader. * \brief Returns the preamble function of a PCO shader.
@ -746,10 +741,10 @@ PCO_DEFINE_CAST(pco_cf_node_as_func,
*/ */
static inline pco_func *pco_preamble(pco_shader *shader) static inline pco_func *pco_preamble(pco_shader *shader)
{ {
if (exec_list_is_empty(&shader->funcs)) if (list_is_empty(&shader->funcs))
return NULL; return NULL;
pco_func *func = exec_node_data_head(pco_func, &shader->funcs, node); pco_func *func = list_first_entry(&shader->funcs, pco_func, link);
if (func->type == PCO_FUNC_TYPE_PREAMBLE) if (func->type == PCO_FUNC_TYPE_PREAMBLE)
return func; return func;
@ -764,16 +759,15 @@ static inline pco_func *pco_preamble(pco_shader *shader)
*/ */
static inline pco_func *pco_entrypoint(pco_shader *shader) static inline pco_func *pco_entrypoint(pco_shader *shader)
{ {
if (exec_list_is_empty(&shader->funcs)) if (list_is_empty(&shader->funcs))
return NULL; return NULL;
/* Entrypoint will either be the first or second function in the shader, /* Entrypoint will either be the first or second function in the shader,
* depending on whether or not there is a preamble. * depending on whether or not there is a preamble.
*/ */
pco_func *preamble = pco_preamble(shader); pco_func *preamble = pco_preamble(shader);
pco_func *func = !preamble pco_func *func = !preamble ? list_first_entry(&shader->funcs, pco_func, link)
? exec_node_data_head(pco_func, &shader->funcs, node) : list_entry(preamble->link.next, pco_func, link);
: exec_node_data_next(pco_func, preamble, node);
if (func->type == PCO_FUNC_TYPE_ENTRYPOINT) if (func->type == PCO_FUNC_TYPE_ENTRYPOINT)
return func; return func;
@ -819,7 +813,7 @@ static inline unsigned pco_igrp_variant(const pco_igrp *igrp,
*/ */
static inline pco_cf_node *pco_first_func_cf_node(pco_func *func) static inline pco_cf_node *pco_first_func_cf_node(pco_func *func)
{ {
if (!exec_list_is_empty(&func->body)) if (!list_is_empty(&func->body))
return pco_cf_node_head(&func->body); return pco_cf_node_head(&func->body);
UNREACHABLE("Empty function."); UNREACHABLE("Empty function.");
@ -833,7 +827,7 @@ static inline pco_cf_node *pco_first_func_cf_node(pco_func *func)
*/ */
static inline pco_cf_node *pco_last_func_cf_node(pco_func *func) static inline pco_cf_node *pco_last_func_cf_node(pco_func *func)
{ {
if (!exec_list_is_empty(&func->body)) if (!list_is_empty(&func->body))
return pco_cf_node_tail(&func->body); return pco_cf_node_tail(&func->body);
UNREACHABLE("Empty function."); UNREACHABLE("Empty function.");
@ -847,19 +841,19 @@ static inline pco_cf_node *pco_last_func_cf_node(pco_func *func)
*/ */
static inline pco_cf_node *pco_first_if_cf_node(pco_if *pif) static inline pco_cf_node *pco_first_if_cf_node(pco_if *pif)
{ {
if (!exec_list_is_empty(&pif->prologue)) if (!list_is_empty(&pif->prologue))
return pco_cf_node_head(&pif->prologue); return pco_cf_node_head(&pif->prologue);
if (!exec_list_is_empty(&pif->then_body)) if (!list_is_empty(&pif->then_body))
return pco_cf_node_head(&pif->then_body); return pco_cf_node_head(&pif->then_body);
if (!exec_list_is_empty(&pif->interlogue)) if (!list_is_empty(&pif->interlogue))
return pco_cf_node_head(&pif->interlogue); return pco_cf_node_head(&pif->interlogue);
if (!exec_list_is_empty(&pif->else_body)) if (!list_is_empty(&pif->else_body))
return pco_cf_node_head(&pif->else_body); return pco_cf_node_head(&pif->else_body);
if (!exec_list_is_empty(&pif->epilogue)) if (!list_is_empty(&pif->epilogue))
return pco_cf_node_head(&pif->epilogue); return pco_cf_node_head(&pif->epilogue);
UNREACHABLE("Empty if."); UNREACHABLE("Empty if.");
@ -873,19 +867,19 @@ static inline pco_cf_node *pco_first_if_cf_node(pco_if *pif)
*/ */
static inline pco_cf_node *pco_last_if_cf_node(pco_if *pif) static inline pco_cf_node *pco_last_if_cf_node(pco_if *pif)
{ {
if (!exec_list_is_empty(&pif->epilogue)) if (!list_is_empty(&pif->epilogue))
return pco_cf_node_tail(&pif->epilogue); return pco_cf_node_tail(&pif->epilogue);
if (!exec_list_is_empty(&pif->else_body)) if (!list_is_empty(&pif->else_body))
return pco_cf_node_tail(&pif->else_body); return pco_cf_node_tail(&pif->else_body);
if (!exec_list_is_empty(&pif->interlogue)) if (!list_is_empty(&pif->interlogue))
return pco_cf_node_tail(&pif->interlogue); return pco_cf_node_tail(&pif->interlogue);
if (!exec_list_is_empty(&pif->then_body)) if (!list_is_empty(&pif->then_body))
return pco_cf_node_tail(&pif->then_body); return pco_cf_node_tail(&pif->then_body);
if (!exec_list_is_empty(&pif->prologue)) if (!list_is_empty(&pif->prologue))
return pco_cf_node_tail(&pif->prologue); return pco_cf_node_tail(&pif->prologue);
UNREACHABLE("Empty if."); UNREACHABLE("Empty if.");
@ -903,25 +897,25 @@ static inline pco_cf_node *pco_next_if_cf_node(pco_cf_node *cf_node)
switch (cf_node->flag) { switch (cf_node->flag) {
case PCO_CF_NODE_FLAG_PROLOGUE: case PCO_CF_NODE_FLAG_PROLOGUE:
if (!exec_list_is_empty(&pif->then_body)) if (!list_is_empty(&pif->then_body))
return pco_cf_node_head(&pif->then_body); return pco_cf_node_head(&pif->then_body);
FALLTHROUGH; FALLTHROUGH;
case PCO_CF_NODE_FLAG_IF_THEN: case PCO_CF_NODE_FLAG_IF_THEN:
if (!exec_list_is_empty(&pif->interlogue)) if (!list_is_empty(&pif->interlogue))
return pco_cf_node_head(&pif->interlogue); return pco_cf_node_head(&pif->interlogue);
FALLTHROUGH; FALLTHROUGH;
case PCO_CF_NODE_FLAG_INTERLOGUE: case PCO_CF_NODE_FLAG_INTERLOGUE:
if (!exec_list_is_empty(&pif->else_body)) if (!list_is_empty(&pif->else_body))
return pco_cf_node_head(&pif->else_body); return pco_cf_node_head(&pif->else_body);
FALLTHROUGH; FALLTHROUGH;
case PCO_CF_NODE_FLAG_IF_ELSE: case PCO_CF_NODE_FLAG_IF_ELSE:
if (!exec_list_is_empty(&pif->epilogue)) if (!list_is_empty(&pif->epilogue))
return pco_cf_node_head(&pif->epilogue); return pco_cf_node_head(&pif->epilogue);
FALLTHROUGH; FALLTHROUGH;
@ -948,25 +942,25 @@ static inline pco_cf_node *pco_prev_if_cf_node(pco_cf_node *cf_node)
switch (cf_node->flag) { switch (cf_node->flag) {
case PCO_CF_NODE_FLAG_EPILOGUE: case PCO_CF_NODE_FLAG_EPILOGUE:
if (!exec_list_is_empty(&pif->else_body)) if (!list_is_empty(&pif->else_body))
return pco_cf_node_tail(&pif->else_body); return pco_cf_node_tail(&pif->else_body);
FALLTHROUGH; FALLTHROUGH;
case PCO_CF_NODE_FLAG_IF_ELSE: case PCO_CF_NODE_FLAG_IF_ELSE:
if (!exec_list_is_empty(&pif->interlogue)) if (!list_is_empty(&pif->interlogue))
return pco_cf_node_tail(&pif->interlogue); return pco_cf_node_tail(&pif->interlogue);
FALLTHROUGH; FALLTHROUGH;
case PCO_CF_NODE_FLAG_INTERLOGUE: case PCO_CF_NODE_FLAG_INTERLOGUE:
if (!exec_list_is_empty(&pif->then_body)) if (!list_is_empty(&pif->then_body))
return pco_cf_node_tail(&pif->then_body); return pco_cf_node_tail(&pif->then_body);
FALLTHROUGH; FALLTHROUGH;
case PCO_CF_NODE_FLAG_IF_THEN: case PCO_CF_NODE_FLAG_IF_THEN:
if (!exec_list_is_empty(&pif->prologue)) if (!list_is_empty(&pif->prologue))
return pco_cf_node_tail(&pif->prologue); return pco_cf_node_tail(&pif->prologue);
FALLTHROUGH; FALLTHROUGH;
@ -989,16 +983,16 @@ static inline pco_cf_node *pco_prev_if_cf_node(pco_cf_node *cf_node)
*/ */
static inline pco_cf_node *pco_first_loop_cf_node(pco_loop *loop) static inline pco_cf_node *pco_first_loop_cf_node(pco_loop *loop)
{ {
if (!exec_list_is_empty(&loop->prologue)) if (!list_is_empty(&loop->prologue))
return pco_cf_node_head(&loop->prologue); return pco_cf_node_head(&loop->prologue);
if (!exec_list_is_empty(&loop->body)) if (!list_is_empty(&loop->body))
return pco_cf_node_head(&loop->body); return pco_cf_node_head(&loop->body);
if (!exec_list_is_empty(&loop->interlogue)) if (!list_is_empty(&loop->interlogue))
return pco_cf_node_head(&loop->interlogue); return pco_cf_node_head(&loop->interlogue);
if (!exec_list_is_empty(&loop->epilogue)) if (!list_is_empty(&loop->epilogue))
return pco_cf_node_head(&loop->epilogue); return pco_cf_node_head(&loop->epilogue);
UNREACHABLE("Empty loop."); UNREACHABLE("Empty loop.");
@ -1012,16 +1006,16 @@ static inline pco_cf_node *pco_first_loop_cf_node(pco_loop *loop)
*/ */
static inline pco_cf_node *pco_last_loop_cf_node(pco_loop *loop) static inline pco_cf_node *pco_last_loop_cf_node(pco_loop *loop)
{ {
if (!exec_list_is_empty(&loop->epilogue)) if (!list_is_empty(&loop->epilogue))
return pco_cf_node_tail(&loop->epilogue); return pco_cf_node_tail(&loop->epilogue);
if (!exec_list_is_empty(&loop->interlogue)) if (!list_is_empty(&loop->interlogue))
return pco_cf_node_tail(&loop->interlogue); return pco_cf_node_tail(&loop->interlogue);
if (!exec_list_is_empty(&loop->body)) if (!list_is_empty(&loop->body))
return pco_cf_node_tail(&loop->body); return pco_cf_node_tail(&loop->body);
if (!exec_list_is_empty(&loop->prologue)) if (!list_is_empty(&loop->prologue))
return pco_cf_node_tail(&loop->prologue); return pco_cf_node_tail(&loop->prologue);
UNREACHABLE("Empty loop."); UNREACHABLE("Empty loop.");
@ -1039,19 +1033,19 @@ static inline pco_cf_node *pco_next_loop_cf_node(pco_cf_node *cf_node)
switch (cf_node->flag) { switch (cf_node->flag) {
case PCO_CF_NODE_FLAG_PROLOGUE: case PCO_CF_NODE_FLAG_PROLOGUE:
if (!exec_list_is_empty(&loop->body)) if (!list_is_empty(&loop->body))
return pco_cf_node_head(&loop->body); return pco_cf_node_head(&loop->body);
FALLTHROUGH; FALLTHROUGH;
case PCO_CF_NODE_FLAG_BODY: case PCO_CF_NODE_FLAG_BODY:
if (!exec_list_is_empty(&loop->interlogue)) if (!list_is_empty(&loop->interlogue))
return pco_cf_node_head(&loop->interlogue); return pco_cf_node_head(&loop->interlogue);
FALLTHROUGH; FALLTHROUGH;
case PCO_CF_NODE_FLAG_INTERLOGUE: case PCO_CF_NODE_FLAG_INTERLOGUE:
if (!exec_list_is_empty(&loop->epilogue)) if (!list_is_empty(&loop->epilogue))
return pco_cf_node_head(&loop->epilogue); return pco_cf_node_head(&loop->epilogue);
FALLTHROUGH; FALLTHROUGH;
@ -1078,19 +1072,19 @@ static inline pco_cf_node *pco_prev_loop_cf_node(pco_cf_node *cf_node)
switch (cf_node->flag) { switch (cf_node->flag) {
case PCO_CF_NODE_FLAG_EPILOGUE: case PCO_CF_NODE_FLAG_EPILOGUE:
if (!exec_list_is_empty(&loop->interlogue)) if (!list_is_empty(&loop->interlogue))
return pco_cf_node_tail(&loop->interlogue); return pco_cf_node_tail(&loop->interlogue);
FALLTHROUGH; FALLTHROUGH;
case PCO_CF_NODE_FLAG_INTERLOGUE: case PCO_CF_NODE_FLAG_INTERLOGUE:
if (!exec_list_is_empty(&loop->body)) if (!list_is_empty(&loop->body))
return pco_cf_node_tail(&loop->body); return pco_cf_node_tail(&loop->body);
FALLTHROUGH; FALLTHROUGH;
case PCO_CF_NODE_FLAG_BODY: case PCO_CF_NODE_FLAG_BODY:
if (!exec_list_is_empty(&loop->prologue)) if (!list_is_empty(&loop->prologue))
return pco_cf_node_tail(&loop->prologue); return pco_cf_node_tail(&loop->prologue);
FALLTHROUGH; FALLTHROUGH;
@ -1105,6 +1099,69 @@ static inline pco_cf_node *pco_prev_loop_cf_node(pco_cf_node *cf_node)
UNREACHABLE(""); UNREACHABLE("");
} }
static inline struct list_head *pco_parent_if_head(pco_cf_node *cf_node)
{
pco_if *parent = pco_cf_node_as_if(cf_node->parent);
switch (cf_node->flag) {
case PCO_CF_NODE_FLAG_PROLOGUE:
return &parent->prologue;
case PCO_CF_NODE_FLAG_IF_THEN:
return &parent->then_body;
case PCO_CF_NODE_FLAG_INTERLOGUE:
return &parent->interlogue;
case PCO_CF_NODE_FLAG_IF_ELSE:
return &parent->else_body;
case PCO_CF_NODE_FLAG_EPILOGUE:
return &parent->epilogue;
default:
UNREACHABLE("");
}
}
static inline struct list_head *pco_parent_loop_head(pco_cf_node *cf_node)
{
pco_loop *parent = pco_cf_node_as_loop(cf_node->parent);
switch (cf_node->flag) {
case PCO_CF_NODE_FLAG_PROLOGUE:
return &parent->prologue;
case PCO_CF_NODE_FLAG_BODY:
return &parent->body;
case PCO_CF_NODE_FLAG_INTERLOGUE:
return &parent->interlogue;
case PCO_CF_NODE_FLAG_EPILOGUE:
return &parent->epilogue;
default:
UNREACHABLE("");
}
}
static inline struct list_head *pco_parent_func_head(pco_cf_node *cf_node)
{
pco_func *parent = pco_cf_node_as_func(cf_node->parent);
switch (cf_node->flag) {
case PCO_CF_NODE_FLAG_BODY:
return &parent->body;
default:
UNREACHABLE("");
}
}
static inline struct list_head *pco_parent_cf_node_head(pco_cf_node *cf_node)
{
pco_cf_node *parent_cf_node = cf_node->parent;
switch (parent_cf_node->type) {
case PCO_CF_NODE_TYPE_IF:
return pco_parent_if_head(cf_node);
case PCO_CF_NODE_TYPE_LOOP:
return pco_parent_loop_head(cf_node);
case PCO_CF_NODE_TYPE_FUNC:
return pco_parent_func_head(cf_node);
default:
UNREACHABLE("");
}
}
/** /**
* \brief Returns the next CF node. * \brief Returns the next CF node.
* *
@ -1116,6 +1173,9 @@ static inline pco_cf_node *pco_prev_loop_cf_node(pco_cf_node *cf_node)
static inline pco_cf_node *pco_next_cf_node(pco_cf_node *cf_node, static inline pco_cf_node *pco_next_cf_node(pco_cf_node *cf_node,
pco_cf_node **cf_node_completed) pco_cf_node **cf_node_completed)
{ {
#define pco_cf_node_next(cf_node) \
list_entry((cf_node)->link.next, pco_cf_node, link)
if (cf_node_completed) if (cf_node_completed)
*cf_node_completed = NULL; *cf_node_completed = NULL;
@ -1124,11 +1184,11 @@ static inline pco_cf_node *pco_next_cf_node(pco_cf_node *cf_node,
switch (cf_node->type) { switch (cf_node->type) {
case PCO_CF_NODE_TYPE_BLOCK: { case PCO_CF_NODE_TYPE_BLOCK: {
pco_cf_node *next_cf_node = pco_cf_node_next(cf_node); struct list_head *parent_list = pco_parent_cf_node_head(cf_node);
/* Not yet reached the end of the list, return the next cf node. */ /* Not yet reached the end of the list, return the next cf node. */
if (next_cf_node) if (cf_node != pco_cf_node_tail(parent_list))
return next_cf_node; return pco_cf_node_next(cf_node);
break; break;
} }
@ -1177,6 +1237,7 @@ static inline pco_cf_node *pco_next_cf_node(pco_cf_node *cf_node,
*cf_node_completed = parent_cf_node; *cf_node_completed = parent_cf_node;
return pco_cf_node_next(parent_cf_node); return pco_cf_node_next(parent_cf_node);
#undef pco_cf_node_next
} }
/** /**
@ -1190,6 +1251,9 @@ static inline pco_cf_node *pco_next_cf_node(pco_cf_node *cf_node,
static inline pco_cf_node *pco_prev_cf_node(pco_cf_node *cf_node, static inline pco_cf_node *pco_prev_cf_node(pco_cf_node *cf_node,
pco_cf_node **cf_node_completed) pco_cf_node **cf_node_completed)
{ {
#define pco_cf_node_prev(cf_node) \
list_entry((cf_node)->link.prev, pco_cf_node, link)
if (cf_node_completed) if (cf_node_completed)
*cf_node_completed = NULL; *cf_node_completed = NULL;
@ -1198,11 +1262,11 @@ static inline pco_cf_node *pco_prev_cf_node(pco_cf_node *cf_node,
switch (cf_node->type) { switch (cf_node->type) {
case PCO_CF_NODE_TYPE_BLOCK: { case PCO_CF_NODE_TYPE_BLOCK: {
pco_cf_node *prev_cf_node = pco_cf_node_prev(cf_node); struct list_head *parent_list = pco_parent_cf_node_head(cf_node);
/* Not yet reached the start of the list, return the previous cf node. */ /* Not yet reached the start of the list, return the previous cf node. */
if (prev_cf_node) if (cf_node != pco_cf_node_head(parent_list))
return prev_cf_node; return pco_cf_node_prev(cf_node);
break; break;
} }
@ -1251,6 +1315,7 @@ static inline pco_cf_node *pco_prev_cf_node(pco_cf_node *cf_node,
*cf_node_completed = parent_cf_node; *cf_node_completed = parent_cf_node;
return pco_cf_node_prev(parent_cf_node); return pco_cf_node_prev(parent_cf_node);
#undef pco_cf_node_prev
} }
/** /**
@ -1280,7 +1345,7 @@ static inline pco_cf_node *pco_next_cf_node_type(pco_cf_node *cf_node,
static inline pco_cf_node * static inline pco_cf_node *
pco_func_first_cf_node_type(pco_func *func, enum pco_cf_node_type type) pco_func_first_cf_node_type(pco_func *func, enum pco_cf_node_type type)
{ {
assert(!exec_list_is_empty(&func->body)); assert(!list_is_empty(&func->body));
pco_cf_node *cf_node = pco_cf_node_head(&func->body); pco_cf_node *cf_node = pco_cf_node_head(&func->body);
if (cf_node->type == type) if (cf_node->type == type)
@ -1316,7 +1381,7 @@ static inline pco_cf_node *pco_prev_cf_node_type(pco_cf_node *cf_node,
static inline pco_cf_node * static inline pco_cf_node *
pco_func_last_cf_node_type(pco_func *func, enum pco_cf_node_type type) pco_func_last_cf_node_type(pco_func *func, enum pco_cf_node_type type)
{ {
assert(!exec_list_is_empty(&func->body)); assert(!list_is_empty(&func->body));
pco_cf_node *cf_node = pco_cf_node_tail(&func->body); pco_cf_node *cf_node = pco_cf_node_tail(&func->body);
if (cf_node->type == type) if (cf_node->type == type)
@ -1371,7 +1436,7 @@ static inline pco_block *pco_next_block_nonempty(pco_block *block)
block = pco_next_block(block); block = pco_next_block(block);
/* Skip over empty blocks. */ /* Skip over empty blocks. */
while (block && exec_list_is_empty(&block->instrs)) while (block && list_is_empty(&block->instrs))
block = pco_next_block(block); block = pco_next_block(block);
return block; return block;
@ -1389,7 +1454,7 @@ static inline pco_block *pco_prev_block_nonempty(pco_block *block)
block = pco_prev_block(block); block = pco_prev_block(block);
/* Skip over empty blocks. */ /* Skip over empty blocks. */
while (block && exec_list_is_empty(&block->instrs)) while (block && list_is_empty(&block->instrs))
block = pco_prev_block(block); block = pco_prev_block(block);
return block; return block;
@ -1403,7 +1468,10 @@ static inline pco_block *pco_prev_block_nonempty(pco_block *block)
*/ */
static inline pco_instr *pco_first_instr(pco_block *block) static inline pco_instr *pco_first_instr(pco_block *block)
{ {
return exec_node_data_head(pco_instr, &block->instrs, node); if (list_is_empty(&block->instrs))
return NULL;
return list_first_entry(&block->instrs, pco_instr, link);
} }
/** /**
@ -1414,7 +1482,10 @@ static inline pco_instr *pco_first_instr(pco_block *block)
*/ */
static inline pco_instr *pco_last_instr(pco_block *block) static inline pco_instr *pco_last_instr(pco_block *block)
{ {
return exec_node_data_tail(pco_instr, &block->instrs, node); if (list_is_empty(&block->instrs))
return NULL;
return list_last_entry(&block->instrs, pco_instr, link);
} }
/** /**
@ -1429,9 +1500,8 @@ static inline pco_instr *pco_next_instr(pco_instr *instr)
if (!instr) if (!instr)
return NULL; return NULL;
pco_instr *next_instr = exec_node_data_next(pco_instr, instr, node); if (instr != pco_last_instr(instr->parent_block))
if (next_instr) return list_entry(instr->link.next, pco_instr, link);
return next_instr;
pco_block *block = pco_next_block_nonempty(instr->parent_block); pco_block *block = pco_next_block_nonempty(instr->parent_block);
return !block ? NULL : pco_first_instr(block); return !block ? NULL : pco_first_instr(block);
@ -1449,9 +1519,8 @@ static inline pco_instr *pco_prev_instr(pco_instr *instr)
if (!instr) if (!instr)
return NULL; return NULL;
pco_instr *prev_instr = exec_node_data_prev(pco_instr, instr, node); if (instr != pco_first_instr(instr->parent_block))
if (prev_instr) return list_entry(instr->link.prev, pco_instr, link);
return prev_instr;
pco_block *block = pco_prev_block_nonempty(instr->parent_block); pco_block *block = pco_prev_block_nonempty(instr->parent_block);
return !block ? NULL : pco_last_instr(block); return !block ? NULL : pco_last_instr(block);
@ -1465,7 +1534,7 @@ static inline pco_instr *pco_prev_instr(pco_instr *instr)
*/ */
static inline pco_igrp *pco_first_igrp(pco_block *block) static inline pco_igrp *pco_first_igrp(pco_block *block)
{ {
return exec_node_data_head(pco_igrp, &block->instrs, node); return list_first_entry(&block->instrs, pco_igrp, link);
} }
/** /**
@ -1476,7 +1545,7 @@ static inline pco_igrp *pco_first_igrp(pco_block *block)
*/ */
static inline pco_igrp *pco_last_igrp(pco_block *block) static inline pco_igrp *pco_last_igrp(pco_block *block)
{ {
return exec_node_data_tail(pco_igrp, &block->instrs, node); return list_first_entry(&block->instrs, pco_igrp, link);
} }
/** /**
@ -1491,9 +1560,8 @@ static inline pco_igrp *pco_next_igrp(pco_igrp *igrp)
if (!igrp) if (!igrp)
return NULL; return NULL;
pco_igrp *next_igrp = exec_node_data_next(pco_igrp, igrp, node); if (igrp != pco_last_igrp(igrp->parent_block))
if (next_igrp) return list_entry(igrp->link.next, pco_igrp, link);
return next_igrp;
pco_block *block = pco_next_block(igrp->parent_block); pco_block *block = pco_next_block(igrp->parent_block);
return !block ? NULL : pco_first_igrp(block); return !block ? NULL : pco_first_igrp(block);
@ -1511,9 +1579,8 @@ static inline pco_igrp *pco_prev_igrp(pco_igrp *igrp)
if (!igrp) if (!igrp)
return NULL; return NULL;
pco_igrp *prev_igrp = exec_node_data_prev(pco_igrp, igrp, node); if (igrp != pco_first_igrp(igrp->parent_block))
if (prev_igrp) return list_entry(igrp->link.prev, pco_igrp, link);
return prev_igrp;
pco_block *block = pco_prev_block(igrp->parent_block); pco_block *block = pco_prev_block(igrp->parent_block);
return !block ? NULL : pco_last_igrp(block); return !block ? NULL : pco_last_igrp(block);

View file

@ -640,7 +640,7 @@ def group_map(op, hdr, enc_ops, srcs=[], iss=[], dests=[]):
assert _enc_op.bname in encode_maps.keys() assert _enc_op.bname in encode_maps.keys()
assert phase in [phase_map for phase_map, *_ in encode_maps[_enc_op.bname].op_ref_maps] assert phase in [phase_map for phase_map, *_ in encode_maps[_enc_op.bname].op_ref_maps]
op_mappings.append(f'exec_node_remove(&{{1}}->node);') op_mappings.append(f'list_del(&{{1}}->link);')
op_mappings.append(f'{{}}->instrs[{phase}] = {{}};') op_mappings.append(f'{{}}->instrs[{phase}] = {{}};')
op_mappings.append(f'{{0}}->instrs[{phase}]->phase = {phase};') op_mappings.append(f'{{0}}->instrs[{phase}]->phase = {phase};')
op_mappings.append(f'{{0}}->instrs[{phase}]->parent_igrp = {{0}};') op_mappings.append(f'{{0}}->instrs[{phase}]->parent_igrp = {{0}};')

View file

@ -746,7 +746,7 @@ bool pco_opt_comp_only_vecs(pco_shader *shader)
bool progress = false; bool progress = false;
pco_foreach_func_in_shader (func, shader) { pco_foreach_func_in_shader (func, shader) {
pco_foreach_instr_in_func_safe (vec, func) { pco_foreach_instr_in_func (vec, func) {
if (vec->op != PCO_OP_VEC) if (vec->op != PCO_OP_VEC)
continue; continue;

View file

@ -974,7 +974,7 @@ static void pco_print_if(pco_print_state *state, pco_if *pif)
pco_printf(state, " {\n"); pco_printf(state, " {\n");
if (!exec_list_is_empty(&pif->prologue)) { if (!list_is_empty(&pif->prologue)) {
pco_printfi(state, "/* if "); pco_printfi(state, "/* if ");
pco_print_if_name(state, pif); pco_print_if_name(state, pif);
pco_printf(state, " prologue start */\n"); pco_printf(state, " prologue start */\n");
@ -990,7 +990,7 @@ static void pco_print_if(pco_print_state *state, pco_if *pif)
pco_printf(state, " prologue end */\n"); pco_printf(state, " prologue end */\n");
} }
if (!exec_list_is_empty(&pif->then_body)) { if (!list_is_empty(&pif->then_body)) {
++state->indent; ++state->indent;
pco_foreach_cf_node_in_if_then (cf_node, pif) { pco_foreach_cf_node_in_if_then (cf_node, pif) {
_pco_print_cf_node(state, cf_node); _pco_print_cf_node(state, cf_node);
@ -998,10 +998,10 @@ static void pco_print_if(pco_print_state *state, pco_if *pif)
--state->indent; --state->indent;
} }
if (!exec_list_is_empty(&pif->else_body)) { if (!list_is_empty(&pif->else_body)) {
pco_printfi(state, "} else {\n"); pco_printfi(state, "} else {\n");
if (!exec_list_is_empty(&pif->interlogue)) { if (!list_is_empty(&pif->interlogue)) {
pco_printfi(state, "/* if "); pco_printfi(state, "/* if ");
pco_print_if_name(state, pif); pco_print_if_name(state, pif);
pco_printf(state, " interlogue start */\n"); pco_printf(state, " interlogue start */\n");
@ -1023,10 +1023,10 @@ static void pco_print_if(pco_print_state *state, pco_if *pif)
} }
--state->indent; --state->indent;
} else { } else {
assert(exec_list_is_empty(&pif->interlogue)); assert(list_is_empty(&pif->interlogue));
} }
if (!exec_list_is_empty(&pif->epilogue)) { if (!list_is_empty(&pif->epilogue)) {
pco_printfi(state, "/* if "); pco_printfi(state, "/* if ");
pco_print_if_name(state, pif); pco_print_if_name(state, pif);
pco_printf(state, " epilogue start */\n"); pco_printf(state, " epilogue start */\n");
@ -1068,7 +1068,7 @@ static void pco_print_loop(pco_print_state *state, pco_loop *loop)
pco_print_loop_name(state, loop); pco_print_loop_name(state, loop);
pco_printf(state, " {\n"); pco_printf(state, " {\n");
if (!exec_list_is_empty(&loop->prologue)) { if (!list_is_empty(&loop->prologue)) {
pco_printfi(state, "/* loop "); pco_printfi(state, "/* loop ");
pco_print_loop_name(state, loop); pco_print_loop_name(state, loop);
pco_printf(state, " prologue start */\n"); pco_printf(state, " prologue start */\n");
@ -1084,7 +1084,7 @@ static void pco_print_loop(pco_print_state *state, pco_loop *loop)
pco_printf(state, " prologue end */\n"); pco_printf(state, " prologue end */\n");
} }
if (!exec_list_is_empty(&loop->body)) { if (!list_is_empty(&loop->body)) {
++state->indent; ++state->indent;
pco_foreach_cf_node_in_loop (cf_node, loop) { pco_foreach_cf_node_in_loop (cf_node, loop) {
_pco_print_cf_node(state, cf_node); _pco_print_cf_node(state, cf_node);
@ -1092,7 +1092,7 @@ static void pco_print_loop(pco_print_state *state, pco_loop *loop)
--state->indent; --state->indent;
} }
if (!exec_list_is_empty(&loop->interlogue)) { if (!list_is_empty(&loop->interlogue)) {
pco_printfi(state, "/* loop "); pco_printfi(state, "/* loop ");
pco_print_loop_name(state, loop); pco_print_loop_name(state, loop);
pco_printf(state, " interlogue start */\n"); pco_printf(state, " interlogue start */\n");
@ -1108,7 +1108,7 @@ static void pco_print_loop(pco_print_state *state, pco_loop *loop)
pco_printf(state, " interlogue end */\n"); pco_printf(state, " interlogue end */\n");
} }
if (!exec_list_is_empty(&loop->epilogue)) { if (!list_is_empty(&loop->epilogue)) {
pco_printfi(state, "/* loop "); pco_printfi(state, "/* loop ");
pco_print_loop_name(state, loop); pco_print_loop_name(state, loop);
pco_printf(state, " epilogue start */\n"); pco_printf(state, " epilogue start */\n");

View file

@ -10,13 +10,13 @@
* \brief NIR translation functions. * \brief NIR translation functions.
*/ */
#include "compiler/list.h"
#include "compiler/shader_enums.h" #include "compiler/shader_enums.h"
#include "hwdef/rogue_hw_defs.h" #include "hwdef/rogue_hw_defs.h"
#include "pco.h" #include "pco.h"
#include "pco_builder.h" #include "pco_builder.h"
#include "pco_internal.h" #include "pco_internal.h"
#include "util/bitset.h" #include "util/bitset.h"
#include "util/list.h"
#include "util/macros.h" #include "util/macros.h"
#include "util/ralloc.h" #include "util/ralloc.h"
@ -40,7 +40,7 @@ typedef struct _trans_ctx {
/* Forward declarations. */ /* Forward declarations. */
static pco_block *trans_cf_nodes(trans_ctx *tctx, static pco_block *trans_cf_nodes(trans_ctx *tctx,
pco_cf_node *parent_cf_node, pco_cf_node *parent_cf_node,
struct exec_list *cf_node_list, struct list_head *cf_node_list,
struct exec_list *nir_cf_node_list); struct exec_list *nir_cf_node_list);
static inline void pco_fence(pco_builder *b) static inline void pco_fence(pco_builder *b)
@ -3111,14 +3111,14 @@ static pco_instr *trans_instr(trans_ctx *tctx, nir_instr *ninstr)
*/ */
static pco_block *trans_block(trans_ctx *tctx, static pco_block *trans_block(trans_ctx *tctx,
pco_cf_node *parent_cf_node, pco_cf_node *parent_cf_node,
struct exec_list *cf_node_list, struct list_head *cf_node_list,
nir_block *nblock) nir_block *nblock)
{ {
pco_block *block = pco_block_create(tctx->func); pco_block *block = pco_block_create(tctx->func);
block->cf_node.flag = tctx->flag; block->cf_node.flag = tctx->flag;
block->cf_node.parent = parent_cf_node; block->cf_node.parent = parent_cf_node;
exec_list_push_tail(cf_node_list, &block->cf_node.node); list_addtail(&block->cf_node.link, cf_node_list);
tctx->b = pco_builder_create(tctx->func, pco_cursor_after_block(block)); tctx->b = pco_builder_create(tctx->func, pco_cursor_after_block(block));
@ -3139,14 +3139,14 @@ static pco_block *trans_block(trans_ctx *tctx,
*/ */
static void trans_if(trans_ctx *tctx, static void trans_if(trans_ctx *tctx,
pco_cf_node *parent_cf_node, pco_cf_node *parent_cf_node,
struct exec_list *cf_node_list, struct list_head *cf_node_list,
nir_if *nif) nir_if *nif)
{ {
pco_if *pif = pco_if_create(tctx->func); pco_if *pif = pco_if_create(tctx->func);
pif->cf_node.flag = tctx->flag; pif->cf_node.flag = tctx->flag;
pif->cf_node.parent = parent_cf_node; pif->cf_node.parent = parent_cf_node;
exec_list_push_tail(cf_node_list, &pif->cf_node.node); list_addtail(&pif->cf_node.link, cf_node_list);
pif->cond = pco_ref_nir_src_t(&nif->condition, tctx); pif->cond = pco_ref_nir_src_t(&nif->condition, tctx);
assert(pco_ref_is_scalar(pif->cond)); assert(pco_ref_is_scalar(pif->cond));
@ -3179,14 +3179,14 @@ static void trans_if(trans_ctx *tctx,
*/ */
static void trans_loop(trans_ctx *tctx, static void trans_loop(trans_ctx *tctx,
pco_cf_node *parent_cf_node, pco_cf_node *parent_cf_node,
struct exec_list *cf_node_list, struct list_head *cf_node_list,
nir_loop *nloop) nir_loop *nloop)
{ {
pco_loop *loop = pco_loop_create(tctx->func); pco_loop *loop = pco_loop_create(tctx->func);
loop->cf_node.flag = tctx->flag; loop->cf_node.flag = tctx->flag;
loop->cf_node.parent = parent_cf_node; loop->cf_node.parent = parent_cf_node;
exec_list_push_tail(cf_node_list, &loop->cf_node.node); list_addtail(&loop->cf_node.link, cf_node_list);
assert(!nir_cf_list_is_empty_block(&nloop->body)); assert(!nir_cf_list_is_empty_block(&nloop->body));
assert(!nir_loop_has_continue_construct(nloop)); assert(!nir_loop_has_continue_construct(nloop));
@ -3252,7 +3252,7 @@ static pco_func *trans_func(trans_ctx *tctx, nir_function_impl *impl)
*/ */
static pco_block *trans_cf_nodes(trans_ctx *tctx, static pco_block *trans_cf_nodes(trans_ctx *tctx,
pco_cf_node *parent_cf_node, pco_cf_node *parent_cf_node,
struct exec_list *cf_node_list, struct list_head *cf_node_list,
struct exec_list *nir_cf_node_list) struct exec_list *nir_cf_node_list)
{ {
pco_block *start_block = NULL; pco_block *start_block = NULL;