X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Fircgcons.c;h=ca32dea81287e988790a9aa071817bfe4fcad0a5;hb=202b43933e0cc0b71cc7fbe2b092b94efb7fd30e;hp=2346b05ef2a48f12eef8818e0811274fe4a1297b;hpb=55d08ea9493bbce65002f33b6a441f768b237932;p=libfirm diff --git a/ir/ir/ircgcons.c b/ir/ir/ircgcons.c index 2346b05ef..ca32dea81 100644 --- a/ir/ir/ircgcons.c +++ b/ir/ir/ircgcons.c @@ -1,23 +1,35 @@ /* - * Project: libFIRM - * File name: ir/ir/ircgcons.c - * Purpose: Construction and removal of interprocedural representation - * (explicit interprocedural dependencies). - * Author: Hubert Schmid - * Modified by: - * Created: 09.06.2002 - * CVS-ID: $Id$ - * Copyright: (c) 2002-2003 Universität Karlsruhe - * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * 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. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif -#ifdef HAVE_STRING_H -#include -#endif +/** + * @file + * @brief Construction and removal of interprocedural representation + * (explicit interprocedural dependencies). + * @author Hubert Schmid + * @date 09.06.2002 + * @version $Id$ + */ +#include "config.h" + +#ifdef INTERPROCEDURAL_VIEW +#include #include #include "ircgcons.h" @@ -55,10 +67,9 @@ typedef struct { ir_node * except, * except_mem; /* EndExcept and Mem for exception return */ } irg_data_t; -static irg_data_t * irg_data_create(void) { - irg_data_t *data = xmalloc(sizeof(*data)); - memset(data, 0, sizeof(*data)); /* init */ - return data; +static irg_data_t * irg_data_create(void) +{ + return XMALLOCZ(irg_data_t); } /** Count the number of callers of each method and mark open methods. @@ -68,7 +79,7 @@ static irg_data_t * irg_data_create(void) { * - are external visible * - are dereferenced somewhere within the program (i.e., the address of the * method is stored somewhere). */ -static void caller_init(int arr_length, entity ** free_methods) { +static void caller_init(int arr_length, ir_entity ** free_methods) { int i, j; for (i = get_irp_n_irgs() - 1; i >= 0; --i) { set_entity_link(get_irg_entity(get_irp_irg(i)), irg_data_create()); @@ -82,9 +93,9 @@ static void caller_init(int arr_length, entity ** free_methods) { ir_node * call; /* We collected all call nodes in a link list at the end node. */ for (call = get_irn_link(get_irg_end(irg)); call; call = get_irn_link(call)) { - if (get_irn_op(call) != op_Call) continue; + if (!is_Call(call)) continue; for (j = get_Call_n_callees(call) - 1; j >= 0; --j) { - entity * ent = get_Call_callee(call, j); + ir_entity * ent = get_Call_callee(call, j); if (get_entity_irg(ent)) { irg_data_t * data = get_entity_link(ent); # ifndef CATE_jni @@ -100,7 +111,7 @@ static void caller_init(int arr_length, entity ** free_methods) { } /* -static INLINE ir_node * tail(ir_node * node) { +static inline ir_node * tail(ir_node * node) { ir_node * link; for (; (link = get_irn_link(node)); node = link) ; return node; @@ -112,7 +123,7 @@ static INLINE ir_node * tail(ir_node * node) { * (auch bei Proj->Call Operationen) und Phi-Operationen in die Liste ihres * Grundblocks einfügen. */ static void collect_phicallproj_walker(ir_node * node, ir_node ** call_tail) { - if (get_irn_op(node) == op_Call) { + if (is_Call(node)) { /* Die Liste von Call an call_tail anhängen. */ ir_node * link; assert(get_irn_link(*call_tail) == NULL); @@ -150,19 +161,24 @@ static void link(ir_node * head, ir_node * node) { * ... -> Proj -> NULL. */ static void collect_phicallproj(void) { int i; + for (i = get_irp_n_irgs() - 1; i >= 0; --i) { ir_graph * irg = get_irp_irg(i); ir_node * start = get_irg_start(irg); ir_node * end = get_irg_end(irg); current_ir_graph = irg; assert(irg && start); + + set_using_irn_link(irg); + /* Die speziellen Parameter der Start-Operation extra verlinken, * auch wenn sie nicht im intraprozeduralen Graphen erreichbar * sind. */ link(start, get_irg_frame(irg)); - link(start, get_irg_globals(irg)); /* walk */ irg_walk_graph(irg, firm_clear_link, (irg_walk_func *) collect_phicallproj_walker, &end); + + clear_using_irn_link(irg); } } @@ -187,6 +203,7 @@ static ir_node * create_Block(int n, ir_node ** in) { ir_node * block; set_optimize(0); block = new_Block(n, in); + set_cur_block(block); set_optimize(rem_opt); return block; } @@ -200,7 +217,7 @@ static void prepare_irg_end_except(ir_graph * irg, irg_data_t * data); * cause cycles we don't want to see, as Unknwon is in the Start Block * of the procedure. Use unknown of outermost irg where the start * block has no predecessors. */ -static INLINE ir_node *get_cg_Unknown(ir_mode *m) { +static inline ir_node *get_cg_Unknown(ir_mode *m) { assert((get_Block_n_cfgpreds(get_irg_start_block(get_irp_main_irg())) == 1) && (get_nodes_block(get_Block_cfgpred(get_irg_start_block(get_irp_main_irg()), 0)) == get_irg_start_block(get_irp_main_irg()))); @@ -242,9 +259,9 @@ static void prepare_irg(ir_graph * irg, irg_data_t * data) { * dass oben für "verschiedene" Proj-Operationen wegen CSE nur eine * Filter-Operation erzeugt worden sein kann. */ for (link = get_irg_start(irg), proj = get_irn_link(link); proj; proj = get_irn_link(proj)) { - if (get_irn_op(proj) == op_Id) { /* replaced with filter */ + if (is_Id(proj)) { /* replaced with filter */ ir_node * filter = get_Id_pred(proj); - assert(get_irn_op(filter) == op_Filter); + assert(is_Filter(filter)); if (filter != link && get_irn_link(filter) == NULL) { set_irn_link(link, filter); link = filter; @@ -252,15 +269,15 @@ static void prepare_irg(ir_graph * irg, irg_data_t * data) { } } /* Globle Einträge für ersetzte Operationen korrigieren. */ - set_irg_frame (irg, skip_Id(get_irg_frame(irg))); - set_irg_globals (irg, skip_Id(get_irg_globals(irg))); - set_irg_initial_mem(irg, skip_Id(get_irg_initial_mem(irg))); + set_irg_initial_exec(irg, skip_Id(get_irg_initial_exec(irg))); + set_irg_frame (irg, skip_Id(get_irg_frame(irg))); + set_irg_initial_mem (irg, skip_Id(get_irg_initial_mem(irg))); /* Unbekannten Aufrufer sofort eintragen. */ if (data->open) { set_Block_cg_cfgpred(start_block, 0, get_cg_Unknown(mode_X)); for (proj = get_irn_link(get_irg_start(irg)); proj; proj = get_irn_link(proj)) { - if (get_irn_op(proj) == op_Filter) { + if (is_Filter(proj)) { set_Filter_cg_pred(proj, 0, get_cg_Unknown(get_irn_mode(proj))); } } @@ -377,8 +394,6 @@ static void prepare_irg_end_except(ir_graph * irg, irg_data_t * data) { in[i] = new_r_Proj(irg, get_nodes_block(node), node, mode_M, pn_Raise_M); } else if (op == op_CopyB) { in[i] = new_r_Proj(irg, get_nodes_block(node), node, mode_M, pn_CopyB_M_except); - } else if (op == op_Bound) { - in[i] = new_r_Proj(irg, get_nodes_block(node), node, mode_M, pn_Bound_M_except); } else { assert(is_fragile_op(node)); /* We rely that all cfops have the memory output at the same position. */ @@ -399,7 +414,7 @@ static void prepare_irg_end_except(ir_graph * irg, irg_data_t * data) { /* Zwischengespeicherte Daten wieder freigeben. */ static void cleanup_irg(ir_graph * irg) { - entity * ent = get_irg_entity(irg); + ir_entity * ent = get_irg_entity(irg); irg_data_t * data = get_entity_link(ent); assert(data); if (data->res) DEL_ARR_F(data->res); @@ -440,7 +455,7 @@ static void move_nodes(ir_node * from_block, ir_node * to_block, ir_node * node) /* Move projs of this node. */ proj = get_irn_link(node); for (; proj; proj = skip_Id(get_irn_link(proj))) { - if (get_irn_op(proj) != op_Proj && get_irn_op(proj) != op_Filter) continue; + if (get_irn_op(proj) != op_Proj && !is_Filter(proj)) continue; if ((get_nodes_block(proj) == from_block) && (skip_Proj(get_irn_n(proj, 0)) == node)) set_nodes_block(proj, to_block); } @@ -449,12 +464,14 @@ static void move_nodes(ir_node * from_block, ir_node * to_block, ir_node * node) /* Abhängigkeiten vom Start-Block und den Filter-Operationen im * Start-Block auf den Aufrufer hinzufügen. */ -static void construct_start(entity * caller, entity * callee, - ir_node * call, ir_node * exec) { +static void construct_start(ir_entity * caller, ir_entity * callee, + ir_node * call, ir_node * exec) +{ irg_data_t *data = get_entity_link(callee); ir_graph *irg = get_entity_irg(callee); ir_node *start = get_irg_start(irg); ir_node *filter; + (void) caller; assert(irg); assert(get_entity_peculiarity(callee) == peculiarity_existent); /* Else data is not initalized. */ @@ -463,7 +480,7 @@ static void construct_start(entity * caller, entity * callee, set_Block_cg_cfgpred(get_nodes_block(start), data->count, exec); for (filter = get_irn_link(start); filter; filter = get_irn_link(filter)) { - if (get_irn_op(filter) != op_Filter) continue; + if (!is_Filter(filter)) continue; if (get_Proj_pred(filter) == start) { switch ((int) get_Proj_proj(filter)) { case pn_Start_M: @@ -554,7 +571,7 @@ static ir_node * get_except(ir_node * call) { * Aufrufstelle nur ein einziges Mal aufgerufen. */ ir_node * proj; for (proj = get_irn_link(call); proj && get_irn_op(proj) == op_Proj; proj = get_irn_link(proj)) { - if (get_Proj_proj(proj) == 1 && get_irn_op(get_Proj_pred(proj)) == op_Call) { + if (get_Proj_proj(proj) == 1 && is_Call(get_Proj_pred(proj))) { return proj; } } @@ -588,6 +605,7 @@ static bool is_outermost_graph(ir_graph *irg) { return true; } +#ifdef INTERPROCEDURAL_VIEW /* Grundblock der Call-Operation aufteilen. CallBegin- und Filter-Operationen * einfügen. Die Steuer- und Datenflussabhängigkeiten von den aufgerufenen * Methoden auf die CallBegin-Operation, und von der Aufrufstelle auf die @@ -596,8 +614,8 @@ static void construct_call(ir_node * call) { int i, n_callees; ir_node *post_block, *pre_block, *except_block, * proj, *jmp, *call_begin; ir_node ** in; - entity * caller; - entity ** callees; + ir_entity * caller; + ir_entity ** callees; ir_graph ** irgs; irg_data_t ** data; @@ -613,7 +631,7 @@ static void construct_call(ir_node * call) { in = NEW_ARR_F(ir_node *, n_callees); caller = get_irg_entity(current_ir_graph); /* entity des aktuellen ir_graph */ - callees = NEW_ARR_F(entity *, n_callees); /* aufgerufene Methoden: entity */ + callees = NEW_ARR_F(ir_entity *, n_callees); /* aufgerufene Methoden: entity */ irgs = NEW_ARR_F(ir_graph *, n_callees); /* aufgerufene Methoden: ir_graph */ data = NEW_ARR_F(irg_data_t *, n_callees); /* aufgerufene Methoden: irg_data_t */ @@ -697,7 +715,7 @@ static void construct_call(ir_node * call) { set_interprocedural_view(1); for (i = 0; i < n_callees; ++i) { - entity * callee = get_Call_callee(call, i); + ir_entity * callee = get_Call_callee(call, i); if (data[i]) { /* explicit */ if (data[i]->except) { in[i] = new_r_Proj(get_entity_irg(callee), get_nodes_block(data[i]->except), @@ -798,9 +816,10 @@ static void construct_call(ir_node * call) { DEL_ARR_F(irgs); DEL_ARR_F(data); } +#endif -void cg_construct(int arr_len, entity ** free_methods_arr) { +void cg_construct(int arr_len, ir_entity ** free_methods_arr) { int i; if (get_irp_ip_view_state() == ip_view_valid) return; @@ -815,7 +834,7 @@ void cg_construct(int arr_len, entity ** free_methods_arr) { /* prepare irgs */ for (i = get_irp_n_irgs() - 1; i >= 0; --i) { ir_graph * irg = get_irp_irg(i); - entity * ent = get_irg_entity(irg); + ir_entity * ent = get_irg_entity(irg); irg_data_t * data = get_entity_link(ent); if (data->count) { prepare_irg(irg, data); @@ -836,7 +855,7 @@ void cg_construct(int arr_len, entity ** free_methods_arr) { current_ir_graph = get_irp_irg(i); for (node = get_irn_link(get_irg_end(current_ir_graph)); node; node = get_irn_link(node)) { - if (get_irn_op(node) == op_Call) { + if (is_Call(node)) { int j, n_callees = get_Call_n_callees(node); for (j = 0; j < n_callees; ++j) if (get_entity_irg(get_Call_callee(node, j))) @@ -857,8 +876,10 @@ void cg_construct(int arr_len, entity ** free_methods_arr) { -static void destruct_walker(ir_node * node, void * env) { - if (get_irn_op(node) == op_Block) { +static void destruct_walker(ir_node * node, void * env) +{ + (void) env; + if (is_Block(node)) { remove_Block_cg_cfgpred_arr(node); /* Do not turn Break into Jmp. Better: merge blocks right away. Well, but there are Breaks left. @@ -868,13 +889,13 @@ static void destruct_walker(ir_node * node, void * env) { if (get_irn_op(pred) == op_Break) exchange(node, get_nodes_block(pred)); } - } else if (get_irn_op(node) == op_Filter) { + } else if (is_Filter(node)) { set_irg_current_block(current_ir_graph, get_nodes_block(node)); exchange(node, new_Proj(get_Filter_pred(node), get_irn_mode(node), get_Filter_proj(node))); } else if (get_irn_op(node) == op_Break) { set_irg_current_block(current_ir_graph, get_nodes_block(node)); exchange(node, new_Jmp()); - } else if (get_irn_op(node) == op_Call) { + } else if (is_Call(node)) { remove_Call_callee_arr(node); } else if (get_irn_op(node) == op_Proj) { /* some ProjX end up in strange blocks. */ @@ -890,11 +911,11 @@ void cg_destruct(void) { ir_graph * irg = get_irp_irg(i); irg_walk_graph(irg, destruct_walker, firm_clear_link, NULL); - set_irg_frame (irg, skip_Id(get_irg_frame(irg))); - set_irg_globals (irg, skip_Id(get_irg_globals(irg))); - set_irg_initial_mem(irg, skip_Id(get_irg_initial_mem(irg))); - set_irg_end_reg (irg, get_irg_end(irg)); - set_irg_end_except (irg, get_irg_end(irg)); + set_irg_initial_exec(irg, skip_Id(get_irg_initial_exec(irg))); + set_irg_frame (irg, skip_Id(get_irg_frame(irg))); + set_irg_initial_mem (irg, skip_Id(get_irg_initial_mem(irg))); + set_irg_end_reg (irg, get_irg_end(irg)); + set_irg_end_except (irg, get_irg_end(irg)); set_irg_callee_info_state(irg, irg_callee_info_none); } @@ -902,3 +923,5 @@ void cg_destruct(void) { set_irp_ip_view(ip_view_no); } } + +#endif