Commit c06a5840 authored by Michael Beck's avatar Michael Beck
Browse files

- add more pass constructors

[r26376]
parent 856c2a59
/* /*
* Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * Copyright (C) 1995-2009 University of Karlsruhe. All right reserved.
* *
* This file is part of libFirm. * This file is part of libFirm.
* *
...@@ -172,4 +172,19 @@ ir_graph_pass_t *def_graph_pass_constructor( ...@@ -172,4 +172,19 @@ ir_graph_pass_t *def_graph_pass_constructor(
ir_prog_pass_t *def_prog_pass( ir_prog_pass_t *def_prog_pass(
const char *name, void (*function)(void)); const char *name, void (*function)(void));
/**
* Creates an ir_prog pass for running void function().
* Uses the default verifier and dumper.
* The pass returns always 0.
*
* @param memory if non-NULL, an already allocated ir_prog_pass_t
* @param name the name of this pass
* @param function the function to run
*
* @return the newly created ir_graph pass
*/
ir_prog_pass_t *def_prog_pass_constructor(
ir_prog_pass_t *memory,
const char *name, void (*function)(ir_prog *irp, void *context));
#endif #endif
...@@ -159,6 +159,17 @@ void lower_CopyB(ir_graph *irg, unsigned max_size, unsigned native_mode_bytes); ...@@ -159,6 +159,17 @@ void lower_CopyB(ir_graph *irg, unsigned max_size, unsigned native_mode_bytes);
*/ */
void lower_switch(ir_graph *irg, unsigned spare_size); void lower_switch(ir_graph *irg, unsigned spare_size);
/**
* Creates an ir_graph pass for lower_switch().
*
* @param name the name of this pass or NULL
* @param spare_size Allowed spare size for table switches in machine words.
* (Default in edgfe: 128)
*
* @return the newly created ir_graph pass
*/
ir_graph_pass_t *lower_switch_pass(const char *name, unsigned spare_size);
/** /**
* A callback type for creating an intrinsic entity for a given opcode. * A callback type for creating an intrinsic entity for a given opcode.
* *
...@@ -190,9 +201,21 @@ typedef struct _lwrdw_param_t { ...@@ -190,9 +201,21 @@ typedef struct _lwrdw_param_t {
/** /**
* Lower all double word operations. * Lower all double word operations.
*
* @param param parameter for lowering
*/ */
void lower_dw_ops(const lwrdw_param_t *param); void lower_dw_ops(const lwrdw_param_t *param);
/**
* Creates an ir_prog pass for lower_dw_ops().
*
* @param name the name of this pass or NULL
* @param param parameter for lowering
*
* @return the newly created ir_prog pass
*/
ir_prog_pass_t *lower_dw_ops_pass(const char *name, const lwrdw_param_t *param);
/** /**
* Default implementation. Context is unused. * Default implementation. Context is unused.
*/ */
...@@ -231,7 +254,7 @@ ir_graph_pass_t *lower_highlevel_graph_pass(const char *name, int lower_bitfield ...@@ -231,7 +254,7 @@ ir_graph_pass_t *lower_highlevel_graph_pass(const char *name, int lower_bitfield
* Handle bit fields by added And/Or calculations. * Handle bit fields by added And/Or calculations.
* Lowers all graphs. * Lowers all graphs.
* *
* @Note: There is NO lowering ob objects oriented types. This is highly compiler * @Note: There is NO lowering of objects oriented types. This is highly compiler
* and ABI specific and should be placed directly in the compiler. * and ABI specific and should be placed directly in the compiler.
*/ */
void lower_highlevel(int lower_bitfields); void lower_highlevel(int lower_bitfields);
...@@ -246,7 +269,7 @@ void lower_const_code(void); ...@@ -246,7 +269,7 @@ void lower_const_code(void);
* *
* @param name the name of this pass or NULL * @param name the name of this pass or NULL
* *
* @return the newly created ir_graph pass * @return the newly created ir_prog pass
*/ */
ir_prog_pass_t *lower_const_code_pass(const char *name); ir_prog_pass_t *lower_const_code_pass(const char *name);
...@@ -271,6 +294,17 @@ typedef struct lower_mode_b_config_t { ...@@ -271,6 +294,17 @@ typedef struct lower_mode_b_config_t {
*/ */
void ir_lower_mode_b(ir_graph *irg, const lower_mode_b_config_t *config); void ir_lower_mode_b(ir_graph *irg, const lower_mode_b_config_t *config);
/**
* Creates an ir_graph pass for ir_lower_mode_b().
*
* @param name the name of this pass or NULL
* @param config configuration for mode_b lowerer
*
* @return the newly created ir_graph pass
*/
ir_graph_pass_t *ir_lower_mode_b_pass(
const char *name, const lower_mode_b_config_t *config);
/** /**
* An intrinsic mapper function. * An intrinsic mapper function.
* *
......
...@@ -433,3 +433,22 @@ ir_prog_pass_t *def_prog_pass( ...@@ -433,3 +433,22 @@ ir_prog_pass_t *def_prog_pass(
return pass; return pass;
} /* def_prog_pass */ } /* def_prog_pass */
/* Creates an ir_prog pass for running void function(void). */
ir_prog_pass_t *def_prog_pass_constructor(
ir_prog_pass_t *pass,
const char *name,
void (*function)(ir_prog *irp, void *context))
{
if (pass == NULL)
pass = XMALLOCZ(ir_prog_pass_t);
pass->kind = k_ir_prog_pass;
pass->run_on_irprog = function;
pass->context = pass;
pass->name = name;
INIT_LIST_HEAD(&pass->list);
return pass;
} /* def_prog_pass_constructor */
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "pdeq.h" #include "pdeq.h"
#include "irdump.h" #include "irdump.h"
#include "array_t.h" #include "array_t.h"
#include "irpass_t.h"
/** A map from mode to a primitive type. */ /** A map from mode to a primitive type. */
static pmap *prim_types; static pmap *prim_types;
...@@ -2685,6 +2686,30 @@ void lower_dw_ops(const lwrdw_param_t *param) ...@@ -2685,6 +2686,30 @@ void lower_dw_ops(const lwrdw_param_t *param)
current_ir_graph = rem; current_ir_graph = rem;
} /* lower_dw_ops */ } /* lower_dw_ops */
struct pass_t {
ir_prog_pass_t pass;
const lwrdw_param_t *param;
};
/**
* Creates a wrapper around lower_dw_ops().
*/
static int pass_wrapper(ir_prog *irp, void *context) {
struct pass_t *pass = context;
(void)irp;
lower_dw_ops(pass->param);
return 0;
} /* pass_wrapper */
ir_prog_pass_t *lower_dw_ops_pass(const char *name, const lwrdw_param_t *param) {
struct pass_t *pass = XMALLOCZ(struct pass_t);
pass->param = param;
return def_prog_pass_constructor(
&pass->pass, name ? name : "lower_dw", pass_wrapper);
} /* lower_dw_ops_pass */
/* Default implementation. */ /* Default implementation. */
ir_entity *def_create_intrinsic_fkt(ir_type *method, const ir_op *op, ir_entity *def_create_intrinsic_fkt(ir_type *method, const ir_op *op,
const ir_mode *imode, const ir_mode *omode, const ir_mode *imode, const ir_mode *omode,
......
...@@ -193,19 +193,12 @@ ir_prog_pass_t *lower_intrinsics_pass( ...@@ -193,19 +193,12 @@ ir_prog_pass_t *lower_intrinsics_pass(
{ {
struct pass_t *pass = xmalloc(sizeof(*pass) + (length-1) * sizeof(pass->list[0])); struct pass_t *pass = xmalloc(sizeof(*pass) + (length-1) * sizeof(pass->list[0]));
memset(&pass->pass, 0, sizeof(pass->pass));
pass->pass.kind = k_ir_prog_pass;
pass->pass.run_on_irprog = pass_wrapper;
pass->pass.context = pass;
pass->pass.name = name ? name : "lower_intrinsics";
INIT_LIST_HEAD(&pass->pass.list);
memcpy(pass->list, list, sizeof(list[0]) * length); memcpy(pass->list, list, sizeof(list[0]) * length);
pass->length = length; pass->length = length;
pass->part_block_used = part_block_used; pass->part_block_used = part_block_used;
return &pass->pass; return def_prog_pass_constructor(
&pass->pass, name ? name : "lower_intrinsics", pass_wrapper);
} /* lower_intrinsics_pass*/ } /* lower_intrinsics_pass*/
/** /**
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "error.h" #include "error.h"
#include "lowering.h" #include "lowering.h"
#include "pdeq.h" #include "pdeq.h"
#include "irpass_t.h"
static lower_mode_b_config_t config; static lower_mode_b_config_t config;
static ir_type *lowered_type = NULL; static ir_type *lowered_type = NULL;
...@@ -417,3 +418,27 @@ void ir_lower_mode_b(ir_graph *irg, const lower_mode_b_config_t *nconfig) ...@@ -417,3 +418,27 @@ void ir_lower_mode_b(ir_graph *irg, const lower_mode_b_config_t *nconfig)
ir_free_resources(irg, IR_RESOURCE_IRN_LINK); ir_free_resources(irg, IR_RESOURCE_IRN_LINK);
} }
struct pass_t {
ir_graph_pass_t pass;
const lower_mode_b_config_t *config;
};
/**
* Wrapper to run ir_lower_mode_b() as an ir_graph pass
*/
static int pass_wrapper(ir_graph *irg, void *context) {
struct pass_t *pass = context;
ir_lower_mode_b(irg, pass->config);
return 0;
}
ir_graph_pass_t *ir_lower_mode_b_pass(
const char *name, const lower_mode_b_config_t *config) {
struct pass_t *pass = XMALLOCZ(struct pass_t);
pass->config = config;
return def_graph_pass_constructor(
&pass->pass, name ? name : "lower_mode_b", pass_wrapper);
}
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "irgwalk.h" #include "irgwalk.h"
#include "irnode_t.h" #include "irnode_t.h"
#include "irouts.h" #include "irouts.h"
#include "irpass_t.h"
#define foreach_out_irn(irn, i, outirn) for(i = get_irn_n_outs(irn) - 1;\ #define foreach_out_irn(irn, i, outirn) for(i = get_irn_n_outs(irn) - 1;\
i >= 0 && (outirn = get_irn_out(irn, i)); --i) i >= 0 && (outirn = get_irn_out(irn, i)); --i)
...@@ -279,3 +280,27 @@ void lower_switch(ir_graph *irg, unsigned spare_size) ...@@ -279,3 +280,27 @@ void lower_switch(ir_graph *irg, unsigned spare_size)
} }
current_ir_graph = rem; current_ir_graph = rem;
} }
struct pass_t {
ir_graph_pass_t pass;
unsigned spare_size;
};
/**
* Wrapper for running lower_switch() as a pass.
*/
static int pass_wrapper(ir_graph *irg, void *context) {
struct pass_t *pass = context;
lower_switch(irg, pass->spare_size);
return 0;
}
/* creates a pass for lower_switch */
ir_graph_pass_t *lower_switch_pass(const char *name, unsigned spare_size) {
struct pass_t *pass = XMALLOCZ(struct pass_t);
pass->spare_size = spare_size;
return def_graph_pass_constructor(
&pass->pass, name ? name : "lower_switch", pass_wrapper);
}
...@@ -1097,17 +1097,11 @@ ir_prog_pass_t *optimize_funccalls_pass( ...@@ -1097,17 +1097,11 @@ ir_prog_pass_t *optimize_funccalls_pass(
const char *name, const char *name,
int force_run, check_alloc_entity_func callback) int force_run, check_alloc_entity_func callback)
{ {
struct pass_t *pass = xmalloc(sizeof(*pass)); struct pass_t *pass = XMALLOCZ(struct pass_t);
pass->pass.kind = k_ir_prog_pass;
pass->pass.run_on_irprog = pass_wrapper;
pass->pass.context = pass;
pass->pass.name = name ? name : "funccalls";
INIT_LIST_HEAD(&pass->pass.list);
pass->force_run = force_run; pass->force_run = force_run;
pass->callback = callback; pass->callback = callback;
return &pass->pass; return def_prog_pass_constructor(
&pass->pass, name ? name : "funccall", pass_wrapper);
} /* optimize_funccalls_pass */ } /* optimize_funccalls_pass */
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