/** * pip_relation2matrix function : * This function is used to keep the compatibility with Piplib */ PipMatrix* pip_relation2matrix(osl_relation_p in) { int i, j, precision; PipMatrix *out; if (in == NULL) return NULL; #ifdef CANDL_LINEAR_VALUE_IS_INT precision = OSL_PRECISION_SP; #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG) precision = OSL_PRECISION_DP; #elif defined(CANDL_LINEAR_VALUE_IS_MP) precision = OSL_PRECISION_MP; #endif if (precision != in->precision) CANDL_error("Precision not compatible with piplib ! (pip_relation2matrix)"); out = pip_matrix_alloc(in->nb_rows, in->nb_columns); for (i = 0 ; i < in->nb_rows ; i++) { for (j = 0 ; j < in->nb_columns ; j++) { #if defined(CANDL_LINEAR_VALUE_IS_INT) CANDL_assign(out->p[i][j], in->m[i][j].sp); #elif defined(CANDL_LINEAR_VALUE_IS_LONGLONG) CANDL_assign(out->p[i][j], in->m[i][j].dp); #elif defined(CANDL_LINEAR_VALUE_IS_MP) CANDL_assign(out->p[i][j], *((mpz_t*)in->m[i][j].mp)); #endif } } return out; }
/** * candl_util_statement_commute function: * This function returns 1 if the two statements given as parameter commute, * 0 otherwise. It uses the statement type information to answer the question. * - 09/12/2005: first version. */ int candl_util_statement_commute(osl_statement_p statement1, osl_statement_p statement2) { candl_statement_usr_p usr1, usr2; int type1, type2; int precision = statement1->domain->precision; int row_1, row_2; usr1 = statement1->usr; usr2 = statement2->usr; type1 = usr1->type; type2 = usr2->type; /* In the case of self-dependence, a statement commutes with hitself if * it is a reduction. */ if ((statement1 == statement2) && ((type1 == OSL_DEPENDENCE_P_REDUCTION) || (type1 == OSL_DEPENDENCE_M_REDUCTION) || (type1 == OSL_DEPENDENCE_T_REDUCTION))) return 1; /* Two statement commute when they are a reduction of the same type (or if * their left and right members are the same, but it's not exploited here). * The type may differ if it is either minus or plus-reduction. Furthermore, * they have to write onto the same array (and only one array). */ if ((type1 == OSL_DEPENDENCE_P_REDUCTION && type2 == OSL_DEPENDENCE_P_REDUCTION) || (type1 == OSL_DEPENDENCE_M_REDUCTION && type2 == OSL_DEPENDENCE_M_REDUCTION) || (type1 == OSL_DEPENDENCE_T_REDUCTION && type2 == OSL_DEPENDENCE_T_REDUCTION) || (type1 == OSL_DEPENDENCE_P_REDUCTION && type2 == OSL_DEPENDENCE_M_REDUCTION) || (type1 == OSL_DEPENDENCE_M_REDUCTION && type2 == OSL_DEPENDENCE_P_REDUCTION)) { /* Here we check that there is one, only one and the same array. */ if (count_nb_access(statement1, OSL_TYPE_WRITE) > 1 || count_nb_access(statement2, OSL_TYPE_WRITE) > 1) return 0; /* search the first osl_write access */ osl_relation_list_p access1 = statement1->access; osl_relation_list_p access2 = statement2->access; for (; access1 != NULL && access2 != NULL ; access1 = access1->next, access2 = access2->next) if (access1->elt->type == OSL_TYPE_WRITE) break; if (access1 == NULL || access2 == NULL || access2->elt->type != OSL_TYPE_WRITE || access2->elt->nb_output_dims != access1->elt->nb_output_dims) { osl_statement_dump(stderr, statement1); osl_statement_dump(stderr, statement2); CANDL_error("These statements haven't the same access array or access is NULL"); } /* Check if the first dim (the Arr column) is the same */ row_1 = candl_relation_get_line(access1->elt, 0); row_2 = candl_relation_get_line(access2->elt, 0); if (!osl_int_eq(precision, access1->elt->m[row_1][access1->elt->nb_columns - 1], access2->elt->m[row_2][access2->elt->nb_columns - 1])) return 0; return 1; } return 0; }
/** * candl_options_read function: * This functions reads all the options and the input/output files thanks * the the user's calling line elements (in argc). It fills a candl_options_t * structure and the FILE structure corresponding to input and output files. * August 5th 2002: first version. * April 19th 2003: now in options.c and support of the candl_options_t structure. */ void candl_options_read(int argc, char** argv, FILE** input, FILE** output, FILE **input_test, candl_options_p* options) { int i, infos = 0, input_is_set = 0, testscop_is_set = 0; /* candl_options_t structure allocation and initialization. */ *options = candl_options_malloc(); /* The default output is the standard output. */ *output = stdout; *input_test = NULL; for (i = 1; i < argc; i++) { if (argv[i][0] == '-') { if (!strcmp(argv[i], "-waw")) { candl_options_set(&(*options)->waw, argc, argv, &i); } else if (!strcmp(argv[i], "-raw")) { candl_options_set(&(*options)->raw, argc, argv, &i); } else if (!strcmp(argv[i], "-war")) { candl_options_set(&(*options)->war, argc, argv, &i); } else if (!strcmp(argv[i], "-rar")) { candl_options_set(&(*options)->rar, argc, argv, &i); } else if (!strcmp(argv[i], "-commute")) { candl_options_set(&(*options)->commute, argc, argv, &i); } else if (!strcmp(argv[i], "-fullcheck")) { candl_options_set(&(*options)->fullcheck, argc, argv, &i); } else if (!strcmp(argv[i], "-scalren")) { candl_options_set(&(*options)->scalar_renaming, argc, argv, &i); } else if (!strcmp(argv[i], "-scalpriv")) { candl_options_set(&(*options)->scalar_privatization, argc, argv, &i); } else if (!strcmp(argv[i], "-scalexp")) { candl_options_set(&(*options)->scalar_expansion, argc, argv, &i); } else if (!strcmp(argv[i], "-lastwriter")) { candl_options_set(&(*options)->lastwriter, argc, argv, &i); } else if (!strcmp(argv[i], "-autocorrect")) { candl_options_set(&(*options)->autocorrect, argc, argv, &i); } else if (!strcmp(argv[i], "-view")) { (*options)->view = 1; } else if (!strcmp(argv[i], "-unions")) { candl_options_set(&(*options)->unions, argc, argv, &i); } else if (!strcmp(argv[i], "-verbose")) { (*options)->verbose = 1; } else if (!strcmp(argv[i], "-outscop")) { (*options)->outscop = 1; } else if (!strcmp(argv[i], "-prune-dups")) { (*options)->prune_dups = 1; } else if ((!strcmp(argv[i], "-struct")) || (!strcmp(argv[i], "-structure"))) { (*options)->structure = 1; } else if ((!strcmp(argv[i], "--help")) || (!strcmp(argv[i], "-h"))) { candl_options_help(); infos = 1; } else if ((!strcmp(argv[i], "--version")) || (!strcmp(argv[i], "-v"))) { candl_options_version(); infos = 1; } else if (!strcmp(argv[i], "-o")) { i++; if (i >= argc) { fprintf(stderr, "[Candl]ERROR: no output name for -o option.\n"); exit(1); } /* stdout is a special value, when used, we set output to standard * output. */ if (!strcmp(argv[i], "stdout")) { *output = stdout; } else { *output = fopen(argv[i], "w"); if (*output == NULL) { fprintf(stderr, "[Candl]ERROR: can't create output file %s.\n", argv[i]); exit(1); } } } else if (!strcmp(argv[i], "-test")) { i++; if (!testscop_is_set) { testscop_is_set = i; /* stdin is a special value, when used, we set input to standard input. */ if (!strcmp(argv[i], "stdin")) { *input_test = stdin; } else { *input_test = fopen(argv[i], "r"); if (*input_test == NULL) { fprintf(stderr, "[Candl]ERROR: %s file does not exist.\n", argv[i]); exit(1); } } } else { fprintf(stderr, "[Candl]ERROR: multiple input files.\n"); exit(1); } } else { fprintf(stderr, "[Candl]ERROR: unknown %s option.\n", argv[i]); } } else { /* open a file */ if (!input_is_set) { input_is_set = i; /* stdin is a special value, when used, we set input to standard input. */ if (!strcmp(argv[i], "stdin")) { *input = stdin; } else { *input = fopen(argv[i], "r"); if (*input == NULL) { fprintf(stderr, "[Candl]ERROR: %s file does not exist.\n", argv[i]); exit(1); } } } else { CANDL_error("multiple input files.\n"); } } } if ((*options)->autocorrect) { (*options)->fullcheck = 1; if (!*input_test) CANDL_error("no test file (-h for help).\n"); } if (!input_is_set) { if (!infos) CANDL_error("no input file (-h for help).\n"); exit(1); } if (*input_test && !strcmp(argv[input_is_set], argv[testscop_is_set])) { if (!infos) CANDL_error("the input file and the test scop can't be the same file.\n"); exit(1); } if (infos) exit(0); }