Stop passing proc around, and use a global instead --- much cleaner.
This commit is contained in:
parent
7aa60a6451
commit
a8ee82d197
|
@ -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; i<proc->blocks.count; i++)
|
||||
for (i=0; i<current_proc->blocks.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; i<proc->blocks.count; i++)
|
||||
for (i=0; i<current_proc->blocks.count; i++)
|
||||
{
|
||||
struct basicblock* bb = proc->blocks.item[i];
|
||||
struct basicblock* bb = current_proc->blocks.item[i];
|
||||
for (j=0; j<bb->irs.count; j++)
|
||||
ir_walk(bb->irs.item[j], collect_outputs_cb, bb);
|
||||
}
|
||||
|
||||
for (i=0; i<proc->blocks.count; i++)
|
||||
for (i=0; i<current_proc->blocks.count; i++)
|
||||
{
|
||||
struct basicblock* bb = proc->blocks.item[i];
|
||||
struct basicblock* bb = current_proc->blocks.item[i];
|
||||
|
||||
for (j=0; j<bb->nexts.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();
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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; i<proc->blocks.count; i++)
|
||||
convert_block(proc, proc->blocks.item[i]);
|
||||
for (i=0; i<cfg.preorder.count; i++)
|
||||
convert_block(cfg.preorder.item[i]);
|
||||
}
|
||||
|
||||
/* vim: set sw=4 ts=4 expandtab : */
|
||||
|
|
|
@ -28,13 +28,13 @@ static void rewrite_jumps(struct basicblock* bb)
|
|||
}
|
||||
}
|
||||
|
||||
void pass_eliminate_trivial_blocks(struct procedure* proc)
|
||||
void pass_eliminate_trivial_blocks(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<proc->blocks.count; i++)
|
||||
for (i=0; i<current_proc->blocks.count; i++)
|
||||
{
|
||||
struct basicblock* bb = proc->blocks.item[i];
|
||||
struct basicblock* bb = current_proc->blocks.item[i];
|
||||
rewrite_jumps(bb);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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; i<proc->blocks.count; i++)
|
||||
for (i=0; i<current_proc->blocks.count; i++)
|
||||
{
|
||||
struct basicblock* bb = proc->blocks.item[i];
|
||||
struct basicblock* bb = current_proc->blocks.item[i];
|
||||
int j;
|
||||
|
||||
for (j=0; j<bb->irs.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();
|
||||
|
|
|
@ -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 : */
|
||||
|
||||
|
||||
|
|
|
@ -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; i<proc->blocks.count; i++)
|
||||
for (i=0; i<cfg.preorder.count; i++)
|
||||
{
|
||||
struct basicblock* bb = proc->blocks.item[i];
|
||||
struct basicblock* bb = cfg.preorder.item[i];
|
||||
int j;
|
||||
|
||||
for (j=0; j<bb->irs.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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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; i<used.count; i++)
|
||||
array_append(&proc->blocks, used.item[i]);
|
||||
array_append(¤t_proc->blocks, used.item[i]);
|
||||
}
|
||||
|
||||
/* vim: set sw=4 ts=4 expandtab : */
|
||||
|
|
|
@ -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; i<proc->blocks.count; i++)
|
||||
changed |= consider_edges_leading_from(proc->blocks.item[i]);
|
||||
for (i=0; i<current_proc->blocks.count; i++)
|
||||
changed |= consider_edges_leading_from(current_proc->blocks.item[i]);
|
||||
|
||||
}
|
||||
while (changed);
|
||||
|
|
|
@ -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; i<proc->locals.count; i++)
|
||||
for (i=0; i<current_proc->locals.count; i++)
|
||||
{
|
||||
current_local = proc->locals.item[i].right;
|
||||
current_local = current_proc->locals.item[i].right;
|
||||
if (current_local->is_register)
|
||||
ssa_convert();
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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; i<proc->blocks.count; i++)
|
||||
tracef(k, "%c: procedure %s\n", k, current_proc->name);
|
||||
for (int i=0; i<current_proc->blocks.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; i<dominance.preorder.count; i++)
|
||||
{
|
||||
struct basicblock* bb = dominance.preorder.item[i];
|
||||
|
@ -159,41 +159,42 @@ static void write_dominance_graph(const char* name)
|
|||
|
||||
void procedure_compile(struct procedure* proc)
|
||||
{
|
||||
pass_group_irs(proc);
|
||||
print_blocks('1', proc);
|
||||
current_proc = proc;
|
||||
|
||||
pass_group_irs();
|
||||
print_blocks('1');
|
||||
|
||||
/* Passes from here on must preserve IR grouping */
|
||||
|
||||
pass_eliminate_trivial_blocks(proc);
|
||||
pass_remove_dead_blocks(proc);
|
||||
pass_eliminate_trivial_blocks();
|
||||
pass_remove_dead_blocks();
|
||||
|
||||
print_blocks('2', proc);
|
||||
update_graph_data(proc);
|
||||
pass_split_critical_edges(proc);
|
||||
update_graph_data(proc);
|
||||
print_blocks('2');
|
||||
update_graph_data();
|
||||
pass_split_critical_edges();
|
||||
update_graph_data();
|
||||
|
||||
/* Passes from here on can't alter the BB graph without also updating prevs
|
||||
* and nexts (and then calling update_graph_data()). */
|
||||
|
||||
print_blocks('3', proc);
|
||||
pass_convert_stack_ops(proc);
|
||||
print_blocks('4', proc);
|
||||
pass_convert_locals_to_ssa(proc);
|
||||
print_blocks('5', proc);
|
||||
print_blocks('3');
|
||||
pass_convert_stack_ops();
|
||||
print_blocks('4');
|
||||
pass_convert_locals_to_ssa();
|
||||
print_blocks('5');
|
||||
pass_remove_dead_phis();
|
||||
pass_promote_float_ops(proc);
|
||||
print_blocks('6', proc);
|
||||
pass_promote_float_ops();
|
||||
print_blocks('6');
|
||||
|
||||
pass_instruction_selector();
|
||||
print_hops('7', proc);
|
||||
print_hops('7');
|
||||
pass_find_phi_congruence_groups();
|
||||
pass_live_vreg_analysis();
|
||||
print_hops('8', proc);
|
||||
pass_register_allocator(proc);
|
||||
pass_add_prologue_epilogue(proc);
|
||||
print_hops('9', proc);
|
||||
print_hops('8');
|
||||
pass_register_allocator();
|
||||
pass_add_prologue_epilogue();
|
||||
print_hops('9');
|
||||
|
||||
platform_calculate_offsets(proc);
|
||||
emit_procedure(proc);
|
||||
|
||||
if (cfg_dot_file)
|
||||
|
|
|
@ -26,6 +26,8 @@ struct procedure
|
|||
extern void procedure_compile(struct procedure* proc);
|
||||
extern void procedure_update_bb_graph(struct procedure* proc);
|
||||
|
||||
extern struct procedure* current_proc;
|
||||
|
||||
#endif
|
||||
|
||||
/* vim: set sw=4 ts=4 expandtab : */
|
||||
|
|
|
@ -74,6 +74,7 @@ REGISTERS
|
|||
cr0 "cr0" cr!;
|
||||
|
||||
|
||||
|
||||
DECLARATIONS
|
||||
|
||||
cr;
|
||||
|
@ -85,6 +86,7 @@ DECLARATIONS
|
|||
address fragment;
|
||||
|
||||
|
||||
|
||||
PATTERNS
|
||||
|
||||
/* Special */
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "mcg.h"
|
||||
|
||||
static struct procedure* current_proc;
|
||||
static struct basicblock* current_bb;
|
||||
|
||||
static int stackptr;
|
||||
|
@ -989,11 +988,10 @@ static void generate_tree(struct basicblock* bb)
|
|||
assert(stackptr == 0);
|
||||
}
|
||||
|
||||
void tb_procedure(struct procedure* proc)
|
||||
void tb_procedure(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
current_proc = proc;
|
||||
for (i=0; i<current_proc->blocks.count; i++)
|
||||
generate_tree(current_proc->blocks.item[i]);
|
||||
|
||||
|
|
Loading…
Reference in a new issue