inputfile ::= regs cfg .
-regs ::= 'regs' regcount . // Anzahl der register (0..regcount-1), die zur Verfuegung stehen
+regs ::= 'regs' regcount 'saved-by-caller' reg-list 'saved-by-callee' reg-list . // Anzahl der register (0..regcount-1), die zur Verfuegung stehen
+
+reg-list ::= reg-nr
+ | reg-nr reg-list
cfg ::= 'cfg' ident '{' block* edge* '}' . // Steuerflussgraph der Prozedur
gen-insn ::= 'insn' insn-nr '{' uses defs '}' .
copy-insn ::= 'copy' insn-nr '{' uses defs '}' .
+call-insn ::= 'call' insn-nr '{' uses defs '}' .
defs ::= 'def' var-list . // Liste der definierten/verwendeten Variablen
uses ::= 'use' var-list .
The output file format
-----------------------
-outputfile ::= action* .
+outputfile ::= action* assign*.
action ::= 'spill' loc var-nr // insert a spill spill(var-nr);
- | 'reload' loc var-nr var-nr // insert a reload var-nr[1] := reload(var-nr[2]);
+ | 'reload' loc new-var-nr var-nr // insert a reload new-var-nr := reload(var-nr);
+ | 'setarg' insn-nr pos var-nr // change a usage to insn(..., var-nr, ...) (equals set_irn_n)
| 'copy' loc var-nr var-nr // insert a copy var-nr[1] := var-nr[2];
- | 'assign' var-nr reg-nr . // assign var-nr the register reg-nr
+
+assign ::= 'assign' var-nr reg-nr . // assign var-nr the register reg-nr
loc ::= 'before' insn-nr
| 'after' insn-nr .
-TODO
- *
- * End of file format docu */
+
+Constraints for output file
+---------------------------
+1) The returned actions must result in a non-ssa-program
+ equivalent to the former input.
+2) All names (numbers) must be defined before their first use.
+ Numbers already occuring in the input file are implicitly defined in the output file.
+3) All spills of a variable must precede the first reload of this variable
+4) Each reload must define a new variable name
+
+
+
+******** End of file format docu ********/
#ifdef HAVE_CONFIG_H
#include "config.h"
#include <libcore/lc_opts_enum.h>
#endif
-#include "pmap.h"
+#include "set.h"
#include "pset.h"
+#include "pmap.h"
#include "bitset.h"
#include "irprintf_t.h"
#include "irnode_t.h"
#include "irgraph_t.h"
#include "irgwalk.h"
+#include "irdom_t.h"
#include "phiclass.h"
#include "beraextern.h"
#include "bearch.h"
#include "benode_t.h"
+#include "beirgmod.h"
#include "besched.h"
#include "beutil.h"
+typedef struct _var_info_t var_info_t;
+
/**
* Environment with all the needed stuff
*/
arch_env_t *aenv;
const arch_register_class_t *cls;
ir_graph *irg;
+ dom_front_info_t *dom_info;
FILE *f; /**< file handle used for out- and input file */
- pmap *vars; /**< maps variable numbers (int) to the corresponding SSA-values (pset of irns) */
- pmap *blocks; /**< maps block numbers (int) to the block (ir_node*) having that node_nr */
+ set *vars; /**< contains all var_info_t */
+ pmap *nodes; /**< maps nodes numbers (int) to the node (ir_node*) having that node_nr */
} be_raext_env_t;
-/******************************************************************************
- ____ _ _
- / __ \ | | (_)
- | | | |_ __ | |_ _ ___ _ __ ___
- | | | | '_ \| __| |/ _ \| '_ \/ __|
- | |__| | |_) | |_| | (_) | | | \__ \
- \____/| .__/ \__|_|\___/|_| |_|___/
- | |
- |_|
- *****************************************************************************/
-
-
-static void ssa_destr_simple(be_raext_env_t *);
-static void ssa_destr_rastello(be_raext_env_t *);
-static void be_ra_extern_main(const be_main_env_t *env, ir_graph *irg);
-
-static void (*ssa_destr)(be_raext_env_t*) = ssa_destr_simple;
-static char callee[128] = "echo";
-
-#ifdef WITH_LIBCORE
-
-static const lc_opt_enum_const_ptr_items_t ssa_destr_items[] = {
- { "simple", ssa_destr_simple },
- { "rastello", ssa_destr_rastello },
- { NULL, NULL }
-};
-
-static lc_opt_enum_const_ptr_var_t ssa_destr_var = {
- (const void **) &ssa_destr, ssa_destr_items
-};
-
-static const lc_opt_table_entry_t be_ra_extern_options[] = {
- LC_OPT_ENT_ENUM_FUNC_PTR("ssa_destr", "SSA destruction flavor", &ssa_destr_var),
- LC_OPT_ENT_STR("callee", "The external program to call", callee, sizeof(callee)),
- { NULL }
-};
-
-static void be_ra_extern_register_options(lc_opt_entry_t *root) {
- lc_opt_entry_t *grp = lc_opt_get_grp(root, "ext");
-
- lc_opt_add_table(grp, be_ra_extern_options);
-}
-
-#endif /* WITH_LIBCORE */
-const be_ra_t be_ra_external_allocator = {
-#ifdef WITH_LIBCORE
- be_ra_extern_register_options,
-#endif
- be_ra_extern_main
-};
/******************************************************************************
_ _ _
|_|
*****************************************************************************/
+
+#define pset_foreach(pset, irn) for(irn=pset_first(pset); irn; irn=pset_next(pset))
+#define set_foreach(set, e) for(e=set_first(set); e; e=set_next(set))
+
+
/**
* Checks if _the_ result of the irn belongs to the
* current register class (raenv->cls)
static void ssa_destr_rastello(be_raext_env_t *raenv) {
+ assert(0 && "NYI");
+ /* TODO
phi_class_compute(raenv->irg);
- //TODO irg_block_walk_graph(irg, ssa_destr_rastello, NULL, &raenv);
+ irg_block_walk_graph(irg, ssa_destr_rastello, NULL, &raenv);
+ */
}
/******************************************************************************
\/ \__,_|_|___/ |____| \/ \__,_|_| |___/
*****************************************************************************/
-#define pmap_insert_sth(pmap, key, val) pmap_insert(pmap, (void *)key, (void *)val)
+/**
+ * This struct maps a variable (nr) to
+ * 1) the values belonging to this variable
+ * 2) the spills of this variable
+ */
+struct _var_info_t {
+ int var_nr; /* the key for comparesion */
+ pset *values; /* the ssa-values belonging to this variable */
+ pset *spills; /* the spills of this variable */
+ pset *reloads; /* the relaods of this variable */
+ unsigned reload_phase:1; /* 0 initially, 1 if a reload of this var has been inserted */
+};
+
+/**
+ * The link field of an irn points to the var_info struct
+ * representing the corresponding variable.
+ */
+#define set_var_info(irn, vi) set_irn_link(irn, vi)
+#define get_var_info(irn) ((var_info_t *)get_irn_link(irn))
+
+/* TODO insn-nr handling if ext defines new ones */
+#define pmap_insert_sth(pmap, key, val) pmap_insert(pmap, (void *)key, (void *)val)
#define pmap_get_sth(pmap, key) pmap_get(pmap, (void *)key)
-#define set_var_nr(irn, nr) set_irn_link(irn, INT_TO_PTR(nr))
-#define get_var_nr(irn) PTR_TO_INT(get_irn_link(irn))
+
+
+#define HASH_VAR_NR(var_nr) var_nr
+
+
+
+static int compare_var_infos(const void *e1, const void *e2, size_t size) {
+ const var_info_t *v1 = e1;
+ const var_info_t *v2 = e2;
+
+ return v1->var_nr != v2->var_nr;
+}
+
+static INLINE var_info_t *var_find(set *vars, int var_nr) {
+ var_info_t vi;
+ vi.var_nr = var_nr;
+
+ return set_find(vars, &vi, sizeof(vi), HASH_VAR_NR(var_nr));
+}
+
+static INLINE var_info_t *var_find_or_insert(set *vars, int var_nr) {
+ var_info_t vi, *found;
+ memset(&vi, 0, sizeof(vi));
+ vi.var_nr = var_nr;
+
+ found = set_insert(vars, &vi, sizeof(vi), HASH_VAR_NR(var_nr));
+
+ if (!found->values) {
+ found->values = pset_new_ptr(1);
+ found->spills = pset_new_ptr(1);
+ found->reloads = pset_new_ptr(1);
+ }
+
+ return found;
+}
+
+/**
+ * Adds a value to a variable. Sets all pointers accordingly.
+ */
+static INLINE var_info_t *var_add_value(be_raext_env_t *raenv, int var_nr, ir_node *irn) {
+ var_info_t *vi = var_find_or_insert(raenv->vars, var_nr);
+
+ /* var 2 value mapping */
+ pset_insert_ptr(vi->values, irn);
+
+ /* value 2 var mapping */
+ set_var_info(irn, vi);
+
+ return vi;
+}
+
+/**
+ * Adds a spill to a variable. Sets all pointers accordingly.
+ */
+static INLINE var_info_t *var_add_spill(be_raext_env_t *raenv, int var_to_spill, ir_node *before) {
+ var_info_t *vi = var_find_or_insert(raenv->vars, var_to_spill);
+ ir_node *blk, *tospill, *spill;
+
+ assert(pset_count(vi->values) && "There are no values associated to this variable (yet?)");
+ assert(!vi->reload_phase && "I have already seen a reload for this variable, so you cant spill anymore!");
+
+ /* add spill to graph and schedule */
+ blk = get_nodes_block(before);
+ tospill = dom_up_search(vi->values, before); /* which value gets spilled */
+ spill = be_new_Spill(raenv->cls, raenv->irg, blk, tospill, tospill); /* the corresponding spill node */
+
+ sched_add_before(before, spill);
+
+ /* the spill also points to the var_info of the spilled node */
+ set_var_info(spill, vi);
+
+ /* remember the spill */
+ pset_insert_ptr(vi->spills, spill);
+
+ return vi;
+}
+
+/**
+ * Adds a reload to a variable. Sets all pointers accordingly.
+ */
+static INLINE var_info_t *var_add_reload(be_raext_env_t *raenv, int var_to_reload, int var_nr_for_reload, ir_node *before) {
+ var_info_t *vi = var_find_or_insert(raenv->vars, var_to_reload);
+ ir_node *blk, *spill, *reload;
+
+ assert(pset_count(vi->spills) && "There are no spills associated to this variable (yet?)");
+ /* now we enter the reload phase, so no more spills are allowed */
+ vi->reload_phase = 1;
+
+ /* add reload to graph and schedule */
+ blk = get_nodes_block(before);
+ spill = pset_first(vi->spills); /* For now use an arbitrary spill node. This is corrected later in fix_reloads */
+ pset_break(vi->spills);
+ reload = be_new_Reload(raenv->cls, raenv->irg, blk, get_irn_mode(get_irn_n(spill, 0)), spill);
+
+ sched_add_before(before, reload);
+
+ /* create a new variable for the result of the reload */
+ assert(!var_find(raenv->vars, var_nr_for_reload) && "Each reload must define a new variable");
+ var_add_value(raenv, var_nr_for_reload, reload);
+
+ /* remember the reload */
+ pset_insert_ptr(vi->reloads, reload);
+
+ return vi;
+}
+
+static INLINE pset *get_var_values(be_raext_env_t *raenv, int var_nr) {
+ var_info_t *vi = var_find(raenv->vars, var_nr);
+ assert(vi && "Variable does not (yet?) exist");
+ return vi->values;
+}
+
+static INLINE pset *get_var_spills(be_raext_env_t *raenv, int var_nr) {
+ var_info_t *vi = var_find(raenv->vars, var_nr);
+ assert(vi && "Variable does not (yet?) exist");
+ return vi->spills;
+}
+
+static INLINE pset *get_var_reloads(be_raext_env_t *raenv, int var_nr) {
+ var_info_t *vi = var_find(raenv->vars, var_nr);
+ assert(vi && "Variable does not (yet?) exist");
+ return vi->reloads;
+}
/**
* Define variables (numbers) for all SSA-values.
pset_insert_ptr(vals, irn);
}
- /* value to var mapping */
+ /* values <--> var mapping */
n = pset_first(vals);
nr = get_irn_node_nr(n);
for (; n; n=pset_next(vals))
- set_var_nr(irn, nr);
+ var_add_value(raenv, nr, n);
+}
+
+/******************************************************************************
+ _ _____ _ _
+ /\ | | | __ \ | | |
+ / \ _ __ _ __ | |_ _ | |__) |___ ___ _ _| | |_
+ / /\ \ | '_ \| '_ \| | | | | | _ // _ \/ __| | | | | __|
+ / ____ \| |_) | |_) | | |_| | | | \ \ __/\__ \ |_| | | |_
+ /_/ \_\ .__/| .__/|_|\__, | |_| \_\___||___/\__,_|_|\__|
+ | | | | __/ |
+ |_| |_| |___/
+ *****************************************************************************/
+
+#define INVALID_FILE_FORMAT assert(0 && "Invalid file format.")
+
+static INLINE int is_before(const char *s, size_t len) {
+ if (!strncmp(s, "before", len))
+ return 1;
+ if (!strncmp(s, "after", len))
+ return 0;
+ INVALID_FILE_FORMAT;
+ return -1;
+}
+
+static void fix_reloads(be_raext_env_t *raenv) {
+ var_info_t *vi;
+ set_foreach(raenv->vars, vi)
+ be_introduce_copies_pset(raenv->dom_info, vi->spills);
+}
+
+/**
+ * Read in the actions performed by the external allocator.
+ * Apply these transformations to the irg.
+ */
+static void read_and_apply_results(be_raext_env_t *raenv, char *filename) {
+ FILE *f;
+ var_info_t *vi;
+ int phase=0;
+
+ if (!(f = fopen(filename, "rt"))) {
+ fprintf(stderr, "Could not open file %s for reading\n", filename);
+ exit(0xdeadbeef);
+ }
+ raenv->f = f;
+
+
+
+ /* parse the file */
+ while (phase == 0) {
+ int loc, var_use_ident, var_def_ident, pos;
+ char where[16];
- /* var to values mapping */
- pmap_insert_sth(raenv->vars, nr, vals);
+ /* handle a spill */
+ if (fscanf(f, " spill %6s %d %d ", &where, &loc, &var_use_ident) == 3) {
+
+ /* determine the node to insert the spill before */
+ ir_node *anchor = pmap_get_sth(raenv->nodes, loc);
+ assert(anchor && "insn-nr does not exist");
+ if (!is_before(where, sizeof(where)))
+ anchor = sched_next(anchor);
+
+ var_add_spill(raenv, var_use_ident, anchor);
+ }
+
+ /* handle a reload */
+ else if (fscanf(f, " reload %s %d %d %d ", &where, &loc, &var_def_ident, &var_use_ident) == 4) {
+
+ /* determine the node to insert the spill before */
+ ir_node *anchor = pmap_get_sth(raenv->nodes, loc);
+ assert(anchor && "insn-nr does not exist");
+ if (!is_before(where, sizeof(where)))
+ anchor = sched_next(anchor);
+
+ var_add_reload(raenv, var_use_ident, var_def_ident, anchor);
+ }
+
+ /* handle a set_irn_n */
+ else if (fscanf(f, " setarg %d %d %d ", &loc, &pos, &var_use_ident) == 3) {
+ ir_node *to_change, *new_arg;
+ var_info_t *vi = var_find(raenv->vars, var_use_ident);
+ assert(vi && vi->values && "New argument does not exist");
+
+ to_change = pmap_get_sth(raenv->nodes, loc);
+ assert(to_change && "insn-nr does not exist");
+
+ new_arg = dom_up_search(vi->values, to_change);
+ set_irn_n(to_change, pos, new_arg);
+ }
+
+ /* handle a copy insertion */
+ else if (fscanf(f, " copy %s %d %d %d ", &where, &loc, &var_def_ident, &var_use_ident) == 4) {
+ /* TODO
+ Ziel der Kopie ist Variable die bereits existiert
+ Ziel der Kopie ist eine neue Variable
+ */
+ }
+
+ else
+ phase++;
+ }
+
+ fix_reloads(raenv);
+
+ while (phase == 1) {
+ int var_use_ident, reg_nr;
+
+ /* assign register */
+ if (fscanf(f, " assign %d %d ", &var_use_ident, ®_nr) == 2) {
+ pset *vals = get_var_values(raenv, var_use_ident);
+ ir_node *irn;
+
+ assert(vals && "Variable does not (yet?) exist!");
+ pset_foreach(vals, irn)
+ arch_set_irn_register(raenv->aenv, irn, arch_register_for_index(raenv->cls, var_use_ident));
+ }
+ else
+ phase++;
+ }
+
+ if (!feof(f))
+ INVALID_FILE_FORMAT;
+
+ fclose(f);
+
+ /* Free the psets held in the variable-infos */
+ set_foreach(raenv->vars, vi) {
+ del_pset(vi->values);
+ del_pset(vi->spills);
+ del_pset(vi->reloads);
+ }
}
/******************************************************************************
FILE *f = raenv->f;
int nr = get_irn_node_nr(blk);
- pmap_insert_sth(raenv->blocks, nr, blk);
+ pmap_insert_sth(raenv->nodes, nr, blk);
/* begin block scope */
fprintf(f, "\n");
/* for each instruction */
for(irn=sched_first(blk); !sched_is_end(irn); irn=sched_next(irn)) {
int max, i;
+ int node_nr;
+
if (is_Phi(irn) || !is_sth_in_reg_class(raenv, irn))
continue;
- if (be_is_Copy(irn))
+ /* kind of instruction */
+ if (arch_irn_classify(raenv->aenv, irn) == arch_irn_class_copy)
fprintf(f, " copy");
+ else if (arch_irn_classify(raenv->aenv, irn) == arch_irn_class_call)
+ fprintf(f, " call");
else
fprintf(f, " insn");
- fprintf(f, " %ld {\n", get_irn_node_nr(irn));
-
- /*
- * print all uses
- */
- fprintf(f, " use");
- for (i=0, max=get_irn_arity(irn); i<max; ++i) {
- ir_node *arg = get_irn_n(irn, i);
- if (arch_irn_has_reg_class(raenv->aenv, arg, -1, raenv->cls)) {
- fprintf(f, " %d", get_var_nr(arg));
- dump_constraint(raenv, irn, i);
- }
+ /* number */
+ node_nr = get_irn_node_nr(irn);
+ fprintf(f, " %ld {\n", node_nr);
+
+ pmap_insert_sth(raenv->nodes, node_nr, irn);
+
+
+ /*
+ * print all uses
+ */
+ fprintf(f, " use");
+ for (i=0, max=get_irn_arity(irn); i<max; ++i) {
+ ir_node *arg = get_irn_n(irn, i);
+ if (arch_irn_has_reg_class(raenv->aenv, arg, -1, raenv->cls)) {
+ fprintf(f, " %d", get_var_info(arg)->var_nr);
+ dump_constraint(raenv, irn, i);
}
- fprintf(f,"\n");
-
- /*
- * print all defs
- */
- fprintf(f, " def");
- /* special handling of projs */
- if (get_irn_mode(irn) == mode_T) {
- for (irn = sched_next(irn); is_Proj(irn); irn = sched_next(irn))
- if (arch_irn_has_reg_class(raenv->aenv, irn, -1, raenv->cls)) {
- fprintf(f, " %d", get_var_nr(irn));
- dump_constraint(raenv, irn, -1);
- }
- irn = sched_prev(irn); /* for outer loop */
- } else {
+ }
+ fprintf(f,"\n");
+
+ /*
+ * print all defs
+ */
+ fprintf(f, " def");
+ /* special handling of projs */
+ if (get_irn_mode(irn) == mode_T) {
+ for (irn = sched_next(irn); is_Proj(irn); irn = sched_next(irn))
if (arch_irn_has_reg_class(raenv->aenv, irn, -1, raenv->cls)) {
- fprintf(f, " %d", get_var_nr(irn));
+ fprintf(f, " %d", get_var_info(irn)->var_nr);
dump_constraint(raenv, irn, -1);
}
+ irn = sched_prev(irn); /* for outer loop */
+ } else {
+ if (arch_irn_has_reg_class(raenv->aenv, irn, -1, raenv->cls)) {
+ fprintf(f, " %d", get_var_info(irn)->var_nr);
+ dump_constraint(raenv, irn, -1);
}
- fprintf(f,"\n");
+ }
+ fprintf(f,"\n");
+ /* end of insn scope */
fprintf(f, " }\n");
}
*/
static void dump_to_file(be_raext_env_t *raenv, char *filename) {
FILE *f;
+ int i, reg_count;
if (!(f = fopen(filename, "wt"))) {
fprintf(stderr, "Could not open file %s for writing\n", filename);
}
raenv->f = f;
- fprintf(f, "regs %d\n", arch_register_class_n_regs(raenv->cls));
- fprintf(f, "cfg %s {\n", filename);
+ /* dump register info */
+ reg_count = arch_register_class_n_regs(raenv->cls);
+ fprintf(f, "regs %d", reg_count);
+
+ fprintf(f, " saved-by-caller");
+ for (i=0; i<reg_count; ++i)
+ if (arch_register_type_is(arch_register_for_index(raenv->cls, i), caller_saved))
+ fprintf(f, " %d", i);
+
+ fprintf(f, " saved-by-callee");
+ for (i=0; i<reg_count; ++i)
+ if (arch_register_type_is(arch_register_for_index(raenv->cls, i), callee_saved))
+ fprintf(f, " %d", i);
+
+ fprintf(f, "\n");
+
+ /* dump the cfg */
+ fprintf(f, "cfg %s {\n", filename);
irg_block_walk_graph(raenv->irg, NULL, dump_blocks, raenv);
irg_block_walk_graph(raenv->irg, NULL, dump_edges, raenv);
-
fprintf(f, "}\n");
fclose(f);
* Execute the external register allocator specified in the
* firm-option firm.be.ra.ext.callee
*/
-static void execute(char *out_file, char *result_file) {
+static void execute(char *prog_to_call, char *out_file, char *result_file) {
char cmd_line[1024];
int ret_status;
- snprintf(cmd_line, sizeof(cmd_line), "%s %s %s", callee, out_file, result_file);
+ snprintf(cmd_line, sizeof(cmd_line), "%s %s %s", prog_to_call, out_file, result_file);
ret_status = system(cmd_line);
assert(ret_status != -1 && "Invokation of external register allocator failed");
}
-/******************************************************************************
- _ _____ _ _
- /\ | | | __ \ | | |
- / \ _ __ _ __ | |_ _ | |__) |___ ___ _ _| | |_
- / /\ \ | '_ \| '_ \| | | | | | _ // _ \/ __| | | | | __|
- / ____ \| |_) | |_) | | |_| | | | \ \ __/\__ \ |_| | | |_
- /_/ \_\ .__/| .__/|_|\__, | |_| \_\___||___/\__,_|_|\__|
- | | | | __/ |
- |_| |_| |___/
- *****************************************************************************/
-
-#define pset_foreach(pset, irn) for(irn=pset_first(pset); irn; irn=pset_next(pset))
-
-#define INVALID_FILE_FORMAT assert(0 && "Invalid file format.")
-
-static INLINE int get_location(const char *s, size_t len) {
- if (!strncmp(s, "before", len))
- return 1;
- if (!strncmp(s, "after", len))
- return 0;
- INVALID_FILE_FORMAT;
- return -1;
-}
-
-/**
- * Read in the actions performed by the external allocator.
- * Apply these transformations to the irg.
- */
-static void read_and_apply_results(be_raext_env_t *raenv, char *filename) {
- FILE *f;
- pmap_entry *pme;
-
- if (!(f = fopen(filename, "rt"))) {
- fprintf(stderr, "Could not open file %s for reading\n", filename);
- exit(0xdeadbeef);
- }
- raenv->f = f;
-
- /* parse the file */
- while (!feof(f)) {
- int loc, var_use, var_def, reg_nr;
- char where[16];
-
- /* assign register */
- if (fscanf(f, " assign %d %d ", &var_use, ®_nr) == 2) {
- pset *vals = pmap_get_sth(raenv->vars, var_use);
- ir_node *irn;
-
- assert(vals && "Variable does not (yet?) exist!");
- pset_foreach(vals, irn)
- arch_set_irn_register(raenv->aenv, irn, arch_register_for_index(raenv->cls, var_use));
- }
-
- /* handle a reload */
- else if (fscanf(f, " reload %s %d %d %d ", &where, &loc, &var_def, &var_use) == 4) {
- int before = get_location(where, sizeof(where));
- /* TODO */
- }
-
- /* handle a spill */
- else if (fscanf(f, " spill %6s %d %d ", &where, &loc, &var_use) == 3) {
- int before = get_location(where, sizeof(where));
- /* TODO */
- }
-
- else
- INVALID_FILE_FORMAT;
- }
-
- fclose(f);
-
- /* Free the psets holding the variable-equivalence classes */
- pmap_foreach(raenv->vars, pme)
- del_pset(pme->value);
-}
-
/******************************************************************************
__ __ _
| \/ | (_)
|_| |_|\__,_|_|_| |_|
*****************************************************************************/
+/**
+ * Default values for options
+ */
+static void (*ssa_destr)(be_raext_env_t*) = ssa_destr_simple;
+static char callee[128] = "echo";
+
+
/**
* Allocate registers with an external program using a text-file interface.
*
be_raext_env_t raenv;
int clsnr, clss;
- raenv.irg = irg;
- raenv.aenv = env->arch_env;
- raenv.vars = pmap_create();
- raenv.blocks = pmap_create();
+ compute_doms(irg);
+ raenv.irg = irg;
+ raenv.aenv = env->arch_env;
+ raenv.dom_info = be_compute_dominance_frontiers(irg);
+ raenv.vars = new_set(compare_var_infos, 64);
+ raenv.nodes = pmap_create();
/* SSA destruction */
ssa_destr(&raenv);
dump_to_file(&raenv, out);
- execute(out, in);
+ execute(callee, out, in);
read_and_apply_results(&raenv, in);
}
/* Clean up */
- pmap_destroy(raenv.blocks);
- pmap_destroy(raenv.vars);
+ pmap_destroy(raenv.nodes);
+ del_set(raenv.vars);
+ be_free_dominance_frontiers(raenv.dom_info);
+
}
+
+/******************************************************************************
+ ____ _ _
+ / __ \ | | (_)
+ | | | |_ __ | |_ _ ___ _ __ ___
+ | | | | '_ \| __| |/ _ \| '_ \/ __|
+ | |__| | |_) | |_| | (_) | | | \__ \
+ \____/| .__/ \__|_|\___/|_| |_|___/
+ | |
+ |_|
+ *****************************************************************************/
+
+#ifdef WITH_LIBCORE
+
+static const lc_opt_enum_const_ptr_items_t ssa_destr_items[] = {
+ { "simple", ssa_destr_simple },
+ { "rastello", ssa_destr_rastello },
+ { NULL, NULL }
+};
+
+static lc_opt_enum_const_ptr_var_t ssa_destr_var = {
+ (const void **) &ssa_destr, ssa_destr_items
+};
+
+static const lc_opt_table_entry_t be_ra_extern_options[] = {
+ LC_OPT_ENT_ENUM_FUNC_PTR("ssa_destr", "SSA destruction flavor", &ssa_destr_var),
+ LC_OPT_ENT_STR("callee", "The external program to call", callee, sizeof(callee)),
+ { NULL }
+};
+
+static void be_ra_extern_register_options(lc_opt_entry_t *root) {
+ lc_opt_entry_t *grp = lc_opt_get_grp(root, "ext");
+
+ lc_opt_add_table(grp, be_ra_extern_options);
+}
+
+#endif /* WITH_LIBCORE */
+
+const be_ra_t be_ra_external_allocator = {
+#ifdef WITH_LIBCORE
+ be_ra_extern_register_options,
+#endif
+ be_ra_extern_main
+};