Commit 2cc256e5 authored by Sebastian Hack's avatar Sebastian Hack
Browse files

Added insert_Perm and be_*_main_env_t

parent 8ed2ea59
......@@ -27,7 +27,6 @@ SOURCES += Makefile.in besched.h belistsched.h belistsched.c \
becopyilp.c becopystat.c bearch_firm.c bearch.c bechordal_draw.c \
bechordal_draw.h beirgmod.c beirgmod.h benode.c benode_t.h \
mps.c lpp.c lpp_local.c lpp_remote.c
#bessadestr.c
include $(topdir)/MakeRules
......
......@@ -7,6 +7,15 @@
#ifndef _BE_T_H
#define _BE_T_H
#include "obst.h"
#include <beirgmod.h>
#include <bearch.h>
#include "benode_t.h"
#if 0
typedef struct _phase_t {
const char *name;
int id;
......@@ -16,5 +25,18 @@ int phase_register(phase_t *phase);
void phase_applied(const ir_graph *irg, const phase_t *phase);
int phase_depends_on(const ir_graph *irg, const phase_t *phase, int n, ...);
int phase_invalidates(const ir_graph *irg, const phase_t *phase, int n, ...);
#endif
typedef struct _be_main_env_t {
struct obstack obst;
be_node_factory_t *node_factory;
arch_env_t *arch_env;
} be_main_env_t;
typedef struct _be_main_session_env_t {
const be_main_env_t *main_env;
ir_graph *irg;
dom_front_info_t *dom_front;
} be_main_session_env_t;
#endif
......@@ -24,6 +24,8 @@ typedef struct _arch_env_t arch_env_t;
typedef struct _arch_irn_ops_t arch_irn_ops_t;
typedef struct _arch_irn_handler_t arch_irn_handler_t;
struct _be_node_factory_t;
typedef enum _arch_register_type_t {
arch_register_type_none = 0,
arch_register_type_write_invariant,
......@@ -440,12 +442,13 @@ struct _arch_isa_if_t {
* Keep this everywhere you're going.
*/
struct _arch_env_t {
const arch_isa_if_t *isa; /** The isa about which everything is. */
const struct _be_node_factory_t *node_factory; /**< The node factory for be nodes. */
const arch_isa_if_t *isa; /**< The isa about which everything is. */
arch_irn_handler_t const *handlers[ARCH_MAX_HANDLERS]; /** The handlers are organized as
a stack. */
arch_irn_handler_t const *handlers[ARCH_MAX_HANDLERS]; /**< The handlers are organized as
a stack. */
int handlers_tos; /** The stack pointer of the handler
int handlers_tos; /**< The stack pointer of the handler
stack. */
};
......
......@@ -5,6 +5,7 @@
#include "pdeq.h"
#include "pset.h"
#include "pmap.h"
#include "util.h"
#include "irflag_t.h"
#include "ircons_t.h"
......@@ -13,7 +14,12 @@
#include "irdom_t.h"
#include "iredges_t.h"
#include "be_t.h"
#include "bearch.h"
#include "besched_t.h"
#include "belive_t.h"
#include "benode_t.h"
#include "beirgmod.h"
struct _dom_front_info_t {
......@@ -277,7 +283,6 @@ static ir_node *search_def(ir_node *usage, int pos, pset *copies, pset *copy_blo
return NULL;
}
static void fix_usages(ir_node *orig, pset *copies, pset *copy_blocks)
{
int i;
......@@ -344,3 +349,59 @@ void be_introduce_copies(dom_front_info_t *info, ir_node *orig, int n, ir_node *
del_pset(copies);
del_pset(copy_blocks);
}
void insert_Perm_after(const be_main_session_env_t *env,
const arch_register_class_t *cls, ir_node *pos)
{
const arch_env_t *arch_env = env->main_env->arch_env;
ir_node *bl = is_Block(pos) ? pos : get_nodes_block(pos);
ir_graph *irg = get_irn_irg(bl);
pset *live_end = get_live_end(bl);
pset *live = pset_new_ptr_default();
ir_node *curr, *irn, *perm, **nodes;
int i, n;
/* put all live ends in the live set. */
for(irn = pset_first(live_end); irn; irn = pset_next(live_end))
pset_insert_ptr(live, irn);
sched_foreach_reverse(bl, irn) {
if(arch_irn_has_reg_class(arch_env, irn, arch_pos_make_out(0), cls))
pset_remove_ptr(live, irn);
for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
ir_node *op = get_irn_n(irn, i);
if(arch_irn_has_reg_class(arch_env, op, arch_pos_make_out(0), cls))
pset_insert_ptr(live, op);
}
if(sched_prev(irn) == pos)
break;
}
n = pset_count(live);
nodes = malloc(n * sizeof(nodes[0]));
for(irn = pset_first(live), i = 0; irn; irn = pset_next(live), i++)
nodes[i] = irn;
curr = perm = new_Perm(env->main_env->node_factory, cls, irg, bl, n, nodes);
sched_add_after(pos, perm);
free(nodes);
for(i = 0; i < n; ++i) {
ir_node *copies[1];
ir_node *perm_op = get_irn_n(perm, i);
ir_mode *mode = get_irn_mode(perm_op);
ir_node *proj = new_r_Proj(irg, bl, perm, mode, i);
sched_add_after(curr, proj);
curr = proj;
copies[0] = proj;
be_introduce_copies(env->dom_front, perm_op, array_size(copies), copies);
}
}
......@@ -54,32 +54,51 @@ void be_init(void)
#endif
}
static void be_init_arch_env(arch_env_t *env)
static be_main_env_t *be_init_env(be_main_env_t *env)
{
const arch_isa_if_t *isa = &firm_isa;
be_node_factory_t *nf;
nf = be_new_node_factory(isa);
obstack_init(&env->obst);
arch_env_init(env, isa);
env->isa->init();
env->arch_env = obstack_alloc(&env->obst, sizeof(env->arch_env[0]));
arch_env_init(env->arch_env, isa);
env->arch_env->isa->init();
arch_env_add_irn_handler(env, &firm_irn_handler);
arch_env_add_irn_handler(env, be_node_get_irn_handler(nf));
env->node_factory = obstack_alloc(&env->obst, sizeof(*env->node_factory));
be_node_factory_init(env->node_factory, isa);
arch_env_add_irn_handler(env->arch_env, &firm_irn_handler);
arch_env_add_irn_handler(env->arch_env,
be_node_get_irn_handler(env->node_factory));
return env;
}
be_main_session_env_t *be_init_session_env(be_main_session_env_t *env,
be_main_env_t *main_env, ir_graph *irg)
{
env->main_env = main_env;
env->irg = irg;
return env;
}
static void be_main_loop(void)
{
int i, n;
arch_env_t arch_env;
const arch_isa_if_t *isa;
be_main_env_t env;
const arch_isa_if_t *isa;
be_init_env(&env);
be_init_arch_env(&arch_env);
isa = arch_env_get_isa(&arch_env);
isa = arch_env_get_isa(env.arch_env);
for(i = 0, n = get_irp_n_irgs(); i < n; ++i) {
int j, m;
ir_graph *irg = get_irp_irg(i);
be_main_session_env_t session;
be_init_session_env(&session, &env, irg);
remove_critical_cf_edges(irg);
......@@ -104,7 +123,7 @@ static void be_main_loop(void)
be_chordal_env_t *chordal_env;
const arch_register_class_t *cls = isa->get_reg_class(j);
chordal_env = be_ra_chordal(irg, &arch_env, cls);
chordal_env = be_ra_chordal(irg, env.arch_env, cls);
#ifdef DUMP_ALLOCATED
dump_allocated_irg(&arch_env, irg, "");
......@@ -112,8 +131,8 @@ static void be_main_loop(void)
#ifdef DO_STAT
stat_collect_irg(irg);
#endif
be_copy_opt(chordal_env);
//TODO be_ssa_destruction(chordal_env);
be_ra_chordal_done(chordal_env);
}
#ifdef DO_STAT
......
......@@ -14,7 +14,7 @@
#include "obst.h"
#include "set.h"
#include "pmap.h"
#include "offset.h"
#include "util.h"
#include "irop_t.h"
#include "irmode_t.h"
......@@ -22,18 +22,6 @@
#include "benode_t.h"
struct _be_node_factory_t {
const arch_isa_if_t *isa;
struct obstack obst;
set *ops;
pmap *irn_op_map;
pmap *reg_req_map;
arch_irn_handler_t handler;
arch_irn_ops_t irn_ops;
};
typedef enum _node_kind_t {
node_kind_spill,
node_kind_reload,
......@@ -259,13 +247,12 @@ int is_Spill(const be_node_factory_t *f, const ir_node *irn)
return bo->kind == node_kind_spill;
}
be_node_factory_t *be_new_node_factory(const arch_isa_if_t *isa)
be_node_factory_t *be_node_factory_init(be_node_factory_t *factory,
const arch_isa_if_t *isa)
{
be_node_factory_t *factory;
char buf[256];
int i, j, n;
factory = malloc(sizeof(*factory));
factory->ops = new_set(cmp_op_map, 64);
factory->irn_op_map = pmap_create();
obstack_init(&factory->obst);
......
......@@ -12,14 +12,29 @@
#ifndef _BENODE_T_H
#define _BENODE_T_H
#include "pmap.h"
#include "irmode.h"
#include "irnode.h"
#include "bearch.h"
struct _be_node_factory_t {
const arch_isa_if_t *isa;
struct obstack obst;
set *ops;
pmap *irn_op_map;
pmap *reg_req_map;
arch_irn_handler_t handler;
arch_irn_ops_t irn_ops;
};
typedef struct _be_node_factory_t be_node_factory_t;
be_node_factory_t *be_new_node_factory(const arch_isa_if_t *isa);
be_node_factory_t *be_node_factory_init(be_node_factory_t *factory,
const arch_isa_if_t *isa);
const arch_irn_handler_t *be_node_get_irn_handler(const be_node_factory_t *f);
......
......@@ -19,7 +19,9 @@ int (get_graph_block_count)(const ir_graph *irn);
ir_node *(get_irn_for_graph_nr)(const ir_graph *irg, int nr);
#if 0
extern const phase_t *phase_numbering;
#endif
void be_numbering(ir_graph *irg);
void be_numbering_done(ir_graph *irg);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment