2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Data structure to hold type information for nodes.
9 * @author Goetz Lindenmaier
12 * Data structure to hold type information for nodes.
14 * This module defines a field "type" of type "type *" for each ir node.
15 * It defines a flag for irgraphs to mark whether the type info of the
16 * graph is valid. Further it defines an auxiliary type "initial_type".
18 * The module defines a map that contains pairs (irnode, type). If an irnode
19 * is not in the map it is assumed to be initialized, i.e., the initialization
20 * requires no compute time. As firm nodes can not be freed and reallocated
21 * pointers for nodes are unique (until a call of dead_node_elimination).
25 #include "irtypeinfo.h"
29 #include "irgraph_t.h"
34 static pmap *type_node_map = NULL;
37 ir_type *initial_type = NULL;
39 void init_irtypeinfo(void)
43 if (initial_type == NULL)
44 initial_type = new_type_class(new_id_from_str("initial_type"));
46 /* We need a new, empty map. */
47 if (type_node_map != NULL)
48 pmap_destroy(type_node_map);
49 type_node_map = pmap_create();
51 for (i = 0, n = get_irp_n_irgs(); i < n; ++i)
52 set_irg_typeinfo_state(get_irp_irg(i), ir_typeinfo_none);
55 void free_irtypeinfo(void)
59 if (initial_type != NULL) {
60 free_type(initial_type);
64 if (type_node_map != NULL) {
65 pmap_destroy(type_node_map);
69 for (i = 0, n = get_irp_n_irgs(); i < n; ++i)
70 set_irg_typeinfo_state(get_irp_irg(i), ir_typeinfo_none);
74 void set_irg_typeinfo_state(ir_graph *irg, ir_typeinfo_state s)
76 assert(is_ir_graph(irg));
77 irg->typeinfo_state = s;
78 if ((irg->typeinfo_state == ir_typeinfo_consistent) &&
79 (irp->typeinfo_state == ir_typeinfo_consistent) &&
80 (s != ir_typeinfo_consistent) )
81 irp->typeinfo_state = ir_typeinfo_inconsistent;
84 ir_typeinfo_state get_irg_typeinfo_state(const ir_graph *irg)
86 assert(is_ir_graph(irg));
87 return irg->typeinfo_state;
91 ir_typeinfo_state get_irp_typeinfo_state(void)
93 return irp->typeinfo_state;
95 void set_irp_typeinfo_state(ir_typeinfo_state s)
97 irp->typeinfo_state = s;
99 void set_irp_typeinfo_inconsistent(void)
101 if (irp->typeinfo_state == ir_typeinfo_consistent)
102 irp->typeinfo_state = ir_typeinfo_inconsistent;
106 ir_type *get_irn_typeinfo_type(const ir_node *n)
109 assert(get_irg_typeinfo_state(get_irn_irg(n)) != ir_typeinfo_none);
111 res = pmap_get(ir_type, type_node_map, n);
119 void set_irn_typeinfo_type(ir_node *n, ir_type *tp)
121 assert(get_irg_typeinfo_state(get_irn_irg(n)) != ir_typeinfo_none);
123 pmap_insert(type_node_map, (void *)n, (void *)tp);