Commit 34042b23 authored by Michael Beck's avatar Michael Beck
Browse files

- removed old and unused dump_irn

- add some doxygen comments
- add the hash irop operation

[r20624]
parent 24749bf9
......@@ -1503,16 +1503,12 @@ void set_irn_dbg_info(ir_node *n, dbg_info *db);
*/
dbg_info *get_irn_dbg_info(const ir_node *n);
/*-----------------------------------------------------------------*/
/** Debug aides **/
/*-----------------------------------------------------------------*/
/** Debug print the node.
/**
* Calculate a hash value of a node. Only inputs, mode and opcode are used.
*
* Writes the node, all its attributes and the predecessors to stdout if DEBUG_libfirm
* is set. Else does nothing. */
void dump_irn(const ir_node *n);
* @param node the node to hash
*/
unsigned firm_default_hash(const ir_node *node);
/*@}*/ /* end of ir_node group definition */
......
......@@ -252,8 +252,17 @@ op_func get_generic_function_ptr(const ir_op *op);
*/
void set_generic_function_ptr(ir_op *op, op_func func);
/**
* Return the irop flags of an IR opcode.
*/
irop_flags get_op_flags(const ir_op *op);
/**
* The hash operation.
* This operation calculates a hash value for a given IR node.
*/
typedef unsigned (*hash_func)(const ir_node *self);
/**
* The compute value operation.
* This operation evaluates an IR node into a tarval if possible,
......@@ -362,6 +371,7 @@ typedef int (*dump_node_func)(ir_node *self, FILE *F, dump_reason_t reason);
* io_op Operations.
*/
typedef struct {
hash_func hash; /**< Calculate a hash value for an IR node. */
computed_value_func computed_value; /**< Evaluates a node into a tarval if possible. */
equivalent_node_func equivalent_node; /**< Optimizes the node by returning an equivalent one. */
transform_node_func transform_node; /**< Optimizes the node by transforming it. */
......
......@@ -1678,6 +1678,7 @@ static void copy_attr(const ir_node *old_node, ir_node *new_node)
}
static const ir_op_ops be_node_op_ops = {
firm_default_hash,
NULL,
NULL,
NULL,
......
......@@ -3209,23 +3209,25 @@ ir_entity *get_Global_entity(const ir_node *node) {
}
#endif
#ifdef DEBUG_libfirm
void dump_irn(const ir_node *n) {
int i, arity = get_irn_arity(n);
printf("%s%s: %ld (%p)\n", get_irn_opname(n), get_mode_name(get_irn_mode(n)), get_irn_node_nr(n), (void *)n);
if (!is_Block(n)) {
ir_node *pred = get_irn_n(n, -1);
printf(" block: %s%s: %ld (%p)\n", get_irn_opname(pred), get_mode_name(get_irn_mode(pred)),
get_irn_node_nr(pred), (void *)pred);
}
printf(" preds: \n");
for (i = 0; i < arity; ++i) {
ir_node *pred = get_irn_n(n, i);
printf(" %d: %s%s: %ld (%p)\n", i, get_irn_opname(pred), get_mode_name(get_irn_mode(pred)),
get_irn_node_nr(pred), (void *)pred);
/*
* Calculate a hash value of a node.
*/
unsigned firm_default_hash(const ir_node *node) {
unsigned h;
int i, irn_arity;
/* hash table value = 9*(9*(9*(9*(9*arity+in[0])+in[1])+ ...)+mode)+code */
h = irn_arity = get_irn_intra_arity(node);
/* consider all in nodes... except the block if not a control flow. */
for (i = is_cfop(node) ? -1 : 0; i < irn_arity; ++i) {
h = 9*h + HASH_PTR(get_irn_intra_n(node, i));
}
}
#else /* DEBUG_libfirm */
void dump_irn(const ir_node *n) { (void) n; }
#endif /* DEBUG_libfirm */
/* ...mode,... */
h = 9*h + HASH_PTR(get_irn_mode(node));
/* ...and code */
h = 9*h + HASH_PTR(get_irn_op(node));
return h;
} /* firm_default_hash */
......@@ -5708,38 +5708,14 @@ int identities_cmp(const void *elt, const void *key) {
/*
* Calculate a hash value of a node.
*
* @param node The IR-node
*/
unsigned ir_node_hash(const ir_node *node) {
unsigned h;
int i, irn_arity;
if (node->op == op_Const) {
/* special value for const, as they only differ in their tarval. */
h = HASH_PTR(node->attr.con.tv);
h = 9*h + HASH_PTR(get_irn_mode(node));
} else if (node->op == op_SymConst) {
/* special value for const, as they only differ in their symbol. */
h = HASH_PTR(node->attr.symc.sym.type_p);
h = 9*h + HASH_PTR(get_irn_mode(node));
} else {
/* hash table value = 9*(9*(9*(9*(9*arity+in[0])+in[1])+ ...)+mode)+code */
h = irn_arity = get_irn_intra_arity(node);
/* consider all in nodes... except the block if not a control flow. */
for (i = is_cfop(node) ? -1 : 0; i < irn_arity; i++) {
h = 9*h + HASH_PTR(get_irn_intra_n(node, i));
}
/* ...mode,... */
h = 9*h + HASH_PTR(get_irn_mode(node));
/* ...and code */
h = 9*h + HASH_PTR(get_irn_op(node));
}
return h;
return node->op->ops.hash(node);
} /* ir_node_hash */
pset *new_identities(void) {
return new_pset(identities_cmp, N_IR_NODES);
} /* new_identities */
......@@ -6187,10 +6163,65 @@ ir_node *optimize_in_place(ir_node *n) {
return optimize_in_place_2(n);
} /* optimize_in_place */
/**
* Calculate a hash value of a Const node.
*/
static unsigned hash_Const(const ir_node *node) {
unsigned h;
/* special value for const, as they only differ in their tarval. */
h = HASH_PTR(node->attr.con.tv);
h = 9*h + HASH_PTR(get_irn_mode(node));
return h;
} /* hash_Const */
/**
* Calculate a hash value of a SymConst node.
*/
static unsigned hash_SymConst(const ir_node *node) {
unsigned h;
/* special value for const, as they only differ in their symbol. */
h = HASH_PTR(node->attr.symc.sym.type_p);
h = 9*h + HASH_PTR(get_irn_mode(node));
return h;
} /* hash_SymConst */
/**
* Set the default hash operation in an ir_op_ops.
*
* @param code the opcode for the default operation
* @param ops the operations initialized
*
* @return
* The operations.
*/
static ir_op_ops *firm_set_default_hash(ir_opcode code, ir_op_ops *ops)
{
#define CASE(a) \
case iro_##a: \
ops->hash = hash_##a; \
break
switch (code) {
CASE(Const);
CASE(SymConst);
default:
/* use input/mode default hash */
ops->hash = firm_default_hash;
}
return ops;
#undef CASE
}
/*
* Sets the default operation for an ir_ops.
*/
ir_op_ops *firm_set_default_operations(ir_opcode code, ir_op_ops *ops) {
ops = firm_set_default_hash(code, ops);
ops = firm_set_default_computed_value(code, ops);
ops = firm_set_default_equivalent_node(code, ops);
ops = firm_set_default_transform_node(code, ops);
......
......@@ -26,22 +26,28 @@
#ifndef FIRM_IR_IROPT_T_H
#define FIRM_IR_IROPT_T_H
#include "irop_t.h"
#include "iropt.h"
#include "irnode_t.h"
#include "pset.h"
#include "tv.h"
ir_node *equivalent_node(ir_node *n);
/**
* Calculate a hash value of a node.
* The hash value is calculated from the nodes predecessors.
* Special handling for Const and SymConst nodes (these don't have predecessors).
*
* @param node The IR-node
*/
unsigned ir_node_hash(const ir_node *node);
/**
* equivalent_node() returns a node equivalent to input n. It skips all nodes that
* perform no actual computation, as, e.g., the Id nodes. It does not create
* new nodes. It is therefore safe to free n if the node returned is not n.
* If a node returns a Tuple we can not just skip it. If the size of the
* in array fits, we transform n into a tuple (e.g., Div).
*/
ir_node *equivalent_node(ir_node *n);
/**
* Creates a new value table used for storing CSE identities.
* The value table is used to identify common expressions.
......
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