1 // Copyright (C) 2009 Free Software Foundation, Inc.
2 // Contributed by Jan Sjodin <jan.sjodin@amd.com>.
4 // This file is part of the Polyhedral Compilation Package Library (libpcp).
6 // Libpcp is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation; either version 2.1 of the License, or
9 // (at your option) any later version.
11 // Libpcp is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with libpcp; see the file COPYING.LIB. If not, write to the
18 // Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 // MA 02110-1301, USA.
21 // As a special exception, if you link this library with other files, some
22 // of which are compiled with GCC, to produce an executable, this library
23 // does not by itself cause the resulting executable to be covered by the
24 // GNU General Public License. This exception does not however invalidate
25 // any other reasons why the executable file might be covered by the GNU
26 // General Public License.
29 #include "pcp_poly_spi.h"
30 #include "pcp_dynamic_array.h"
31 #include "pcp_string_buffer.h"
33 class PcpPolySpiDummy
: public PcpPolySpi
36 class DummyCoefficient
: public Coefficient
42 class DummyLinearExpr
: public LinearExpr
48 class DummyConstraint
: public Constraint
52 LinearExpr
* linearExpr
;
55 class DummyConstraintSystem
: public ConstraintSystem
60 class DummyPolyhedron
: public Polyhedron
65 class DummyPointsetPowerset
: public PointsetPowerset
69 // Coefficient primitives
70 int coefficientGetValue(Coefficient
* coeff
)
72 return ((DummyCoefficient
*)coeff
)->value
;
75 PcpPolySpi::Coefficient
* coefficientCreate(int value
)
77 DummyCoefficient
* coeff
= new DummyCoefficient();
83 coefficientToString(Coefficient
* coeff
)
85 PcpStringBuffer buffer
;
86 buffer
.appendInt(((DummyCoefficient
*)coeff
)->value
);
87 return buffer
.toString();
90 void coefficientDestroy(Coefficient
* coeff
)
92 delete (DummyCoefficient
*)coeff
;
95 // Linear Expr Primitives
96 PcpPolySpi::LinearExpr
* linearExprCopy(LinearExpr
* linearExpr
)
101 void linearExprAddToCoefficient(LinearExpr
* linearExpr
, int dimension
, Coefficient
* value
)
103 PcpArray
<int>* array
= ((DummyLinearExpr
*)linearExpr
)->array
;
104 array
->set(dimension
, array
->get(dimension
) + ((DummyCoefficient
*)value
)->value
);
107 void linearExprAddToInhomogenous(LinearExpr
* linearExpr
, Coefficient
* value
)
109 PcpArray
<int>* array
= ((DummyLinearExpr
*)linearExpr
)->array
;
110 int index
= array
->getSize()-1;
111 linearExprAddToCoefficient(linearExpr
, index
, value
);
114 void linearExprSetCoefficient(LinearExpr
* linearExpr
, int dimension
, Coefficient
* value
)
116 PcpArray
<int>* array
= ((DummyLinearExpr
*)linearExpr
)->array
;
117 array
->set(dimension
, ((DummyCoefficient
*)value
)->value
);
120 int linearExprGetNumDimensions(LinearExpr
* linearExpr
)
122 return ((DummyLinearExpr
*)linearExpr
)->array
->getSize();
125 void linearExprSubtract(LinearExpr
* linearExpr
, LinearExpr
* subtract
)
131 linearExprToString(LinearExpr
* linearExpr
)
133 PcpArray
<int>* array
= ((DummyLinearExpr
*) linearExpr
)->array
;
134 PcpStringBuffer buffer
;
135 for(int i
= 0; i
< array
->getSize(); i
++)
139 buffer
.appendInt(array
->get(i
));
141 return buffer
.toString();
144 PcpPolySpi::LinearExpr
* linearExprCreate()
149 PcpPolySpi::LinearExpr
* linearExprCreate(int numDimensions
)
151 DummyLinearExpr
* linearExpr
= new DummyLinearExpr();
152 linearExpr
->array
= new PcpArray
<int>(numDimensions
);
156 void linearExprDestroy(LinearExpr
* linearExpr
)
158 delete ((DummyLinearExpr
*)linearExpr
)->array
;
161 // Constraint primitives
162 PcpPolySpi::Constraint
* constraintCreateEqualZero(LinearExpr
* linearExpr
)
164 DummyConstraint
* constraint
= new DummyConstraint();
165 constraint
->kind
= 0;
166 constraint
->linearExpr
= linearExpr
;
170 PcpPolySpi::Constraint
* constraintCreateGreaterEqualZero(LinearExpr
* linearExpr
)
172 DummyConstraint
* constraint
= new DummyConstraint();
173 constraint
->kind
= 1;
174 constraint
->linearExpr
= linearExpr
;
178 void constraintDestroy(Constraint
* constraint
)
180 delete ((DummyConstraint
*)constraint
)->linearExpr
;
184 constraintToString(Constraint
* constraint
)
186 DummyConstraint
* dconstraint
= (DummyConstraint
*) constraint
;
187 PcpStringBuffer buffer
;
188 const char* linearExprString
= linearExprToString(dconstraint
->linearExpr
);
189 buffer
.append(linearExprString
);
190 buffer
.append(dconstraint
->kind
== 0 ? " == 0" : " >= 0");
191 return buffer
.toString();
195 // Polyhedron primitives
196 PcpPolySpi::ConstraintSystem
* polyhedronGetConstraintSystem(Polyhedron
* polyhedron
)
201 void polyhedronAddConstraint(Polyhedron
* polyhedron
, Constraint
* constraint
)
205 void polyhedronAddConstraints(Polyhedron
* polyhedron
, ConstraintSystem
* constraintSystem
)
209 void polyhedronRemap(Polyhedron
* polyhedron
, PcpArray
<int>* map
)
213 PcpPolySpi::Polyhedron
* polyhedronCopy(Polyhedron
* polyhedron
)
218 PcpPolySpi::Polyhedron
* polyhedronCreate(int numDimensions
)
223 void polyhedronDestroy(Polyhedron
* polyhedron
)
227 void pointsetPowersetDestroy(PointsetPowerset
* poinsetPowerset
)
232 PcpPolySpi::PointsetPowerset
* pointsetPowersetCreate(Polyhedron
* polyhedron
)
240 #include "pcp_poly_spi_c.h"
241 PcpPolySpi
* PcpPolySpi::create()
243 //return new PcpPolySpiDummy();
244 return createPPLPolySpi();