Fix DealII type problems.
[official-gcc/Ramakrishna.git] / libpcp / pcp_poly.cc
blobee1d773f7514cc7cb7cbd40f2a464cbf478b3ccf
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
14 // more details.
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.
28 #include "pcp_poly.h"
31 // PcpPoly
32 PcpPoly* PcpPoly::theDefault = NULL;
34 PcpPoly* PcpPoly::getDefault()
36 if(PcpPoly::theDefault == NULL)
38 theDefault = new PcpPoly(PcpPolySpi::create());
40 return theDefault;
43 PcpPoly::PcpPoly(PcpPolySpi* spi)
45 setSpi(spi);
48 void
49 PcpPoly::setSpi(PcpPolySpi* spi)
51 this->spi = spi;}
53 PcpPolySpi*
54 PcpPoly::getSpi()
56 return this->spi;
59 int
60 PcpPoly::coefficientGetValue(PcpPolySpi::Coefficient* coefficient)
62 return getSpi()->coefficientGetValue(coefficient);
65 const char*
66 PcpPoly::coefficientToString(PcpPolySpi::Coefficient* coefficient)
68 return getSpi()->coefficientToString(coefficient);
72 PcpPolySpi::Coefficient*
73 PcpPoly::coefficientCreate(int value)
75 return getSpi()->coefficientCreate(value);
78 void
79 PcpPoly::coefficientDestroy(PcpPolySpi::Coefficient* coefficient)
81 getSpi()->coefficientDestroy(coefficient);
84 PcpPolySpi::LinearExpr*
85 PcpPoly::linearExprCopy(PcpPolySpi::LinearExpr* linearExpr)
87 return getSpi()->linearExprCopy(linearExpr);
90 void
91 PcpPoly::linearExprAddToCoefficient(PcpPolySpi::LinearExpr* linearExpr,
92 int dimension,
93 PcpPolySpi::Coefficient* coefficient)
95 getSpi()->linearExprAddToCoefficient(linearExpr, dimension, coefficient);
98 void
99 PcpPoly::linearExprAddToCoefficient(PcpPolySpi::LinearExpr* linearExpr, int dimension, int value)
101 getSpi()->linearExprAddToCoefficient(linearExpr, dimension, getSpi()->coefficientCreate(value));
104 void
105 PcpPoly::linearExprAddToInhomogenous(PcpPolySpi::LinearExpr* linearExpr, PcpPolySpi::Coefficient* value)
107 getSpi()->linearExprAddToInhomogenous(linearExpr, value);
110 void
111 PcpPoly::linearExprAddToInhomogenous(PcpPolySpi::LinearExpr* linearExpr, int value)
113 getSpi()->linearExprAddToInhomogenous(linearExpr, getSpi()->coefficientCreate(value));
116 void
117 PcpPoly::linearExprSetCoefficient(PcpPolySpi::LinearExpr* linearExpr, int dimension,
118 PcpPolySpi::Coefficient* coefficient)
120 return getSpi()->linearExprSetCoefficient(linearExpr, dimension, coefficient);
123 void
124 PcpPoly::linearExprSetCoefficient(PcpPolySpi::LinearExpr* linearExpr, int dimension, int value)
126 return getSpi()->linearExprSetCoefficient(linearExpr, dimension, getSpi()->coefficientCreate(value));
129 void
130 PcpPoly::linearExprSubtract(PcpPolySpi::LinearExpr* linearExpr, PcpPolySpi::LinearExpr* subtract)
132 getSpi()->linearExprSubtract(linearExpr, subtract);
135 const char*
136 PcpPoly::linearExprToString(PcpPolySpi::LinearExpr* linearExpr)
138 return getSpi()->linearExprToString(linearExpr);
142 PcpPolySpi::LinearExpr*
143 PcpPoly::linearExprCreate()
145 return getSpi()->linearExprCreate();
148 PcpPolySpi::LinearExpr*
149 PcpPoly::linearExprCreate(int numDimensions)
151 return getSpi()->linearExprCreate(numDimensions);
154 void
155 PcpPoly::linearExprDestroy(PcpPolySpi::LinearExpr* linearExpr)
157 getSpi()->linearExprDestroy(linearExpr);
161 PcpPolySpi::Constraint*
162 PcpPoly::constraintCreateEqualZero(PcpPolySpi::LinearExpr* linearExpr)
164 return getSpi()->constraintCreateEqualZero(linearExpr);
167 PcpPolySpi::Constraint*
168 PcpPoly::constraintCreateGreaterEqualZero(PcpPolySpi::LinearExpr* linearExpr)
170 return getSpi()->constraintCreateGreaterEqualZero(linearExpr);
173 void
174 PcpPoly::constraintDestroy(PcpPolySpi::Constraint* constraint)
176 getSpi()->constraintDestroy(constraint);
179 const char*
180 PcpPoly::constraintToString(PcpPolySpi::Constraint* constraint)
182 getSpi()->constraintToString(constraint);
185 PcpPolySpi::ConstraintSystem*
186 PcpPoly::polyhedronGetConstraintSystem(PcpPolySpi::Polyhedron* polyhedron)
188 return getSpi()->polyhedronGetConstraintSystem(polyhedron);
191 void
192 PcpPoly::polyhedronAddConstraint(PcpPolySpi::Polyhedron* polyhedron,
193 PcpPolySpi::Constraint* constraint)
195 getSpi()->polyhedronAddConstraint(polyhedron, constraint);
198 void
199 PcpPoly::polyhedronAddConstraints(PcpPolySpi::Polyhedron* polyhedron,
200 PcpPolySpi::ConstraintSystem* constraintSystem)
202 getSpi()->polyhedronAddConstraints(polyhedron, constraintSystem);
205 void
206 PcpPoly::polyhedronRemap(PcpPolySpi::Polyhedron* polyhedron, PcpArray<int>* map)
208 getSpi()->polyhedronRemap(polyhedron, map);
211 PcpPolySpi::Polyhedron*
212 PcpPoly::polyhedronCopy(PcpPolySpi::Polyhedron* polyhedron)
214 getSpi()->polyhedronCopy(polyhedron);
217 PcpPolySpi::Polyhedron*
218 PcpPoly::polyhedronCreate(int numDimensions)
220 return getSpi()->polyhedronCreate(numDimensions);
223 void
224 PcpPoly::polyhedronDestroy(PcpPolySpi::Polyhedron* polyhedron)
226 getSpi()->polyhedronDestroy(polyhedron);
229 PcpPolySpi::PointsetPowerset*
230 PcpPoly::pointsetPowersetCreate(PcpPolySpi::Polyhedron* polyhedron)
232 return getSpi()->pointsetPowersetCreate(polyhedron);
235 void
236 PcpPoly::pointsetPowersetDestroy(PcpPolySpi::PointsetPowerset* poinsetPowerset)
238 return pointsetPowersetDestroy(poinsetPowerset);
241 ///////////////////////////////////////////////////////////////////////////////
242 // PcpPolyCoefficient
244 void
245 PcpPolyCoefficient::setCoefficient(PcpPolySpi::Coefficient* coefficient)
247 this->coefficient = coefficient;
250 PcpPolySpi::Coefficient*
251 PcpPolyCoefficient::getCoefficient()
253 return this->coefficient;
256 void
257 PcpPolyCoefficient::setValue(int value)
259 setCoefficient(PcpPoly::getDefault()->coefficientCreate(value));
263 PcpPolyCoefficient::getValue()
265 return PcpPoly::getDefault()->coefficientGetValue(this->getCoefficient());
268 PcpPolyCoefficient::PcpPolyCoefficient(int value)
270 setValue(value);
273 PcpPolyCoefficient::~PcpPolyCoefficient()
275 PcpPoly::getDefault()->coefficientDestroy(this->getCoefficient());
278 // PcpPolyLinearExpr
279 void
280 PcpPolyLinearExpr::setLinearExpr(PcpPolySpi::LinearExpr* linearExpr)
282 this->linearExpr = linearExpr;
285 PcpPolySpi::LinearExpr*
286 PcpPolyLinearExpr::getLinearExpr()
288 return this->linearExpr;
292 PcpPolyLinearExpr*
293 PcpPolyLinearExpr::copy()
295 PcpPoly::getDefault()->linearExprCopy(this->getLinearExpr());
298 void
299 PcpPolyLinearExpr::addToCoefficient(int dimension, int value)
301 PcpPoly::getDefault()->linearExprAddToCoefficient(this->getLinearExpr(), dimension, value);
304 void
305 PcpPolyLinearExpr::addToInhomogenous(int value)
307 PcpPoly::getDefault()->linearExprAddToInhomogenous(this->getLinearExpr(), value);
310 void
311 PcpPolyLinearExpr::setCoefficient(int dimension, int value)
313 PcpPoly::getDefault()->linearExprSetCoefficient(this->getLinearExpr(), dimension, value);
316 void
317 PcpPolyLinearExpr::subtract(PcpPolyLinearExpr* expr)
319 PcpPoly::getDefault()->linearExprSubtract(this->getLinearExpr(), expr->getLinearExpr());
322 const char* PcpPolyLinearExpr::toString()
324 return PcpPoly::getDefault()->linearExprToString(this->getLinearExpr());
328 PcpPolyLinearExpr::PcpPolyLinearExpr()
330 this->setLinearExpr(PcpPoly::getDefault()->linearExprCreate());
333 PcpPolyLinearExpr::PcpPolyLinearExpr(int numDimensions)
335 this->setLinearExpr(PcpPoly::getDefault()->linearExprCreate(numDimensions));
338 PcpPolyLinearExpr::~PcpPolyLinearExpr()
340 PcpPoly::getDefault()->linearExprDestroy(this->getLinearExpr());
343 ///////////////////////////////////////////////////////////////////////////////
344 // PcpPolyConstraint
346 void
347 PcpPolyConstraint::setOperator(PcpPolyConstraintOperator oper)
349 this->oper = oper;
352 PcpPolyConstraintOperator
353 PcpPolyConstraint::getOperator()
355 return this->oper;
358 void
359 PcpPolyConstraint::setConstraint(PcpPolySpi::Constraint* constraint)
361 this->constraint = constraint;
364 PcpPolySpi::Constraint*
365 PcpPolyConstraint::getConstraint()
367 return this->constraint;
370 const char*
371 PcpPolyConstraint::toString()
373 return PcpPoly::getDefault()->constraintToString(this->getConstraint());
377 PcpPolyConstraint::PcpPolyConstraint(PcpPolyConstraintOperator oper,
378 PcpPolyLinearExpr* expr)
380 this->setOperator(oper);
381 PcpPolySpi::LinearExpr* spiExpr = expr->getLinearExpr();
382 this->setConstraint(oper.isEqualZero()
383 ? PcpPoly::getDefault()->constraintCreateEqualZero(spiExpr)
384 : PcpPoly::getDefault()->constraintCreateGreaterEqualZero(spiExpr));
387 PcpPolyConstraint::~PcpPolyConstraint()
389 PcpPoly::getDefault()->constraintDestroy(this->getConstraint());
392 ///////////////////////////////////////////////////////////////////////////////
393 // PcpPolyConstraintSystem
395 void
396 PcpPolyConstraintSystem::setConstraintSystem(PcpPolySpi::ConstraintSystem* constraintSystem)
398 this->constraintSystem = constraintSystem;
401 PcpPolySpi::ConstraintSystem*
402 PcpPolyConstraintSystem::getConstraintSystem()
404 return this->constraintSystem;
407 PcpPolyConstraintSystem::PcpPolyConstraintSystem(PcpPolySpi::ConstraintSystem* constraintSystem)
409 this->setConstraintSystem(constraintSystem);
412 ///////////////////////////////////////////////////////////////////////////////
413 // PcpPolyPolyhedron
415 void
416 PcpPolyPolyhedron::setPolyhedron(PcpPolySpi::Polyhedron* polyhedron)
418 this->polyhedron = polyhedron;
421 PcpPolySpi::Polyhedron*
422 PcpPolyPolyhedron::getPolyhedron()
424 return this->polyhedron;
427 PcpPolyConstraintSystem*
428 PcpPolyPolyhedron::getConstraintSystem()
430 PcpPolySpi::Polyhedron* polyhedron = this->getPolyhedron();
431 return new PcpPolyConstraintSystem(PcpPoly::getDefault()->polyhedronGetConstraintSystem(polyhedron));
434 void
435 PcpPolyPolyhedron::addConstraint(PcpPolyConstraint* constraint)
437 PcpPoly::getDefault()->polyhedronAddConstraint(this->getPolyhedron(), constraint->getConstraint());
440 void
441 PcpPolyPolyhedron::addConstraints(PcpPolyConstraintSystem* constraintSystem)
443 PcpPoly::getDefault()->polyhedronAddConstraints(this->getPolyhedron(),
444 constraintSystem->getConstraintSystem());
447 void
448 PcpPolyPolyhedron::remap(PcpArray<int>* map)
450 PcpPoly::getDefault()->polyhedronRemap(this->getPolyhedron(), map);
453 PcpPolyPolyhedron::PcpPolyPolyhedron(PcpPolyPolyhedron* polyhedron)
455 this->setPolyhedron(PcpPoly::getDefault()->polyhedronCopy(polyhedron->getPolyhedron()));
458 PcpPolyPolyhedron::PcpPolyPolyhedron(int numDimensions)
460 this->setPolyhedron(PcpPoly::getDefault()->polyhedronCreate(numDimensions));
463 PcpPolyPolyhedron::~PcpPolyPolyhedron()
465 PcpPoly::getDefault()->polyhedronDestroy(this->getPolyhedron());
468 ///////////////////////////////////////////////////////////////////////////////
469 void PcpPolyPointsetPowerset::setPointsetPowerset(PcpPolySpi::PointsetPowerset* pointsetPowerset)
471 this->pointsetPowerset = pointsetPowerset;
474 PcpPolySpi::PointsetPowerset*
475 PcpPolyPointsetPowerset::getPointsetPowerset()
477 return this->pointsetPowerset;
480 PcpPolyPointsetPowerset::PcpPolyPointsetPowerset(PcpPolyPolyhedron* polyhedron)
482 this->setPointsetPowerset(PcpPoly::getDefault()->pointsetPowersetCreate(polyhedron->getPolyhedron()));
485 PcpPolyPointsetPowerset::~PcpPolyPointsetPowerset()
487 PcpPoly::getDefault()->pointsetPowersetDestroy(this->getPointsetPowerset());