/*
- * 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 <string.h>
-#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 <string.h>
#include <stdbool.h>
#include "ircgcons.h"
#include "irgmod.h"
#include "irgwalk.h"
#include "irflag_t.h"
-
+#include "irtools.h"
/* Return the current state of the interprocedural view. */
ip_view_state get_irp_ip_view_state(void) {
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.
* - 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());
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);
- if (get_entity_irg(ent)) {
- irg_data_t * data = get_entity_link(ent);
+ ir_entity * ent = get_Call_callee(call, j);
+ if (get_entity_irg(ent)) {
+ irg_data_t * data = get_entity_link(ent);
# ifndef CATE_jni
- assert(get_entity_irg(ent) && data);
- ++data->count;
+ assert(get_entity_irg(ent) && data);
+ ++data->count;
# endif /* ndef CATE_jni */
- } else {
- set_entity_link(ent, NULL);
- }
+ } else {
+ set_entity_link(ent, NULL);
+ }
}
}
}
}
-
-static INLINE void clear_link(ir_node * node, void * env) {
- set_irn_link(node, NULL);
-}
-
/*
-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;
* (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);
* ... -> 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, clear_link, (irg_walk_func *) collect_phicallproj_walker, &end);
+ irg_walk_graph(irg, firm_clear_link, (irg_walk_func *) collect_phicallproj_walker, &end);
+
+ clear_using_irn_link(irg);
}
}
ir_node * block;
set_optimize(0);
block = new_Block(n, in);
+ set_cur_block(block);
set_optimize(rem_opt);
return block;
}
* 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())));
* 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;
}
}
/* 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)));
}
}
int n_ret = 0;
for (i = get_Block_n_cfgpreds(end_block) - 1; i >= 0; --i) {
- if (get_irn_op(cfgpred_arr[i]) == op_Return) {
+ if (is_Return(cfgpred_arr[i])) {
if (ret_arr) {
- ARR_APP1(ir_node *, ret_arr, cfgpred_arr[i]);
+ ARR_APP1(ir_node *, ret_arr, cfgpred_arr[i]);
} else {
- ret_arr = NEW_ARR_F(ir_node *, 1);
- ret_arr[0] = cfgpred_arr[i];
+ ret_arr = NEW_ARR_F(ir_node *, 1);
+ ret_arr[0] = cfgpred_arr[i];
}
++n_ret;
}
int n_except = 0;
ir_node ** cfgpred_arr = get_Block_cfgpred_arr(end_block);
for (i = get_Block_n_cfgpreds(end_block) - 1; i >= 0; --i) {
- if (get_irn_op(cfgpred_arr[i]) != op_Return) {
+ if (! is_Return(cfgpred_arr[i])) {
if (except_arr) {
- ARR_APP1(ir_node *, except_arr, cfgpred_arr[i]);
+ ARR_APP1(ir_node *, except_arr, cfgpred_arr[i]);
} else {
- except_arr = NEW_ARR_F(ir_node *, 1);
- except_arr[0] = cfgpred_arr[i];
+ except_arr = NEW_ARR_F(ir_node *, 1);
+ except_arr[0] = cfgpred_arr[i];
}
++n_except;
}
data->except = new_EndExcept();
/* mem */
for (i = n_except - 1; i >= 0; --i) {
- ir_node * node = skip_Proj(skip_Tuple(except_arr[i]));
- if (get_irn_op(node) == op_Call) {
- in[i] = new_r_Proj(irg, get_nodes_block(node), node, mode_M, 3);
- } else if (get_irn_op(node) == op_Raise) {
- in[i] = new_r_Proj(irg, get_nodes_block(node), node, mode_M, 1);
+ ir_node *node = skip_Proj(skip_Tuple(except_arr[i]));
+ ir_op *op = get_irn_op(node);
+ if (op == op_Call) {
+ in[i] = new_r_Proj(irg, get_nodes_block(node), node, mode_M, pn_Call_M_except);
+ } else if (op == op_Raise) {
+ 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 {
- assert(is_fragile_op(node));
- /* We rely that all cfops have the memory output at the same position. */
- in[i] = new_r_Proj(irg, get_nodes_block(node), node, mode_M, 0);
+ assert(is_fragile_op(node));
+ /* We rely that all cfops have the memory output at the same position. */
+ in[i] = new_r_Proj(irg, get_nodes_block(node), node, mode_M, 0);
}
}
data->except_mem = new_Phi(n_except, in, mode_M);
/* 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);
/* 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);
}
/* 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. */
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:
* 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;
}
}
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
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;
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 */
set_nodes_block(proj, except_block);
exchange(proj, new_Break());
set_irg_current_block(current_ir_graph, pre_block);
- set_irn_n(except_block, 0, new_Proj(call, mode_X, 1));
+ set_irn_n(except_block, 0, new_Proj(call, mode_X, pn_Call_X_except));
set_irg_current_block(current_ir_graph, post_block);
}
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),
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;
/* 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);
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) {
- 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)))
- break;
- if (j < n_callees) /* There is an entity with a graph */
- construct_call(node);
+ 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)))
+ break;
+ if (j < n_callees) /* There is an entity with a graph */
+ construct_call(node);
}
}
}
-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. */
+ /* Do not turn Break into Jmp. Better: merge blocks right away.
+ Well, but there are Breaks left.
+ See exc1 from ajacs-rts/Exceptions.java. */
if (get_Block_n_cfgpreds(node) == 1) {
ir_node *pred = get_Block_cfgpred(node, 0);
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) {
+ set_irg_current_block(current_ir_graph, get_nodes_block(node));
+ exchange(node, new_Jmp());
+ } 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. */
if (get_irp_ip_view_state() != ip_view_no) {
for (i = get_irp_n_irgs() - 1; i >= 0; --i) {
ir_graph * irg = get_irp_irg(i);
- irg_walk_graph(irg, destruct_walker, 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)));
+ irg_walk_graph(irg, destruct_walker, firm_clear_link, NULL);
+
+ 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);
- set_irg_end_reg(irg, get_irg_end(irg));
- set_irg_end_except(irg, get_irg_end(irg));
}
+
set_irp_ip_view(ip_view_no);
}
}
+
+#endif