X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fana%2Firtypeinfo.c;h=77b871e906905d5132ef58488225e04ac9c781be;hb=555593b0aebec433b871920acc2b0a869b072055;hp=1b5591f313cc142a12b62b1e17ba76880cd16aca;hpb=ce6161a7e42a48f7422b7babcc64d8ace18e2687;p=libfirm diff --git a/ir/ana/irtypeinfo.c b/ir/ana/irtypeinfo.c index 1b5591f31..77b871e90 100644 --- a/ir/ana/irtypeinfo.c +++ b/ir/ana/irtypeinfo.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * Copyright (C) 1995-2011 University of Karlsruhe. All right reserved. * * This file is part of libFirm. * @@ -22,7 +22,6 @@ * @brief Data structure to hold type information for nodes. * @author Goetz Lindenmaier * @date 28.8.2003 - * @version $Id$ * @brief * Data structure to hold type information for nodes. * @@ -46,30 +45,14 @@ #include "irnode_t.h" #include "pmap.h" -/* ------------ The map. ---------------------------------------------- */ - - static pmap *type_node_map = NULL; -/* ------------ Auxiliary type. --------------------------------------- */ - -/* This auxiliary type expresses that a field is uninitialized. The - * variable is set by init_irtypeinfo. The type is freed by - * free_irtypeinfo. - */ ir_type *initial_type = NULL; -/* ------------ Initializing this module. ----------------------------- */ - -/* Initializes the type information module. - * Generates a type "initial_type" and sets the type of all nodes to this type. - * Calling set/get_irn_type is invalid before calling init. Requires memory - * in the order of MIN(, #irnodes). - */ void init_irtypeinfo(void) { - int i; + size_t i, n; if (initial_type == NULL) initial_type = new_type_class(new_id_from_str("initial_type")); @@ -79,13 +62,13 @@ void init_irtypeinfo(void) pmap_destroy(type_node_map); type_node_map = pmap_create(); - for (i = get_irp_n_irgs() - 1; i >= 0; --i) + for (i = 0, n = get_irp_n_irgs(); i < n; ++i) set_irg_typeinfo_state(get_irp_irg(i), ir_typeinfo_none); } void free_irtypeinfo(void) { - int i; + size_t i, n; if (initial_type != NULL) { free_type(initial_type); @@ -97,13 +80,11 @@ void free_irtypeinfo(void) type_node_map = NULL; } - for (i = get_irp_n_irgs() - 1; i >= 0; --i) + for (i = 0, n = get_irp_n_irgs(); i < n; ++i) set_irg_typeinfo_state(get_irp_irg(i), ir_typeinfo_none); } -/* ------------ Irgraph state handling. ------------------------------- */ - void set_irg_typeinfo_state(ir_graph *irg, ir_typeinfo_state s) { assert(is_ir_graph(irg)); @@ -121,12 +102,6 @@ ir_typeinfo_state get_irg_typeinfo_state(const ir_graph *irg) } -/* Returns accumulated type information state information. - * - * Returns ir_typeinfo_consistent if the type information of all irgs is - * consistent. Returns ir_typeinfo_inconsistent if at least one irg has inconsistent - * or no type information. Returns ir_typeinfo_none if no irg contains type information. - */ ir_typeinfo_state get_irp_typeinfo_state(void) { return irp->typeinfo_state; @@ -135,7 +110,6 @@ void set_irp_typeinfo_state(ir_typeinfo_state s) { irp->typeinfo_state = s; } -/* If typeinfo is consistent, sets it to inconsistent. */ void set_irp_typeinfo_inconsistent(void) { if (irp->typeinfo_state == ir_typeinfo_consistent) @@ -143,29 +117,22 @@ void set_irp_typeinfo_inconsistent(void) } -/* ------------ Irnode type information. ------------------------------ */ - -/* These routines only work properly if the ir_graph is in state - * ir_typeinfo_consistent or ir_typeinfo_inconsistent. They - * assume current_ir_graph set properly. - */ ir_type *get_irn_typeinfo_type(const ir_node *n) { - ir_type *res = initial_type; - pmap_entry *entry; - + ir_type *res; assert(get_irg_typeinfo_state(get_irn_irg(n)) != ir_typeinfo_none); - entry = pmap_find(type_node_map, n); - if (entry != NULL) - res = (ir_type*) entry->value; + res = pmap_get(ir_type, type_node_map, n); + if (res == NULL) { + res = initial_type; + } return res; } void set_irn_typeinfo_type(ir_node *n, ir_type *tp) { - assert(get_irg_typeinfo_state(current_ir_graph) != ir_typeinfo_none); + assert(get_irg_typeinfo_state(get_irn_irg(n)) != ir_typeinfo_none); pmap_insert(type_node_map, (void *)n, (void *)tp); }