From a8ee82d197171c7c4e045bb693b9ef078e5ea80e Mon Sep 17 00:00:00 2001 From: David Given Date: Sat, 15 Oct 2016 23:19:44 +0200 Subject: [PATCH] Stop passing proc around, and use a global instead --- much cleaner. --- mach/proto/mcg/graph.c | 24 ++++----- mach/proto/mcg/graph.h | 2 +- mach/proto/mcg/mcg.h | 26 ++++----- mach/proto/mcg/parse_em.c | 3 +- mach/proto/mcg/pass_convertstackops.c | 8 +-- mach/proto/mcg/pass_eliminatetrivialblocks.c | 6 +-- mach/proto/mcg/pass_groupirs.c | 10 ++-- mach/proto/mcg/pass_prologueepilogue.c | 16 +++--- mach/proto/mcg/pass_promotefloatops.c | 10 ++-- mach/proto/mcg/pass_registerallocator.c | 6 +-- mach/proto/mcg/pass_removedeadblocks.c | 8 +-- mach/proto/mcg/pass_splitcriticaledges.c | 10 ++-- mach/proto/mcg/pass_ssa.c | 6 +-- mach/proto/mcg/powerpc.c | 24 ++++----- mach/proto/mcg/procedure.c | 57 ++++++++++---------- mach/proto/mcg/procedure.h | 2 + mach/proto/mcg/table | 2 + mach/proto/mcg/treebuilder.c | 4 +- 18 files changed, 108 insertions(+), 116 deletions(-) diff --git a/mach/proto/mcg/graph.c b/mach/proto/mcg/graph.c index 395b7bfca..4be0a548b 100644 --- a/mach/proto/mcg/graph.c +++ b/mach/proto/mcg/graph.c @@ -18,26 +18,26 @@ static bool collect_outputs_cb(struct ir* ir, void* user) return false; } -static void update_block_pointers_from_ir(struct procedure* proc) +static void update_block_pointers_from_ir(void) { int i, j; - for (i=0; iblocks.count; i++) + for (i=0; iblocks.count; i++) { - struct basicblock* bb = proc->blocks.item[i]; + struct basicblock* bb = current_proc->blocks.item[i]; bb->prevs.count = bb->nexts.count = 0; } - for (i=0; iblocks.count; i++) + for (i=0; iblocks.count; i++) { - struct basicblock* bb = proc->blocks.item[i]; + struct basicblock* bb = current_proc->blocks.item[i]; for (j=0; jirs.count; j++) ir_walk(bb->irs.item[j], collect_outputs_cb, bb); } - for (i=0; iblocks.count; i++) + for (i=0; iblocks.count; i++) { - struct basicblock* bb = proc->blocks.item[i]; + struct basicblock* bb = current_proc->blocks.item[i]; for (j=0; jnexts.count; j++) { @@ -189,15 +189,15 @@ static void walk_dominance_graph(void) } } -void update_graph_data(struct procedure* proc) +void update_graph_data(void) { - cfg.entry = proc->blocks.item[0]; + cfg.entry = current_proc->blocks.item[0]; cfg.graph.count = 0; - update_block_pointers_from_ir(proc); + update_block_pointers_from_ir(); walk_cfg_graph(); - assert(cfg.postorder.count == proc->blocks.count); - assert(cfg.preorder.count == proc->blocks.count); + assert(cfg.postorder.count == current_proc->blocks.count); + assert(cfg.preorder.count == current_proc->blocks.count); calculate_dominance_graph(); diff --git a/mach/proto/mcg/graph.h b/mach/proto/mcg/graph.h index 93991b82f..ed8e8ba21 100644 --- a/mach/proto/mcg/graph.h +++ b/mach/proto/mcg/graph.h @@ -19,7 +19,7 @@ struct dominance_data extern struct graph_data cfg; extern struct dominance_data dominance; -extern void update_graph_data(struct procedure* proc); +extern void update_graph_data(void); #endif diff --git a/mach/proto/mcg/mcg.h b/mach/proto/mcg/mcg.h index 005324d0d..78c7f0456 100644 --- a/mach/proto/mcg/mcg.h +++ b/mach/proto/mcg/mcg.h @@ -99,28 +99,28 @@ extern void data_bss(arith size, int init); extern void tb_filestart(void); extern void tb_fileend(void); -extern void tb_procedure(struct procedure* proc); +extern void tb_procedure(void); extern void tb_regvar(struct procedure* proc, arith offset, int size, int type, int priority); -extern void pass_convert_locals_to_ssa(struct procedure* proc); -extern void pass_convert_stack_ops(struct procedure* proc); -extern void pass_eliminate_trivial_blocks(struct procedure* proc); +extern void pass_convert_locals_to_ssa(void); +extern void pass_convert_stack_ops(void); +extern void pass_eliminate_trivial_blocks(void); extern void pass_find_phi_congruence_groups(void); -extern void pass_group_irs(struct procedure* proc); +extern void pass_group_irs(void); extern void pass_insert_moves(void); extern void pass_instruction_selector(void); extern void pass_live_vreg_analysis(void); -extern void pass_add_prologue_epilogue(struct procedure* proc); -extern void pass_promote_float_ops(struct procedure* proc); -extern void pass_register_allocator(struct procedure* proc); -extern void pass_remove_dead_blocks(struct procedure* proc); +extern void pass_add_prologue_epilogue(void); +extern void pass_promote_float_ops(void); +extern void pass_register_allocator(void); +extern void pass_remove_dead_blocks(void); extern void pass_remove_dead_phis(void); -extern void pass_split_critical_edges(struct procedure* proc); +extern void pass_split_critical_edges(void); -extern struct hop* platform_prologue(struct procedure* proc); -extern struct hop* platform_epilogue(struct procedure* proc); +extern void platform_calculate_offsets(void); +extern struct hop* platform_prologue(void); +extern struct hop* platform_epilogue(void); extern struct hop* platform_move(struct basicblock* bb, struct hreg* src, struct hreg* dest); -extern void platform_calculate_offsets(struct procedure* proc); extern FILE* outputfile; extern FILE* dominance_dot_file; diff --git a/mach/proto/mcg/parse_em.c b/mach/proto/mcg/parse_em.c index eaa712a4f..c49922ac8 100644 --- a/mach/proto/mcg/parse_em.c +++ b/mach/proto/mcg/parse_em.c @@ -1,7 +1,6 @@ #include "mcg.h" static struct e_instr em; -static struct procedure* current_proc; static struct basicblock* code_bb; static struct basicblock* data_bb; @@ -321,7 +320,7 @@ static void parse_pseu(void) } case ps_end: /* procedure end */ - tb_procedure(current_proc); + tb_procedure(); current_proc = NULL; code_bb = NULL; diff --git a/mach/proto/mcg/pass_convertstackops.c b/mach/proto/mcg/pass_convertstackops.c index 64bca0762..692a11a62 100644 --- a/mach/proto/mcg/pass_convertstackops.c +++ b/mach/proto/mcg/pass_convertstackops.c @@ -40,7 +40,7 @@ static struct ir* get_first_pop(struct basicblock* bb) return NULL; } -static void convert_block(struct procedure* proc, struct basicblock* bb) +static void convert_block(struct basicblock* bb) { int i, j; struct ir* ir; @@ -108,12 +108,12 @@ static void convert_block(struct procedure* proc, struct basicblock* bb) } } -void pass_convert_stack_ops(struct procedure* proc) +void pass_convert_stack_ops(void) { int i; - for (i=0; iblocks.count; i++) - convert_block(proc, proc->blocks.item[i]); + for (i=0; iblocks.count; i++) + for (i=0; iblocks.count; i++) { - struct basicblock* bb = proc->blocks.item[i]; + struct basicblock* bb = current_proc->blocks.item[i]; rewrite_jumps(bb); } } diff --git a/mach/proto/mcg/pass_groupirs.c b/mach/proto/mcg/pass_groupirs.c index ac86ff230..57b850a9b 100644 --- a/mach/proto/mcg/pass_groupirs.c +++ b/mach/proto/mcg/pass_groupirs.c @@ -14,14 +14,14 @@ static void addall(struct ir* ir) addall(ir->right); } -static void collect_irs(struct procedure* proc) +static void collect_irs(void) { int i; allirs.count = rootirs.count = 0; - for (i=0; iblocks.count; i++) + for (i=0; iblocks.count; i++) { - struct basicblock* bb = proc->blocks.item[i]; + struct basicblock* bb = current_proc->blocks.item[i]; int j; for (j=0; jirs.count; j++) @@ -82,9 +82,9 @@ static void find_non_roots(void) } } -void pass_group_irs(struct procedure* proc) +void pass_group_irs(void) { - collect_irs(proc); + collect_irs(); clear_roots(); find_roots(); find_non_roots(); diff --git a/mach/proto/mcg/pass_prologueepilogue.c b/mach/proto/mcg/pass_prologueepilogue.c index 056630707..53cc498ec 100644 --- a/mach/proto/mcg/pass_prologueepilogue.c +++ b/mach/proto/mcg/pass_prologueepilogue.c @@ -1,19 +1,17 @@ #include "mcg.h" -void pass_add_prologue_epilogue(struct procedure* proc) +void pass_add_prologue_epilogue(void) { - struct hop* prologue = platform_prologue(proc); - array_insert(&proc->entry->hops, prologue, 0); + platform_calculate_offsets(); - if (proc->exit) + array_insert(¤t_proc->entry->hops, platform_prologue(), 0); + + if (current_proc->exit) { - struct hop* epilogue = platform_epilogue(proc); - - proc->exit->hops.count = 0; - array_append(&proc->exit->hops, epilogue); + current_proc->exit->hops.count = 0; + array_append(¤t_proc->exit->hops, platform_epilogue()); } } /* vim: set sw=4 ts=4 expandtab : */ - diff --git a/mach/proto/mcg/pass_promotefloatops.c b/mach/proto/mcg/pass_promotefloatops.c index 1fdff6f4a..33992145c 100644 --- a/mach/proto/mcg/pass_promotefloatops.c +++ b/mach/proto/mcg/pass_promotefloatops.c @@ -14,15 +14,15 @@ static void addall(struct ir* ir) addall(ir->right); } -static void collect_irs(struct procedure* proc) +static void collect_irs(void) { int i; pending.count = 0; promotable.count = 0; - for (i=0; iblocks.count; i++) + for (i=0; iblocks.item[i]; + struct basicblock* bb = cfg.preorder.item[i]; int j; for (j=0; jirs.count; j++) @@ -87,9 +87,9 @@ static void modify_promotable_irs(void) } } -void pass_promote_float_ops(struct procedure* proc) +void pass_promote_float_ops(void) { - collect_irs(proc); + collect_irs(); search_for_promotable_irs(); modify_promotable_irs(); } diff --git a/mach/proto/mcg/pass_registerallocator.c b/mach/proto/mcg/pass_registerallocator.c index 6dadc2c76..393395e37 100644 --- a/mach/proto/mcg/pass_registerallocator.c +++ b/mach/proto/mcg/pass_registerallocator.c @@ -6,8 +6,6 @@ struct assignment struct vreg* out; }; -static struct procedure* current_proc; - static ARRAYOF(struct hreg) hregs; static PMAPOF(struct vreg, struct hreg) evicted; @@ -705,10 +703,8 @@ static void layout_stack_frame(void) current_proc->spills_size = stacksize; } -void pass_register_allocator(struct procedure* proc) +void pass_register_allocator(void) { - current_proc = proc; - populate_hregs(); wire_up_blocks_ins_outs(); diff --git a/mach/proto/mcg/pass_removedeadblocks.c b/mach/proto/mcg/pass_removedeadblocks.c index 24cb41889..8a9a07fb4 100644 --- a/mach/proto/mcg/pass_removedeadblocks.c +++ b/mach/proto/mcg/pass_removedeadblocks.c @@ -24,16 +24,16 @@ static void walk_blocks(struct basicblock* bb) } } -void pass_remove_dead_blocks(struct procedure* proc) +void pass_remove_dead_blocks(void) { int i, j; used.count = 0; - walk_blocks(proc->blocks.item[0]); + walk_blocks(current_proc->blocks.item[0]); - proc->blocks.count = 0; + current_proc->blocks.count = 0; for (i=0; iblocks, used.item[i]); + array_append(¤t_proc->blocks, used.item[i]); } /* vim: set sw=4 ts=4 expandtab : */ diff --git a/mach/proto/mcg/pass_splitcriticaledges.c b/mach/proto/mcg/pass_splitcriticaledges.c index 38628d995..27e832e44 100644 --- a/mach/proto/mcg/pass_splitcriticaledges.c +++ b/mach/proto/mcg/pass_splitcriticaledges.c @@ -12,8 +12,6 @@ * http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.25.749 */ -static struct procedure* current_proc; - struct rewrite_params { struct basicblock* find; @@ -85,19 +83,17 @@ static bool consider_edges_leading_from(struct basicblock* bb) return changed; } -void pass_split_critical_edges(struct procedure* proc) +void pass_split_critical_edges(void) { int i; bool changed; - current_proc = proc; - do { changed = false; - for (i=0; iblocks.count; i++) - changed |= consider_edges_leading_from(proc->blocks.item[i]); + for (i=0; iblocks.count; i++) + changed |= consider_edges_leading_from(current_proc->blocks.item[i]); } while (changed); diff --git a/mach/proto/mcg/pass_ssa.c b/mach/proto/mcg/pass_ssa.c index 9bf2d777b..99f4928ef 100644 --- a/mach/proto/mcg/pass_ssa.c +++ b/mach/proto/mcg/pass_ssa.c @@ -213,15 +213,15 @@ static void ssa_convert(void) recursively_rewrite_tree(cfg.entry); } -void pass_convert_locals_to_ssa(struct procedure* proc) +void pass_convert_locals_to_ssa(void) { int i; calculate_dominance_frontier_graph(); - for (i=0; ilocals.count; i++) + for (i=0; ilocals.count; i++) { - current_local = proc->locals.item[i].right; + current_local = current_proc->locals.item[i].right; if (current_local->is_register) ssa_convert(); } diff --git a/mach/proto/mcg/powerpc.c b/mach/proto/mcg/powerpc.c index 8cd2e269f..a47d8a8cc 100644 --- a/mach/proto/mcg/powerpc.c +++ b/mach/proto/mcg/powerpc.c @@ -14,29 +14,29 @@ * */ -void platform_calculate_offsets(struct procedure* proc) +void platform_calculate_offsets(void) { - proc->fp_to_st = proc->spills_size; - proc->fp_to_ap = proc->fp_to_st + proc->saved_size + 8; - proc->fp_to_lb = 0; + current_proc->fp_to_st = current_proc->spills_size; + current_proc->fp_to_ap = current_proc->fp_to_st + current_proc->saved_size + 8; + current_proc->fp_to_lb = 0; } -struct hop* platform_prologue(struct procedure* proc) +struct hop* platform_prologue(void) { - struct hop* hop = new_hop(proc->entry, NULL); + struct hop* hop = new_hop(current_proc->entry, NULL); - hop_add_insel(hop, "addi sp, sp, %d", proc->fp_to_ap + proc->locals_size); + hop_add_insel(hop, "addi sp, sp, %d", current_proc->fp_to_ap + current_proc->locals_size); hop_add_insel(hop, "mfspr 0, lr"); - hop_add_insel(hop, "stw fp, %d(sp)", proc->fp_to_st + proc->locals_size); - hop_add_insel(hop, "stw 0, %d(sp)", proc->fp_to_st + proc->locals_size + 4); - hop_add_insel(hop, "addi fp, sp, %d", proc->locals_size); + hop_add_insel(hop, "stw fp, %d(sp)", current_proc->fp_to_st + current_proc->locals_size); + hop_add_insel(hop, "stw 0, %d(sp)", current_proc->fp_to_st + current_proc->locals_size + 4); + hop_add_insel(hop, "addi fp, sp, %d", current_proc->locals_size); return hop; } -struct hop* platform_epilogue(struct procedure* proc) +struct hop* platform_epilogue(void) { - struct hop* hop = new_hop(proc->exit, NULL); + struct hop* hop = new_hop(current_proc->exit, NULL); hop_add_insel(hop, "b .ret"); diff --git a/mach/proto/mcg/procedure.c b/mach/proto/mcg/procedure.c index 00c1a457b..1484c2af9 100644 --- a/mach/proto/mcg/procedure.c +++ b/mach/proto/mcg/procedure.c @@ -1,15 +1,15 @@ #include "mcg.h" -extern struct procedure* current_proc; +struct procedure* current_proc; -static void print_blocks(char k, struct procedure* proc) +static void print_blocks(char k) { int i; - tracef(k, "%c: procedure %s\n", k, proc->name); - for (int i=0; iblocks.count; i++) + tracef(k, "%c: procedure %s\n", k, current_proc->name); + for (int i=0; iblocks.count; i++) { - struct basicblock* bb = proc->blocks.item[i]; + struct basicblock* bb = current_proc->blocks.item[i]; int j; tracef(k, "%c:\n", k); @@ -38,11 +38,11 @@ static void print_blocks(char k, struct procedure* proc) } } -static void print_hops(char k, struct procedure* proc) +static void print_hops(char k) { int i; - tracef(k, "%c: procedure %s\n", k, proc->name); + tracef(k, "%c: procedure %s\n", k, current_proc->name); for (int i=0; iblocks.count; i++) generate_tree(current_proc->blocks.item[i]);