Candl
0.6.1
|
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <candl/candl.h>
#include <candl/piplib-wrapper.h>
#include <assert.h>
------ ( ----------------------------------------------------------** )\ CAnDL ** ----- / ) --------------------------------------------------------** ( * ( dependence.c ** ---- #/ --------------------------------------------------------** .-"#'-. First version: september 18th 2003 ** --- |"-.-"| -------------------------------------------------------** | | | | | | ************************************************************* CAnDL '-._,-' the Chunky Analyzer for Dependences in Loops (experimental) *
* Copyright (C) 2003-2008 Cedric Bastoul * * This is free software; you can redistribute it and/or modify it under the * terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 3 of the License, or (at your option) * any later version. * * This software is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with software; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * CAnDL, the Chunky Dependence Analyzer * Written by Cedric Bastoul, Cedric.Bastoul@inria.fr * *
void candl_compute_last_writer | ( | CandlDependence * | dep, |
CandlProgram * | prog | ||
) |
Compute the last writer for each RAW, WAW, and RAR dependence. This will modify the dependence polyhedra. Be careful of any references to the old dependence polyhedra. They are freed and new ones allocated.
References candl_dep_compute_lastwriter(), CANDL_RAR, CANDL_RAW, CANDL_WAW, candldependence::next, and candldependence::type.
Referenced by candl_dependence().
static int candl_dep_compute_lastwriter | ( | CandlDependence ** | dep, |
CandlProgram * | prog | ||
) | [static] |
References CANDL_assign, candl_dependence_malloc(), candl_program::context, candldependence::depth, candldependence::next, quast_to_polyhedra(), candldependence::ref_source, candldependence::ref_target, candldependence::source, candldependence::target, candldependence::type, and candldependence::usr.
Referenced by candl_compute_last_writer().
candl_dependence_p candl_dependence | ( | candl_program_p | program, |
CandlOptions * | options | ||
) |
candl_dependence function: this function builds the dependence graph of a program (program) according to some user options (options).
References candl_compute_last_writer(), candl_dependence_add(), candl_dependence_analyze_scalars(), candl_dependence_between(), candl_dependence_prune_scalar_waw(), candl_dependence_prune_transitively_covered(), candl_dependence_prune_with_privatization(), candl_dependence_scalar_renaming(), candl_program::context, candloptions::lastwriter, candl_program::nb_statements, candloptions::prune_dups, candloptions::scalar_expansion, candloptions::scalar_privatization, candloptions::scalar_renaming, and candl_program::statement.
Referenced by candl_dependence_scalar_renaming(), candl_violation(), and main().
void candl_dependence_add | ( | candl_dependence_p * | start, |
candl_dependence_p * | now, | ||
candl_dependence_p | dependence | ||
) |
candl_dependence_add function: This function adds a CandlDependence structure (dependence) at a given place (now) of a NULL terminated list of CandlDependence structures. The beginning of this list is (start). This function updates (now) to the end of the loop list (loop), and updates (start) if the added element is the first one -that is when (start) is NULL-.
References candldependence::next.
Referenced by candl_dependence(), and candl_dependence_between().
int candl_dependence_analyze_scalars | ( | candl_program_p | program, |
CandlOptions * | options | ||
) |
candl_dependence_analyze_scalars function: This function checks, for all scalar variables of the program, and all loop levels, if the scalar can be privatized at that level.
References candl_dependence_check_domain_is_included(), candl_dependence_expand_scalar(), candl_dependence_extract_scalar_variables(), candl_dependence_refvar_chain(), candl_dependence_var_is_ref(), CANDL_get_si, CANDL_set_si, CANDL_VAR_IS_DEF, CANDL_VAR_UNDEF, candl_program::context, candlstatement::index, max, candl_program::nb_statements, candloptions::scalar_expansion, candloptions::scalar_privatization, candl_program::scalars_privatizable, candl_program::statement, candloptions::verbose, and candlstatement::written.
Referenced by candl_dependence(), candl_dependence_prune_with_privatization(), and candl_dependence_scalar_is_privatizable_at().
candl_dependence_p candl_dependence_between | ( | CandlStatement * | source, |
CandlStatement * | target, | ||
CandlMatrix * | context, | ||
CandlOptions * | options | ||
) |
candl_dependence_between function : this function builds the dependence list from the statement "source" to statement "target": it will study the dependence for each reference and for each depth, under a particular context (context) and according to some user options.
References candl_dependence_add(), candl_dependence_system(), CANDL_eq, CANDL_notzero_p, CANDL_RAR, CANDL_RAW, candl_statement_commute(), CANDL_WAR, CANDL_WAW, candloptions::commute, candlstatement::depth, candlstatement::index, candloptions::rar, candloptions::raw, candlstatement::read, candloptions::war, candloptions::waw, and candlstatement::written.
Referenced by candl_dependence().
static CandlMatrix* candl_dependence_build_system | ( | CandlStatement * | source, |
CandlStatement * | target, | ||
CandlMatrix * | array_s, | ||
CandlMatrix * | array_t, | ||
int | ref_s, | ||
int | ref_t, | ||
int | depth, | ||
int | before, | ||
int | nb_par | ||
) | [static] |
candl_dependence_build_system function: this function builds the constraint system corresponding to a data dependence, for a given statement couple (with iteration domains "source" and "target"), for a given reference couple (the source reference is array "ref_s" in "array_s" and the target reference is the array "ref_t" in "array_t"), at a given depth "depth" and knowing if the source is textually before the target (boolean "before"). The system is built... as always ! See the [bastoul and Feautrier, PPL 2005] paper for details !
References CANDL_assign, CANDL_clear, CANDL_init, candl_matrix_malloc(), CANDL_oppose, CANDL_set_si, and CANDL_subtract.
Referenced by candl_dependence_system().
int candl_dependence_check_domain_is_included | ( | CandlStatement * | s1, |
CandlStatement * | s2, | ||
CandlMatrix * | context, | ||
int | level | ||
) |
candl_dependence_check_domain_is_included function: This function checks if the 'level'-first iterators of 2 domains are in such a way that s1 is larger or equal to s2, for the considered iterator dimensions.
References CANDL_assign, CANDL_clear, CANDL_decrement, candl_dependence_compute_lb(), CANDL_get_si, CANDL_init, candl_matrix_check_point(), candl_matrix_free(), candl_matrix_malloc(), CANDL_oppose, CANDL_set_si, candlstatement::depth, candlstatement::domain, and max.
Referenced by candl_dependence_analyze_scalars(), and candl_dependence_scalar_renaming().
static void candl_dependence_compute_lb | ( | CandlMatrix * | m, |
Entier * | lb, | ||
int | col | ||
) | [static] |
candl_dependence_compute_lb function: This function assigns to the Entier 'lb' the lexmin of variable 'col'-1 in the polyhedron 'm'.
References CANDL_assign.
Referenced by candl_dependence_check_domain_is_included().
static void candl_dependence_expand_scalar | ( | CandlStatement ** | sl, |
int | scalar_idx | ||
) | [static] |
candl_dependence_expand_scalar function: Expand the variable of index 'scalar_idx' by adding one dimension (x becomes x[0]) to each access matrix refering this variable in the statement list.
References CANDL_assign, CANDL_get_si, candl_matrix_free(), candl_matrix_malloc(), CANDL_set_si, candlstatement::read, and candlstatement::written.
Referenced by candl_dependence_analyze_scalars().
int* candl_dependence_extract_scalar_variables | ( | candl_program_p | program | ) |
candl_dependence_extract_scalar_variables function: This functions returns a -1-terminated array of the program scalar variables.
References candl_dependence_var_is_scalar(), CANDL_FAIL, CANDL_get_si, candl_program::nb_statements, candlstatement::read, candl_program::statement, and candlstatement::written.
Referenced by candl_dependence_analyze_scalars(), candl_dependence_prune_scalar_waw(), and candl_dependence_scalar_renaming().
void candl_dependence_free | ( | candl_dependence_p | dependence | ) |
References candl_matrix_free(), candldependence::domain, and candldependence::next.
Referenced by candl_dependence_scalar_renaming(), and main().
static int candl_dependence_gcd | ( | int | a, |
int | b | ||
) | [static] |
GCD computation.
Referenced by candl_dependence_gcd_test().
int candl_dependence_gcd_test | ( | CandlStatement * | source, |
CandlStatement * | target, | ||
CandlMatrix * | system, | ||
int | level | ||
) |
candl_dependence_gcd_test function: This functions performs a GCD test on a dependence polyhedra represented exactly by a set of constraints 'system' organized in such a way:
The function returns false if the dependence is impossible, true otherwise. A series of simple checks (SIV/ZIV/MIV/bounds checking) are also performed before the actual GCD test.
References candl_dependence_gcd(), candl_dependence_gcd_test_context(), CANDL_get_si, candlstatement::depth, and candlstatement::domain.
Referenced by candl_dependence_system().
static int candl_dependence_gcd_test_context | ( | CandlMatrix * | system, |
int | id | ||
) | [static] |
Referenced by candl_dependence_gcd_test().
static void candl_dependence_get_array_refs_in_dep | ( | CandlDependence * | tmp, |
int * | refs, | ||
int * | reft | ||
) | [static] |
candl_dependence_get_array_refs_in_dep function: This function return the array indices referenced in the dependence.
References CANDL_get_si, CANDL_RAR, CANDL_RAW, CANDL_WAR, CANDL_WAW, candlstatement::read, candldependence::ref_source, candldependence::ref_target, candldependence::source, candldependence::target, candldependence::type, and candlstatement::written.
Referenced by candl_dependence_prune_scalar_waw(), and candl_dependence_prune_with_privatization().
int candl_dependence_is_loop_carried | ( | candl_program_p | program, |
CandlDependence * | dep, | ||
int | loop_index | ||
) |
candl_dependence_is_loop_carried function: This function returns true if the dependence 'dep' is loop-carried for loop 'loop_index', false otherwise.
References CANDL_assign, CANDL_get_si, candl_matrix_free(), candl_matrix_malloc(), CANDL_RAR, CANDL_RAW, CANDL_set_si, CANDL_WAR, candlstatement::depth, candldependence::depth, candldependence::domain, candlstatement::index, pip_has_rational_point(), candlstatement::read, candldependence::ref_source, candldependence::ref_target, candldependence::source, candldependence::target, candldependence::type, and candlstatement::written.
Referenced by candl_dependence_prune_with_privatization().
candl_dependence_malloc function: This function allocates the memory space for a CandlDependence structure and sets its fields with default values. Then it returns a pointer to the allocated space.
References CANDL_FAIL, CANDL_UNSET, candldependence::depth, candldependence::domain, candldependence::next, candldependence::ref_source, candldependence::ref_target, candldependence::source, candldependence::target, candldependence::type, and candldependence::usr.
Referenced by candl_dep_compute_lastwriter(), candl_dependence_read_one_dep(), and candl_dependence_system().
void candl_dependence_pprint | ( | FILE * | file, |
candl_dependence_p | dependence | ||
) |
References CANDL_RAR, CANDL_RAW, CANDL_RELEASE, CANDL_UNSET, CANDL_VERSION, CANDL_WAR, CANDL_WAW, candldependence::depth, candlstatement::label, candldependence::next, candldependence::ref_source, candldependence::ref_target, candldependence::source, candldependence::target, and candldependence::type.
Referenced by candl_dependence_view(), and main().
void candl_dependence_print | ( | FILE * | file, |
candl_dependence_p | dependence | ||
) |
References candl_dependence_print_structure().
Referenced by main().
void candl_dependence_print_scop | ( | FILE * | input, |
FILE * | output, | ||
CandlDependence * | dependence | ||
) |
Print the scop, containing the list of dependences.
References candl_dependence_update_scop_with_deps().
Referenced by main().
void candl_dependence_print_structure | ( | FILE * | file, |
candl_dependence_p | dependence, | ||
int | level | ||
) |
candl_dependence_print_structure function: Displays a CandlDependence structure (dependence) into a file (file, possibly stdout) in a way that trends to be understandable without falling in a deep depression or, for the lucky ones, getting a headache... It includes an indentation level (level) in order to work with others print_structure functions.
References candl_matrix_print_structure(), CANDL_RAR, CANDL_RAW, candl_statement_print_structure(), CANDL_UNSET, CANDL_WAR, CANDL_WAW, candldependence::depth, candldependence::domain, candldependence::next, candldependence::source, candldependence::target, and candldependence::type.
Referenced by candl_dependence_print(), and candl_violation_print_structure().
void candl_dependence_prune_scalar_waw | ( | candl_program_p | program, |
CandlOptions * | options, | ||
CandlDependence ** | deps | ||
) |
candl_dependence_prune_scalar_waw function: This function removes all WAW dependences between the same scalar (they are useless dependences).
References candl_dependence_extract_scalar_variables(), candl_dependence_get_array_refs_in_dep(), candl_matrix_free(), CANDL_WAW, candldependence::domain, candldependence::next, candldependence::type, and candloptions::verbose.
Referenced by candl_dependence().
void candl_dependence_prune_with_privatization | ( | candl_program_p | program, |
CandlOptions * | options, | ||
CandlDependence ** | deps | ||
) |
candl_dependence_prune_with_privatization function: This function prunes the dependence graph 'deps' by removing loop-carried dependences involving a scalar variable privatizable for that loop.
References candl_dependence_analyze_scalars(), candl_dependence_get_array_refs_in_dep(), candl_dependence_is_loop_carried(), candl_dependence_scalar_is_privatizable_at(), candl_matrix_free(), candl_options_free(), candl_options_malloc(), candlstatement::depth, candldependence::domain, candlstatement::index, candl_program::nb_statements, candldependence::next, candloptions::scalar_privatization, candl_program::scalars_privatizable, candldependence::source, candldependence::target, and candloptions::verbose.
Referenced by candl_dependence().
CandlDependence* candl_dependence_read_from_scop | ( | scoplib_scop_p | scop, |
CandlProgram * | program | ||
) |
Retrieve a CandlDependence list from the option tag in the scop.
References candl_dependence_read_one_dep(), and candldependence::next.
static CandlDependence* candl_dependence_read_one_dep | ( | char * | str, |
char ** | next, | ||
CandlProgram * | program | ||
) | [static] |
candl_dependence_print_scop function: This function adds to the .scop file provided as the 'input' the optional tags to represent the dependences 'dependence' of the program. Finally, it prints the updated .scop to the file 'output'. Read one dependence from a string.
References candl_dependence_malloc(), candl_matrix_malloc(), CANDL_RAR, CANDL_RAW, CANDL_set_si, CANDL_WAR, CANDL_WAW, candldependence::depth, candldependence::domain, candlstatement::label, candl_program::nb_statements, candlstatement::read, candldependence::ref_source, candldependence::ref_target, candldependence::source, candl_program::statement, candldependence::target, candldependence::type, and candlstatement::written.
Referenced by candl_dependence_read_from_scop().
CandlStatement** candl_dependence_refvar_chain | ( | candl_program_p | program, |
CandlStatement * | dom, | ||
int | var_index, | ||
int | level | ||
) |
candl_dependence_refvar_chain function: This function returns a chain of statements as a feshly allocated array of pointer on statements, of all statements reading or writing the variable 'var_index', surrounded by the 'level' common loops of 'dom'. Output is a NULL-terminated array.
References candl_dependence_var_is_ref(), CANDL_VAR_UNDEF, candlstatement::depth, candlstatement::index, candl_program::nb_statements, and candl_program::statement.
Referenced by candl_dependence_analyze_scalars(), and candl_dependence_scalar_renaming().
int candl_dependence_scalar_is_privatizable_at | ( | candl_program_p | program, |
int | var_index, | ||
int | loop_index | ||
) |
candl_dependence_is_privatizable function: This function checks if a given scalar 'var_index' is privatizable for loop 'loop_index'.
References candl_dependence_analyze_scalars(), candl_options_free(), candl_options_malloc(), candloptions::scalar_privatization, and candl_program::scalars_privatizable.
Referenced by candl_dependence_prune_with_privatization().
int candl_dependence_scalar_renaming | ( | candl_program_p | program, |
CandlOptions * | options, | ||
CandlDependence ** | deps | ||
) |
candl_dependence_scalar_renaming function: This function renames scalars in the program. In case scalars have been renamed, the dependence analysis is re-run.
References candl_dependence(), candl_dependence_check_domain_is_included(), candl_dependence_extract_scalar_variables(), candl_dependence_free(), candl_dependence_refvar_chain(), candl_dependence_var_is_ref(), CANDL_get_si, CANDL_set_si, CANDL_VAR_IS_DEF, CANDL_VAR_IS_DEF_USED, CANDL_VAR_IS_USED, candl_program::context, candlstatement::depth, candlstatement::index, candlstatement::label, candl_program::nb_statements, candlstatement::read, candloptions::scalar_privatization, candloptions::scalar_renaming, candl_program::scalars_privatizable, candl_program::statement, candloptions::verbose, and candlstatement::written.
Referenced by candl_dependence().
candl_dependence_p candl_dependence_system | ( | CandlStatement * | source, |
CandlStatement * | target, | ||
CandlMatrix * | context, | ||
CandlMatrix * | array_s, | ||
CandlMatrix * | array_t, | ||
int | ref_s, | ||
int | ref_t, | ||
int | type, | ||
int | depth | ||
) |
candl_dependence_system function : this function builds a node of the dependence graph: it studies a dependence between a given statement couple, reference couple, type and depth. If a data dependence actually exists, it returns a dependence structure, it returns NULL otherwise.
References candl_dependence_build_system(), candl_dependence_gcd_test(), candl_dependence_malloc(), candl_matrix_free(), candldependence::depth, candldependence::domain, candlstatement::label, pip_has_rational_point(), candldependence::ref_source, candldependence::ref_target, candldependence::source, candldependence::target, and candldependence::type.
Referenced by candl_dependence_between().
void candl_dependence_update_scop_with_deps | ( | scoplib_scop_p | scop, |
CandlDependence * | dependence | ||
) |
Update the scop option tag with the dependence list.
References CANDL_FAIL, and candl_program_deps_to_string().
Referenced by candl_dependence_print_scop().
int candl_dependence_var_is_ref | ( | CandlStatement * | s, |
int | var_index | ||
) |
candl_dependence_var_is_ref function: This function checks if a var 'var_index' is referenced (DEF or USE) by the statement.
References CANDL_get_si, CANDL_VAR_IS_DEF, CANDL_VAR_IS_DEF_USED, CANDL_VAR_IS_USED, CANDL_VAR_UNDEF, candlstatement::read, and candlstatement::written.
Referenced by candl_dependence_analyze_scalars(), candl_dependence_refvar_chain(), and candl_dependence_scalar_renaming().
int candl_dependence_var_is_scalar | ( | candl_program_p | program, |
int | var_index | ||
) |
candl_dependence_var_is_scalar function: This function returns true if the variable indexed by 'var_index' is a scalar in the whole program.
References CANDL_get_si, candl_program::nb_statements, candlstatement::read, candl_program::statement, and candlstatement::written.
Referenced by candl_dependence_extract_scalar_variables().
void candl_dependence_view | ( | candl_dependence_p | dependence | ) |
References candl_dependence_pprint(), and CANDL_TEMP_OUTPUT.
Referenced by main().
int candl_num_dependences | ( | CandlDependence * | candl_deps | ) |
candl_num_dependences function: This function returns the number of dependences in the dependence list
dependence | The first dependence of the dependence list. |
References candldependence::next.
static char* candl_program_deps_to_string | ( | CandlDependence * | dependence | ) | [static] |
Returns a string containing the dependence, formatted to fit the .scop representation.
References CANDL_FAIL, CANDL_get_si, CANDL_RAR, CANDL_RAW, CANDL_UNSET, CANDL_WAR, CANDL_WAW, candldependence::depth, candldependence::domain, candlstatement::label, candldependence::next, candlstatement::read, candldependence::ref_source, candldependence::ref_target, candldependence::source, candldependence::target, candldependence::type, and candlstatement::written.
Referenced by candl_dependence_update_scop_with_deps().
static PipMatrix** quast_to_polyhedra | ( | PipQuast * | quast, |
int * | num, | ||
int | nvar, | ||
int | npar | ||
) | [static] |
References CANDL_assign, CANDL_get_si, and CANDL_set_si.
Referenced by candl_dep_compute_lastwriter().