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"
29 #include "pcp_alloc.h"
31 #include "pcp_visitor.h"
37 PcpObject::initialize()
45 PcpObject::setName(const char* name
)
57 // Set annotation to ANNOT.
59 PcpObject::setAnnots(PcpAnnotSet
* annots
)
61 this->annots
= annots
;
64 // Get number of annotations.
65 int PcpObject::getNumAnnots()
67 return this->getAnnots() == NULL
? 0 : this->getAnnots()->getNumAnnots();
70 // Get annotation with given INDEX.
71 PcpAnnotTerm
* PcpObject::getAnnot(int index
)
73 pcpAssert(this->getAnnots() != NULL
);
74 return this->getAnnots()->getAnnot(index
);
77 // Get annotation with given TAG.
78 PcpAnnotTerm
* PcpObject::getAnnotWithTag(const char* tag
)
83 if(this->getAnnots() == NULL
)
86 numAnnots
= this->getNumAnnots();
87 for(i
= 0; i
< numAnnots
; i
++)
89 PcpAnnotTerm
* annotTerm
= this->getAnnot(i
);
90 if(annotTerm
->tagEquals(tag
))
96 // Returns true if an annotation with given TAG exists.
98 PcpObject::containsAnnotWithTag(const char* tag
)
100 return this->getAnnotWithTag(tag
) != NULL
;
104 void PcpObject::addAnnot(PcpAnnotTerm
* annot
)
106 PcpAnnotSet
* annots
= this->getAnnots();
109 annots
= new PcpAnnotSet();
110 this->setAnnots(annots
);
112 annots
->addAnnot(annot
);
117 PcpObject::getAnnots()
122 // Return true if this is an array type.
124 PcpObject::isArrayType()
129 // Return true if this is an expr.
136 // Return true if this is an iv.
143 // Return true if this is a parameter.
145 PcpObject::isParameter()
151 // Return true if this is a bool_expr.
153 PcpObject::isBoolExpr()
158 // Return true if this is a variable.
160 PcpObject::isVariable()
165 // Return true if this is an array access.
167 PcpObject::isArrayAccess()
172 // Return true if this is a stmt.
179 // Return true if this is a scop.
186 // Cast this to array type.
188 PcpObject::toArrayType()
194 // Cast this to expr.
202 // Cast this to parameter.
204 PcpObject::toParameter()
218 // Cast this to bool expr.
220 PcpObject::toBoolExpr()
226 // Cast this to variable.
228 PcpObject::toVariable()
234 // Cast this to array access.
236 PcpObject::toArrayAccess()
242 // Cast this to stmt.
250 // Cast this to scop.
258 // Set annotations array in ANNOTSet to ANNOTS.
260 PcpAnnotSet::setAnnots(PcpDynamicArray
<PcpAnnotTerm
*>* annots
)
262 this->annots
= annots
;
265 // Get annotation array in ANNOTSet.
266 PcpDynamicArray
<PcpAnnotTerm
*>*
267 PcpAnnotSet::getAnnots()
272 // Get the annotation in ANNOTSet with given INDEX.
273 PcpAnnotTerm
* PcpAnnotSet::getAnnot(int index
)
275 PcpAnnotTerm
* result
= this->getAnnots()->get(index
);
279 // Get number of annotations in ANNOTSet.
281 PcpAnnotSet::getNumAnnots()
283 return this->getAnnots()->getSize();
286 // Get the annotation with TAG in ANNOTSet.
287 PcpAnnotTerm
* PcpAnnotSet::getAnnotWithTag(const char* tag
)
290 int numAnnots
= this->getNumAnnots();
291 for(i
= 0; i
< numAnnots
; i
++)
293 PcpAnnotTerm
* annotTerm
= this->getAnnot(i
);
294 const char* annotTag
= annotTerm
->getTag();
295 if(strcmp(annotTag
, tag
) == 0)
301 // Add ANNOT to ANNOTSet. Assert that no previous annotation with the
304 PcpAnnotSet::addAnnot(PcpAnnotTerm
* annot
)
306 PcpAnnotTerm
* existingTerm
= this->getAnnotWithTag(annot
->getTag());
307 if(existingTerm
!= NULL
)
310 printf("Existing tag: %s\n", annot
->getTag());
313 this->getAnnots()->add(annot
);
316 PcpAnnotSet::PcpAnnotSet()
318 PcpDynamicArray
<PcpAnnotTerm
*>* annots
=
319 new PcpDynamicArray
<PcpAnnotTerm
*>(1);
320 this->setAnnots(annots
);
324 PcpAnnotSet::accept(PcpVisitor
* visitor
)
326 visitor
->visit(this);
329 // Return true if ANNOT is an int.
331 PcpAnnot::isAnnotInt()
336 // Return true if ANNOT is a string.
338 PcpAnnot::isAnnotString()
343 // Return true if ANNOT is an object.
345 PcpAnnot::isAnnotObject()
350 // Return true if ANNOT is a term.
352 PcpAnnot::isAnnotTerm()
357 // Cast ANNOT to int.
359 PcpAnnot::toAnnotInt()
365 // Cast ANNOT to string.
367 PcpAnnot::toAnnotString()
373 // Cast ANNOT to object.
375 PcpAnnot::toAnnotObject()
381 // Cast ANNOT to term.
383 PcpAnnot::toAnnotTerm()
389 // Set value of ANNOTInt to VALUE.
391 PcpAnnotInt::setValue(int value
)
396 // Get value of ANNOTInt.
398 PcpAnnotInt::getValue()
403 // Create annot int with given VALUE.
404 PcpAnnotInt::PcpAnnotInt(int value
)
406 this->setValue(value
);
410 PcpAnnotInt::isAnnotInt()
416 PcpAnnotInt::toAnnotInt()
422 PcpAnnotInt::accept(PcpVisitor
* visitor
)
424 visitor
->visit(this);
428 bool PcpAnnotString::isAnnotString()
432 PcpAnnotString
* PcpAnnotString::toAnnotString()
437 // Set string of ANNOTString to STRING.
439 PcpAnnotString::setString(const char* string
)
441 this->string
= string
;
444 // Get string of ANNOTString.
446 PcpAnnotString::getString()
451 // Create annot string with given STRING.
452 PcpAnnotString::PcpAnnotString(const char* string
)
454 this->setString(string
);
458 PcpAnnotString::accept(PcpVisitor
* visitor
)
460 visitor
->visit(this);
465 bool PcpAnnotObject::isAnnotObject()
470 PcpAnnotObject
* PcpAnnotObject::toAnnotObject()
475 // Set object to OBJECT.
477 PcpAnnotObject::setObject(PcpObject
* object
)
479 this->object
= object
;
484 PcpAnnotObject::getObject()
489 // Create annot object with given OBJECT.
490 PcpAnnotObject::PcpAnnotObject(PcpObject
* object
)
492 this->setObject(object
);
496 PcpAnnotObject::accept(PcpVisitor
* visitor
)
498 visitor
->visit(this);
503 // Return true if this is an annot term.
504 bool PcpAnnotTerm::isAnnotTerm()
509 // Convert this to an annot term.
510 PcpAnnotTerm
* PcpAnnotTerm::toAnnotTerm()
517 PcpAnnotTerm::setTag(const char* tag
)
524 PcpAnnotTerm::getTag()
529 // Return true if tag equals TAG.
531 PcpAnnotTerm::tagEquals(const char* tag
)
533 return strcmp(tag
, this->getTag()) == 0;
536 // Get number of arguments.
538 PcpAnnotTerm::getNumArguments()
540 return this->getArguments()->getSize();
543 // Set arguments to ARGUMENTS.
545 PcpAnnotTerm::setArguments(PcpArray
<PcpAnnot
*>* arguments
)
547 this->arguments
= arguments
;
552 PcpAnnotTerm::getArguments()
554 return this->arguments
;
557 // Set argument with given INDENT to ANNOT.
559 PcpAnnotTerm::setArgument(int index
, PcpAnnot
* annot
)
561 this->getArguments()->set(index
, annot
);
564 // Get argument with given INDEX.
566 PcpAnnotTerm::getArgument(int index
)
568 return this->getArguments()->get(index
);
571 // Create annot term with TAG, and ARGUMENTS.
572 PcpAnnotTerm::PcpAnnotTerm(const char* tag
, PcpArray
<PcpAnnot
*>* arguments
)
575 this->setArguments(arguments
);
579 PcpAnnotTerm::accept(PcpVisitor
* visitor
)
581 visitor
->visit(this);
584 // PCP Annot Term Builder
588 PcpAnnotTermBuilder::setTag(const char* tag
)
595 PcpAnnotTermBuilder::getTag()
600 // Set arguments to ARGUMENTS.
602 PcpAnnotTermBuilder::setArguments(PcpDynamicArray
<PcpAnnot
*>* arguments
)
604 this->arguments
= arguments
;
608 PcpDynamicArray
<PcpAnnot
*>*
609 PcpAnnotTermBuilder::getArguments()
611 return this->arguments
;
616 PcpAnnotTermBuilder::addArgument(PcpAnnot
* argument
)
618 this->getArguments()->add(argument
);
621 // Create new annot term builder.
622 PcpAnnotTermBuilder::PcpAnnotTermBuilder()
625 this->setArguments(new PcpDynamicArray
<PcpAnnot
*>(1));
628 // Create annot term.
630 PcpAnnotTermBuilder::createAnnot()
632 PcpAnnotTerm
* annotTerm
;
633 annotTerm
= new PcpAnnotTerm(this->getTag(), this->getArguments());
639 // Return true if this is an array type.
641 PcpArrayType::isArrayType()
646 // Cast this to array type.
648 PcpArrayType::toArrayType()
653 // Return the number of dimensions.
655 PcpArrayType::getNumDimensions()
657 return this->getDimensions()->getSize();
660 // Set the dimensions to DIMENSIONS.
662 PcpArrayType::setDimensions(PcpArray
<PcpExpr
*>* dimensions
)
664 this->dimensions
= dimensions
;
669 PcpArrayType::getDimensions()
671 return this->dimensions
;
674 // Return the size of dimension with given INDEX
676 PcpArrayType::getDimension(int index
)
678 return this->getDimensions()->get(index
);
681 // Get iterator over the dimensions.
682 PcpIterator
<PcpExpr
*>*
683 PcpArrayType::getDimensionsIterator()
685 return this->getDimensions()->getIterator();
688 // Create new array type.
689 PcpArrayType::PcpArrayType(PcpArray
<PcpExpr
*>* dimensions
)
692 this->setDimensions(dimensions
);
696 PcpArrayType::accept(PcpVisitor
* visitor
)
698 visitor
->visit(this);
701 // Pcp Array Type Builder
703 // Set array to ARRAY.
705 PcpArrayTypeBuilder::setArray(PcpDynamicArray
<PcpExpr
*>* array
)
711 PcpDynamicArray
<PcpExpr
*>*
712 PcpArrayTypeBuilder::getArray()
717 // Create array type builder.
718 PcpArrayTypeBuilder::PcpArrayTypeBuilder()
720 this->setArray(new PcpDynamicArray
<PcpExpr
*>(2));
723 // Add a new dimension with the given SIZE.
725 PcpArrayTypeBuilder::addDimension(PcpExpr
* size
)
727 this->getArray()->add(size
);
730 // Add a new dimension with given SIZE
732 PcpArrayTypeBuilder::addIntDimension(int size
)
734 this->addDimension(new PcpConstant(size
));
737 // Create new array type from BUIDER.
739 PcpArrayTypeBuilder::createType()
741 return new PcpArrayType(this->getArray());
746 // Return true if this is an expr.
747 bool PcpExpr::isExpr()
752 // Convert this to an expr.
753 PcpExpr
* PcpExpr::toExpr()
758 // Return true if this is a pcpParameter, otherwise return false.
760 PcpExpr::isParameter()
765 // Return true if this is a pcpArith, otherwise return false.
772 // Return true if this is a pcpConstant, otherwise return false.
774 PcpExpr::isConstant()
779 // Return true if this is a pcpIv, otherwise return false.
786 // Cast this to pcpParameter.
788 PcpExpr::toParameter()
794 // Cast this to pcpArith.
802 // Cast this to pcpConstant.
804 PcpExpr::toConstant()
810 // Cast this to pcpIv.
820 // Return true if this is a bool expr.
822 PcpBoolExpr::isBoolExpr()
827 // Cast this to a bool expr.
828 PcpBoolExpr
* PcpBoolExpr::toBoolExpr()
833 // Return true if this is a compare.
835 PcpBoolExpr::isCompare()
840 // Return true if this is a boolean arithmetic operation.
842 PcpBoolExpr::isBoolArith()
847 // Convert this to a compare.
849 PcpBoolExpr::toCompare()
855 // Cast BOOLExpr to bool arith, if it is not a boolean arithmetic operator return NULL.
857 PcpBoolExpr::toBoolArith()
866 // Return true if this is a compare.
868 PcpCompare::isCompare()
873 // Convert this to a compare.
875 PcpCompare::toCompare()
880 // Set operator to OPER.
882 PcpCompare::setOperator(PcpCompareOperator oper
)
889 PcpCompare::getOperator()
896 PcpCompare::setLhs(PcpExpr
* lhs
)
910 PcpCompare::setRhs(PcpExpr
* rhs
)
922 // Create new compare with given OPER, LHS and RHS
923 PcpCompare::PcpCompare(PcpCompareOperator oper
,
928 this->setOperator(oper
);
934 PcpCompare::accept(PcpVisitor
* visitor
)
936 visitor
->visit(this);
941 // Return true if this is a bool arith
942 bool PcpBoolArith::isBoolArith()
947 // Convert this to a bool arith.
948 PcpBoolArith
* PcpBoolArith::toBoolArith()
954 // Set operator to OPERATOR.
956 PcpBoolArith::setOperator(PcpBoolArithOperator oper
)
963 PcpBoolArith::getOperator()
968 // Get number of operands.
970 PcpBoolArith::getNumOperands()
972 return this->getOperands()->getSize();
975 // Set operands to OPERANDS.
977 PcpBoolArith::setOperands(PcpArray
<PcpBoolExpr
*>* operands
)
979 this->operands
= operands
;
983 PcpArray
<PcpBoolExpr
*>*
984 PcpBoolArith::getOperands()
986 return this->operands
;
989 // Get operand with given INDEX.
991 PcpBoolArith::getOperand(int index
)
993 return this->getOperands()->get(index
);
996 PcpIterator
<PcpBoolExpr
*>*
997 PcpBoolArith::getOperandsIterator()
999 return this->getOperands()->getIterator();
1003 // Create new boolean arithmetic operation.
1004 PcpBoolArith::PcpBoolArith(PcpBoolArithOperator oper
,
1005 PcpArray
<PcpBoolExpr
*>* operands
)
1008 this->setOperator(oper
);
1009 this->setOperands(operands
);
1013 PcpBoolArith::accept(PcpVisitor
* visitor
)
1015 visitor
->visit(this);
1018 // PCP Bool Arith Builder.
1020 // Set operator to OPERATOR.
1022 PcpBoolArithBuilder::setOperator(PcpBoolArithOperator oper
)
1028 PcpBoolArithOperator
1029 PcpBoolArithBuilder::getOperator()
1034 // Set operands to OPERANDS.
1036 PcpBoolArithBuilder::setOperands(PcpDynamicArray
<PcpBoolExpr
*>* operands
)
1038 this->operands
= operands
;
1042 PcpDynamicArray
<PcpBoolExpr
*>*
1043 PcpBoolArithBuilder::getOperands()
1045 return this->operands
;
1050 PcpBoolArithBuilder::addOperand(PcpBoolExpr
* operand
)
1052 this->getOperands()->add(operand
);
1055 // Create new boolean arithmetic operation builder.
1056 PcpBoolArithBuilder::PcpBoolArithBuilder()
1058 this->setOperator(PcpBoolArithOperator::unknown());
1059 this->setOperands(new PcpDynamicArray
<PcpBoolExpr
*>(2));
1063 // Create new boolean arithmetic operation.
1065 PcpBoolArithBuilder::createBoolArith()
1067 PcpBoolArith
* boolArith
;
1068 boolArith
= new PcpBoolArith(this->getOperator(), this->getOperands());
1073 // Create binary arithmetic operation with OPERATOR, LHS, RHS.
1075 PcpBoolArith::pcpBoolArithBinaryCreate(PcpBoolArithOperator oper
,
1079 PcpBoolArith
* result
;
1080 PcpBoolArithBuilder
* builder
= new PcpBoolArithBuilder();
1081 builder
->setOperator(oper
);
1082 builder
->addOperand(lhs
);
1083 builder
->addOperand(rhs
);
1084 result
= builder
->createBoolArith();
1089 // Set operator of ARITH to OPERATOR.
1091 // Return true if this is an arithmetic operation.
1092 bool PcpArith::isArith()
1097 // Cast this to an arithmetic operation.
1098 PcpArith
* PcpArith::toArith()
1103 // Set operator to OPER.
1105 PcpArith::setOperator(PcpArithOperator oper
)
1110 // Get operator of ARITH.
1112 PcpArith::getOperator()
1117 // Get number of operands.
1118 int PcpArith::getNumOperands()
1120 return this->getOperands()->getSize();
1123 // Set operands to OPERANDS.
1125 PcpArith::setOperands(PcpArray
<PcpExpr
*>* operands
)
1127 this->operands
= operands
;
1130 // Get operands of ARITH.
1132 PcpArith::getOperands()
1134 return this->operands
;
1137 // Get operand with given INDEX.
1139 PcpArith::getOperand(int index
)
1141 return this->getOperands()->get(index
);
1144 PcpIterator
<PcpExpr
*>*
1145 PcpArith::getOperandsIterator()
1147 return this->getOperands()->getIterator();
1151 // Create new arithmetic operation.
1152 PcpArith::PcpArith(PcpArithOperator oper
, PcpArray
<PcpExpr
*>* operands
)
1155 this->setOperator(oper
);
1156 this->setOperands(operands
);
1159 // Create binary arithmetic operation with OPERATOR, LHS, RHS.
1161 PcpArith::pcpArithBinaryCreate(PcpArithOperator oper
,
1166 PcpArithBuilder
* builder
= new PcpArithBuilder();
1167 builder
->setOperator(oper
);
1168 builder
->addOperand(lhs
);
1169 builder
->addOperand(rhs
);
1170 arith
= builder
->createArith();
1176 PcpArith::accept(PcpVisitor
* visitor
)
1178 visitor
->visit(this);
1182 // PCP Arith Builder.
1184 // Set operator to OPERATOR.
1186 PcpArithBuilder::setOperator(PcpArithOperator oper
)
1193 PcpArithBuilder::getOperator()
1198 // Set operands to OPERANDS.
1200 PcpArithBuilder::setOperands(PcpDynamicArray
<PcpExpr
*>* operands
)
1202 this->operands
= operands
;
1206 PcpDynamicArray
<PcpExpr
*>*
1207 PcpArithBuilder::getOperands()
1209 return this->operands
;
1214 PcpArithBuilder::addOperand(PcpExpr
* operand
)
1216 this->getOperands()->add(operand
);
1219 // Create new arithmetic operation.
1221 PcpArithBuilder::createArith()
1224 arith
= new PcpArith(this->getOperator(), this->getOperands());
1228 // Create new arithmetic operation builder.
1229 PcpArithBuilder::PcpArithBuilder()
1231 this->setOperator(PcpArithOperator::unknown());
1232 this->setOperands(new PcpDynamicArray
<PcpExpr
*>(2));
1237 // Set value of CONSTANT to VALUE.
1239 PcpConstant::setValue(int value
)
1241 this->value
= value
;
1244 // Get value of CONSTANT.
1246 PcpConstant::getValue()
1251 // Return true if this is a constant.
1253 PcpConstant::isConstant()
1258 // Cast this to a constant.
1260 PcpConstant::toConstant()
1265 // Create constant with VALUE.
1266 PcpConstant::PcpConstant(int value
)
1269 this->setValue(value
);
1273 PcpConstant::accept(PcpVisitor
* visitor
)
1275 visitor
->visit(this);
1278 // PCP Induction Variable
1280 // Return true if this is an iv.
1287 // Convert this to an iv.
1294 // Create iv with NAME.
1295 PcpIv::PcpIv(const char* name
)
1298 this->setName(name
);
1302 PcpIv::accept(PcpVisitor
* visitor
)
1304 visitor
->visit(this);
1309 // Return true if this is a variable.
1310 bool PcpVariable::isVariable()
1315 // Cast this to a variable.
1316 PcpVariable
* PcpVariable::toVariable()
1321 // Set is input of to ISINPUT.
1323 PcpVariable::setIsInput(bool isInput
)
1325 this->isInput
= isInput
;
1330 PcpVariable::getIsInput()
1332 return this->isInput
;
1335 // Set is output to ISOUTPUT.
1337 PcpVariable::setIsOutput(bool isOutput
)
1339 this->isOutput
= isOutput
;
1344 PcpVariable::getIsOutput()
1346 return this->isOutput
;
1349 // Set type to TYPE.
1351 PcpVariable::setType(PcpArrayType
* type
)
1358 PcpVariable::getType()
1363 // Create variable given TYPE and NAME.
1364 PcpVariable::PcpVariable(PcpArrayType
* type
, const char* name
)
1367 this->setType(type
);
1368 this->setName(name
);
1369 this->setIsInput(false);
1370 this->setIsOutput(false);
1374 PcpVariable::accept(PcpVisitor
* visitor
)
1376 visitor
->visit(this);
1381 // Return true if this is a parameter.
1382 bool PcpParameter::isParameter()
1387 // Cast this to a parameter.
1388 PcpParameter
* PcpParameter::toParameter()
1393 // Create parameter with the given NAME.
1394 PcpParameter::PcpParameter(const char* name
)
1397 this->setName(name
);
1401 PcpParameter::accept(PcpVisitor
* visitor
)
1403 visitor
->visit(this);
1408 // Return true if this is an array access
1409 bool PcpArrayAccess::isArrayAccess()
1414 // Cast this to an array access.
1416 PcpArrayAccess::toArrayAccess()
1421 // Set operator to OPERATOR.
1423 PcpArrayAccess::setOperator(PcpArrayOperator oper
)
1430 PcpArrayAccess::getOperator()
1435 // Set base to BASE.
1437 PcpArrayAccess::setBase(PcpVariable
* base
)
1444 PcpArrayAccess::getBase()
1449 // Set subscripts to SUBSCRIPTS.
1451 PcpArrayAccess::setSubscripts(PcpArray
<PcpExpr
*>* subscripts
)
1453 this->subscripts
= subscripts
;
1458 PcpArrayAccess::getSubscripts()
1460 return this->subscripts
;
1463 // Set subscript at INDEX to SUBSCRIPT.
1465 PcpArrayAccess::setSubscript(int index
, PcpExpr
* subscript
)
1467 this->getSubscripts()->set(index
, subscript
);
1470 // Get subscript at INDEX.
1472 PcpArrayAccess::getSubscript(int index
)
1474 return this->getSubscripts()->get(index
);
1477 // Get number of subscripts.
1479 PcpArrayAccess::getNumSubscripts()
1481 PcpVariable
* variable
= this->getBase();
1482 PcpArrayType
* type
= variable
->getType();
1483 int typeNumDims
= type
->getNumDimensions();
1487 PcpIterator
<PcpExpr
*>*
1488 PcpArrayAccess::getSubscriptsIterator()
1490 return this->getSubscripts()->getIterator();
1494 // Create array access given OPERATOR, BASE and SUBSCRIPTS.
1495 PcpArrayAccess::PcpArrayAccess(PcpArrayOperator oper
,
1497 PcpArray
<PcpExpr
*>* subscripts
)
1500 this->setOperator(oper
);
1501 this->setBase(base
);
1502 this->setSubscripts(subscripts
);
1506 PcpArrayAccess::accept(PcpVisitor
* visitor
)
1508 visitor
->visit(this);
1511 // Return true if this is a use, otherwise return false.
1513 PcpArrayAccess::isUse()
1515 return this->getOperator().isUse();
1518 // Return true if this is a def, otherwise return false.
1520 PcpArrayAccess::isDef()
1522 return this->getOperator().isDef();
1525 // Return true if this is a maydef, otherwise return false.
1527 PcpArrayAccess::isMaydef()
1529 return this->getOperator().isMaydef();
1532 // PCP Array Access Builder
1534 // Set base to BASE.
1536 PcpArrayAccessBuilder::setBase(PcpVariable
* base
)
1543 PcpArrayAccessBuilder::getBase()
1548 // Set operator to OPERATOR.
1550 PcpArrayAccessBuilder::setOperator(PcpArrayOperator oper
)
1557 PcpArrayAccessBuilder::getOperator()
1562 // Set subscript index to SUBSCRIPTINDEX.
1564 PcpArrayAccessBuilder::setSubscriptIndex(int subscriptIndex
)
1566 this->subscriptIndex
= subscriptIndex
;
1569 // Get subscript index.
1571 PcpArrayAccessBuilder::getSubscriptIndex()
1573 return this->subscriptIndex
;
1578 PcpArrayAccessBuilder::getSubscripts()
1580 return this->subscripts
;
1583 // Set subscript with given INDEX to SUBSCRIPT.
1585 PcpArrayAccessBuilder::setSubscript(int index
, PcpExpr
* subscript
)
1587 this->getSubscripts()->set(index
, subscript
);
1591 // Set subscripts to SUBSCRIPTS.
1593 PcpArrayAccessBuilder::setSubscripts(PcpArray
<PcpExpr
*>* subscripts
)
1595 this->subscripts
= subscripts
;
1598 // Get subscript with given INDEX.
1600 PcpArrayAccessBuilder::getSubscript(int index
)
1602 return this->getSubscripts()->get(index
);
1605 // Get number of dimensions of base.
1607 PcpArrayAccessBuilder::getBaseNumDimensions()
1609 PcpVariable
* variable
= this->getBase();
1610 PcpArrayType
* type
= variable
->getType();
1611 int typeNumDims
= type
->getNumDimensions();
1617 PcpArrayAccessBuilder::addSubscript(PcpExpr
* subscript
)
1619 int currentIndex
= this->getSubscriptIndex();
1620 int typeNumDims
= this->getBaseNumDimensions();
1622 pcpAssert(currentIndex
< typeNumDims
);
1623 this->setSubscript(currentIndex
, subscript
);
1624 this->setSubscriptIndex(currentIndex
+ 1);
1628 // Create new access builder with given BASE.
1629 PcpArrayAccessBuilder::PcpArrayAccessBuilder(PcpVariable
* base
)
1631 PcpArrayType
* type
= base
->getType();
1632 PcpArray
<PcpExpr
*>* subscripts
= new PcpArray
<PcpExpr
*>(type
->getNumDimensions());
1634 this->setBase(base
);
1635 this->setOperator(PcpArrayOperator::unknown());
1636 this->setSubscriptIndex(0);
1637 this->setSubscripts(subscripts
);
1640 // Create array access.
1642 PcpArrayAccessBuilder::createAccess()
1644 pcpAssert(!this->getOperator().isUnknown());
1645 pcpAssert(this->getSubscriptIndex() == this->getBaseNumDimensions());
1646 return new PcpArrayAccess(this->getOperator(),
1648 this->getSubscripts());
1653 // Return true if this is a statement
1660 // Cast this to a statement.
1661 PcpStmt
* PcpStmt::toStmt()
1666 // Returns true if this is a copy stmt.
1673 // Returns true if this is a user stmt.
1675 PcpStmt::isUserStmt()
1680 // Returns true if this is a loop stmt.
1687 // Returns true if this is a guard stmt.
1694 // Returns true if this is a sequence stmt.
1696 PcpStmt::isSequence()
1701 // Cast this to copy stmt
1709 // Cast this to user stmt
1711 PcpStmt::toUserStmt()
1717 // Cast this to guard stmt
1725 // Cast this to loop stmt
1733 // Cast this to sequence stmt
1735 PcpStmt::toSequence()
1743 // Return true if this is a copy.
1744 bool PcpCopy::isCopy()
1749 // Cast this to a copy.
1750 PcpCopy
* PcpCopy::toCopy()
1755 // Set source to SRC.
1757 PcpCopy::setSrc(PcpArrayAccess
* src
)
1769 // Set destination to DEST.
1771 PcpCopy::setDest(PcpArrayAccess
* dest
)
1783 // Create new copy statement given DEST and SRC.
1784 PcpCopy::PcpCopy(PcpArrayAccess
* dest
, PcpArrayAccess
* src
)
1787 this->setDest(dest
);
1792 PcpCopy::accept(PcpVisitor
* visitor
)
1794 visitor
->visit(this);
1799 // Return true if this is a user stmt.
1800 bool PcpUserStmt::isUserStmt()
1805 // Cast this to a user stmt.
1806 PcpUserStmt
* PcpUserStmt::toUserStmt()
1811 // Get numer of accessses in USERStmt.
1813 PcpUserStmt::getNumAccesses()
1815 return this->getArrayAccesses()->getSize();
1818 // Set array accesses of USERStmt to ACCESSSES.
1820 PcpUserStmt::setArrayAccesses(PcpArray
<PcpArrayAccess
*>* accesses
)
1822 this->accesses
= accesses
;
1825 // Get array accesses of USERStmt.
1826 PcpArray
<PcpArrayAccess
*>*
1827 PcpUserStmt::getArrayAccesses()
1829 return this->accesses
;
1832 // Set array access in USERStmt with given INDEX to ACCESS.
1834 PcpUserStmt::setArrayAccess(int index
, PcpArrayAccess
* access
)
1836 this->getArrayAccesses()->set(index
, access
);
1839 // Get array access in USERStmt with given INDEX.
1841 PcpUserStmt::getArrayAccess(int index
)
1843 return this->getArrayAccesses()->get(index
);
1846 PcpIterator
<PcpArrayAccess
*>*
1847 PcpUserStmt::getArrayAccessesIterator()
1849 return this->getArrayAccesses()->getIterator();
1852 // Create new user stmt with given NAME and ACCESSES.
1853 PcpUserStmt::PcpUserStmt(const char* name
,
1854 PcpArray
<PcpArrayAccess
*>* accesses
)
1857 this->setName(name
);
1858 this->setArrayAccesses(accesses
);
1862 PcpUserStmt::accept(PcpVisitor
* visitor
)
1864 visitor
->visit(this);
1867 // PCP User Stmt Builder
1869 // Set name to NAME.
1871 PcpUserStmtBuilder::setName(const char* name
)
1878 PcpUserStmtBuilder::getName()
1883 // Set accesses to ACCESSES.
1885 PcpUserStmtBuilder::setAccesses(PcpDynamicArray
<PcpArrayAccess
*>* accesses
)
1887 this->accesses
= accesses
;
1891 PcpDynamicArray
<PcpArrayAccess
*>*
1892 PcpUserStmtBuilder::getAccesses()
1894 return this->accesses
;
1899 PcpUserStmtBuilder::addAccess(PcpArrayAccess
* access
)
1901 this->getAccesses()->add(access
);
1904 // Create stmt builder.
1905 PcpUserStmtBuilder::PcpUserStmtBuilder()
1907 this->setName(NULL
);
1908 this->setAccesses(new PcpDynamicArray
<PcpArrayAccess
*>(2));
1912 // Create user stmt.
1914 PcpUserStmtBuilder::createUserStmt()
1916 PcpUserStmt
* userStmt
;
1917 pcpAssert(this->getName() != NULL
);
1918 userStmt
= new PcpUserStmt(this->getName(),this->getAccesses());
1924 // Return true if this is a sequence.
1925 bool PcpSequence::isSequence()
1930 // Cast this to a sequence.
1931 PcpSequence
* PcpSequence::toSequence()
1936 // Get number of statements.
1938 PcpSequence::getNumStmts()
1940 return this->getStmts()->getSize();
1943 // Set stmts to STMTS.
1945 PcpSequence::setStmts(PcpArray
<PcpStmt
*>* stmts
)
1947 this->stmts
= stmts
;
1952 PcpSequence::getStmts()
1957 // Set statement with given INDEX to STMT.
1959 PcpSequence::setStmt(int index
, PcpStmt
* stmt
)
1961 this->getStmts()->set(index
, stmt
);
1964 // Get statment with given INDEX.
1966 PcpSequence::getStmt(int index
)
1968 return this->getStmts()->get(index
);
1971 PcpIterator
<PcpStmt
*>*
1972 PcpSequence::getStmtsIterator()
1974 return this->getStmts()->getIterator();
1978 // Create Sequence with STMTS
1979 PcpSequence::PcpSequence(PcpArray
<PcpStmt
*>* stmts
)
1982 this->setStmts(stmts
);
1986 PcpSequence::accept(PcpVisitor
* visitor
)
1988 visitor
->visit(this);
1990 // PCP Sequence Builder
1992 // Set stmts to STMTS.
1994 PcpSequenceBuilder::setStmts(PcpDynamicArray
<PcpStmt
*>* stmts
)
1996 this->stmts
= stmts
;
2000 PcpDynamicArray
<PcpStmt
*>*
2001 PcpSequenceBuilder::getStmts()
2006 // Add STMT to the end of the sequence.
2008 PcpSequenceBuilder::add(PcpStmt
* stmt
)
2010 this->getStmts()->add(stmt
);
2013 // Create sequence builder.
2014 PcpSequenceBuilder::PcpSequenceBuilder()
2016 this->setStmts(new PcpDynamicArray
<PcpStmt
*>(3));
2021 PcpSequenceBuilder::createSequence()
2023 PcpSequence
* sequence
;
2024 sequence
= new PcpSequence(this->getStmts());
2030 // Return true if this is a guard.
2031 bool PcpGuard::isGuard()
2036 // Cast this to a guard.
2037 PcpGuard
* PcpGuard::toGuard()
2042 // Set condition to CONDITION.
2044 PcpGuard::setCondition(PcpBoolExpr
* condition
)
2046 this->condition
= condition
;
2051 PcpGuard::getCondition()
2053 return this->condition
;
2056 // Set body to BODY.
2058 PcpGuard::setBody(PcpStmt
* body
)
2070 // Create guard with given CONDITION and BODY.
2071 PcpGuard::PcpGuard(PcpBoolExpr
* condition
, PcpStmt
* body
)
2074 this->setCondition(condition
);
2075 this->setBody(body
);
2079 PcpGuard::accept(PcpVisitor
* visitor
)
2081 visitor
->visit(this);
2086 // Return true if this is a loop.
2087 bool PcpLoop::isLoop()
2092 // Cast this to a loop.
2093 PcpLoop
* PcpLoop::toLoop()
2100 PcpLoop::setIv(PcpIv
* iv
)
2112 // Set start to START.
2114 PcpLoop::setStart(PcpExpr
* start
)
2116 this->start
= start
;
2126 // Set condition to CONDITION.
2128 PcpLoop::setCondition(PcpBoolExpr
* condition
)
2130 this->condition
= condition
;
2135 PcpLoop::getCondition()
2137 return this->condition
;
2140 // Set stride to STRIDE.
2142 PcpLoop::setStride(PcpConstant
* stride
)
2144 this->stride
= stride
;
2149 PcpLoop::getStride()
2151 return this->stride
;
2154 // Set body to BODY.
2156 PcpLoop::setBody(PcpStmt
* body
)
2168 // Create loop as loop(IV, START, CONDITION, STRIDE) { BODY }.
2169 PcpLoop::PcpLoop(PcpIv
* iv
, PcpExpr
* start
, PcpBoolExpr
* condition
,
2170 PcpConstant
* stride
, PcpStmt
* body
)
2174 this->setStart(start
);
2175 this->setCondition(condition
);
2176 this->setStride(stride
);
2177 this->setBody(body
);
2181 PcpLoop::accept(PcpVisitor
* visitor
)
2183 visitor
->visit(this);
2188 // Return true if this is a scop.
2189 bool PcpScop::isScop()
2194 // Cast this to a scop.
2195 PcpScop
* PcpScop::toScop()
2200 // Get numer of variables.
2202 PcpScop::getNumVariables()
2204 return this->getVariables()->getSize();
2207 // Set variables to VARIABLES.
2209 PcpScop::setVariables(PcpArray
<PcpVariable
*>* variables
)
2211 this->variables
= variables
;
2215 PcpArray
<PcpVariable
*>*
2216 PcpScop::getVariables()
2218 return this->variables
;
2221 // Get variable with given INDEX.
2223 PcpScop::getVariable(int index
)
2225 return this->getVariables()->get(index
);
2228 // Get number of paramters.
2230 PcpScop::getNumParameters()
2232 return this->getParameters()->getSize();
2235 // Set paramters to PARAMTERS.
2237 PcpScop::setParameters(PcpArray
<PcpParameter
*>* parameters
)
2239 this->parameters
= parameters
;
2243 PcpArray
<PcpParameter
*>*
2244 PcpScop::getParameters()
2246 return this->parameters
;
2249 // Get parameter with given INDEX.
2251 PcpScop::getParameter(int index
)
2253 return this->getParameters()->get(index
);
2256 // Set body to BODY.
2258 PcpScop::setBody(PcpStmt
* body
)
2270 PcpIterator
<PcpVariable
*>*
2271 PcpScop::getVariablesIterator()
2273 return this->getVariables()->getIterator();
2276 PcpIterator
<PcpParameter
*>*
2277 PcpScop::getParametersIterator()
2279 return this->getParameters()->getIterator();
2283 // Create new scop given VARIABLES, PARAMETERS and BODY.
2284 PcpScop::PcpScop(PcpArray
<PcpVariable
*>* variables
,
2285 PcpArray
<PcpParameter
*>* parameters
,
2289 this->setVariables(variables
);
2290 this->setParameters(parameters
);
2291 this->setBody(body
);
2295 PcpScop::accept(PcpVisitor
* visitor
)
2297 visitor
->visit(this);
2300 // Set varaibles to VARAIBLES.
2302 PcpScopBuilder::setVariables(PcpDynamicArray
<PcpVariable
*>* variables
)
2304 this->variables
= variables
;
2308 PcpDynamicArray
<PcpVariable
*>*
2309 PcpScopBuilder::getVariables()
2311 return this->variables
;
2314 // Set parameters to PARAMETERS.
2316 PcpScopBuilder::setParameters(PcpDynamicArray
<PcpParameter
*>* parameters
)
2318 this->parameters
= parameters
;
2322 PcpDynamicArray
<PcpParameter
*>*
2323 PcpScopBuilder::getParameters()
2325 return this->parameters
;
2328 // Return true if VARIABLE already exists in the variables array.
2330 PcpScopBuilder::containsVariable(PcpVariable
* variable
)
2332 PcpDynamicArray
<PcpVariable
*>* variables
= this->getVariables();
2333 PcpIterator
<PcpVariable
*>* iter
;
2334 bool result
= false;
2335 for(iter
= variables
->getIterator(); iter
->hasNext(); iter
->next())
2337 if(variable
== iter
->get())
2346 PcpScopBuilder::addVariable(PcpVariable
* variable
)
2348 if(!this->containsVariable(variable
))
2349 this->getVariables()->add(variable
);
2354 PcpScopBuilder::addParameter(PcpParameter
* parameter
)
2356 this->getParameters()->add(parameter
);
2359 // Set body to BODY.
2361 PcpScopBuilder::setBody(PcpStmt
* body
)
2368 PcpScopBuilder::getBody()
2373 // Create new scop builder.
2374 PcpScopBuilder::PcpScopBuilder()
2376 this->setVariables(new PcpDynamicArray
<PcpVariable
*>(5));
2377 this->setParameters(new PcpDynamicArray
<PcpParameter
*>(5));
2378 this->setBody(NULL
);
2383 PcpScopBuilder::createScop()
2385 PcpScop
* scop
= new PcpScop(this->getVariables(),
2386 this->getParameters(),