X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fana%2Firtypeinfo.c;h=1b5591f313cc142a12b62b1e17ba76880cd16aca;hb=e98f2bd09ccc403c64e3ebe30f3b0183760bccc6;hp=e14cedb133fd002b89670166465725039166c4df;hpb=a763f0583a07c4be377c0f1b9908dc166dce835b;p=libfirm diff --git a/ir/ana/irtypeinfo.c b/ir/ana/irtypeinfo.c index e14cedb13..1b5591f31 100644 --- a/ir/ana/irtypeinfo.c +++ b/ir/ana/irtypeinfo.c @@ -1,40 +1,49 @@ -/** +/* + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. * - * @file irtypeinfo.c + * This file is part of libFirm. * - * Project: libFIRM - * File name: ir/ana/irtypeinfo.c - * Purpose: Data structure to hold type information for nodes. - * Author: Goetz Lindenmaier - * Modified by: - * Created: 28.8.2003 - * CVS-ID: $Id$ - * Copyright: (c) 2003 Universität Karlsruhe - * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. * - * Data structure to hold type information for nodes. + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. * - * This module defines a field "type" of type "type *" for each ir node. - * It defines a flag for irgraphs to mark whether the type info of the - * graph is valid. Further it defines an auxiliary type "initial_type". + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. + */ + +/** + * @file + * @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. * - * The module defines a map that contains pairs (irnode, type). If an irnode - * is not in the map it is assumed to be initialized, i.e., the initialization - * requires no compute time. As firm nodes can not be freed and reallocated - * pointers for nodes are unique (until a call of dead_node_elimination). + * This module defines a field "type" of type "type *" for each ir node. + * It defines a flag for irgraphs to mark whether the type info of the + * graph is valid. Further it defines an auxiliary type "initial_type". * + * The module defines a map that contains pairs (irnode, type). If an irnode + * is not in the map it is assumed to be initialized, i.e., the initialization + * requires no compute time. As firm nodes can not be freed and reallocated + * pointers for nodes are unique (until a call of dead_node_elimination). */ - -#ifdef HAVE_CONFIG_H #include "config.h" -#endif #include "irtypeinfo.h" #include -#include "irgraph_t.h" /* for setting the state flag. */ +#include "irgraph_t.h" #include "irprog_t.h" +#include "irnode_t.h" #include "pmap.h" /* ------------ The map. ---------------------------------------------- */ @@ -49,8 +58,7 @@ static pmap *type_node_map = NULL; * variable is set by init_irtypeinfo. The type is freed by * free_irtypeinfo. */ -type *initial_type = NULL; - +ir_type *initial_type = NULL; /* ------------ Initializing this module. ----------------------------- */ @@ -59,112 +67,105 @@ type *initial_type = NULL; * Calling set/get_irn_type is invalid before calling init. Requires memory * in the order of MIN(, #irnodes). */ -void init_irtypeinfo(void) { - int i; +void init_irtypeinfo(void) +{ + int i; - if (!initial_type) - initial_type = new_type_class(new_id_from_str("initial_type")); + if (initial_type == NULL) + initial_type = new_type_class(new_id_from_str("initial_type")); - /* We need a new, empty map. */ - if (type_node_map) pmap_destroy(type_node_map); - type_node_map = pmap_create(); + /* We need a new, empty map. */ + if (type_node_map != NULL) + pmap_destroy(type_node_map); + type_node_map = pmap_create(); - for (i = 0; i < get_irp_n_irgs(); ++i) - set_irg_typeinfo_state(get_irp_irg(i), irg_typeinfo_none); + for (i = get_irp_n_irgs() - 1; i >= 0; --i) + set_irg_typeinfo_state(get_irp_irg(i), ir_typeinfo_none); } -void free_irtypeinfo(void) { - int i; +void free_irtypeinfo(void) +{ + int i; - if (initial_type) { - free_type(initial_type); - initial_type = NULL; - } else - assert(0 && "call init_type_info before freeing"); + if (initial_type != NULL) { + free_type(initial_type); + initial_type = NULL; + } - if (type_node_map) { - pmap_destroy(type_node_map); - type_node_map = NULL; - } else - assert(0 && "call init_type_info before freeing"); + if (type_node_map != NULL) { + pmap_destroy(type_node_map); + type_node_map = NULL; + } - for (i = 0; i < get_irp_n_irgs(); ++i) - set_irg_typeinfo_state(get_irp_irg(i), irg_typeinfo_none); + for (i = get_irp_n_irgs() - 1; i >= 0; --i) + set_irg_typeinfo_state(get_irp_irg(i), ir_typeinfo_none); } /* ------------ Irgraph state handling. ------------------------------- */ -void set_irg_typeinfo_state(ir_graph *irg, irg_typeinfo_state s) { - assert(is_ir_graph(irg)); - irg->typeinfo_state = s; +void set_irg_typeinfo_state(ir_graph *irg, ir_typeinfo_state s) +{ + assert(is_ir_graph(irg)); + irg->typeinfo_state = s; + if ((irg->typeinfo_state == ir_typeinfo_consistent) && + (irp->typeinfo_state == ir_typeinfo_consistent) && + (s != ir_typeinfo_consistent) ) + irp->typeinfo_state = ir_typeinfo_inconsistent; } -irg_typeinfo_state get_irg_typeinfo_state(ir_graph *irg) { - assert(is_ir_graph(irg)); - return irg->typeinfo_state; +ir_typeinfo_state get_irg_typeinfo_state(const ir_graph *irg) +{ + assert(is_ir_graph(irg)); + return irg->typeinfo_state; } + +/* 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; +} +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) + irp->typeinfo_state = ir_typeinfo_inconsistent; +} + + /* ------------ Irnode type information. ------------------------------ */ /* These routines only work properly if the ir_graph is in state - * irg_typeinfo_consistent or irg_typeinfo_inconsistent. They + * ir_typeinfo_consistent or ir_typeinfo_inconsistent. They * assume current_ir_graph set properly. */ -type *get_irn_typeinfo_type(ir_node *n) { - type *res = initial_type; - assert(get_irg_typeinfo_state(current_ir_graph) == irg_typeinfo_consistent || - get_irg_typeinfo_state(current_ir_graph) == irg_typeinfo_inconsistent ); - - if (pmap_contains(type_node_map, (void *)n)) - res = (type *) pmap_get(type_node_map, (void *)n); +ir_type *get_irn_typeinfo_type(const ir_node *n) +{ + ir_type *res = initial_type; + pmap_entry *entry; - return res; -} + assert(get_irg_typeinfo_state(get_irn_irg(n)) != ir_typeinfo_none); -void set_irn_typeinfo_type(ir_node *n, type *tp) { - assert(get_irg_typeinfo_state(current_ir_graph) == irg_typeinfo_consistent || - get_irg_typeinfo_state(current_ir_graph) == irg_typeinfo_inconsistent ); + entry = pmap_find(type_node_map, n); + if (entry != NULL) + res = (ir_type*) entry->value; - pmap_insert(type_node_map, (void *)n, (void *)tp); + return res; } -type *get_irn_type(ir_node *n) { - type *tp = NULL; - switch(get_irn_opcode(n)) { - case iro_Const: tp = get_Const_type(n); break; - case iro_SymConst: tp = get_SymConst_value_type(n); break; - case iro_Cast: tp = get_Cast_type(n); break; - case iro_Proj: { - ir_node *pred = get_Proj_pred(n); - switch (get_irn_opcode(pred)) { - case iro_Proj: { - ir_node *pred_pred; - /* Deal with Start / Call here: we need to know the Proj Nr. */ - assert(get_irn_mode(pred) == mode_T); - pred_pred = get_Proj_pred(pred); - if (get_irn_op(pred_pred) == op_Start) { - type *mtp = get_entity_type(get_irg_entity(get_irn_irg(pred_pred))); - tp = get_method_param_type(mtp, get_Proj_proj(n)); - } else if (get_irn_op(pred_pred) == op_Call) { - type *mtp = get_Call_type(pred_pred); - tp = get_method_res_type(mtp, get_Proj_proj(n)); - } - } break; - case iro_Start: break; - case iro_Call: break; - case iro_Load: { - ir_node *a = get_Load_ptr(pred); - if (get_irn_op(a) == op_Sel) - tp = get_entity_type(get_Sel_entity(a)); - } break; - default: - break; - } - } break; /* iro_Proj */ - default: - tp = NULL; - } - - return tp; +void set_irn_typeinfo_type(ir_node *n, ir_type *tp) +{ + assert(get_irg_typeinfo_state(current_ir_graph) != ir_typeinfo_none); + + pmap_insert(type_node_map, (void *)n, (void *)tp); }