Commit 2a2ba142 authored by Götz Lindenmaier's avatar Götz Lindenmaier
Browse files

functionality to hash types efficiently.

[r3045]
parent 655778e8
......@@ -16,13 +16,13 @@ topdir = ../..
subdir := ir/tr
INSTALL_HEADERS = entity.h mangle.h tpop.h type.h typewalk.h type_or_entity.h \
typegmod.h trvrfy.h
typegmod.h trvrfy.h type_identify.h
SOURCES = $(INSTALL_HEADERS)
SOURCES += Makefile.in \
entity.c entity_t.h mangle.c tpop.c tpop_t.h type.c type_t.h \
typewalk.c typegmod.c trvrfy.h trvrfy.c
typewalk.c typegmod.c trvrfy.h trvrfy.c type_identify.c
include $(topdir)/MakeRules
......
......@@ -141,7 +141,7 @@ ident* get_type_ident(type *tp);
void set_type_ident(type *tp, ident* id);
const char* get_type_name(type *tp);
/** The state of a type layout. */
/** The state of the type layout. */
typedef enum {
layout_undefined, /**< The layout of this type is not defined.
Address computation to access fields is not
......
/*
* Project: libFIRM
* File name: ir/tr/type.c
* Purpose: Representation of types.
* Author: Goetz Lindenmaier
* Modified by:
* Created:
* CVS-ID: $Id$
* Copyright: (c) 2001-2003 Universität Karlsruhe
* Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
*/
/**
*
* file type.c - implementation of the datastructure to hold
* type information.
* (C) 2004 by Universitaet Karlsruhe
* Goetz Lindenmaier
*
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "type_identify.h"
# include <stdlib.h>
# include <stddef.h>
# include <string.h>
# include "type_t.h"
# include "tpop_t.h"
# include "irprog_t.h"
# include "typegmod.h"
# include "array.h"
# include "irprog.h"
# include "mangle.h"
#include "pset.h"
/* The hash set for types. */
static pset *type_table = NULL;
int compare_names (const void *tp1, const void *tp2) {
type *t1 = (type *) tp1;
type *t2 = (type *) tp2;
return (t1 != t2 &&
(t1->type_op != t2->type_op ||
t1->name != t2->name ) );
}
/* stuff for comparing two types. */
//static int compare_strict (type *tp1, type *tp2) {
static int compare_strict (const void *tp1, const void *tp2) {
type *t1 = (type *) tp1;
type *t2 = (type *) tp2;
return t1 != t2;
}
compare_types_func_tp compare_types_func = compare_strict;
/* stuff to compute a hash value for a type. */
int hash_name (type *tp) {
unsigned h = (unsigned)tp->type_op;
h = 9*h + (unsigned)tp->name;
return h;
}
hash_types_func_tp hash_types_func = hash_name;
/* The function that hashes a type. */
type *mature_type(type *tp) {
type *o;
assert(type_table);
o = pset_insert (type_table, tp, hash_types_func(tp) );
if (!o || o == tp) return tp;
exchange_types(tp, o);
return o ;
}
void init_type_identify(void) {
//type_table = new_pset ((int (const void *, const void *))compare_types_func, 8);
type_table = new_pset (compare_types_func, 8);
//type_table = new_pset (compare_names, 8);
}
/**
*
* @file type.h
*
* Project: libFIRM <br>
* File name: ir/tr/type.h <br>
* Purpose: Representation of types. <br>
* Author: Goetz Lindenmaier <br>
* Modified by: <br>
* Created: <br>
* Copyright: (c) 2001-2003 Universität Karlsruhe <br>
* Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. <br>
* CVS-ID: $Id$
*
*
*/
# ifndef _TYPE_IDENTIFY_H_
# define _TYPE_IDENTIFY_H_
#ifndef _TYPE_TYPEDEF_
#define _TYPE_TYPEDEF_
typedef struct type type;
#endif
/* ------------------------------------------------------------------------ */
/** Type for a function that compares two types.
*
* @param tp1 The first type to compare.
* @param tp2 The second type to compare.
*/
//typedef int (*compare_types_func_tp) (type *tp1, type *tp2);
typedef int (*compare_types_func_tp) (const void *tp1, const void *tp2);
/** Compares two types by their name.
*
* Compares the opcode and the name of the types. If these are
* equal returns true, else false.
*/
int compare_names (const void *tp1, const void *tp2);
/** Compares two types strict.
*
* returns true if tp1 == tp2
*/
int compare_strict (const void *tp1, const void *tp2);
/** A variable that holds a compare function for types.
*
* The compare function is used to identify equal types. The
* variable is initialized with the function compare_strict().
*
* The variable must be set before calling init_firm()! Later changes
* have no effect.
*/
extern compare_types_func_tp compare_types_func;
/* ------------------------------------------------------------------------ */
/** Type for a function that computes a hash value for a type.
*
* @param tp The type to compute a hash for.
*/
typedef int (*hash_types_func_tp)(type *tp);
/** Computes a hash value by the type name.
*
* Uses the name of the type and the type opcode to compute the hash.
*/
int hash_name (type *tp);
/** A variable that holds a hash function for a type.
*
* The hash function is used to identify equal types. The
* variable is initialized with the function hash_name().
*
* The variable must be set before calling init_firm()! Later changes
* have no effect.
*/
extern hash_types_func_tp hash_types_func;
/* ------------------------------------------------------------------------ */
/** Finalize type construction.
*
* Indicate that a type is so far completed that it can be
* distinguished from other types. Mature_type hashes the type into a
* table. It uses the function in compare_types_func to compare the
* types. If it find a type identical to tp it returns this type. In
* this case it also turns tp into the Id type. The caller should free
* tp if he knows that there are no other references to tp. The memory
* of tp is not lost, but will remain alive for an unknown time.
*
* @param tp The type to mature.
*/
type * mature_type(type *tp);
# endif /* _TYPE_IDENTIFY_H_ */
......@@ -40,7 +40,7 @@
void exchange_types(type *old_type, type *new_type);
/**
* skip id types until a useful type is reached.
* Skip id types until a useful type is reached.
*
* @param tp - A type of arbitrary kind.
*
......
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