OSDN Git Service

2009-08-12 Paolo Bonzini <bonzini@gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / graphite-ppl.h
1 /* Gimple Represented as Polyhedra.
2    Copyright (C) 2009 Free Software Foundation, Inc.
3    Contributed by Sebastian Pop <sebastian.pop@inria.fr>
4    and Tobias Grosser <grosser@fim.uni-passau.de>.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21 #ifndef GCC_GRAPHITE_PPL_H
22 #define GCC_GRAPHITE_PPL_H
23
24 #include "double-int.h"
25 #include "tree.h"
26
27 CloogMatrix *new_Cloog_Matrix_from_ppl_Polyhedron (ppl_const_Polyhedron_t);
28 CloogDomain *new_Cloog_Domain_from_ppl_Polyhedron (ppl_const_Polyhedron_t);
29 CloogDomain * new_Cloog_Domain_from_ppl_Pointset_Powerset (
30   ppl_Pointset_Powerset_C_Polyhedron_t);
31 void new_C_Polyhedron_from_Cloog_Matrix (ppl_Polyhedron_t *, CloogMatrix *);
32 void insert_constraint_into_matrix (CloogMatrix *, int, ppl_const_Constraint_t);
33 ppl_Polyhedron_t ppl_strip_loop (ppl_Polyhedron_t, ppl_dimension_type, int);
34 int ppl_lexico_compare_linear_expressions (ppl_Linear_Expression_t,
35                                            ppl_Linear_Expression_t);
36
37 void ppl_print_polyhedron_matrix (FILE *, ppl_const_Polyhedron_t);
38 void ppl_print_powerset_matrix (FILE *, ppl_Pointset_Powerset_C_Polyhedron_t);
39 void debug_ppl_polyhedron_matrix (ppl_Polyhedron_t);
40 void debug_ppl_powerset_matrix (ppl_Pointset_Powerset_C_Polyhedron_t);
41 void ppl_read_polyhedron_matrix (ppl_Polyhedron_t *, FILE *);
42 void ppl_insert_dimensions (ppl_Polyhedron_t, int, int);
43 void ppl_insert_dimensions_pointset (ppl_Pointset_Powerset_C_Polyhedron_t, int,
44                                      int);
45 void ppl_set_inhomogeneous_gmp (ppl_Linear_Expression_t, Value);
46 void ppl_set_coef_gmp (ppl_Linear_Expression_t, ppl_dimension_type, Value);
47
48 /* Assigns to RES the value of the INTEGER_CST T.  */
49
50 static inline void
51 tree_int_to_gmp (tree t, Value res)
52 {
53   double_int di = tree_to_double_int (t);
54   mpz_set_double_int (res, di, TYPE_UNSIGNED (TREE_TYPE (t)));
55 }
56
57 /* Converts a GMP constant VAL to a tree and returns it.  */
58
59 static inline tree
60 gmp_cst_to_tree (tree type, Value val)
61 {
62   tree t = type ? type : integer_type_node;
63   Value tmp;
64   double_int di;
65
66   value_init (tmp);
67   value_assign (tmp, val);
68   di = mpz_get_double_int (t, tmp, true);
69   value_clear (tmp);
70
71   return double_int_to_tree (t, di);
72 }
73
74 /* Set the inhomogeneous term of E to the integer X.  */
75
76 static inline void
77 ppl_set_inhomogeneous (ppl_Linear_Expression_t e, int x)
78 {
79   Value v;
80   value_init (v);
81   value_set_si (v, x);
82   ppl_set_inhomogeneous_gmp (e, v);
83   value_clear (v);
84 }
85
86 /* Set the inhomogeneous term of E to the tree X.  */
87
88 static inline void
89 ppl_set_inhomogeneous_tree (ppl_Linear_Expression_t e, tree x)
90 {
91   Value v;
92   value_init (v);
93   tree_int_to_gmp (x, v);
94   ppl_set_inhomogeneous_gmp (e, v);
95   value_clear (v);
96 }
97
98 /* Set E[I] to integer X.  */
99
100 static inline void
101 ppl_set_coef (ppl_Linear_Expression_t e, ppl_dimension_type i, int x)
102 {
103   Value v;
104   value_init (v);
105   value_set_si (v, x);
106   ppl_set_coef_gmp (e, i, v);
107   value_clear (v);
108 }
109
110 /* Set E[I] to tree X.  */
111
112 static inline void
113 ppl_set_coef_tree (ppl_Linear_Expression_t e, ppl_dimension_type i, tree x)
114 {
115   Value v;
116   value_init (v);
117   tree_int_to_gmp (x, v);
118   ppl_set_coef_gmp (e, i, v);
119   value_clear (v);
120 }
121
122 /* Sets RES to the max of V1 and V2.  */
123
124 static inline void
125 value_max (Value res, Value v1, Value v2)
126 {
127   if (value_compare (v1, v2) < 0)
128     value_assign (res, v2);
129   value_assign (res, v1);
130 }
131
132 /* Builds a new identity map for dimension DIM.  */
133
134 static inline ppl_dimension_type *
135 ppl_new_id_map (ppl_dimension_type dim)
136 {
137   ppl_dimension_type *map, i;
138
139   map = (ppl_dimension_type *) XNEWVEC (ppl_dimension_type, dim);
140
141   for (i = 0; i < dim; i++)
142     map[i] = i;
143
144   return map;
145 }
146
147 /* Builds an interchange of dimensions A and B in MAP.  */
148
149 static inline void
150 ppl_interchange (ppl_dimension_type *map,
151                  ppl_dimension_type a,
152                  ppl_dimension_type b)
153 {
154   map[a] = b;
155   map[b] = a;
156 }
157
158 #endif
159