4 * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved.
6 * This file is part of libFirm.
8 * This file may be distributed and/or modified under the terms of the
9 * GNU General Public License version 2 as published by the Free Software
10 * Foundation and appearing in the file LICENSE.GPL included in the
11 * packaging of this file.
13 * Licensees holding valid libFirm Professional Edition licenses may use
14 * this file in accordance with the libFirm Commercial License.
15 * Agreement provided with the Software.
17 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * @brief Utilitites for PTO
26 * @date Sat Nov 13 19:35:27 CET 2004
34 pto_util: Utilitites for PTO
37 # include "pto_util.h"
39 # include "irnode_t.h"
43 # include "pto_debug.h"
50 # endif /* not defined TRUE */
52 /* Local Data Types: */
53 /* Environment for find_irg_args */
54 typedef struct find_irg_args_env {
57 } find_irg_args_env_t;
60 /* Local Variables: */
62 /* Local Prototypes: */
64 /* ===================================================
66 =================================================== */
67 /* Helper for find_irg_args */
68 static void find_irg_arg (ir_node *node, void *env)
70 find_irg_args_env_t *arg_env = (find_irg_args_env_t*) env;
72 if (iro_Proj == get_irn_opcode (node)) {
73 if (arg_env->arg == get_Proj_pred (node)) {
74 long n = get_Proj_proj (node);
76 assert (! arg_env->args [n]);
78 arg_env->args [n] = node;
83 /* ===================================================
84 Exported Implementation:
85 =================================================== */
86 /* Find the arguments of a graph. For a method that has n args, the
87 result array has 'n+1' entries, the last of which is written NULL.
88 Note that not all entries in [0..n-1] will be populated all the time.
90 ir_node **find_irg_args (ir_graph *graph)
92 ir_type *tp = get_entity_type (get_irg_entity (graph));
93 const int n_args = get_method_n_params (tp);
94 ir_node **args = xcalloc (n_args + 1, sizeof (ir_node*));
95 ir_node *arg = get_irg_args (graph);
96 find_irg_args_env_t *arg_env;
98 arg_env = (find_irg_args_env_t*) xmalloc (sizeof (find_irg_args_env_t));
100 arg_env->args = args;
104 ir_graph *save = get_current_ir_graph ();
106 set_current_ir_graph (graph);
107 irg_walk (get_irg_end (graph), find_irg_arg, NULL, arg_env);
108 set_current_ir_graph (save);
111 memset (arg_env, 0x00, sizeof (find_irg_args_env_t));
114 args [n_args] = NULL;
119 /* Get the entity of a ptr */
120 ir_entity *get_ptr_ent (ir_node *ptr)
122 ir_entity *ent = NULL;
123 const ir_opcode ptr_op = get_irn_opcode (ptr);
126 ent = get_ptr_ent (get_Cast_op (ptr));
129 ent = get_Sel_entity (ptr);
132 case (iro_SymConst): {
133 ent = get_SymConst_entity (ptr);
137 fprintf (stderr, "%s: no ent for ptr=%s[%ld]\n",
139 get_op_name (get_irn_op (ptr)),
140 get_irn_node_nr (ptr));
148 /* Check whether the load of the given ptr is a dummy */
149 int is_dummy_load_ptr (ir_node *ptr)
151 const ir_opcode ptr_op = get_irn_opcode (ptr);
155 return (is_dummy_load_ptr (get_Cast_op (ptr)));
158 case (iro_SymConst): {
171 Revision 1.19 2007/01/16 15:45:42 beck
172 renamed type opcode to ir_opcode
174 Revision 1.18 2006/12/13 19:46:47 beck
175 rename type entity into ir_entity
177 Revision 1.17 2006/06/08 10:49:07 beck
178 renamed type to ir_type
180 Revision 1.16 2005/01/14 14:13:32 liekweg
183 Revision 1.15 2005/01/10 17:26:34 liekweg
184 fixup printfs, don't put environments on the stack
186 Revision 1.14 2004/12/23 15:47:09 beck
187 removed uneeded allocations
190 Revision 1.13 2004/12/22 14:43:14 beck
191 made allocations C-like
193 Revision 1.12 2004/12/21 15:53:12 beck
194 removed GNUC constructs
196 Revision 1.11 2004/12/20 17:34:35 liekweg
197 fix recursion handling
199 Revision 1.10 2004/12/06 12:55:06 liekweg
202 Revision 1.9 2004/12/02 16:17:51 beck
203 fixed config.h include
205 Revision 1.8 2004/11/26 15:59:14 liekweg
206 recognize dummy loads
208 Revision 1.7 2004/11/24 14:53:56 liekweg
211 Revision 1.6 2004/11/18 16:37:07 liekweg