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.
28 #include "pcp_error.h"
30 #include "pcp_emitter.h"
31 #include "pcp_scalar_order.h"
34 PcpScalarOrder::Visitor::setIvCount(int ivCount
)
36 this->ivCount
= ivCount
;
40 PcpScalarOrder::Visitor::getIvCount()
46 PcpScalarOrder::Visitor::incrementIvCount()
48 this->setIvCount(this->getIvCount() + 1);
52 PcpScalarOrder::Visitor::decrementIvCount()
54 this->setIvCount(this->getIvCount() - 1);
59 PcpScalarOrder::Visitor::setParameterCount(int parameterCount
)
61 this->parameterCount
= parameterCount
;
65 PcpScalarOrder::Visitor::getParameterCount()
67 return this->parameterCount
;
71 PcpScalarOrder::Visitor::incrementParameterCount()
73 this->setParameterCount(this->getParameterCount() + 1);
77 PcpScalarOrder::Visitor::decrementParameterCount()
79 this->setParameterCount(this->getParameterCount() - 1);
83 PcpScalarOrder::Visitor::setOrderMap(PcpMap
<PcpExpr
*, int>* orderMap
)
85 this->orderMap
= orderMap
;
88 PcpMap
<PcpExpr
*, int>*
89 PcpScalarOrder::Visitor::getOrderMap()
91 return this->orderMap
;
95 PcpScalarOrder::Visitor::visit(PcpScop
* scop
)
97 PcpIterator
<PcpParameter
*>* paramIter
= scop
->getParametersIterator();
98 for(;paramIter
->hasNext(); paramIter
->next())
100 paramIter
->get()->accept(this);
103 scop
->getBody()->accept(this);
107 PcpScalarOrder::Visitor::visit(PcpLoop
* loop
)
109 loop
->getIv()->accept(this);
110 this->incrementIvCount();
111 loop
->getBody()->accept(this);
112 this->decrementIvCount();
116 PcpScalarOrder::Visitor::visit(PcpSequence
* sequence
)
118 this->visitChildren(sequence
);
122 PcpScalarOrder::Visitor::visit(PcpGuard
* guard
)
124 guard
->getBody()->accept(this);
128 PcpScalarOrder::Visitor::visit(PcpIv
* iv
)
130 //printf("IV: (%s, %d)\n", iv->getName(), this->getIvCount());
131 this->getOrderMap()->insert(iv
, this->getIvCount());
136 PcpScalarOrder::Visitor::visit(PcpParameter
* parameter
)
138 //printf("Param: (%s, %d)\n", parameter->getName(), this->getParameterCount());
139 this->getOrderMap()->insert(parameter
, this->getParameterCount());
140 incrementParameterCount();
143 PcpScalarOrder::Visitor::Visitor(PcpMap
<PcpExpr
*, int>* orderMap
)
146 this->setParameterCount(1);
147 this->setOrderMap(orderMap
);
152 PcpScalarOrder::setOrderMap(PcpMap
<PcpExpr
*, int>* orderMap
)
154 this->orderMap
= orderMap
;
157 PcpMap
<PcpExpr
*, int>*
158 PcpScalarOrder::getOrderMap()
160 return this->orderMap
;
164 PcpScalarOrder::equal(PcpExpr
* expr1
, PcpExpr
* expr2
)
166 return expr1
== expr2
|| expr1
->isConstant() && expr2
->isConstant();
170 PcpScalarOrder::less(PcpExpr
* expr1
, PcpExpr
* expr2
)
172 if(this->equal(expr1
, expr2
))
175 if(expr2
->isConstant())
178 if(expr2
->isParameter())
180 if(expr1
->isParameter())
182 int value1
= this->getOrderMap()->lookup(expr1
);
183 int value2
= this->getOrderMap()->lookup(expr2
);
184 pcpAssert(value1
!= value2
);
185 return value1
< value2
;
187 else if(expr1
->isConstant())
193 if(expr2
->isIv() && expr1
->isIv())
195 pcpAssert(this->getOrderMap()->contains(expr1
));
196 pcpAssert(this->getOrderMap()->contains(expr1
));
198 if(!this->getOrderMap()->contains(expr1
))
199 printf("Non existing 1 iv: %s\n", PcpEmitter::pcpExprToString(expr1
));
200 if(!this->getOrderMap()->contains(expr2
))
201 printf("Non existing 2 iv: %s\n", PcpEmitter::pcpExprToString(expr2
));
203 int value1
= this->getOrderMap()->lookup(expr1
);
204 int value2
= this->getOrderMap()->lookup(expr2
);
205 pcpAssert(value1
!= value2
);
206 return value1
< value2
;
212 PcpScalarOrder::PcpScalarOrder(PcpScop
* scop
)
214 this->setOrderMap(new PcpTreeMap
<PcpExpr
*, int>());
215 PcpScalarOrder::Visitor
visitor(this->getOrderMap());