Commit 38df4fef authored by Matthias Braun's avatar Matthias Braun
Browse files

change betranshelp semantic to panic instead of duplicating node in case of...

change betranshelp semantic to panic instead of duplicating node in case of missing transformer. Add generic API for setting transformers

[r27712]
parent 43eec2cc
......@@ -248,61 +248,26 @@ static ir_node *gen_Phi(ir_node *node)
return phi;
}
static ir_node *bad_transform(ir_node *node)
{
panic("TEMPLATE backend: unexpected node %+F", node);
}
static void set_transformer(ir_op *op, be_transform_func transform_func)
{
op->ops.generic = (op_func)transform_func;
}
static void TEMPLATE_register_transformers(void)
{
/* first clear the generic function pointer for all ops */
clear_irp_opcodes_generic_func();
set_transformer(op_Add, gen_Add);
set_transformer(op_And, gen_And);
set_transformer(op_Const, gen_Const);
set_transformer(op_Eor, gen_Eor);
set_transformer(op_Jmp, gen_Jmp);
set_transformer(op_Load, gen_Load);
set_transformer(op_Minus, gen_Minus);
set_transformer(op_Mul, gen_Mul);
set_transformer(op_Not, gen_Not);
set_transformer(op_Or, gen_Or);
set_transformer(op_Phi, gen_Phi);
set_transformer(op_Quot, gen_Quot);
set_transformer(op_Shl, gen_Shl);
set_transformer(op_Shr, gen_Shr);
set_transformer(op_Store, gen_Store);
set_transformer(op_Sub, gen_Sub);
/* TODO: implement missing nodes */
/* you should not see the following nodes */
set_transformer(op_ASM, bad_transform);
set_transformer(op_Builtin, bad_transform);
set_transformer(op_CallBegin, bad_transform);
set_transformer(op_Cast, bad_transform);
set_transformer(op_Confirm, bad_transform);
set_transformer(op_DivMod, bad_transform);
set_transformer(op_EndExcept, bad_transform);
set_transformer(op_EndReg, bad_transform);
set_transformer(op_Filter, bad_transform);
set_transformer(op_Free, bad_transform);
set_transformer(op_Id, bad_transform);
set_transformer(op_InstOf, bad_transform);
set_transformer(op_Mulh, bad_transform);
set_transformer(op_Mux, bad_transform);
set_transformer(op_Raise, bad_transform);
set_transformer(op_Sel, bad_transform);
set_transformer(op_Tuple, bad_transform);
be_start_transform_setup();
be_set_transform_function(op_Add, gen_Add);
be_set_transform_function(op_And, gen_And);
be_set_transform_function(op_Const, gen_Const);
be_set_transform_function(op_Eor, gen_Eor);
be_set_transform_function(op_Jmp, gen_Jmp);
be_set_transform_function(op_Load, gen_Load);
be_set_transform_function(op_Minus, gen_Minus);
be_set_transform_function(op_Mul, gen_Mul);
be_set_transform_function(op_Not, gen_Not);
be_set_transform_function(op_Or, gen_Or);
be_set_transform_function(op_Phi, gen_Phi);
be_set_transform_function(op_Quot, gen_Quot);
be_set_transform_function(op_Shl, gen_Shl);
be_set_transform_function(op_Shr, gen_Shr);
be_set_transform_function(op_Store, gen_Store);
be_set_transform_function(op_Sub, gen_Sub);
}
/**
......
......@@ -583,31 +583,26 @@ static void amd64_pretransform_node(void)
// nomem = get_irg_no_mem(current_ir_graph);
}
static void set_transformer(ir_op *op, be_transform_func amd64_transform_func)
{
op->ops.generic = (op_func)amd64_transform_func;
}
static void amd64_register_transformers(void)
{
clear_irp_opcodes_generic_func();
set_transformer(op_Const, gen_Const);
set_transformer(op_SymConst, gen_SymConst);
set_transformer(op_Add, gen_Add);
set_transformer(op_Sub, gen_Sub);
set_transformer(op_Mul, gen_Mul);
set_transformer(op_be_Call, gen_be_Call);
set_transformer(op_be_FrameAddr, gen_be_FrameAddr);
set_transformer(op_Conv, gen_Conv);
set_transformer(op_Jmp, gen_Jmp);
set_transformer(op_Cmp, gen_Cmp);
set_transformer(op_Cond, gen_Cond);
set_transformer(op_Phi, gen_Phi);
set_transformer(op_Load, gen_Load);
set_transformer(op_Store, gen_Store);
set_transformer(op_Proj, gen_Proj);
set_transformer(op_Minus, gen_Minus);
be_start_transform_setup();
be_set_transform_function(op_Const, gen_Const);
be_set_transform_function(op_SymConst, gen_SymConst);
be_set_transform_function(op_Add, gen_Add);
be_set_transform_function(op_Sub, gen_Sub);
be_set_transform_function(op_Mul, gen_Mul);
be_set_transform_function(op_be_Call, gen_be_Call);
be_set_transform_function(op_be_FrameAddr, gen_be_FrameAddr);
be_set_transform_function(op_Conv, gen_Conv);
be_set_transform_function(op_Jmp, gen_Jmp);
be_set_transform_function(op_Cmp, gen_Cmp);
be_set_transform_function(op_Cond, gen_Cond);
be_set_transform_function(op_Phi, gen_Phi);
be_set_transform_function(op_Load, gen_Load);
be_set_transform_function(op_Store, gen_Store);
be_set_transform_function(op_Proj, gen_Proj);
be_set_transform_function(op_Minus, gen_Minus);
}
......
......@@ -1501,79 +1501,44 @@ static ir_node *gen_Phi(ir_node *node)
return phi;
}
/**
* the BAD transformer.
*/
static ir_node *bad_transform(ir_node *irn)
{
panic("ARM backend: unexpected node %+F", irn);
}
/**
* Set a node emitter. Make it a bit more type safe.
*/
static void set_transformer(ir_op *op, be_transform_func arm_transform_func)
{
op->ops.generic = (op_func)arm_transform_func;
}
/**
* Enters all transform functions into the generic pointer
*/
static void arm_register_transformers(void)
{
/* first clear the generic function pointer for all ops */
clear_irp_opcodes_generic_func();
set_transformer(op_Abs, gen_Abs);
set_transformer(op_Add, gen_Add);
set_transformer(op_And, gen_And);
set_transformer(op_be_AddSP, gen_be_AddSP);
set_transformer(op_be_Call, gen_be_Call);
set_transformer(op_be_Copy, gen_be_Copy);
set_transformer(op_be_FrameAddr, gen_be_FrameAddr);
set_transformer(op_be_SubSP, gen_be_SubSP);
set_transformer(op_Cmp, gen_Cmp);
set_transformer(op_Cond, gen_Cond);
set_transformer(op_Const, gen_Const);
set_transformer(op_Conv, gen_Conv);
set_transformer(op_CopyB, gen_CopyB);
set_transformer(op_Eor, gen_Eor);
set_transformer(op_Jmp, gen_Jmp);
set_transformer(op_Load, gen_Load);
set_transformer(op_Minus, gen_Minus);
set_transformer(op_Mul, gen_Mul);
set_transformer(op_Not, gen_Not);
set_transformer(op_Or, gen_Or);
set_transformer(op_Phi, gen_Phi);
set_transformer(op_Proj, gen_Proj);
set_transformer(op_Quot, gen_Quot);
set_transformer(op_Rotl, gen_Rotl);
set_transformer(op_Shl, gen_Shl);
set_transformer(op_Shr, gen_Shr);
set_transformer(op_Shrs, gen_Shrs);
set_transformer(op_Store, gen_Store);
set_transformer(op_Sub, gen_Sub);
set_transformer(op_SymConst, gen_SymConst);
set_transformer(op_Unknown, gen_Unknown);
set_transformer(op_ASM, bad_transform);
set_transformer(op_Builtin, bad_transform);
set_transformer(op_CallBegin, bad_transform);
set_transformer(op_Cast, bad_transform);
set_transformer(op_Confirm, bad_transform);
set_transformer(op_DivMod, bad_transform);
set_transformer(op_EndExcept, bad_transform);
set_transformer(op_EndReg, bad_transform);
set_transformer(op_Filter, bad_transform);
set_transformer(op_Free, bad_transform);
set_transformer(op_Id, bad_transform);
set_transformer(op_InstOf, bad_transform);
set_transformer(op_Mulh, bad_transform);
set_transformer(op_Mux, bad_transform);
set_transformer(op_Raise, bad_transform);
set_transformer(op_Sel, bad_transform);
set_transformer(op_Tuple, bad_transform);
be_start_transform_setup();
be_set_transform_function(op_Abs, gen_Abs);
be_set_transform_function(op_Add, gen_Add);
be_set_transform_function(op_And, gen_And);
be_set_transform_function(op_be_AddSP, gen_be_AddSP);
be_set_transform_function(op_be_Call, gen_be_Call);
be_set_transform_function(op_be_Copy, gen_be_Copy);
be_set_transform_function(op_be_FrameAddr, gen_be_FrameAddr);
be_set_transform_function(op_be_SubSP, gen_be_SubSP);
be_set_transform_function(op_Cmp, gen_Cmp);
be_set_transform_function(op_Cond, gen_Cond);
be_set_transform_function(op_Const, gen_Const);
be_set_transform_function(op_Conv, gen_Conv);
be_set_transform_function(op_CopyB, gen_CopyB);
be_set_transform_function(op_Eor, gen_Eor);
be_set_transform_function(op_Jmp, gen_Jmp);
be_set_transform_function(op_Load, gen_Load);
be_set_transform_function(op_Minus, gen_Minus);
be_set_transform_function(op_Mul, gen_Mul);
be_set_transform_function(op_Not, gen_Not);
be_set_transform_function(op_Or, gen_Or);
be_set_transform_function(op_Phi, gen_Phi);
be_set_transform_function(op_Proj, gen_Proj);
be_set_transform_function(op_Quot, gen_Quot);
be_set_transform_function(op_Rotl, gen_Rotl);
be_set_transform_function(op_Shl, gen_Shl);
be_set_transform_function(op_Shr, gen_Shr);
be_set_transform_function(op_Shrs, gen_Shrs);
be_set_transform_function(op_Store, gen_Store);
be_set_transform_function(op_Sub, gen_Sub);
be_set_transform_function(op_SymConst, gen_SymConst);
be_set_transform_function(op_Unknown, gen_Unknown);
}
/**
......
......@@ -42,6 +42,7 @@
#include "beirg.h"
#include "betranshlp.h"
#include "belive.h"
#include "benode.h"
typedef struct be_transform_env_t {
ir_graph *irg; /**< The irg, the node should be created in */
......@@ -95,6 +96,31 @@ void be_dep_on_frame(ir_node* node)
add_irn_dep(node, get_irg_frame(irg));
}
void be_set_transform_function(ir_op *op, be_transform_func func)
{
/* shouldn't be assigned twice (except for exchanging the default
* be_duplicate_node entries) */
assert(op->ops.generic == NULL
|| op->ops.generic == (op_func) be_duplicate_node);
op->ops.generic = (op_func) func;
}
void be_start_transform_setup(void)
{
clear_irp_opcodes_generic_func();
be_set_transform_function(op_Bad, be_duplicate_node);
be_set_transform_function(op_NoMem, be_duplicate_node);
be_set_transform_function(op_Start, be_duplicate_node);
be_set_transform_function(op_be_Start, be_duplicate_node);
be_set_transform_function(op_Pin, be_duplicate_node);
be_set_transform_function(op_Sync, be_duplicate_node);
be_set_transform_function(op_be_Barrier, be_duplicate_node);
be_set_transform_function(op_be_Copy, be_duplicate_node);
be_set_transform_function(op_be_CopyKeep, be_duplicate_node);
be_set_transform_function(op_be_Keep, be_duplicate_node);
}
ir_node *be_duplicate_node(ir_node *node)
{
ir_node *block = be_transform_node(get_nodes_block(node));
......@@ -141,14 +167,13 @@ ir_node *be_transform_node(ir_node *node)
DEBUG_ONLY(be_set_transformed_node(node, NULL));
op = get_irn_op(node);
if (op->ops.generic) {
be_transform_func *transform = (be_transform_func *)op->ops.generic;
new_node = transform(node);
assert(new_node != NULL);
} else {
new_node = be_duplicate_node(node);
if (op->ops.generic == NULL) {
panic("No transform function registered for node %+F.", node);
}
be_transform_func *transform = (be_transform_func *)op->ops.generic;
new_node = transform(node);
assert(new_node != NULL);
be_set_transformed_node(node, new_node);
hook_dead_node_elim_subst(current_ir_graph, node, new_node);
......
......@@ -64,6 +64,13 @@ void be_dep_on_frame(ir_node *node);
*/
ir_node *be_duplicate_node(ir_node *node);
/** clear transform functions and sets some virtual nodes like
* Start, Sync, Pin to the duplication transformer */
void be_start_transform_setup(void);
/** register a transform function for a specific node type */
void be_set_transform_function(ir_op *op, be_transform_func func);
/**
* Associate an old node with a transformed node. Uses link field.
*/
......
......@@ -4415,14 +4415,6 @@ static ir_node *gen_ia32_l_FloattoLL(ir_node *node)
return mem;
}
/**
* the BAD transformer.
*/
static ir_node *bad_transform(ir_node *node)
{
panic("No transform function for %+F available.", node);
}
static ir_node *gen_Proj_l_FloattoLL(ir_node *node)
{
ir_node *block = be_transform_node(get_nodes_block(node));
......@@ -5704,10 +5696,10 @@ static ir_node *gen_Proj(ir_node *node)
static void register_transformers(void)
{
/* first clear the generic function pointer for all ops */
clear_irp_opcodes_generic_func();
be_start_transform_setup();
#define GEN(a) { be_transform_func *func = gen_##a; op_##a->ops.generic = (op_func) func; }
#define BAD(a) { op_##a->ops.generic = (op_func)bad_transform; }
#define GEN(a) { be_set_transform_function(op_##a, gen_##a); }
#define DUP(a) { be_set_transform_function(op_##a, be_duplicate_node); }
GEN(Add)
GEN(Sub)
......@@ -5766,21 +5758,6 @@ static void register_transformers(void)
GEN(SymConst)
GEN(Unknown)
/* we should never see these nodes */
BAD(Raise)
BAD(Sel)
BAD(InstOf)
BAD(Cast)
BAD(Free)
BAD(Tuple)
BAD(Id)
//BAD(Bad)
BAD(Confirm)
BAD(Filter)
BAD(CallBegin)
BAD(EndReg)
BAD(EndExcept)
/* handle builtins */
GEN(Builtin)
......@@ -5793,8 +5770,16 @@ static void register_transformers(void)
GEN(be_SubSP)
GEN(be_Copy)
DUP(ia32_Minus64Bit)
DUP(ia32_Push)
DUP(ia32_PopEbp)
DUP(ia32_Leave)
DUP(ia32_NoReg_GP)
DUP(ia32_NoReg_VFP)
DUP(ia32_NoReg_XMM)
#undef GEN
#undef BAD
#undef DUP
}
/**
......
......@@ -1043,104 +1043,59 @@ static ir_node *gen_Jmp(ir_node *node)
return new_bd_sparc_Jmp(dbgi, new_block);
}
/**
* the BAD transformer.
*/
static ir_node *bad_transform(ir_node *irn)
{
panic("SPARC backend: Not implemented: %+F", irn);
}
/**
* Set a node emitter. Make it a bit more type safe.
*/
static void set_transformer(ir_op *op, be_transform_func sparc_transform_func)
{
op->ops.generic = (op_func)sparc_transform_func;
}
/**
* configure transformation callbacks
*/
void sparc_register_transformers(void)
{
clear_irp_opcodes_generic_func();
set_transformer(op_Add, gen_Add);
set_transformer(op_Store, gen_Store);
set_transformer(op_Const, gen_Const);
set_transformer(op_Load, gen_Load);
set_transformer(op_Sub, gen_Sub);
be_start_transform_setup();
be_set_transform_function(op_Add, gen_Add);
be_set_transform_function(op_Store, gen_Store);
be_set_transform_function(op_Const, gen_Const);
be_set_transform_function(op_Load, gen_Load);
be_set_transform_function(op_Sub, gen_Sub);
set_transformer(op_be_AddSP, gen_be_AddSP);
set_transformer(op_be_SubSP, gen_be_SubSP);
set_transformer(op_be_Copy, gen_be_Copy);
set_transformer(op_be_Call, gen_be_Call);
set_transformer(op_be_FrameAddr, gen_be_FrameAddr);
be_set_transform_function(op_be_AddSP, gen_be_AddSP);
be_set_transform_function(op_be_SubSP, gen_be_SubSP);
be_set_transform_function(op_be_Copy, gen_be_Copy);
be_set_transform_function(op_be_Call, gen_be_Call);
be_set_transform_function(op_be_FrameAddr, gen_be_FrameAddr);
set_transformer(op_Cond, gen_Cond);
set_transformer(op_Cmp, gen_Cmp);
be_set_transform_function(op_Cond, gen_Cond);
be_set_transform_function(op_Cmp, gen_Cmp);
set_transformer(op_SymConst, gen_SymConst);
be_set_transform_function(op_SymConst, gen_SymConst);
set_transformer(op_Phi, gen_Phi);
set_transformer(op_Proj, gen_Proj);
be_set_transform_function(op_Phi, gen_Phi);
be_set_transform_function(op_Proj, gen_Proj);
set_transformer(op_Conv, gen_Conv);
set_transformer(op_Jmp, gen_Jmp);
be_set_transform_function(op_Conv, gen_Conv);
be_set_transform_function(op_Jmp, gen_Jmp);
set_transformer(op_Mul, gen_Mul);
set_transformer(op_Mulh, gen_Mulh);
set_transformer(op_Div, gen_Div);
set_transformer(op_Abs, gen_Abs);
set_transformer(op_Shl, gen_Shl);
set_transformer(op_Shr, gen_Shr);
set_transformer(op_Shrs, gen_Shra);
be_set_transform_function(op_Mul, gen_Mul);
be_set_transform_function(op_Mulh, gen_Mulh);
be_set_transform_function(op_Div, gen_Div);
be_set_transform_function(op_Abs, gen_Abs);
be_set_transform_function(op_Shl, gen_Shl);
be_set_transform_function(op_Shr, gen_Shr);
be_set_transform_function(op_Shrs, gen_Shra);
set_transformer(op_Minus, gen_Minus);
set_transformer(op_Not, gen_Not);
set_transformer(op_And, gen_And);
set_transformer(op_Or, gen_Or);
be_set_transform_function(op_Minus, gen_Minus);
be_set_transform_function(op_Not, gen_Not);
be_set_transform_function(op_And, gen_And);
be_set_transform_function(op_Or, gen_Or);
set_transformer(op_Unknown, gen_Unknown);
be_set_transform_function(op_Unknown, gen_Unknown);
/* node list */
/*
set_transformer(op_CopyB, gen_CopyB);
set_transformer(op_Eor, gen_Eor);
set_transformer(op_Quot, gen_Quot);
set_transformer(op_Rotl, gen_Rotl);
be_set_transform_function(op_CopyB, gen_CopyB);
be_set_transform_function(op_Eor, gen_Eor);
be_set_transform_function(op_Quot, gen_Quot);
be_set_transform_function(op_Rotl, gen_Rotl);
*/
set_transformer(op_ASM, bad_transform);
set_transformer(op_Builtin, bad_transform);
set_transformer(op_CallBegin, bad_transform);
set_transformer(op_Cast, bad_transform);
set_transformer(op_Confirm, bad_transform);
set_transformer(op_DivMod, bad_transform);
set_transformer(op_EndExcept, bad_transform);
set_transformer(op_EndReg, bad_transform);
set_transformer(op_Filter, bad_transform);
set_transformer(op_Free, bad_transform);
set_transformer(op_Id, bad_transform);
set_transformer(op_InstOf, bad_transform);
set_transformer(op_Mux, bad_transform);
set_transformer(op_Raise, bad_transform);
set_transformer(op_Sel, bad_transform);
set_transformer(op_Tuple, bad_transform);
}
/**
* Pre-transform all unknown nodes.
*/
static void sparc_pretransform_node(void)
{
sparc_code_gen_t *cg = env_cg;
(void) cg;
//cg->unknown_gp = be_pre_transform_node(cg->unknown_gp);
//cg->unknown_fpa = be_pre_transform_node(cg->unknown_fpa);
}
/**
......@@ -1150,7 +1105,7 @@ void sparc_transform_graph(sparc_code_gen_t *cg)
{
sparc_register_transformers();
env_cg = cg;
be_transform_graph(cg->irg, sparc_pretransform_node);
be_transform_graph(cg->irg, NULL);
}
void sparc_init_transform(void)
......
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