コード例 #1
0
ファイル: matrix.c プロジェクト: periscop/cloog
/**
 * Read a matrix in PolyLib format from input.
 */
CloogMatrix *cloog_matrix_read_of_size(FILE *input,
	unsigned n_row, unsigned n_col)
{
	CloogMatrix *M;
	unsigned int i, j;
	char line[1024];
	char val[1024];
	char *p;

	M = cloog_matrix_alloc(n_row, n_col);
	if (!M)
		cloog_die("memory overflow.\n");
	for (i = 0; i < n_row; ++i) {
		int offset;
		int n;

		p = next_line(input, line, sizeof(line));
		if (!p)
			cloog_die("Input error.\n");
		for (j = 0; j < n_col; ++j) {
			n = sscanf(p, "%s%n", val, &offset);
			if (!n)
				cloog_die("Input error.\n");
			cloog_int_read(M->p[i][j], val);
			p += offset;
		}
	}

	return M;
}
コード例 #2
0
static CloogMatrix *
new_Cloog_Matrix_from_ppl_Constraint_System (ppl_const_Constraint_System_t pcs)
{
  CloogMatrix *matrix;
  ppl_Constraint_System_const_iterator_t cit, end;
  ppl_dimension_type dim;
  int rows;
  int row = 0;

  rows = ppl_Constrain_System_number_of_constraints (pcs);
  ppl_Constraint_System_space_dimension (pcs, &dim);
  matrix = cloog_matrix_alloc (rows, dim + 2);
  ppl_new_Constraint_System_const_iterator (&cit);
  ppl_new_Constraint_System_const_iterator (&end);

  for (ppl_Constraint_System_begin (pcs, cit),
        ppl_Constraint_System_end (pcs, end);
       !ppl_Constraint_System_const_iterator_equal_test (cit, end);
       ppl_Constraint_System_const_iterator_increment (cit))
    {
      ppl_const_Constraint_t c;
      ppl_Constraint_System_const_iterator_dereference (cit, &c);
      insert_constraint_into_matrix (matrix, row, c);
      row++;
    }

  ppl_delete_Constraint_System_const_iterator (cit);
  ppl_delete_Constraint_System_const_iterator (end);

  return matrix;
}
コード例 #3
0
ファイル: constraintset.c プロジェクト: Ced/cloog
/**
 * Create a CloogConstraintSet containing enough information to perform
 * a reduction on the upper equality (in this case lower is an invalid
 * CloogConstraint) or the pair of inequalities upper and lower
 * from within insert_modulo_guard.
 * In the PolyLib backend, we return a CloogConstraintSet containting only
 * the upper bound.  The reduction will not change the stride so there
 * will be no need to recompute the bound on the modulo expression.
 */
CloogConstraintSet *cloog_constraint_set_for_reduction(CloogConstraint *upper,
	 CloogConstraint *lower)
{
	CloogConstraintSet *set;

	set = cloog_constraint_set_from_cloog_matrix(
		cloog_matrix_alloc(1, upper->set->M.NbColumns));
	cloog_seq_cpy(set->M.p[0], upper->line[0], set->M.NbColumns);
	return set;
}
コード例 #4
0
static
CloogMatrix* convert_to_cloogmatrix(scoplib_matrix_p mat)
{
  CloogMatrix* ret = cloog_matrix_alloc (mat->NbRows, mat->NbColumns);

  int i, j;
  for (i = 0; i < mat->NbRows; ++i)
    for (j = 0; j < mat->NbColumns; ++j)
      cloog_int_set_si(ret->p[i][j], SCOPVAL_get_si(mat->p[i][j]));

  return ret;
}
コード例 #5
0
ファイル: constraintset.c プロジェクト: Ced/cloog
/**
 * cloog_constraint_set_copy function:
 * this functions builds and returns a "hard copy" (not a pointer copy) of a
 * CloogMatrix data structure.
 * - October 26th 2005: first version.
 */
CloogConstraintSet *cloog_constraint_set_copy(CloogConstraintSet *constraints)
{ int i, j ;
  CloogMatrix *copy;
  CloogMatrix *matrix = &constraints->M;

  copy = cloog_matrix_alloc(matrix->NbRows, matrix->NbColumns);
  
  for (i=0;i<matrix->NbRows;i++)
  for (j=0;j<matrix->NbColumns;j++)
      cloog_int_set(copy->p[i][j], matrix->p[i][j]);
  
  return cloog_constraint_set_from_cloog_matrix(copy);
}
コード例 #6
0
ファイル: constraintset.c プロジェクト: Ced/cloog
CloogEqualities *cloog_equal_alloc(int n, int nb_levels,
			int nb_parameters)
{
    int i;
    CloogEqualities *equal = ALLOC(CloogEqualities);

    equal->constraints = cloog_constraint_set_from_cloog_matrix(
		cloog_matrix_alloc(n, nb_levels + nb_parameters + 1));
    equal->types = ALLOCN(int, n);
    for (i = 0; i < n; ++i)
	equal->types[i] = EQTYPE_NONE;
    return equal;
}
コード例 #7
0
ファイル: constraintset.c プロジェクト: Ced/cloog
/**
 * cloog_constraint_set_simplify function:
 * this function simplify all constraints inside the matrix "matrix" thanks to
 * an equality matrix "equal" that gives for some elements of the affine
 * constraint an equality with other elements, preferably constants.
 * For instance, if a row of the matrix contains i+j+3>=0 and the equality
 * matrix gives i=n and j=2, the constraint is simplified to n+3>=0. The
 * simplified constraints are returned back inside a new simplified matrix.
 * - matrix is the set of constraints to simplify,
 * - equal is the matrix of equalities,
 * - level is a level we don't want to simplify (-1 if none),
 * - nb_par is the number of parameters of the program.
 **
 * - November 4th 2005: first version.
 */
CloogConstraintSet *cloog_constraint_set_simplify(CloogConstraintSet *constraints,
	CloogEqualities *equal, int level, int nb_par)
{ int i, j, k ;
	struct cloog_vec *vector;
  CloogMatrix *simplified;
  CloogMatrix *matrix = &constraints->M;
  
  if (matrix == NULL)
  return NULL ;
  
  /* The simplified matrix is such that each row has been simplified thanks
   * tho the "equal" matrix. We allocate the memory for the simplified matrix,
   * then for each row of the original matrix, we compute the simplified
   * vector and we copy its content into the according simplified row.
   */
  simplified = cloog_matrix_alloc(matrix->NbRows, matrix->NbColumns);
  for (i=0;i<matrix->NbRows;i++)
  { vector = cloog_equal_vector_simplify(equal, matrix->p[i],
					  matrix->NbColumns, level, nb_par);
    for (j=0;j<matrix->NbColumns;j++)
    cloog_int_set(simplified->p[i][j], vector->p[j]);
    
    cloog_vec_free(vector);
  }
  
  /* After simplification, it may happen that few constraints are the same,
   * we remove them here by replacing them with 0=0 constraints.
   */
  for (i=0;i<simplified->NbRows;i++)
  for (j=i+1;j<simplified->NbRows;j++)
  { for (k=0;k<simplified->NbColumns;k++)
    if (cloog_int_ne(simplified->p[i][k],simplified->p[j][k]))
    break ;
    
    if (k == matrix->NbColumns)
    { for (k=0;k<matrix->NbColumns;k++)
        cloog_int_set_si(simplified->p[j][k],0);
    }
  }
  
  return cloog_constraint_set_from_cloog_matrix(simplified);
}