PIPS
|
add inlining support to pips, with two flavors More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "genC.h"
#include "linear.h"
#include "ri.h"
#include "effects.h"
#include "ri-util.h"
#include "prettyprint.h"
#include "effects-util.h"
#include "text.h"
#include "pipsdbm.h"
#include "workspace-util.h"
#include "resources.h"
#include "properties.h"
#include "misc.h"
#include "callgraph.h"
#include "effects-generic.h"
#include "effects-convex.h"
#include "preprocessor.h"
#include "text-util.h"
#include "parser_private.h"
#include "pipsmake.h"
#include "accel-util.h"
Go to the source code of this file.
Data Structures | |
struct | iparam |
structure containing all the parameters needed by inlining. More... | |
Functions | |
unfolding | |
static bool | run_inlining (string caller_name, const char *module_name, inlining_parameters p) |
get ressources for the call to inline and call apropriate inlining function More... | |
static bool | do_unfolding (inlining_parameters p, char *module_name) |
this should inline all call in module ‘module_name’ it does not works recursievly, so multiple pass may be needed returns true if at least one function has been inlined More... | |
bool | unfolding (char *module_name) |
perform unfolding using effect More... | |
bool | unfolding_simple (char *module_name) |
perform unfolding without using effects More... | |
inlining | |
#define | IPARAM_INIT |
#define | inlined_module(p) (p)->_inlined_module_ |
#define | inlined_module_statement(p) (p)->_inlined_module_statement_ |
#define | new_statements(p) (p)->_new_statements_ |
#define | has_static_declaration(p) (p)->_has_static_declaration_ |
#define | has_inlinable_calls(p) (p)->_has_inlinable_calls_ |
#define | laststmt(p) (p)->_laststmt_ |
#define | tail_ins(p) (p)->_tail_ins_ |
#define | returned_entity(p) (p)->_returned_entity_ |
#define | use_effects(p) (p)->_use_effects_ |
typedef struct iparam * | inlining_parameters |
static statement | expanded |
static void | inline_return_remover (statement s, inlining_parameters p) |
replace return instruction by a goto More... | |
static void | inline_return_crawler (statement s, inlining_parameters p) |
replace return instruction by an assignment and a goto More... | |
static bool | inline_should_inline (entity inlined_module, call callee) |
helper function to check if a call is a call to the inlined function More... | |
static bool | has_similar_entity (entity e, set se) |
static void | solve_name_clashes (statement s, entity new) |
look for entity locally named has ‘new’ in statements ‘s’ when found, find a new name and perform substitution More... | |
static bool | inline_has_static_declaration (list iter) |
return true if an entity declared in ‘iter’ is static to ‘module’ More... | |
static void | statement_with_static_declarations_p (statement s, inlining_parameters p) |
return true if an entity declared in the statement ‘s’ from ‘p->inlined_module’ More... | |
static entity | make_temporary_scalar_entity (expression from, statement *assign) |
create a scalar similar to ‘efrom’ initialized with expression ‘from’ More... | |
static void | inlining_regenerate_labels (statement s, entity new_module) |
regenerate the label of each statement with a label. More... | |
bool | has_entity_with_same_name (entity e, list l) |
inlining.c More... | |
static void | do_slightly_rename_entities (statement s, hash_table old_new) |
static void | slightly_rename_entities (statement s) |
sg: this is another inlining mostruosity it ensures all entities in s have new pointer and different name (is it usefull ?) it takes care of dependant types More... | |
static statement | inline_expression_call (inlining_parameters p, expression modified_expression, call callee) |
this should inline the call callee calling module inlined_module More... | |
static void | inline_expression (expression expr, inlining_parameters p) |
recursievly inline an expression if needed More... | |
static void | inline_has_inlinable_calls_crawler (call callee, inlining_parameters p) |
check if a call has inlinable calls More... | |
static bool | inline_has_inlinable_calls (entity inlined_module, void *elem) |
static void | inline_statement_crawler (statement stmt, inlining_parameters p) |
this is in charge of replacing instruction by new ones only apply if this instruction does not contain other instructions More... | |
static void | inline_split_declarations (statement s, entity inlined_module) |
split the declarations from s from their initialization if they contain a call to inlined_module More... | |
static void | inline_calls (inlining_parameters p, char *module) |
this should replace all call to ‘inlined’ in ‘module’ by the expansion of ‘inlined’ More... | |
static bool | do_inlining (inlining_parameters p, const char *module_name) |
this should inline all calls to module ‘module_name’ in calling modules, if possible ... More... | |
bool | inlining (const char *module_name) |
perform inlining using effects More... | |
bool | inlining_simple (const char *module_name) |
perform inlining without using effects More... | |
add inlining support to pips, with two flavors
Definition in file inlining.c.
#define has_inlinable_calls | ( | p | ) | (p)->_has_inlinable_calls_ |
Definition at line 99 of file inlining.c.
#define has_static_declaration | ( | p | ) | (p)->_has_static_declaration_ |
Definition at line 98 of file inlining.c.
#define inlined_module | ( | p | ) | (p)->_inlined_module_ |
Definition at line 95 of file inlining.c.
#define inlined_module_statement | ( | p | ) | (p)->_inlined_module_statement_ |
Definition at line 96 of file inlining.c.
#define IPARAM_INIT |
Definition at line 84 of file inlining.c.
#define laststmt | ( | p | ) | (p)->_laststmt_ |
Definition at line 100 of file inlining.c.
#define new_statements | ( | p | ) | (p)->_new_statements_ |
Definition at line 97 of file inlining.c.
#define returned_entity | ( | p | ) | (p)->_returned_entity_ |
Definition at line 102 of file inlining.c.
#define tail_ins | ( | p | ) | (p)->_tail_ins_ |
Definition at line 101 of file inlining.c.
#define use_effects | ( | p | ) | (p)->_use_effects_ |
Definition at line 103 of file inlining.c.
typedef struct iparam * inlining_parameters |
|
static |
this should inline all calls to module ‘module_name’ in calling modules, if possible ...
module_name | name of the module to inline |
Get the module ressource
check them
parse filter property
or get module's callers
inline call in each caller
Should have worked:
Definition at line 885 of file inlining.c.
References callees_callees, caller_name, CONS, db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, db_resource_p(), debug_off, debug_on, ENDP, entity_function_p(), entity_subroutine_p(), FOREACH, gen_remove_once(), get_bool_property(), get_string_property(), inline_calls(), inlined_module, inlined_module_statement, module_name(), module_name_to_entity(), NIL, pips_assert, pips_debug, recompile_module(), reset_cumulated_rw_effects(), same_string_p, set_cumulated_rw_effects(), statement_undefined_p, strdup(), STRING, and use_effects.
Referenced by inlining(), and inlining_simple().
|
static |
forge a new name with a magical block number
beacause of bottom up transversal, we are sure old_new has already been fed
Definition at line 262 of file inlining.c.
References asprintf, BLOCK_SEP_STRING, copy_entity(), declaration_statement_p(), ENDP, entity_name, entity_user_name(), formal_parameter_p(), free(), hash_get(), hash_put(), HASH_UNDEFINED_VALUE, int, POP, REFCAR, statement_block_p, statement_declarations, and strndup().
Referenced by slightly_rename_entities().
|
static |
this should inline all call in module ‘module_name’ it does not works recursievly, so multiple pass may be needed returns true if at least one function has been inlined
module_name | name of the module to unfold |
parse filter property
parse callee property
gather all referenced calls as long as there are some
gather all referenced calls
maybe the user put a restriction on the calls to inline ?
maybe the user used a filter ?
there is something to inline
Definition at line 1032 of file inlining.c.
References callees_callees, compute_callees(), db_get_memory_resource(), debug_off, debug_on, FOREACH, free(), free_callees(), gen_free_list(), gen_map(), gen_qsort_string_cmp(), get_bool_property(), get_string_property(), module_name(), pips_debug, pips_user_warning, recompile_module(), remove_useless_label(), run_inlining(), set_add_element(), set_assign_list(), set_difference(), set_empty_p(), set_free(), set_intersection(), set_make(), set_string, set_to_sorted_list(), strdup(), STRING, and strsplit().
Referenced by unfolding(), and unfolding_simple().
Definition at line 256 of file inlining.c.
References ENTITY, FOREACH, and same_entity_name_p().
Referenced by check_private_variables_loop_walker(), inline_expression_call(), and outliner_independent_recursively().
Definition at line 148 of file inlining.c.
References entity_user_name(), same_string_p, and SET_FOREACH.
Referenced by solve_name_clashes().
|
static |
this should replace all call to ‘inlined’ in ‘module’ by the expansion of ‘inlined’
get target module's ressources
first pass : convert some declaration with assignment to declarations + statements, if needed
inline all calls to inlined_module
Definition at line 848 of file inlining.c.
References compute_callees(), db_get_memory_resource(), DB_PUT_MEMORY_RESOURCE, entity_user_name(), gen_context_recurse, gen_true2(), ifdebug, inline_split_declarations(), inline_statement_crawler(), inlined_module, module, module_name_to_entity(), pips_assert, pips_debug, print_statement(), reset_current_module_entity(), reset_current_module_statement(), set_current_module_entity(), set_current_module_statement(), statement_consistent_p(), statement_domain, and statement_undefined_p.
Referenced by do_inlining(), and run_inlining().
|
static |
recursievly inline an expression if needed
Definition at line 705 of file inlining.c.
References callee, expression_call_p(), expression_syntax, ifdebug, inline_expression_call(), inline_should_inline(), inlined_module, insert_statement(), new_statements, pips_debug, print_statement(), statement_consistent_p(), statement_undefined_p, and syntax_call.
Referenced by inline_statement_crawler().
|
static |
this should inline the call callee calling module inlined_module
only inline the right call
stop if the function has static declaration
create the new instruction sequence no need to change all entities in the new statements, because we build a new text resource later sg: not so true, because of dependant types
add external declarations for all extern referenced entities it is needed because inlined module and current module may not share the same compilation unit. Not relevant for Fortran
FI: However, it would be nice to check first if the entity is not already in the scope for the function or in the scope of its compilation unit (OK, the later is difficult because the order of declarations has to be taken into account).
special hook for struct member : consider their structure instead of the field
enum member cannot be added to declarations
formal parameters are not considered
g: unsafe sg: I am unsure this is still needed
ensure block status
avoid duplicated label due to copy_statement
add label at the end of the statement
fix ‘return’ calls in case a goto is immediately followed by its targeted label the goto is not needed (SG: seems difficult to do in the previous gen_recurse)
only replace return statement by gotos
replace by affectation + goto
create new variable to receive computation result
do the replacement
change the caller from an expression call to a call to a constant
... or to a reference
fix declarations
retrieve formal parameters
store association between new and old declarations
some basic checks
iterate over the parameters and perform substitution between formal and actual parameters
check if there is a write effect on this parameter
generate a copy for this parameter
fix value
add the entity to our list
substitute variables
get new reference
need a temporary variable
this one is more complicated than I thought, what of the side effect of the call ? we must create a new variable holding the call result before
need a temporary variable
check wether the substitution will cause naming clashes then perform the substitution
SG: C dependant types are a pain in the a**, we fix them here, that is perform substitution if needed
add declaration at the beginning of the statement
final cleanings
Definition at line 314 of file inlining.c.
References AddEntityToCurrentModule(), AddEntityToDeclarations(), AddEntityToModuleCompilationUnit(), AddLocalEntityToDeclarations(), ADDRESS_OF_OPERATOR_NAME, c_module_p(), call_arguments, call_function, callee, CAR, cast_expression, CDR, code_declarations, code_decls_text, code_externs, compare_entities(), compilation_unit_of_module(), CONS, copy_basic(), copy_expression(), copy_statement(), copy_storage(), copy_type(), copy_value(), DEREFERENCING_OPERATOR_NAME, empty_string_p(), ENDP, ENTITY, entity_area_p(), entity_basic(), entity_code(), entity_constant_p, entity_declarations, entity_enum_member_p(), entity_field_p(), entity_field_to_entity_struct_or_union(), entity_formal_p(), entity_initial, entity_intrinsic(), entity_local_name(), entity_module_name(), entity_pointer_p(), entity_scalar_p(), entity_storage, entity_to_expression(), entity_type, entity_undefined, entity_undefined_p, entity_user_name(), entity_variable_p, expanded, EXPRESSION, expression_constant_p(), expression_syntax, expression_undefined, extern_entity_p(), find_write_effect_on_entity(), FindEntity(), FindOrCreateEntity(), fix_statement_attributes_if_sequence(), FOREACH, formal_parameter_p(), free(), free_expression(), functional_result, gen_append(), gen_context_recurse, gen_free_list(), gen_full_copy_list(), gen_last(), gen_length(), gen_recurse, gen_true(), gen_true2(), get_bool_property(), get_current_module_entity(), get_current_module_name(), get_referenced_entities(), has_entity_with_same_name(), has_static_declaration, ifdebug, implicit_c_variable_p(), inline_has_static_declaration(), inline_return_crawler(), inline_return_remover(), inline_should_inline(), inlined_module, inlined_module_statement, inlining_regenerate_labels(), insert_statement(), instruction_sequence, instruction_to_statement(), is_syntax_call, is_syntax_cast, is_syntax_reference, is_syntax_sizeofexpression, is_syntax_subscript, laststmt, make_assign_statement(), make_call(), make_continue_statement(), make_empty_block_statement(), make_global_entity_from_local(), make_instruction_sequence(), make_new_array_variable_with_prefix(), make_new_label(), make_new_scalar_variable_with_prefix(), make_reference(), make_sequence(), make_syntax_call(), make_syntax_reference(), make_temporary_pointer_to_array_entity(), make_temporary_scalar_entity(), make_value_expression(), MakeUnaryCall(), module_formal_parameters(), module_name_to_entity(), NIL, pips_assert, pips_debug, pips_internal_error, pips_user_warning, POP, print_statement(), reference_indices, reference_variable, replace_entity(), replace_entity_by_expression(), returned_entity, same_string_p, sequence_statements, set_free(), set_to_sorted_list(), slightly_rename_entities(), solve_name_clashes(), STATEMENT, statement_block_p, statement_consistent_p(), statement_domain, statement_instruction, statement_undefined, statement_undefined_p, statement_with_static_declarations_p(), strdup(), syntax_call, syntax_cast, syntax_reference, syntax_tag, tail_ins, type_functional, type_variable, type_variable_p, type_void_p, unnormalize_expression(), use_effects, value_code, value_code_p, variable_basic, variable_dimensions, variable_entity_p(), and variable_static_p().
Referenced by inline_expression().
Definition at line 736 of file inlining.c.
References iparam::_inlined_module_, call_domain, gen_context_recurse, gen_true2(), has_inlinable_calls, inline_has_inlinable_calls_crawler(), and inlined_module.
Referenced by inline_split_declarations(), and inline_statement_crawler().
|
static |
check if a call has inlinable calls
Definition at line 729 of file inlining.c.
References callee, gen_recurse_stop(), has_inlinable_calls, inline_should_inline(), and inlined_module.
Referenced by inline_has_inlinable_calls().
return true if an entity declared in ‘iter’ is static to ‘module’
Definition at line 194 of file inlining.c.
References ENTITY, FOREACH, and variable_static_p().
Referenced by inline_expression_call(), and statement_with_static_declarations_p().
|
static |
replace return instruction by an assignment and a goto
Definition at line 118 of file inlining.c.
References call_arguments, CAR, CDR, CONS, copy_expression(), copy_statement(), ENDP, entity_to_expression(), EXPRESSION, instruction_to_statement(), laststmt, make_assign_statement(), make_instruction_goto(), make_instruction_sequence(), make_sequence(), make_statement_list, NIL, pips_assert, return_statement_p(), returned_entity, STATEMENT, statement_call(), statement_instruction, tail_ins, and update_statement_instruction().
Referenced by inline_expression_call().
|
static |
replace return instruction by a goto
Definition at line 109 of file inlining.c.
References copy_statement(), laststmt, make_instruction_goto(), return_statement_p(), and update_statement_instruction().
Referenced by inline_expression_call().
helper function to check if a call is a call to the inlined function
Definition at line 143 of file inlining.c.
References call_function, callee, inlined_module, and same_entity_lname_p().
Referenced by inline_expression(), inline_expression_call(), and inline_has_inlinable_calls_crawler().
split the declarations from s from their initialization if they contain a call to inlined_module
the first condition is a bit tricky : check int a = foo(); int b=bar(); once we decide to inline foo(), we must split b=bar() because foo may touch a global variable used in bar()
Definition at line 808 of file inlining.c.
References CONS, copy_expression(), declaration_statement_p(), ENDP, ENTITY, entity_initial, entity_to_expression(), FOREACH, free_value(), gen_free_list(), inline_has_inlinable_calls(), inlined_module, insert_statement(), make_assign_statement(), make_value_unknown(), NIL, pips_user_warning, set_add_element(), set_free(), set_make(), set_pointer, STATEMENT, statement_block_p, statement_declarations, value_expression, value_expression_p, and value_undefined_p.
Referenced by inline_calls().
|
static |
this is in charge of replacing instruction by new ones only apply if this instruction does not contain other instructions
the gen_recurse can only handle expressions, so we turn this call into an expression
something happens on the way to heaven
Definition at line 749 of file inlining.c.
References asprintf, call_to_expression(), CAR, continue_statement_p(), control_domain, copy_call(), copy_instruction(), ENDP, entity_type, entity_user_name(), expression_domain, free(), functional_result, gen_context_recurse, gen_get_ancestor(), gen_true2(), get_bool_property(), ifdebug, inline_expression(), inline_has_inlinable_calls(), inlined_module, insert_comments_to_statement(), insert_statement(), instruction_call, instruction_call_p, instruction_to_statement(), int_to_expression(), make_block_statement(), make_instruction_expression(), make_instruction_test(), make_test(), new_statements, NIL, pips_debug, POP, print_statement(), STATEMENT, statement_block(), statement_block_p, statement_consistent_p(), statement_instruction, type_functional, type_void_p, and update_statement_instruction().
Referenced by inline_calls().
bool inlining | ( | const char * | module_name | ) |
perform inlining using effects
module_name | name of the module to inline |
module_name | odule_name |
Definition at line 957 of file inlining.c.
References do_inlining(), IPARAM_INIT, module_name(), and use_effects.
regenerate the label of each statement with a label.
it avoid duplications due to copy_statement
Definition at line 236 of file inlining.c.
References entity_empty_label_p(), entity_local_name(), entity_undefined_p, find_label_entity(), FindOrCreateEntity(), label_local_name(), loop_label, make_new_label(), module_local_name(), statement_label, statement_loop(), and statement_loop_p().
Referenced by inline_expression_call().
bool inlining_simple | ( | const char * | module_name | ) |
perform inlining without using effects
module_name | name of the module to inline |
module_name | odule_name |
Definition at line 971 of file inlining.c.
References do_inlining(), IPARAM_INIT, module_name(), and use_effects.
|
static |
create a scalar similar to ‘efrom’ initialized with expression ‘from’
create the scalar
set intial
Definition at line 216 of file inlining.c.
References copy_expression(), entity_to_expression(), expression_consistent_p(), expression_undefined_p, get_current_module_entity(), make_assign_statement(), make_new_scalar_variable(), pips_assert, and some_basic_of_any_expression().
Referenced by inline_expression_call().
|
static |
get ressources for the call to inline and call apropriate inlining function
caller_name | calling module name |
module_name | called module name |
Get the module ressource
check them
inline call
Definition at line 992 of file inlining.c.
References caller_name, db_get_memory_resource(), ENDP, entity_function_p(), entity_subroutine_p(), inline_calls(), inlined_module, inlined_module_statement, module_name(), module_name_to_entity(), pips_assert, pips_user_warning, reset_cumulated_rw_effects(), set_cumulated_rw_effects(), statement_block(), statement_block_p, statement_undefined_p, and use_effects.
Referenced by do_unfolding().
|
static |
sg: this is another inlining mostruosity it ensures all entities in s have new pointer and different name (is it usefull ?) it takes care of dependant types
Definition at line 298 of file inlining.c.
References do_slightly_rename_entities(), gen_context_recurse, gen_true2(), HASH_DEFAULT_SIZE, HASH_FOREACH, hash_pointer, hash_table_free(), hash_table_make(), replace_entities(), and statement_domain.
Referenced by inline_expression_call().
look for entity locally named has ‘new’ in statements ‘s’ when found, find a new name and perform substitution
Definition at line 163 of file inlining.c.
References asprintf, CAR, copy_entity(), ENDP, ENTITY, entity_name, entity_user_name(), expanded, free(), gen_recurse_stop(), get_referenced_entities(), has_similar_entity(), implicit_c_variable_p(), POP, replace_entity(), same_string_p, set_free(), statement_declarations, and strdup().
Referenced by inline_expression_call().
|
static |
return true if an entity declared in the statement ‘s’ from ‘p->inlined_module’
Definition at line 208 of file inlining.c.
References has_static_declaration, inline_has_static_declaration(), and statement_declarations.
Referenced by inline_expression_call().
bool unfolding | ( | char * | module_name | ) |
perform unfolding using effect
module_name | name of the module to unfold |
module_name | odule_name |
Definition at line 1118 of file inlining.c.
References do_unfolding(), IPARAM_INIT, module_name(), and use_effects.
bool unfolding_simple | ( | char * | module_name | ) |
perform unfolding without using effects
module_name | name of the module to unfold |
module_name | odule_name |
Definition at line 1133 of file inlining.c.
References do_unfolding(), IPARAM_INIT, module_name(), and use_effects.
|
static |
Definition at line 157 of file inlining.c.
Referenced by array_expansion(), do_array_expansion(), do_array_expansion_aux(), inline_expression_call(), and solve_name_clashes().