Remove outermost loop parameter.
[official-gcc/graphite-test-results.git] / libpcp / pcp_scalar_order.cc
blobf992d567507195437f5eb4d17418d07256326582
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_error.h"
29 #include "pcp.h"
30 #include "pcp_emitter.h"
31 #include "pcp_scalar_order.h"
33 void
34 PcpScalarOrder::Visitor::setIvCount(int ivCount)
36 this->ivCount = ivCount;
39 int
40 PcpScalarOrder::Visitor::getIvCount()
42 return this->ivCount;
45 void
46 PcpScalarOrder::Visitor::incrementIvCount()
48 this->setIvCount(this->getIvCount() + 1);
51 void
52 PcpScalarOrder::Visitor::decrementIvCount()
54 this->setIvCount(this->getIvCount() - 1);
58 void
59 PcpScalarOrder::Visitor::setParameterCount(int parameterCount)
61 this->parameterCount = parameterCount;
64 int
65 PcpScalarOrder::Visitor::getParameterCount()
67 return this->parameterCount;
70 void
71 PcpScalarOrder::Visitor::incrementParameterCount()
73 this->setParameterCount(this->getParameterCount() + 1);
76 void
77 PcpScalarOrder::Visitor::decrementParameterCount()
79 this->setParameterCount(this->getParameterCount() - 1);
82 void
83 PcpScalarOrder::Visitor::setOrderMap(PcpMap<PcpExpr*, int>* orderMap)
85 this->orderMap = orderMap;
88 PcpMap<PcpExpr*, int>*
89 PcpScalarOrder::Visitor::getOrderMap()
91 return this->orderMap;
94 void
95 PcpScalarOrder::Visitor::visit(PcpScop* scop)
97 PcpIterator<PcpParameter*>* paramIter = scop->getParametersIterator();
98 for(;paramIter->hasNext(); paramIter->next())
100 paramIter->get()->accept(this);
102 delete paramIter;
103 scop->getBody()->accept(this);
106 void
107 PcpScalarOrder::Visitor::visit(PcpLoop* loop)
109 loop->getIv()->accept(this);
110 this->incrementIvCount();
111 loop->getBody()->accept(this);
112 this->decrementIvCount();
115 void
116 PcpScalarOrder::Visitor::visit(PcpSequence* sequence)
118 this->visitChildren(sequence);
121 void
122 PcpScalarOrder::Visitor::visit(PcpGuard* guard)
124 guard->getBody()->accept(this);
127 void
128 PcpScalarOrder::Visitor::visit(PcpIv* iv)
130 //printf("IV: (%s, %d)\n", iv->getName(), this->getIvCount());
131 this->getOrderMap()->insert(iv, this->getIvCount());
135 void
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)
145 this->setIvCount(1);
146 this->setParameterCount(1);
147 this->setOrderMap(orderMap);
151 void
152 PcpScalarOrder::setOrderMap(PcpMap<PcpExpr*, int>* orderMap)
154 this->orderMap = orderMap;
157 PcpMap<PcpExpr*, int>*
158 PcpScalarOrder::getOrderMap()
160 return this->orderMap;
163 bool
164 PcpScalarOrder::equal(PcpExpr* expr1, PcpExpr* expr2)
166 return expr1 == expr2 || expr1->isConstant() && expr2->isConstant();
169 bool
170 PcpScalarOrder::less(PcpExpr* expr1, PcpExpr* expr2)
172 if(this->equal(expr1, expr2))
173 return false;
175 if(expr2->isConstant())
176 return true;
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())
188 return false;
189 else
190 return true;
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;
208 else
209 return false;
212 PcpScalarOrder::PcpScalarOrder(PcpScop* scop)
214 this->setOrderMap(new PcpTreeMap<PcpExpr*, int>());
215 PcpScalarOrder::Visitor visitor(this->getOrderMap());
216 visitor.visit(scop);