Commit 02a3b164 authored by Matthias Braun's avatar Matthias Braun
Browse files

Use pdeq_new instead of pdeq

parent 7af7151a
......@@ -12,7 +12,6 @@
#include <assert.h>
#include "adt/pdeq.h"
#include "debug.h"
#include "iredges_t.h"
#include "irgwalk.h"
......
......@@ -20,13 +20,13 @@
#include "debug.h"
#include "irnode_t.h"
#include "tv.h"
#include "pdeq.h"
#include "pdeq_new.h"
#include "irgwalk.h"
#include "dca.h"
DEBUG_ONLY(static firm_dbg_module_t *dbg;)
static pdeq *worklist;
static deq_t worklist;
/**
* Set cared for bits in irn, possibly putting it on the worklist.
......@@ -51,7 +51,7 @@ static void care_for(ir_node *irn, ir_tarval *care)
DBG((dbg, LEVEL_3, "queueing %+F: %T->%T\n", irn, old_care, care));
assert(old_care != tarval_b_true || care == tarval_b_true);
set_irn_link(irn, (void *)care);
pdeq_putr(worklist, irn);
deq_push_pointer_right(&worklist, irn);
} else {
DBG((dbg, LEVEL_3, "no change on %+F: %T\n", irn, old_care, care));
}
......@@ -417,13 +417,13 @@ void dca_analyze(ir_graph *irg)
irg_walk_graph(irg, dca_init_node, NULL, 0);
worklist = new_pdeq();
deq_init(&worklist);
care_for(get_irg_end(irg), 0);
while (!pdeq_empty(worklist)) {
ir_node *n = (ir_node*)pdeq_getl(worklist);
while (!deq_empty(&worklist)) {
ir_node *n = deq_pop_pointer_left(ir_node, &worklist);
dca_transfer(n);
}
del_pdeq(worklist);
deq_free(&worklist);
}
......@@ -17,7 +17,7 @@
#include "iredges_t.h"
#include "tv.h"
#include "irprintf.h"
#include "pdeq.h"
#include "pdeq_new.h"
#include "irnodemap.h"
#include "irhooks.h"
#include "bitset.h"
......@@ -26,7 +26,7 @@
DEBUG_ONLY(static firm_dbg_module_t *dbg;)
typedef struct vrp_env_t {
pdeq *workqueue;
deq_t workqueue;
bitset_t *visited;
ir_vrp_info *info;
} vrp_env_t;
......@@ -471,7 +471,7 @@ static void vrp_first_pass(ir_node *n, void *e)
foreach_irn_out_r(n, i, succ) {
if (bitset_is_set(env->visited, get_irn_idx(succ))) {
/* we found a loop*/
pdeq_putr(env->workqueue, succ);
deq_push_pointer_right(&env->workqueue, succ);
}
}
}
......@@ -515,25 +515,25 @@ void set_vrp_data(ir_graph *irg)
}
vrp_env_t *env = OALLOCZ(&irg->vrp.obst, vrp_env_t);
env->workqueue = new_pdeq();
env->info = info;
deq_init(&env->workqueue);
env->visited = bitset_malloc(get_irg_last_idx(irg));
irg_walk_graph(irg, NULL, vrp_first_pass, env);
free(env->visited);
/* while there are entries in the worklist, continue*/
while (!pdeq_empty(env->workqueue)) {
ir_node *node = (ir_node*) pdeq_getl(env->workqueue);
while (!deq_empty(&env->workqueue)) {
ir_node *node = deq_pop_pointer_left(ir_node, &env->workqueue);
if (vrp_update_node(info, node)) {
/* if something changed, add successors to worklist*/
foreach_irn_out_r(node, i, succ) {
pdeq_putr(env->workqueue, succ);
deq_push_pointer_right(&env->workqueue, succ);
}
}
}
del_pdeq(env->workqueue);
deq_free(&env->workqueue);
}
void free_vrp_data(ir_graph *irg)
......
......@@ -31,7 +31,7 @@
#include "irgmod.h"
#include "irgwalk.h"
#include "irnode_t.h"
#include "pdeq.h"
#include "pdeq_new.h"
#include "util.h"
DEBUG_ONLY(static firm_dbg_module_t *dbg = NULL;)
......@@ -162,7 +162,7 @@ struct blocksched_env_t {
ir_graph *irg;
struct obstack obst;
edge_t *edges;
pdeq *worklist;
deq_t worklist;
unsigned blockcount;
};
......@@ -441,7 +441,7 @@ static void pick_block_successor(blocksched_entry_t *entry, blocksched_env_t *en
continue;
DB((dbg, LEVEL_1, "Put %+F into worklist\n", succ_entry->block));
pdeq_putr(env->worklist, succ_entry->block);
deq_push_pointer_right(&env->worklist, succ_entry->block);
}
if (entry->next != NULL) {
......@@ -476,11 +476,11 @@ static void pick_block_successor(blocksched_entry_t *entry, blocksched_env_t *en
DB((dbg, LEVEL_1, "pick from worklist\n"));
do {
if (pdeq_empty(env->worklist)) {
if (deq_empty(&env->worklist)) {
DB((dbg, LEVEL_1, "worklist empty\n"));
return;
}
succ = (ir_node*)pdeq_getl(env->worklist);
succ = deq_pop_pointer_left(ir_node, &env->worklist);
} while (irn_visited(succ));
}
......@@ -500,12 +500,12 @@ static blocksched_entry_t *finish_block_schedule(blocksched_env_t *env)
/* Exclude the end block from the block schedule. */
mark_irn_visited(get_irg_end_block(irg));
env->worklist = new_pdeq();
deq_init(&env->worklist);
ir_node *const startblock = get_irg_start_block(irg);
blocksched_entry_t *const entry = get_blocksched_entry(startblock);
pick_block_successor(entry, env);
assert(pdeq_empty(env->worklist));
del_pdeq(env->worklist);
assert(deq_empty(&env->worklist));
deq_free(&env->worklist);
ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
......@@ -536,7 +536,6 @@ ir_node **be_create_block_schedule(ir_graph *irg)
blocksched_env_t env = {
.irg = irg,
.edges = NEW_ARR_F(edge_t, 0),
.worklist = NULL,
.blockcount = 0,
};
obstack_init(&env.obst);
......
......@@ -26,7 +26,7 @@
#include "irnodemap.h"
#include "pqueue.h"
#include "xmalloc.h"
#include "pdeq.h"
#include "pdeq_new.h"
#include "irprintf.h"
#include "util.h"
#include "irtools.h"
......@@ -674,20 +674,21 @@ static void expand_chunk_from(co_mst_env_t *env, co_mst_irn_t *node,
aff_chunk_t *orig_chunk, decide_func_t *decider,
unsigned col)
{
pdeq *nodes = new_pdeq();
deq_t nodes;
deq_init(&nodes);
DBG((dbg, LEVEL_1, "\n\tExpanding new chunk (#%u) from %+F, color %d:",
chunk->id, node->irn, col));
/* init queue and chunk */
pdeq_putr(nodes, node);
deq_push_pointer_right(&nodes, node);
bitset_set(visited, get_irn_idx(node->irn));
aff_chunk_add_node(chunk, node);
DB((dbg, LEVEL_1, " %+F", node->irn));
/* as long as there are nodes in the queue */
while (!pdeq_empty(nodes)) {
co_mst_irn_t *n = (co_mst_irn_t*)pdeq_getl(nodes);
while (!deq_empty(&nodes)) {
co_mst_irn_t *n = deq_pop_pointer_left(co_mst_irn_t, &nodes);
affinity_node_t *an = get_affinity_info(env->co, n->irn);
/* check all affinity neighbors */
......@@ -713,14 +714,14 @@ static void expand_chunk_from(co_mst_env_t *env, co_mst_irn_t *node,
aff_chunk_add_node(chunk, n2);
DB((dbg, LEVEL_1, " %+F", n2->irn));
/* enqueue for further search */
pdeq_putr(nodes, n2);
deq_push_pointer_right(&nodes, n2);
}
}
}
}
DB((dbg, LEVEL_1, "\n"));
del_pdeq(nodes);
deq_free(&nodes);
}
/**
......@@ -728,7 +729,7 @@ static void expand_chunk_from(co_mst_env_t *env, co_mst_irn_t *node,
* color.
*/
static aff_chunk_t *fragment_chunk(co_mst_env_t *env, unsigned col,
aff_chunk_t *c, pdeq *tmp)
aff_chunk_t *c, deq_t *tmp)
{
bitset_t *visited = bitset_malloc(get_irg_last_idx(env->co->irg));
aff_chunk_t *best = NULL;
......@@ -752,7 +753,7 @@ static aff_chunk_t *fragment_chunk(co_mst_env_t *env, unsigned col,
/* create a new chunk starting at current node */
aff_chunk_t *tmp_chunk = new_aff_chunk(env);
pdeq_putr(tmp, tmp_chunk);
deq_push_pointer_right(tmp, tmp_chunk);
expand_chunk_from(env, node, visited, tmp_chunk, c, decider, col);
assert(ARR_LEN(tmp_chunk->n) > 0 && "No nodes added to chunk");
......@@ -1068,8 +1069,9 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c)
* which one to take anyway.
* TODO Sebastian: Perhaps we should at all nodes and figure out
* a suitable color using costs as done above (determine_color_costs). */
pdeq *tmp_chunks = new_pdeq();
pdeq *best_starts = NULL;
deq_t tmp_chunks;
deq_init(&tmp_chunks);
deq_t *best_starts = NULL;
unsigned n_nodes = ARR_LEN(c->n);
aff_chunk_t *best_chunk = NULL;
int best_color = -1;
......@@ -1083,7 +1085,8 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c)
/* try to bring all nodes of given chunk to the current color. */
unsigned n_succeeded = 0;
pdeq *good_starts = new_pdeq();
deq_t *good_starts = XMALLOC(deq_t);
deq_init(good_starts);
for (size_t idx = 0, len = ARR_LEN(c->n); idx < len; ++idx) {
const ir_node *irn = c->n[idx];
co_mst_irn_t *node = get_co_mst_irn(env, irn);
......@@ -1099,7 +1102,7 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c)
bool good = change_node_color(env, node, col, &changed);
stat_ev_tim_pop("heur4_recolor");
if (good) {
pdeq_putr(good_starts, node);
deq_push_pointer_right(good_starts, node);
materialize_coloring(&changed);
node->fixed = 1;
} else {
......@@ -1118,12 +1121,13 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c)
/* try next color when failed */
if (n_succeeded == 0) {
del_pdeq(good_starts);
deq_free(good_starts);
free(good_starts);
continue;
}
/* fragment the chunk according to the coloring */
aff_chunk_t *local_best = fragment_chunk(env, col, c, tmp_chunks);
aff_chunk_t *local_best = fragment_chunk(env, col, c, &tmp_chunks);
/* search the best of the good list
and make it the new best if it is better than the current */
......@@ -1136,16 +1140,20 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c)
if (!best_chunk || best_chunk->weight < local_best->weight) {
best_chunk = local_best;
best_color = col;
if (best_starts)
del_pdeq(best_starts);
if (best_starts) {
deq_free(best_starts);
free(best_starts);
}
best_starts = good_starts;
DB((dbg, LEVEL_3, "\n\t\t... setting global best chunk (id %u), color %d\n", best_chunk->id, best_color));
} else {
DB((dbg, LEVEL_3, "\n\t\t... omitting, global best is better\n"));
del_pdeq(good_starts);
deq_free(good_starts);
free(good_starts);
}
} else {
del_pdeq(good_starts);
deq_free(good_starts);
free(good_starts);
}
/* if all nodes were recolored, bail out */
......@@ -1156,17 +1164,19 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c)
stat_ev_int("heur4_colors_tried", i);
/* free all intermediate created chunks except best one */
while (!pdeq_empty(tmp_chunks)) {
aff_chunk_t *tmp = (aff_chunk_t*)pdeq_getl(tmp_chunks);
while (!deq_empty(&tmp_chunks)) {
aff_chunk_t *tmp = deq_pop_pointer_left(aff_chunk_t, &tmp_chunks);
if (tmp != best_chunk)
delete_aff_chunk(tmp);
}
del_pdeq(tmp_chunks);
deq_free(&tmp_chunks);
/* return if coloring failed */
if (!best_chunk) {
if (best_starts)
del_pdeq(best_starts);
if (best_starts) {
deq_free(best_starts);
free(best_starts);
}
return;
}
......@@ -1242,8 +1252,10 @@ static void color_aff_chunk(co_mst_env_t *env, aff_chunk_t *c)
/* clear obsolete chunks and free some memory */
delete_aff_chunk(best_chunk);
free(visited);
if (best_starts)
del_pdeq(best_starts);
if (best_starts) {
deq_free(best_starts);
free(best_starts);
}
stat_ev_ctx_pop("heur4_color_chunk");
}
......
......@@ -37,7 +37,7 @@
#include "debug.h"
#include "irprintf.h"
#include "panic.h"
#include "pdeq.h"
#include "pdeq_new.h"
DEBUG_ONLY(static firm_dbg_module_t *dbg;)
......@@ -397,22 +397,44 @@ static void build_clique_star_cstr(ilp_env_t *ienv)
}
}
static void extend_path(ilp_env_t *ienv, pdeq *path, const ir_node *irn)
static bool path_contains(deq_t const *const path, ir_node const *const node)
{
deq_foreach_pointer(path, ir_node, n) {
if (n == node)
return true;
}
return false;
}
static unsigned path_len(deq_t const *const path)
{
unsigned res = 0;
deq_foreach_pointer(path, ir_node, n) {
(void)n;
++res;
}
return res;
}
static void extend_path(ilp_env_t *ienv, deq_t *path, const ir_node *irn)
{
/* do not walk backwards or in circles */
if (pdeq_contains(path, irn))
if (path_contains(path, irn))
return;
if (arch_irn_is_ignore(irn))
return;
/* insert the new irn */
pdeq_putr(path, irn);
deq_push_pointer_right(path, (ir_node*)irn);
/* check for forbidden interferences */
int const len = pdeq_len(path);
int const len = path_len(path);
ir_node **const curr_path = ALLOCAN(ir_node*, len);
pdeq_copyl(path, (const void **)curr_path);
unsigned i = 0;
deq_foreach_pointer(path, ir_node, n) {
curr_path[i++] = n;
}
for (int i = 1; i < len; ++i) {
if (be_values_interfere(irn, curr_path[i]))
......@@ -448,7 +470,7 @@ static void extend_path(ilp_env_t *ienv, pdeq *path, const ir_node *irn)
end:
/* remove the irn */
pdeq_getr(path);
deq_pop_pointer_right(ir_node, path);
}
/**
......@@ -461,9 +483,10 @@ static void build_path_cstr(ilp_env_t *ienv)
{
/* for each node with affinity edges */
co_gs_foreach_aff_node(ienv->co, aff_info) {
pdeq *const path = new_pdeq();
extend_path(ienv, path, aff_info->irn);
del_pdeq(path);
deq_t path;
deq_init(&path);
extend_path(ienv, &path, aff_info->irn);
deq_free(&path);
}
}
......
......@@ -42,7 +42,7 @@
#include "obst.h"
#include "raw_bitset.h"
#include "unionfind.h"
#include "pdeq.h"
#include "pdeq_new.h"
#include "hungarian.h"
#include "statev.h"
#include "bechordal_t.h"
......@@ -1629,9 +1629,10 @@ static void determine_block_order(void)
ir_node **blocklist = be_get_cfgpostorder(irg);
size_t n_blocks = ARR_LEN(blocklist);
int dfs_num = 0;
pdeq *worklist = new_pdeq();
ir_node **order = XMALLOCN(ir_node*, n_blocks);
size_t order_p = 0;
deq_t worklist;
deq_init(&worklist);
/* clear block links... */
ir_reserve_resources(irg, IR_RESOURCE_IRN_LINK);
......@@ -1684,7 +1685,7 @@ static void determine_block_order(void)
float best_costs = -1;
int n_cfgpred = get_Block_n_cfgpreds(block);
pdeq_putr(worklist, block);
deq_push_pointer_right(&worklist, block);
mark_Block_block_visited(block);
for (int i = 0; i < n_cfgpred; ++i) {
ir_node *pred_block = get_Block_cfgpred_block(block, i);
......@@ -1703,14 +1704,14 @@ static void determine_block_order(void)
} while (block != NULL && !Block_block_visited(block));
/* now put all nodes in the worklist in our final order */
while (!pdeq_empty(worklist)) {
ir_node *pblock = (ir_node*)pdeq_getr(worklist);
while (!deq_empty(&worklist)) {
ir_node *pblock = deq_pop_pointer_right(ir_node, &worklist);
assert(order_p < n_blocks);
order[order_p++] = pblock;
}
}
assert(order_p == n_blocks);
del_pdeq(worklist);
deq_free(&worklist);
ir_free_resources(irg, IR_RESOURCE_IRN_LINK | IR_RESOURCE_BLOCK_VISITED);
......
......@@ -155,21 +155,20 @@ static void introduce_use(be_ssa_construction_env_t *env, ir_node *use)
info->is_use = true;
block_info->is_use = true;
pdeq_putr(env->worklist, use);
deq_push_pointer_right(&env->worklist, use);
}
/**
* Calculates the iterated dominance frontier of a set of blocks. Marks the
* blocks as visited.
*/
static void mark_iterated_dominance_frontiers(
const be_ssa_construction_env_t *env)
static void mark_iterated_dominance_frontiers(be_ssa_construction_env_t *env)
{
stat_ev_cnt_decl(blocks);
DBG((dbg, LEVEL_3, "Dominance Frontier:"));
stat_ev_tim_push();
while (!pdeq_empty(env->worklist)) {
ir_node *block = (ir_node*)pdeq_getl(env->worklist);
while (!deq_empty(&env->worklist)) {
ir_node *block = deq_pop_pointer_left(ir_node, &env->worklist);
ir_node **domfront = ir_get_dominance_frontier(block);
for (size_t i = 0, len = ARR_LEN(domfront); i < len; ++i) {
ir_node *y = domfront[i];
......@@ -177,7 +176,7 @@ static void mark_iterated_dominance_frontiers(
continue;
if (!irn_visited(y))
pdeq_putr(env->worklist, y);
deq_push_pointer_right(&env->worklist, y);
DBG((dbg, LEVEL_3, " %+F", y));
mark_Block_block_visited(y);
......@@ -208,7 +207,7 @@ static ir_node *insert_dummy_phi(be_ssa_construction_env_t *env, ir_node *block)
DBG((dbg, LEVEL_2, "\tcreating phi %+F in %+F\n", phi, block));
introduce_definition(env, phi);
pdeq_putr(env->worklist, phi);
deq_push_pointer_right(&env->worklist, phi);
return phi;
}
......@@ -361,7 +360,7 @@ void be_ssa_construction_init(be_ssa_construction_env_t *env, ir_graph *irg)
memset(env, 0, sizeof(env[0]));
env->irg = irg;
env->new_phis = NEW_ARR_F(ir_node*, 0);
env->worklist = new_pdeq();
deq_init(&env->worklist);
ir_nodemap_init(&env->infos, irg);
obstack_init(&env->obst);
......@@ -384,7 +383,7 @@ void be_ssa_construction_destroy(be_ssa_construction_env_t *env)
stat_ev_int("bessaconstr_phis", ARR_LEN(env->new_phis));
obstack_free(&env->obst, NULL);
ir_nodemap_destroy(&env->infos);
del_pdeq(env->worklist);
deq_free(&env->worklist);
DEL_ARR_F(env->new_phis);
ir_free_resources(env->irg, IR_RESOURCE_IRN_VISITED
......@@ -417,7 +416,7 @@ void be_ssa_construction_add_copy(be_ssa_construction_env_t *env,
ir_node *block = get_nodes_block(copy);
if (!has_definition(block))
pdeq_putr(env->worklist, block);
deq_push_pointer_right(&env->worklist, block);
introduce_definition(env, copy);
}
......@@ -432,7 +431,7 @@ void be_ssa_construction_add_copies(be_ssa_construction_env_t *env,
ir_node *block = get_nodes_block(copy);
if (!has_definition(block)) {
pdeq_putr(env->worklist, block);
deq_push_pointer_right(&env->worklist, block);
}
introduce_definition(env, copy);
}
......@@ -489,7 +488,7 @@ void be_ssa_construction_fix_users_array(be_ssa_construction_env_t *env,
DBG((dbg, LEVEL_1, "\tfixing users array\n"));
assert(pdeq_empty(env->worklist));
assert(deq_empty(&env->worklist));
stat_ev_tim_push();
......@@ -508,8 +507,8 @@ void be_ssa_construction_fix_users_array(be_ssa_construction_env_t *env,
}
stat_ev_cnt_decl(uses);
while (!pdeq_empty(env->worklist)) {
ir_node *use = (ir_node *)pdeq_getl(env->worklist);
while (!deq_empty(&env->worklist)) {
ir_node *use = deq_pop_pointer_left(ir_node, &env->worklist);
constr_info *info = get_info(env, use);
if (info->already_processed)
......
......@@ -37,14 +37,14 @@
#include <stdbool.h>
#include "firm_types.h"
#include "belive.h"
#include "pdeq.h"
#include "pdeq_new.h"
#include "irnodemap.h"
#include "obst.h"
typedef struct be_ssa_construction_env_t {
ir_graph *irg;
const arch_register_req_t *phi_req;
pdeq *worklist;
deq_t worklist;
ir_node **new_phis;
bool iterated_domfront_calculated;
ir_nodemap infos;
......
......@@ -33,12 +33,12 @@
#include "irouts.h"
#include "irtools.h"
#include "panic.h"
#include "pdeq.h"
#include "pdeq_new.h"
#include "util.h"
#include "vrp.h"
typedef struct be_transform_env_t {
pdeq *worklist; /**< worklist of nodes that still need to be transformed */
deq_t worklist; /**< worklist of nodes that still need to be transformed */
} be_transform_env_t;
static be_transform_env_t env;
......@@ -235,7 +235,7 @@ void be_enqueue_operands(ir_node *node)
{
/* put the preds in the worklist */
foreach_irn_in(node, i, pred) {
pdeq_putr(env.worklist, pred);
deq_push_pointer_right(&env.worklist, pred);
}
}
......@@ -286,7 +286,7 @@ static void transform_nodes(ir_graph *irg, arch_pretrans_nodes *pre_transform)
{
inc_irg_visited(irg);
env.worklist = new_pdeq();
deq_init(&env.worklist);
ir_node *const old_anchor = irg->anchor;
ir_node *const new_anchor = new_r_Anchor(irg);
......@@ -304,8 +304,8 @@ static void transform_nodes(ir_graph *irg, arch_pretrans_nodes *pre_transform)
pre_transform(irg);
/* process worklist (this should transform all nodes in the graph) */
while (!pdeq_empty(env.worklist))