comparison src/cospy.c @ 11:bf14d3ed008e

Move code of show arguments from before all_pass to before genericize
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 09 Sep 2010 15:57:08 +0800
parents ecc20b5a4942
children 6fdb0cfdc2a7
comparison
equal deleted inserted replaced
10:ecc20b5a4942 11:bf14d3ed008e
111 111
112 /*! \brief Find all call expression in a code block. 112 /*! \brief Find all call expression in a code block.
113 */ 113 */
114 static void 114 static void
115 find_call_expr(tree fn) { 115 find_call_expr(tree fn) {
116 tree code_blk; 116 tree bind, body;
117 117
118 code_blk = DECL_SAVED_TREE(fn); 118 bind = DECL_SAVED_TREE(fn);
119 printf("%d:%d\n", TREE_CODE(code_blk), BIND_EXPR); 119 body = BIND_EXPR_BODY(bind);
120 printf("%d:%d\n", TREE_CODE(body), BIND_EXPR);
120 } 121 }
121 122
122 /*! \brief This function is called before running all_passes. 123 /*! \brief This function is called before running all_passes.
123 * 124 *
124 * all_passes is a list of optimization passes of GCC. See 125 * all_passes is a list of optimization passes of GCC. See
127 * This function is called for every function. 128 * This function is called for every function.
128 */ 129 */
129 static void 130 static void
130 handle_all_passes(void *gcc_data, void *user_data) { 131 handle_all_passes(void *gcc_data, void *user_data) {
131 tree decl; 132 tree decl;
132 tree arg, arg_name;
133 tree arg_type;
134 struct cgraph_node *cgn; 133 struct cgraph_node *cgn;
135 char *arg_type_str;
136 function_args_iterator itr;
137 134
138 /* 135 /*
139 * GCC uses cgraph_node to save information of functions and 136 * GCC uses cgraph_node to save information of functions and
140 * relationships between functions (a.k.a call graphy). 137 * relationships between functions (a.k.a call graphy).
141 */ 138 */
145 printf("%s:%d:%s\n", current_function_name(), 142 printf("%s:%d:%s\n", current_function_name(),
146 DECL_SOURCE_LINE(decl), 143 DECL_SOURCE_LINE(decl),
147 DECL_SOURCE_FILE(decl)); 144 DECL_SOURCE_FILE(decl));
148 145
149 show_callees(cgn); 146 show_callees(cgn);
147 }
148
149 /*! \brief Called before every optimization pass.
150 */
151 static void
152 handle_every_pass(void *gcc_data, void *user_data) {
153 #if 0
154 printf("PASS %s (type=%x)\n", current_pass->name, current_pass->type);
155 #endif
156 }
157
158 /*! \brief Callback before any optimization pass.
159 *
160 * It supposed to get function body in GIMPLE statements. If we don't
161 * do this, here, it, GIMPLE statements, would be destroyed by
162 * optimization passes.
163 */
164 static void
165 handle_pre_genericize(void *gcc_data, void *user_data) {
166 tree fndecl;
167 /* for arguments */
168 tree arg, arg_name;
169 tree arg_type;
170 char *arg_type_str;
171
172 fndecl = cfun->decl;
173
174 printf("%s:%d:%s\n", current_function_name(),
175 DECL_SOURCE_LINE(fndecl),
176 DECL_SOURCE_FILE(fndecl));
150 177
151 /* 178 /*
152 * Parse and show arguments of the function. 179 * Parse and show arguments of the function.
153 */ 180 */
154 arg = DECL_ARGUMENTS(decl); 181 arg = DECL_ARGUMENTS(fndecl);
155 while(arg) { 182 while(arg) {
156 /* 183 /*
157 * The structure of an argument. 184 * The structure of an argument.
158 * - parm 185 * - parm
159 * - name:identifier 186 * - name:identifier
168 IDENTIFIER_POINTER(arg_name), 195 IDENTIFIER_POINTER(arg_name),
169 arg_type_str); 196 arg_type_str);
170 ggc_free(arg_type_str); 197 ggc_free(arg_type_str);
171 arg = TREE_CHAIN(arg); 198 arg = TREE_CHAIN(arg);
172 } 199 }
173 } 200
174
175 /*! \brief Called before every optimization pass.
176 */
177 static void
178 handle_every_pass(void *gcc_data, void *user_data) {
179 #if 0
180 printf("PASS %s (type=%x)\n", current_pass->name, current_pass->type);
181 #endif
182 }
183
184 static void
185 handle_pre_genericize(void *gcc_data, void *user_data) {
186 tree fndecl;
187
188 fndecl = cfun->decl;
189 find_call_expr(fndecl); 201 find_call_expr(fndecl);
190 } 202 }
191 203
192 /*! \brief Initialize function for the plugin. 204 /*! \brief Initialize function for the plugin.
193 */ 205 */
194 int 206 int
195 plugin_init(struct plugin_name_args *plugin_info, 207 plugin_init(struct plugin_name_args *plugin_info,
196 struct plugin_gcc_version *version) { 208 struct plugin_gcc_version *version) {
197 struct cgraph_node_hook_list *hook;
198
199 if (!plugin_default_version_check (version, &gcc_version)) 209 if (!plugin_default_version_check (version, &gcc_version))
200 return 1; 210 return 1;
201 printf("Initialize plugin %s\n", plugin_info->base_name); 211 printf("Initialize plugin %s\n", plugin_info->base_name);
202 212
203 /* 213 /*