size_t n_params = get_method_n_params(called_type);
size_t n_arguments = get_method_n_params(call_type);
size_t n_res = get_method_n_ress(called_type);
- irg_inline_property prop = get_irg_inline_property(called_graph);
+ mtp_additional_properties props = get_entity_additional_properties(called);
size_t i;
bool res;
- if (prop == irg_inline_forbidden)
+ if (props & mtp_property_noinline)
return false;
if (n_arguments != n_params) {
/* Inlines a method at the given call site. */
int inline_method(ir_node *call, ir_graph *called_graph)
{
- ir_node *pre_call;
- ir_node *post_call, *post_bl;
- ir_node *in[pn_Start_max+1];
- ir_node *end, *end_bl, *block;
- ir_node **res_pred;
- ir_node **cf_pred;
- ir_node **args_in;
- ir_node *ret, *phi;
- int arity, n_ret, n_exc, n_res, i, j, rem_opt;
- int irn_arity, n_params;
- int n_mem_phi;
- enum exc_mode exc_handling;
- ir_type *mtp;
- ir_type *ctp;
- ir_entity *ent;
- ir_graph *rem;
- ir_graph *irg = get_irn_irg(call);
-
/* we cannot inline some types of calls */
if (! can_inline(call, called_graph))
return 0;
/* We cannot inline a recursive call. The graph must be copied before
* the call the inline_method() using create_irg_copy(). */
+ ir_graph *irg = get_irn_irg(call);
if (called_graph == irg)
return 0;
- ent = get_irg_entity(called_graph);
- mtp = get_entity_type(ent);
- ctp = get_Call_type(call);
- n_params = get_method_n_params(mtp);
- n_res = get_method_n_ress(mtp);
+ ir_entity *ent = get_irg_entity(called_graph);
+ ir_type *mtp = get_entity_type(ent);
+ ir_type *ctp = get_Call_type(call);
+ int n_params = get_method_n_params(mtp);
- rem = current_ir_graph;
+ ir_graph *rem = current_ir_graph;
current_ir_graph = irg;
DB((dbg, LEVEL_1, "Inlining %+F(%+F) into %+F\n", call, called_graph, irg));
/* optimizations can cause problems when allocating new nodes */
- rem_opt = get_opt_optimize();
+ int rem_opt = get_opt_optimize();
set_optimize(0);
/* Handle graph state */
- assert(get_irg_phase_state(irg) != phase_building);
assert(get_irg_pinned(irg) == op_pin_state_pinned);
assert(get_irg_pinned(called_graph) == op_pin_state_pinned);
clear_irg_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE
exc_handling:
0 There is a handler.
2 Exception handling not represented in Firm. -- */
- {
- ir_node *Xproj = NULL;
- ir_node *proj;
- for (proj = (ir_node*)get_irn_link(call); proj != NULL;
- proj = (ir_node*)get_irn_link(proj)) {
- long proj_nr = get_Proj_proj(proj);
- if (proj_nr == pn_Call_X_except) Xproj = proj;
- }
- exc_handling = Xproj != NULL ? exc_handler : exc_no_handler;
+ ir_node *Xproj = NULL;
+ for (ir_node *proj = (ir_node*)get_irn_link(call); proj != NULL;
+ proj = (ir_node*)get_irn_link(proj)) {
+ long proj_nr = get_Proj_proj(proj);
+ if (proj_nr == pn_Call_X_except) Xproj = proj;
}
+ enum exc_mode exc_handling = Xproj != NULL ? exc_handler : exc_no_handler;
/* create the argument tuple */
- args_in = ALLOCAN(ir_node*, n_params);
+ ir_node **args_in = ALLOCAN(ir_node*, n_params);
- block = get_nodes_block(call);
- for (i = n_params - 1; i >= 0; --i) {
+ ir_node *block = get_nodes_block(call);
+ for (int i = n_params - 1; i >= 0; --i) {
ir_node *arg = get_Call_param(call, i);
ir_type *param_tp = get_method_param_type(mtp, i);
ir_mode *mode = get_type_mode(param_tp);
/* the procedure and later replaces the Start node of the called graph.
* Post_call is the old Call node and collects the results of the called
* graph. Both will end up being a tuple. */
- post_bl = get_nodes_block(call);
+ ir_node *post_bl = get_nodes_block(call);
/* XxMxPxPxPxT of Start + parameter of Call */
+ ir_node *in[pn_Start_max+1];
in[pn_Start_M] = get_Call_mem(call);
in[pn_Start_X_initial_exec] = new_r_Jmp(post_bl);
in[pn_Start_P_frame_base] = get_irg_frame(irg);
in[pn_Start_T_args] = new_r_Tuple(post_bl, n_params, args_in);
- pre_call = new_r_Tuple(post_bl, pn_Start_max+1, in);
- post_call = call;
+ ir_node *pre_call = new_r_Tuple(post_bl, pn_Start_max+1, in);
+ ir_node *post_call = call;
/* --
The new block gets the ins of the old block, pre_call and all its
* node, similar for singleton nodes like NoMem and Bad.
* Note: this will prohibit predecessors to be copied - only do it for
* nodes without predecessors */
- {
- ir_node *start_block;
- ir_node *start;
- ir_node *nomem;
-
- start_block = get_irg_start_block(called_graph);
- set_new_node(start_block, get_nodes_block(pre_call));
- mark_irn_visited(start_block);
-
- start = get_irg_start(called_graph);
- set_new_node(start, pre_call);
- mark_irn_visited(start);
-
- nomem = get_irg_no_mem(called_graph);
- set_new_node(nomem, get_irg_no_mem(irg));
- mark_irn_visited(nomem);
- }
+ ir_node *start_block = get_irg_start_block(called_graph);
+ set_new_node(start_block, get_nodes_block(pre_call));
+ mark_irn_visited(start_block);
+
+ ir_node *start = get_irg_start(called_graph);
+ set_new_node(start, pre_call);
+ mark_irn_visited(start);
+
+ ir_node *nomem = get_irg_no_mem(called_graph);
+ set_new_node(nomem, get_irg_no_mem(irg));
+ mark_irn_visited(nomem);
/* entitiy link is used to link entities on old stackframe to the
* new stackframe */
*/
/* Precompute some values */
- end_bl = get_new_node(get_irg_end_block(called_graph));
- end = get_new_node(get_irg_end(called_graph));
- arity = get_Block_n_cfgpreds(end_bl); /* arity = n_exc + n_ret */
- n_res = get_method_n_ress(get_Call_type(call));
+ ir_node *end_bl = get_new_node(get_irg_end_block(called_graph));
+ ir_node *end = get_new_node(get_irg_end(called_graph));
+ int arity = get_Block_n_cfgpreds(end_bl); /* arity = n_exc + n_ret */
+ int n_res = get_method_n_ress(get_Call_type(call));
- res_pred = XMALLOCN(ir_node*, n_res);
- cf_pred = XMALLOCN(ir_node*, arity);
+ ir_node **res_pred = XMALLOCN(ir_node*, n_res);
+ ir_node **cf_pred = XMALLOCN(ir_node*, arity);
/* archive keepalives */
- irn_arity = get_irn_arity(end);
- for (i = 0; i < irn_arity; i++) {
+ int irn_arity = get_irn_arity(end);
+ for (int i = 0; i < irn_arity; i++) {
ir_node *ka = get_End_keepalive(end, i);
if (! is_Bad(ka))
add_End_keepalive(get_irg_end(irg), ka);
}
/* replace Return nodes by Jump nodes */
- n_ret = 0;
- for (i = 0; i < arity; i++) {
- ir_node *ret;
- ret = get_Block_cfgpred(end_bl, i);
+ int n_ret = 0;
+ for (int i = 0; i < arity; i++) {
+ ir_node *ret = get_Block_cfgpred(end_bl, i);
if (is_Return(ret)) {
ir_node *block = get_nodes_block(ret);
cf_pred[n_ret] = new_r_Jmp(block);
* add Phi node if there was more than one Return. */
turn_into_tuple(post_call, pn_Call_max+1);
/* First the Memory-Phi */
- n_mem_phi = 0;
- for (i = 0; i < arity; i++) {
- ret = get_Block_cfgpred(end_bl, i);
+ int n_mem_phi = 0;
+ for (int i = 0; i < arity; i++) {
+ ir_node *ret = get_Block_cfgpred(end_bl, i);
if (is_Return(ret)) {
cf_pred[n_mem_phi++] = get_Return_mem(ret);
}
cf_pred[n_mem_phi++] = new_r_Proj(ret, mode_M, 1);
}
}
- phi = new_r_Phi(post_bl, n_mem_phi, cf_pred, mode_M);
+ ir_node *phi = new_r_Phi(post_bl, n_mem_phi, cf_pred, mode_M);
set_Tuple_pred(call, pn_Call_M, phi);
/* Conserve Phi-list for further inlinings -- but might be optimized */
if (get_nodes_block(phi) == post_bl) {
}
/* Now the real results */
if (n_res > 0) {
- ir_node *result_tuple;
- for (j = 0; j < n_res; j++) {
+ for (int j = 0; j < n_res; j++) {
ir_type *res_type = get_method_res_type(ctp, j);
ir_mode *res_mode = get_type_mode(res_type);
- n_ret = 0;
- for (i = 0; i < arity; i++) {
- ret = get_Block_cfgpred(end_bl, i);
+ int n_ret = 0;
+ for (int i = 0; i < arity; i++) {
+ ir_node *ret = get_Block_cfgpred(end_bl, i);
if (is_Return(ret)) {
ir_node *res = get_Return_res(ret, j);
if (get_irn_mode(res) != res_mode) {
set_Block_phis(post_bl, phi);
}
}
- result_tuple = new_r_Tuple(post_bl, n_res, res_pred);
+ ir_node *result_tuple = new_r_Tuple(post_bl, n_res, res_pred);
set_Tuple_pred(call, pn_Call_T_result, result_tuple);
} else {
set_Tuple_pred(call, pn_Call_T_result, new_r_Bad(irg, mode_T));
branches to the End node.
*/
if (exc_handling == exc_handler) {
- n_exc = 0;
- for (i = 0; i < arity; i++) {
- ir_node *ret, *irn;
- ret = get_Block_cfgpred(end_bl, i);
- irn = skip_Proj(ret);
+ int n_exc = 0;
+ for (int i = 0; i < arity; i++) {
+ ir_node *ret = get_Block_cfgpred(end_bl, i);
+ ir_node *irn = skip_Proj(ret);
if (is_fragile_op(irn) || is_Raise(irn)) {
cf_pred[n_exc] = ret;
++n_exc;
set_Tuple_pred(call, pn_Call_X_except, new_r_Bad(irg, mode_X));
}
} else {
- ir_node *main_end_bl;
- int main_end_bl_arity;
- ir_node **end_preds;
-
/* assert(exc_handling == 1 || no exceptions. ) */
- n_exc = 0;
- for (i = 0; i < arity; i++) {
+ int n_exc = 0;
+ for (int i = 0; i < arity; i++) {
ir_node *ret = get_Block_cfgpred(end_bl, i);
ir_node *irn = skip_Proj(ret);
n_exc++;
}
}
- main_end_bl = get_irg_end_block(irg);
- main_end_bl_arity = get_irn_arity(main_end_bl);
- end_preds = XMALLOCN(ir_node*, n_exc + main_end_bl_arity);
+ ir_node *main_end_bl = get_irg_end_block(irg);
+ int main_end_bl_arity = get_irn_arity(main_end_bl);
+ ir_node **end_preds = XMALLOCN(ir_node*, n_exc+main_end_bl_arity);
- for (i = 0; i < main_end_bl_arity; ++i)
+ for (int i = 0; i < main_end_bl_arity; ++i)
end_preds[i] = get_irn_n(main_end_bl, i);
- for (i = 0; i < n_exc; ++i)
+ for (int i = 0; i < n_exc; ++i)
end_preds[main_end_bl_arity + i] = cf_pred[i];
set_irn_in(main_end_bl, n_exc + main_end_bl_arity, end_preds);
set_Tuple_pred(call, pn_Call_X_except, new_r_Bad(irg, mode_X));
{
ir_graph *rem = current_ir_graph;
inline_env_t env;
- call_entry *entry;
current_ir_graph = irg;
- /* Handle graph state */
- assert(get_irg_phase_state(irg) != phase_building);
free_callee_info(irg);
/* Find Call nodes to inline.
collect_phiprojs(irg);
list_for_each_entry(call_entry, entry, &env.calls, list) {
- ir_graph *callee = entry->callee;
- irg_inline_property prop = get_irg_inline_property(callee);
+ ir_graph *callee = entry->callee;
+ ir_entity *called = get_irg_entity(callee);
+ mtp_additional_properties props
+ = get_entity_additional_properties(called);
- if (prop == irg_inline_forbidden) {
+ if (props & mtp_property_noinline)
continue;
- }
- if (prop >= irg_inline_forced ||
- _obstack_memory_used(callee->obst) - (int)obstack_room(callee->obst) < size) {
+ struct obstack *const obst = get_irg_obstack(callee);
+ if ((props & mtp_property_always_inline) ||
+ _obstack_memory_used(obst) - (int)obstack_room(obst) < size) {
inline_method(entry->call, callee);
}
}
*/
static void append_call_list(inline_irg_env *dst, inline_irg_env *src, int loop_depth)
{
- call_entry *entry, *nentry;
+ call_entry *nentry;
/* Note that the src list points to Call nodes in the inlined graph, but
we need Call nodes in our graph. Luckily the inliner leaves this information
ir_graph *rem;
int did_inline;
wenv_t wenv;
- call_entry *entry, *next;
- const call_entry *centry;
pmap *copied_graphs;
pmap_entry *pm_entry;
for (i = 0; i < n_irgs; ++i) {
ir_graph *irg = get_irp_irg(i);
- assert(get_irg_phase_state(irg) != phase_building);
free_callee_info(irg);
assure_irg_properties(irg,
did_inline = 0;
for (i = 0; i < n_irgs; ++i) {
- ir_node *call;
int phiproj_computed = 0;
current_ir_graph = get_irp_irg(i);
ir_reserve_resources(current_ir_graph, IR_RESOURCE_IRN_LINK|IR_RESOURCE_PHI_LIST);
list_for_each_entry_safe(call_entry, entry, next, &env->calls, list) {
- ir_graph *callee;
- irg_inline_property prop;
-
if (env->n_nodes > maxsize)
break;
- call = entry->call;
- callee = entry->callee;
-
- prop = get_irg_inline_property(callee);
- if (prop == irg_inline_forbidden) {
+ ir_node *call = entry->call;
+ ir_graph *callee = entry->callee;
+ ir_entity *called = get_irg_entity(callee);
+ mtp_additional_properties props
+ = get_entity_additional_properties(called);
+ if (props & mtp_property_noinline)
continue;
- }
if (is_leaf(callee) && (
- is_smaller(callee, leafsize) || prop >= irg_inline_forced)) {
+ is_smaller(callee, leafsize) || (props & mtp_property_always_inline))) {
if (!phiproj_computed) {
phiproj_computed = 1;
collect_phiprojs(current_ir_graph);
/* inline other small functions. */
for (i = 0; i < n_irgs; ++i) {
- ir_node *call;
int phiproj_computed = 0;
current_ir_graph = get_irp_irg(i);
/* note that the list of possible calls is updated during the process */
list_for_each_entry_safe(call_entry, entry, next, &env->calls, list) {
- irg_inline_property prop;
- ir_graph *callee;
- ir_graph *calleee;
+ ir_node *call = entry->call;
+ ir_graph *callee = entry->callee;
+ ir_entity *called = get_irg_entity(callee);
- call = entry->call;
- callee = entry->callee;
-
- prop = get_irg_inline_property(callee);
- if (prop == irg_inline_forbidden) {
+ mtp_additional_properties props = get_entity_additional_properties(called);
+ if (props & mtp_property_noinline)
continue;
- }
- calleee = (ir_graph*)pmap_get(copied_graphs, callee);
+ ir_graph *calleee = pmap_get(ir_graph, copied_graphs, callee);
if (calleee != NULL) {
/*
* Remap callee if we have a copy.
callee = calleee;
}
- if (prop >= irg_inline_forced ||
+ if ((props & mtp_property_always_inline) ||
(is_smaller(callee, size) && env->n_nodes < maxsize) /* small function */) {
if (current_ir_graph == callee) {
/*
*/
static unsigned calc_method_local_weight(ir_node *arg)
{
- int i, j, k;
+ int j;
unsigned v, weight = 0;
- for (i = get_irn_n_outs(arg) - 1; i >= 0; --i) {
+ for (unsigned i = get_irn_n_outs(arg); i-- > 0; ) {
ir_node *succ = get_irn_out(arg, i);
switch (get_irn_opcode(succ)) {
ir_node *pred = get_Tuple_pred(succ, j);
if (pred == arg) {
/* look for Proj(j) */
- for (k = get_irn_n_outs(succ) - 1; k >= 0; --k) {
+ for (unsigned k = get_irn_n_outs(succ); k-- > 0; ) {
ir_node *succ_succ = get_irn_out(succ, k);
if (is_Proj(succ_succ)) {
if (get_Proj_proj(succ_succ) == j) {
ir_entity *ent = get_irg_entity(irg);
ir_type *mtp;
size_t nparams;
- int i;
long proj_nr;
ir_node *irg_args, *arg;
assure_irg_outs(irg);
irg_args = get_irg_args(irg);
- for (i = get_irn_n_outs(irg_args) - 1; i >= 0; --i) {
+ for (unsigned i = get_irn_n_outs(irg_args); i-- > 0; ) {
arg = get_irn_out(irg_args, i);
proj_nr = get_Proj_proj(arg);
env->local_weights[proj_nr] = calc_method_local_weight(arg);
int weight = 0;
int all_const;
unsigned cc, v;
- irg_inline_property prop;
inline_irg_env *callee_env;
- prop = get_irg_inline_property(callee);
- if (prop == irg_inline_forbidden) {
+ mtp_additional_properties props = get_entity_additional_properties(ent);
+ if (props & mtp_property_noinline) {
DB((dbg, LEVEL_2, "In %+F Call to %+F: inlining forbidden\n",
call, callee));
return entry->benefice = INT_MIN;
if (is_parameter_entity(frame_ent)) {
// TODO inliner should handle parameter entities by inserting Store operations
DB((dbg, LEVEL_2, "In %+F Call to %+F: inlining forbidden due to parameter entity\n", call, callee));
- set_irg_inline_property(callee, irg_inline_forbidden);
+ add_entity_additional_properties(ent, mtp_property_noinline);
return entry->benefice = INT_MIN;
}
}
- if (get_irg_additional_properties(callee) & mtp_property_noreturn) {
+ if (props & mtp_property_noreturn) {
DB((dbg, LEVEL_2, "In %+F Call to %+F: not inlining noreturn or weak\n",
call, callee));
return entry->benefice = INT_MIN;
static void maybe_push_call(pqueue_t *pqueue, call_entry *call,
int inline_threshold)
{
- ir_graph *callee = call->callee;
- irg_inline_property prop = get_irg_inline_property(callee);
- int benefice = calc_inline_benefice(call, callee);
+ ir_graph *callee = call->callee;
+ int benefice = calc_inline_benefice(call, callee);
DB((dbg, LEVEL_2, "In %+F Call %+F to %+F has benefice %d\n",
get_irn_irg(call->call), call->call, callee, benefice));
- if (prop < irg_inline_forced && benefice < inline_threshold) {
+ ir_entity *ent = get_irg_entity(callee);
+ mtp_additional_properties props = get_entity_additional_properties(ent);
+ if (!(props & mtp_property_always_inline) && benefice < inline_threshold) {
return;
}
{
int phiproj_computed = 0;
inline_irg_env *env = (inline_irg_env*)get_irg_link(irg);
- call_entry *curr_call;
wenv_t wenv;
pqueue_t *pqueue;
ir_graph *callee = curr_call->callee;
ir_node *call_node = curr_call->call;
inline_irg_env *callee_env = (inline_irg_env*)get_irg_link(callee);
- irg_inline_property prop = get_irg_inline_property(callee);
+ ir_entity *ent = get_irg_entity(callee);
+ mtp_additional_properties props
+ = get_entity_additional_properties(ent);
ir_graph *calleee;
int loop_depth;
- const call_entry *centry;
- if ((prop < irg_inline_forced) && env->n_nodes + callee_env->n_nodes > maxsize) {
+ if (!(props & mtp_property_always_inline)
+ && env->n_nodes + callee_env->n_nodes > maxsize) {
DB((dbg, LEVEL_2, "%+F: too big (%d) + %+F (%d)\n", irg,
env->n_nodes, callee, callee_env->n_nodes));
continue;
}
- calleee = (ir_graph*)pmap_get(copied_graphs, callee);
+ calleee = pmap_get(ir_graph, copied_graphs, callee);
if (calleee != NULL) {
int benefice = curr_call->benefice;
/*