Fix DealII type problems.
[official-gcc/Ramakrishna.git] / libpcp / pcp_c.cc
blob80077721e63ab91a3d5924cc640db0ead47ecab9
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.h"
29 #include "pcp_c.h"
31 // PCP Object
33 // Set name of OBJECT to NAME.
34 void
35 pcp_object_set_name(pcp_object* object, const char* name)
37 object->setName(name);
40 // Get name of OBJECT.
41 const char*
42 pcp_object_get_name(pcp_object* object)
44 return object->getName();
47 // Get number of annotations in OBJECT.
48 int pcp_object_get_num_annots(pcp_object* object)
50 return object->getAnnots()->getNumAnnots();
54 // Get annotation in OBJECT with given INDEX.
55 pcp_annot_term* pcp_object_get_annot(pcp_object* object, int index)
57 return object->getAnnots()->getAnnot(index);
61 // Get annotation in OBJECT with given TAG.
62 pcp_annot_term* pcp_object_get_annot_with_tag(pcp_object* object,
63 const char* tag)
65 return object->getAnnotWithTag(tag);
69 // Returns true if an annotation with given TAG exists in OBJECT.
70 bool
71 pcp_object_contains_annot_with_tag(pcp_object* object, const char* tag)
73 return object->containsAnnotWithTag(tag);
76 // Add ANNOT to OBJECT.
77 void pcp_object_add_annot(pcp_object* object, pcp_annot_term* annot)
79 object->addAnnot(annot);
83 // Get annotation of OBJECT.
84 pcp_annot_set*
85 pcp_object_get_annots(pcp_object* object)
87 return object->getAnnots();
91 // Return true if OBJECT is an array type.
92 bool
93 pcp_object_is_array_type(pcp_object* object)
95 return object->isArrayType();
98 // Return true if OBJECT is an expr.
99 bool
100 pcp_object_is_expr(pcp_object* object)
102 return object->isExpr();
105 // Return true if OBJECT is an iv.
106 bool
107 pcp_object_is_iv(pcp_object* object)
109 return object->isIv();
112 // Return true if OBJECT is a parameter.
113 bool
114 pcp_object_is_parameter(pcp_object* object)
117 return object->isParameter();
120 // Return true if OBJECT is a bool_expr.
121 bool
122 pcp_object_is_bool_expr(pcp_object* object)
124 return object->isBoolExpr();
127 // Return true if OBJECT is a variable.
128 bool
129 pcp_object_is_variable(pcp_object* object)
131 return object->isVariable();
134 // Return true if OBJECT is an array access.
135 bool
136 pcp_object_is_array_access(pcp_object* object)
138 return object->isArrayAccess();
141 // Return true if OBJECT is a stmt.
142 bool
143 pcp_object_is_stmt(pcp_object* object)
145 return object->isStmt();
148 // Return true if OBJECT is a scop.
149 bool
150 pcp_object_is_scop(pcp_object* object)
152 return object->isScop();
155 // Cast OBJECT to array type.
156 pcp_array_type*
157 pcp_object_to_array_type(pcp_object* object)
159 return object->toArrayType();
162 // Cast OBJECT to expr.
163 pcp_expr*
164 pcp_object_to_expr(pcp_object* object)
166 return object->toExpr();
169 // Cast OBJECT to parameter.
170 pcp_parameter*
171 pcp_object_to_parameter(pcp_object* object)
173 return object->toParameter();
176 // Cast OBJECT to IV.
177 pcp_iv*
178 pcp_object_to_iv(pcp_object* object)
180 return object->toIv();
183 // Cast OBJECT to bool expr.
184 pcp_bool_expr*
185 pcp_object_to_bool_expr(pcp_object* object)
187 return object->toBoolExpr();
190 // Cast OBJECT to variable.
191 pcp_variable*
192 pcp_object_to_variable(pcp_object* object)
194 return object->toVariable();
197 // Cast OBJECT to array access.
198 pcp_array_access*
199 pcp_object_to_array_access(pcp_object* object)
201 return object->toArrayAccess();
204 // Cast OBJECT to stmt.
205 pcp_stmt*
206 pcp_object_to_stmt(pcp_object* object)
208 return object->toStmt();
211 // Cast OBJECT to scop.
212 pcp_scop*
213 pcp_object_to_scop(pcp_object* object)
215 return object->toScop();
218 // PCP Annotation Set
220 // Get the annotation in ANNOT_SET with given INDEX.
221 pcp_annot_term* pcp_annot_set_get_annot(pcp_annot_set* annot_set, int index)
223 return annot_set->getAnnot(index);
226 // Get number of annotations in ANNOT_SET.
227 int pcp_annot_set_get_num_annots(pcp_annot_set* annot_set)
229 return annot_set->getNumAnnots();
232 // Get the annotation with TAG in ANNOT_SET.
233 pcp_annot_term* pcp_annot_set_get_annot_with_tag(pcp_annot_set* annot_set,
234 const char* tag)
236 return annot_set->getAnnotWithTag(tag);
239 // Add ANNOT to ANNOT_SET. Assert that no previous annotation with the
240 // same tag exists.
241 void pcp_annot_set_add_annot(pcp_annot_set* annot_set, pcp_annot_term* annot)
243 annot_set->addAnnot(annot);
246 // PCP Annotation
248 // Get kind of ANNOT.
249 pcp_annot_kind pcp_annot_get_kind(pcp_annot* annot)
251 return annot->isAnnotInt() ? pcp_annot_kind_int :
252 annot->isAnnotString() ? pcp_annot_kind_string :
253 annot->isAnnotObject() ? pcp_annot_kind_object
254 : pcp_annot_kind_term;
257 // Return true if ANNOT is an int.
258 bool
259 pcp_annot_is_annot_int(pcp_annot* annot)
261 return annot->isAnnotInt();
264 // Return true if ANNOT is a string.
265 bool
266 pcp_annot_is_annot_string(pcp_annot* annot)
268 return annot->isAnnotString();
271 // Return true if ANNOT is an object.
272 bool
273 pcp_annot_is_annot_object(pcp_annot* annot)
275 return annot->isAnnotObject();
278 // Return true if ANNOT is a term.
279 bool
280 pcp_annot_is_annot_term(pcp_annot* annot)
282 return annot->isAnnotTerm();
285 // Cast ANNOT to int.
286 pcp_annot_int*
287 pcp_annot_to_annot_int(pcp_annot* annot)
289 return annot->toAnnotInt();
292 // Cast ANNOT to string.
293 pcp_annot_string*
294 pcp_annot_to_annot_string(pcp_annot* annot)
296 return annot->toAnnotString();
299 // Cast ANNOT to object.
300 pcp_annot_object*
301 pcp_annot_to_annot_object(pcp_annot* annot)
303 return annot->toAnnotObject();
306 // Cast ANNOT to term.
307 pcp_annot_term*
308 pcp_annot_to_annot_term(pcp_annot* annot)
310 return annot->toAnnotTerm();
313 // PCP Annot Int
315 // Cast ANNOT_INT to annot.
316 pcp_annot*
317 pcp_annot_int_to_annot(pcp_annot_int* annot_int)
319 return annot_int;
322 // Get value of ANNOT_INT.
324 pcp_annot_int_get_value(pcp_annot_int* annot_int)
326 return annot_int->getValue();
329 // Create annot int with given VALUE.
330 pcp_annot_int*
331 pcp_annot_int_create(int value)
333 return new PcpAnnotInt(value);
336 // PCP Annot String
338 // Cast ANNOT_STRING to annot.
339 pcp_annot*
340 pcp_annot_string_to_annot(pcp_annot_string* annot_string)
342 return annot_string;
345 // Get string of ANNOT_STRING.
346 const char*
347 pcp_annot_string_get_string(pcp_annot_string* annot_string)
349 return annot_string->getString();
352 // Create annot string with given STRING.
353 pcp_annot_string*
354 pcp_annot_string_create(const char* string)
356 return new PcpAnnotString(string);
359 // PCP Annot Object
361 // Cast ANNOT_OBJECT to annot.
362 pcp_annot*
363 pcp_annot_object_to_annot(pcp_annot_object* annot_object)
365 return annot_object;
368 // Get object of ANNOT_OBJECT.
369 pcp_object*
370 pcp_annot_object_get_object(pcp_annot_object* annot_object)
372 return annot_object->getObject();
375 // Create annot object with given OBJECT.
376 pcp_annot_object*
377 pcp_annot_object_create(pcp_object* object)
379 return new PcpAnnotObject(object);
382 // PCP Annot Term
384 // Cast ANNOT_TERM to annot.
385 pcp_annot*
386 pcp_annot_term_to_annot(pcp_annot_term* annot_term)
388 return annot_term;
391 // Get tag of ANNOT_TERM.
392 const char*
393 pcp_annot_term_get_tag(pcp_annot_term* annot_term)
395 return annot_term->getTag();
398 // Return true if ANNOT_TERM tag equals TAG.
399 bool pcp_annot_term_tag_equals(pcp_annot_term* annot_term, const char* tag)
401 return annot_term->tagEquals(tag);
404 // Get number of arguments of ANNOT_TERM.
406 pcp_annot_term_get_num_arguments(pcp_annot_term* annot_term)
408 return annot_term->getNumArguments();
411 // Get ANNOT_TERM argument with given INDEX.
412 pcp_annot*
413 pcp_annot_term_get_argument(pcp_annot_term* annot_term, int index)
415 return annot_term->getArgument(index);
418 // PCP Annot Term Builder
420 // Set tag of BUILDER to TAG.
421 void
422 pcp_annot_term_builder_set_tag(pcp_annot_term_builder* builder,
423 const char* tag)
425 builder->setTag(tag);
428 // Add ARGUMENT to BUILDER.
429 void
430 pcp_annot_term_builder_add_argument(pcp_annot_term_builder* builder,
431 pcp_annot* argument)
433 builder->addArgument(argument);
436 // Create new annot term builder.
437 pcp_annot_term_builder*
438 pcp_annot_term_builder_create()
440 return new PcpAnnotTermBuilder();
443 // Create annot term from BUILDER.
444 pcp_annot_term*
445 pcp_annot_term_builder_create_annot(pcp_annot_term_builder* builder)
447 return builder->createAnnot();
450 // Array Type
452 // Cast ARRAY_TYPE to object.
453 pcp_object*
454 pcp_array_type_to_object(pcp_array_type* array_type)
456 return array_type;
459 // Return the number of dimensions of ARRAY_TYPE.
461 pcp_array_type_get_num_dimensions(pcp_array_type* array_type)
463 return array_type->getNumDimensions();
466 // Return the size of dimension of INDEX in ARRAY_TYPE.
467 pcp_expr*
468 pcp_array_type_get_dimension(pcp_array_type* array_type, int index)
470 return array_type->getDimension(index);
473 // Array Type Builder
475 // Create array type builder.
476 pcp_array_type_builder*
477 pcp_array_type_builder_create()
479 return new PcpArrayTypeBuilder();
482 // Add a new dimension with the given SIZE to BUILDER.
483 void
484 pcp_array_type_builder_add_dimension(pcp_array_type_builder* builder,
485 pcp_expr* size)
487 builder->addDimension(size);
490 void pcp_array_type_builder_add_int_dimension(pcp_array_type_builder* builder,
491 int size)
493 builder->addIntDimension(size);
496 // Create new array type from BUIDER.
497 pcp_array_type*
498 pcp_array_type_builder_create_type(pcp_array_type_builder* builder)
500 return builder->createType();
503 // PCP Linear Expr
505 // Cast EXPR to object.
506 pcp_object*
507 pcp_expr_to_object(pcp_expr* expr)
509 return expr;
512 // Get expression kind.
513 pcp_expr_kind
514 pcp_expr_get_kind(pcp_expr* expr)
516 return expr->isParameter() ? pcp_expr_kind_parameter :
517 expr->isConstant() ? pcp_expr_kind_constant :
518 expr->isIv() ? pcp_expr_kind_iv :
519 pcp_expr_kind_arith;
522 // Return true if EXPR is a pcp_parameter, otherwise return false.
523 bool
524 pcp_expr_is_parameter(pcp_expr* expr)
526 return expr->isParameter();
529 // Return true if EXPR is a pcp_arith, otherwise return false.
530 bool
531 pcp_expr_is_arith(pcp_expr* expr)
533 return expr->isArith();
536 // Return true if EXPR is a pcp_constant, otherwise return false.
537 bool
538 pcp_expr_is_constant(pcp_expr* expr)
540 return expr->isConstant();
543 // Return true if EXPR is a pcp_iv, otherwise return false.
544 bool
545 pcp_expr_is_iv(pcp_expr* expr)
547 return expr->isIv();
550 // Cast EXPR to pcp_parameter.
551 pcp_parameter*
552 pcp_expr_to_parameter(pcp_expr* expr)
554 return expr->toParameter();
557 // Cast EXPR to pcp_arith.
558 pcp_arith*
559 pcp_expr_to_arith(pcp_expr* expr)
561 return expr->toArith();
564 // Cast EXPR to pcp_constant.
565 pcp_constant*
566 pcp_expr_to_constant(pcp_expr* expr)
568 return expr->toConstant();
571 // Cast EXPR to pcp_iv.
572 pcp_iv*
573 pcp_expr_to_iv(pcp_expr* expr)
575 return expr->toIv();
578 // PCP Bool Expr
580 // Cast BOOL_EXPR to object.
581 pcp_object*
582 pcp_bool_expr_to_object(pcp_bool_expr* bool_expr)
584 return bool_expr;
587 // Get kind of BOOL_EXPR.
588 pcp_bool_expr_kind
589 pcp_bool_expr_get_kind(pcp_bool_expr* bool_expr)
591 return bool_expr->isCompare() ? pcp_bool_expr_compare
592 : pcp_bool_expr_arith;
595 // Return true if BOOL_EXPR is a compare.
596 bool
597 pcp_bool_expr_is_compare(pcp_bool_expr* bool_expr)
599 return bool_expr->isCompare();
602 // Return true if BOOL_EXPR is a boolean arithmetic operation.
603 bool
604 pcp_bool_expr_is_bool_arith(pcp_bool_expr* bool_expr)
606 return bool_expr->isBoolArith();
609 // Cast BOOL_EXPR to pcp_compare.
610 pcp_compare* pcp_bool_expr_to_compare(pcp_bool_expr* bool_expr)
612 return bool_expr->toCompare();
615 // Cast BOOL_EXPR to bool arith, if it is not a boolean arithmetic operator return NULL.
616 pcp_bool_arith*
617 pcp_bool_expr_to_bool_arith(pcp_bool_expr* bool_expr)
619 return bool_expr->toBoolArith();
622 // PCP Compare
623 pcp_bool_expr*
624 pcp_compare_to_bool_expr(pcp_compare* compare)
626 return compare;
629 // Convert OPER to a PcpCompareOperator.
630 static PcpCompareOperator
631 pcp_compare_operator_to_class(pcp_compare_operator oper)
633 switch(oper)
635 case pcp_compare_operator_equal:
636 return PcpCompareOperator::equal();
637 case pcp_compare_operator_greater_equal:
638 return PcpCompareOperator::greaterEqual();
639 default:
640 return PcpCompareOperator::unknown();
644 // Convert oper to a pcp_compare_operator.
645 static pcp_compare_operator
646 pcp_compare_operator_from_class(PcpCompareOperator oper)
648 if(oper.isEqual())
649 return pcp_compare_operator_equal;
650 else if(oper.isGreaterEqual())
651 return pcp_compare_operator_greater_equal;
652 else
653 return pcp_compare_operator_unknown;
656 // Get pcp_compare_operator of COMPARE.
657 pcp_compare_operator
658 pcp_compare_get_operator(pcp_compare* compare)
660 return pcp_compare_operator_from_class(compare->getOperator());
663 // Get lhs of COMPARE.
664 pcp_expr*
665 pcp_compare_get_lhs(pcp_compare* compare)
667 return compare->getLhs();
670 // Get rhs of COMPARE.
671 pcp_expr*
672 pcp_compare_get_rhs(pcp_compare* compare)
674 return compare->getRhs();
677 // Create compare given OPER, LHS and RHS.
678 pcp_compare* pcp_compare_create(pcp_compare_operator oper,
679 pcp_expr* lhs,
680 pcp_expr* rhs)
682 PcpCompareOperator operClass = pcp_compare_operator_to_class(oper);
683 return new PcpCompare(operClass, lhs, rhs);
686 // PCP Bool Arith
687 static PcpBoolArithOperator
688 pcp_bool_arith_operator_to_class(pcp_bool_arith_operator oper)
690 switch(oper)
692 case pcp_bool_arith_operator_and:
693 return PcpBoolArithOperator::boolAnd();
694 case pcp_bool_arith_operator_or:
695 return PcpBoolArithOperator::boolOr();
696 default:
697 return PcpBoolArithOperator::unknown();
701 // Convert oper to pcp_bool_arith_operator type.
702 static pcp_bool_arith_operator
703 pcp_bool_arith_operator_from_class(PcpBoolArithOperator oper)
705 if(oper.isBoolAnd())
706 return pcp_bool_arith_operator_and;
707 if(oper.isBoolOr())
708 return pcp_bool_arith_operator_or;
709 else
710 return pcp_bool_arith_operator_unknown;
713 // Get operator of BOOL_ARITH.
714 pcp_bool_arith_operator
715 pcp_bool_arith_get_operator(pcp_bool_arith* bool_arith)
717 return pcp_bool_arith_operator_from_class(bool_arith->getOperator());
720 // Get number of operands of BOOL_ARITH.
722 pcp_bool_arith_get_num_operands(pcp_bool_arith* bool_arith)
724 return bool_arith->getNumOperands();
727 // Get operand of BOOL_ARITH with given INDEX.
728 pcp_bool_expr*
729 pcp_bool_arith_get_operand(pcp_bool_arith* bool_arith, int index)
731 return bool_arith->getOperand(index);
734 // Cast BOOL_ARITH to object.
735 pcp_object*
736 pcp_bool_arith_to_object(pcp_bool_arith* bool_arith)
738 return bool_arith;
741 // Cast BOOL_ARITH to bool_expr.
742 pcp_bool_expr*
743 pcp_bool_arith_to_bool_expr(pcp_bool_arith* bool_arith)
745 return bool_arith;
748 // PCP Bool Arith Builder.
749 // Set operator in BUILDER to OPERATOR.
750 void
751 pcp_bool_arith_builder_set_operator(pcp_bool_arith_builder* builder,
752 pcp_bool_arith_operator oper)
754 builder->setOperator(pcp_bool_arith_operator_to_class(oper));
757 // Add OPERAND to BUILDER.
758 void
759 pcp_bool_arith_builder_add_operand(pcp_bool_arith_builder* builder,
760 pcp_bool_expr* operand)
762 builder->addOperand(operand);
765 // Create new boolean arithmetic operation builder.
766 pcp_bool_arith_builder*
767 pcp_bool_arith_builder_create()
769 return new PcpBoolArithBuilder();
772 // Create new boolean arithmetic operation from BUILDER.
773 pcp_bool_arith*
774 pcp_bool_arith_builder_create_bool_arith(pcp_bool_arith_builder* builder)
776 return builder->createBoolArith();
779 // Create binary arithmetic operation with OPERATOR, LHS, RHS.
780 pcp_bool_arith*
781 pcp_bool_arith_binary_create(pcp_bool_arith_operator oper,
782 pcp_bool_expr* lhs,
783 pcp_bool_expr* rhs)
786 return PcpBoolArith::pcpBoolArithBinaryCreate(pcp_bool_arith_operator_to_class(oper), lhs, rhs);
789 // PCP Arith
791 // Convert oper enum to PcpArithOperator class
792 static PcpArithOperator
793 pcp_arith_operator_to_class(pcp_arith_operator oper)
795 switch(oper)
797 case pcp_arith_operator_add:
798 return PcpArithOperator::add();
799 case pcp_arith_operator_multiply:
800 return PcpArithOperator::multiply();
801 case pcp_arith_operator_subtract:
802 return PcpArithOperator::subtract();
803 case pcp_arith_operator_min:
804 return PcpArithOperator::min();
805 case pcp_arith_operator_max:
806 return PcpArithOperator::max();
807 case pcp_arith_operator_floor:
808 return PcpArithOperator::floor();
809 case pcp_arith_operator_ceiling:
810 return PcpArithOperator::ceiling();
811 default:
812 return PcpArithOperator::unknown();
816 // Convert oper class to pcp_arith_operator enum.
817 static pcp_arith_operator
818 pcp_arith_operator_from_class(PcpArithOperator oper)
820 return oper.isAdd() ? pcp_arith_operator_add :
821 oper.isMultiply() ? pcp_arith_operator_multiply :
822 oper.isSubtract() ? pcp_arith_operator_subtract :
823 oper.isMin() ? pcp_arith_operator_min :
824 oper.isMax() ? pcp_arith_operator_max :
825 oper.isFloor() ? pcp_arith_operator_floor :
826 oper.isCeiling() ? pcp_arith_operator_ceiling :
827 pcp_arith_operator_unknown;
830 // Cast ARITH to object.
831 pcp_object* pcp_arith_to_object(pcp_arith* arith)
833 return arith;
836 // Cast ARITH to expr.
837 pcp_expr* pcp_arith_to_expr(pcp_arith* arith)
839 return arith;
842 // Get operator of ARITH.
843 pcp_arith_operator pcp_arith_get_operator(pcp_arith* arith)
845 return pcp_arith_operator_from_class(arith->getOperator());
848 // Get number of operands of ARITH.
849 int pcp_arith_get_num_operands(pcp_arith* arith)
851 return arith->getNumOperands();
854 // Get operand of ARITH with given INDEX.
855 pcp_expr*
856 pcp_arith_get_operand(pcp_arith* arith, int index)
858 return arith->getOperand(index);
861 // PCP Arith Builder.
863 // Set operator in BUILDER to OPERATOR.
864 void
865 pcp_arith_builder_set_operator(pcp_arith_builder* builder,
866 pcp_arith_operator oper)
868 builder->setOperator(pcp_arith_operator_to_class(oper));
871 // Add OPERAND to BUILDER.
872 void
873 pcp_arith_builder_add_operand(pcp_arith_builder* builder,
874 pcp_expr* operand)
876 builder->addOperand(operand);
879 // Create new arithmetic operation from BUILDER.
880 pcp_arith*
881 pcp_arith_builder_create_arith(pcp_arith_builder* builder)
883 return builder->createArith();
886 // Create new arithmetic operation builder.
887 pcp_arith_builder*
888 pcp_arith_builder_create()
890 return new PcpArithBuilder();
893 // PCP Constant
895 // Cast CONSTANT to object.
896 pcp_object*
897 pcp_constant_to_object(pcp_constant* constant)
899 return constant;
902 // Cast CONSTANT to pcp_expr.
903 pcp_expr*
904 pcp_constant_to_expr(pcp_constant* constant)
906 return constant;
909 // Get value of CONSTANT.
911 pcp_constant_get_value(pcp_constant* constant)
913 return constant->getValue();
916 // Create constant with VALUE.
917 pcp_constant*
918 pcp_constant_create(int value)
920 return new PcpConstant(value);
923 // PCP Induction Variable
925 // Cast IV to object.
926 pcp_object*
927 pcp_iv_to_object(pcp_iv* iv)
929 return iv;
932 // Cast IV to pcp_expr.
933 pcp_expr*
934 pcp_iv_to_expr(pcp_iv* iv)
936 return iv;
939 // Get name of IV.
940 const char*
941 pcp_iv_get_name(pcp_iv* iv)
943 return iv->getName();
946 // Create iv with NAME.
947 pcp_iv*
948 pcp_iv_create(const char* name)
950 return new PcpIv(name);
953 // PCP Variable
955 // Cast VAR to object.
956 pcp_object*
957 pcp_variable_to_object(pcp_variable* var)
959 return var;
962 // Set is input of VAR to IS_INPUT.
963 void
964 pcp_variable_set_is_input(pcp_variable* var, bool is_input)
966 var->setIsInput(is_input);
969 // Get is input of VAR.
970 bool
971 pcp_variable_get_is_input(pcp_variable* var)
973 return var->getIsInput();
976 // Set is output of VAR to IS_OUTPUT.
977 void
978 pcp_variable_set_is_output(pcp_variable* var, bool is_output)
980 var->setIsOutput(is_output);
983 // Get is output of VAR.
984 bool
985 pcp_variable_get_is_output(pcp_variable* var)
987 return var->getIsOutput();
990 // Get tpe of VAR.
991 pcp_array_type*
992 pcp_variable_get_type(pcp_variable* var)
994 return var->getType();
997 // Get name of VAR.
998 const char*
999 pcp_variable_get_name(pcp_variable* var)
1001 return var->getName();
1004 // Create variable given TYPE and NAME.
1005 pcp_variable*
1006 pcp_variable_create(pcp_array_type* type, const char* name)
1008 return new PcpVariable(type, name);
1011 // PCP Parameter
1013 // Cast PARAMETER to pcp_object.
1014 pcp_object*
1015 pcp_parameter_to_object(pcp_parameter* parameter)
1017 return parameter;
1020 // Cast PARAMETER to pcp_expr.
1021 pcp_expr*
1022 pcp_parameter_to_expr(pcp_parameter* parameter)
1024 return parameter;
1027 // Get name of PARAMETER.
1028 const char*
1029 pcp_parameter_get_name(pcp_parameter* parameter)
1031 return parameter->getName();
1034 // Create parameter with the given NAME.
1035 pcp_parameter*
1036 pcp_parameter_create(const char* name)
1038 return new PcpParameter(name);
1041 // Create binary arithmetic operation with OPERATOR, LHS, RHS.
1042 pcp_arith*
1043 pcp_arith_binary_create(pcp_arith_operator oper,
1044 pcp_expr* lhs,
1045 pcp_expr* rhs)
1047 return PcpArith::pcpArithBinaryCreate(pcp_arith_operator_to_class(oper),
1048 lhs, rhs);
1051 // PCP Array Access
1053 // Convert oper enum to PcpArrayOperator object
1054 static PcpArrayOperator
1055 pcp_array_operator_to_class(pcp_array_operator oper)
1057 switch(oper)
1059 case pcp_array_operator_use:
1060 return PcpArrayOperator::use();
1061 case pcp_array_operator_def:
1062 return PcpArrayOperator::def();
1063 case pcp_array_operator_maydef:
1064 return PcpArrayOperator::maydef();
1065 default:
1066 return PcpArrayOperator::unknown();
1070 // Convert oper object to pcp_array_operator enum.
1071 static pcp_array_operator
1072 pcp_array_operator_from_class(PcpArrayOperator oper)
1074 return oper.isUse() ? pcp_array_operator_use :
1075 oper.isDef() ? pcp_array_operator_def :
1076 oper.isMaydef() ? pcp_array_operator_maydef :
1077 pcp_array_operator_unknown;
1080 // Cast ACCESS to object.
1081 pcp_object*
1082 pcp_array_access_to_object(pcp_array_access* access)
1084 return access;
1087 // Get operator enum from ACCESS.
1088 pcp_array_operator
1089 pcp_array_access_get_operator(pcp_array_access* access)
1091 return pcp_array_operator_from_class(access->getOperator());
1094 // Get base of ACCESS.
1095 pcp_variable*
1096 pcp_array_access_get_base(pcp_array_access* access)
1098 return access->getBase();
1101 // Get ACCESS subscript at INDEX.
1102 pcp_expr*
1103 pcp_array_access_get_subscript(pcp_array_access* access, int index)
1105 return access->getSubscript(index);
1108 // Get number of subscripts in ACCESS.
1110 pcp_array_access_get_num_subscripts(pcp_array_access* access)
1112 return access->getNumSubscripts();
1115 // Return true if ACCESS is use, otherwise return false.
1116 bool
1117 pcp_array_access_is_use(pcp_array_access* access)
1119 return access->getOperator().isUse();
1122 // Return true if ACCESS is def, otherwise return false.
1123 bool
1124 pcp_array_access_is_def(pcp_array_access* access)
1126 return access->getOperator().isDef();
1129 // Return true if ACCESS is maydef, otherwise return false.
1130 bool
1131 pcp_array_access_is_maydef(pcp_array_access* access)
1133 return access->getOperator().isMaydef();
1136 // PCP Array Access Builder
1138 // Set operator of BUIDLER to OPERATOR.
1139 void
1140 pcp_array_access_builder_set_operator(pcp_array_access_builder* builder,
1141 pcp_array_operator oper)
1143 builder->setOperator(pcp_array_operator_to_class(oper));
1146 // Add SUBSCRIPT to BUILDER.
1147 void
1148 pcp_array_access_builder_add_subscript(pcp_array_access_builder* builder,
1149 pcp_expr* subscript)
1151 builder->addSubscript(subscript);
1154 // Create new access builder with given BASE.
1155 pcp_array_access_builder*
1156 pcp_array_access_builder_create(pcp_variable* base)
1158 return new PcpArrayAccessBuilder(base);
1161 // Create array access from BUILDER.
1162 pcp_array_access*
1163 pcp_array_access_builder_create_access(pcp_array_access_builder* builder)
1165 return builder->createAccess();
1168 // PCP Stmt
1169 static pcp_stmt_kind
1170 pcp_stmt_kind_from_class(pcp_stmt* stmt)
1172 return stmt->isCopy() ? pcp_stmt_kind_copy :
1173 stmt->isUserStmt() ? pcp_stmt_kind_user :
1174 stmt->isSequence() ? pcp_stmt_kind_sequence :
1175 stmt->isGuard() ? pcp_stmt_kind_guard :
1176 stmt->isLoop() ? pcp_stmt_kind_loop :
1177 pcp_stmt_kind_unknown;
1181 // Cast STMT to object.
1182 pcp_object*
1183 pcp_stmt_to_object(pcp_stmt* stmt)
1185 return stmt;
1188 // Get kind of STMT.
1189 pcp_stmt_kind
1190 pcp_stmt_get_kind(pcp_stmt* stmt)
1192 return pcp_stmt_kind_from_class(stmt);
1195 // Returns true if STMT is a copy stmt.
1196 bool
1197 pcp_stmt_is_copy(pcp_stmt* stmt)
1199 return stmt->isCopy();
1202 // Returns true if STMT is a user stmt.
1203 bool
1204 pcp_stmt_is_user_stmt(pcp_stmt* stmt)
1206 return stmt->isUserStmt();
1209 // Returns true if STMT is a loop stmt.
1210 bool
1211 pcp_stmt_is_loop(pcp_stmt* stmt)
1213 return stmt->isLoop();
1216 // Returns true if STMT is a guard stmt.
1217 bool
1218 pcp_stmt_is_guard(pcp_stmt* stmt)
1220 return stmt->isGuard();
1223 // Returns true if STMT is a sequence stmt.
1224 bool
1225 pcp_stmt_is_sequence(pcp_stmt* stmt)
1227 return stmt->isSequence();
1230 // Cast STMT to copy stmt, if STMT is not a copy return NULL.
1231 pcp_copy*
1232 pcp_stmt_to_copy(pcp_stmt* stmt)
1234 return stmt->toCopy();
1237 // Cast SfTMT to user stmt, if STMT is not a user stmt return NULL.
1238 pcp_user_stmt*
1239 pcp_stmt_to_user_stmt(pcp_stmt* stmt)
1241 return stmt->toUserStmt();
1244 // Cast STMT to guard stmt, if STMT is not a guard return NULL.
1245 pcp_guard*
1246 pcp_stmt_to_guard(pcp_stmt* stmt)
1248 return stmt->toGuard();
1251 // Cast STMT to loop stmt, if STMT is not a loop return NULL.
1252 pcp_loop*
1253 pcp_stmt_to_loop(pcp_stmt* stmt)
1255 return stmt->toLoop();
1258 // Cast STMT to sequence stmt, if STMT is not a sequence return NULL.
1259 pcp_sequence*
1260 pcp_stmt_to_sequence(pcp_stmt* stmt)
1262 return stmt->toSequence();
1265 // PCP Copy Stmt
1267 // Cast COPY to object.
1268 pcp_object*
1269 pcp_copy_to_object(pcp_copy* copy)
1271 return copy;
1274 // Cast COPU to stmt.
1275 pcp_stmt*
1276 pcp_copy_to_stmt(pcp_copy* copy)
1278 return copy;
1281 // Get source of COPY.
1282 pcp_array_access*
1283 pcp_copy_get_src(pcp_copy* copy)
1285 return copy->getSrc();
1288 // Get destination of COPY.
1289 pcp_array_access*
1290 pcp_copy_get_dest(pcp_copy* copy)
1292 return copy->getDest();
1295 // Create new copy statement given DEST and SRC.
1296 pcp_copy*
1297 pcp_copy_create(pcp_array_access* dest, pcp_array_access* src)
1299 return new PcpCopy(dest, src);
1302 // PCP User Stmt
1304 // Cast USER_STMT to object.
1305 pcp_object*
1306 pcp_user_stmt_to_object(pcp_user_stmt* user_stmt)
1308 return user_stmt;
1311 // Cast USER_STMT to stmt.
1312 pcp_stmt*
1313 pcp_user_stmt_to_stmt(pcp_user_stmt* user_stmt)
1315 return user_stmt;
1318 // Get name of USER_STMT.
1319 const char*
1320 pcp_user_stmt_get_name(pcp_user_stmt* user_stmt)
1322 return user_stmt->getName();
1325 // Get numer of accessses in USER_STMT.
1327 pcp_user_stmt_get_num_accesses(pcp_user_stmt* user_stmt)
1329 return user_stmt->getNumAccesses();
1332 // Get array access in USER_STMT with given INDEX.
1333 pcp_array_access*
1334 pcp_user_stmt_get_array_access(pcp_user_stmt* user_stmt, int index)
1336 return user_stmt->getArrayAccess(index);
1339 // PCP User Stmt Builder
1341 // Set name in BUILDER to NAME.
1342 void
1343 pcp_user_stmt_builder_set_name(pcp_user_stmt_builder* builder,
1344 const char* name)
1346 builder->setName(name);
1349 // Add ACCESS to BUILDER.
1350 void
1351 pcp_user_stmt_builder_add_access(pcp_user_stmt_builder* builder,
1352 pcp_array_access* access)
1354 builder->addAccess(access);
1357 // Create stmt builder.
1358 pcp_user_stmt_builder*
1359 pcp_user_stmt_builder_create()
1361 return new PcpUserStmtBuilder();
1364 // Create user stmt from BUILDER.
1365 pcp_user_stmt*
1366 pcp_user_stmt_builder_create_user_stmt(pcp_user_stmt_builder* builder)
1368 return builder->createUserStmt();
1371 // PCP Sequence
1373 // Cast SEQUENCE to stmt.
1374 pcp_stmt*
1375 pcp_sequence_to_stmt(pcp_sequence* sequence)
1377 return sequence;
1380 // Get number of statements in SEQUENCE.
1382 pcp_sequence_get_num_stmts(pcp_sequence* sequence)
1384 return sequence->getNumStmts();
1387 // Get statment in SEQUENCE with given INDEX.
1388 pcp_stmt*
1389 pcp_sequence_get_stmt(pcp_sequence* sequence, int index)
1391 return sequence->getStmt(index);
1394 // PCP Sequence Builder
1396 // Add STMT to the end of the sequence in BUILDER.
1397 void
1398 pcp_sequence_builder_add(pcp_sequence_builder* builder, pcp_stmt* stmt)
1400 builder->add(stmt);
1403 // Create sequence builder.
1404 pcp_sequence_builder*
1405 pcp_sequence_builder_create()
1407 return new PcpSequenceBuilder();
1410 // Create sequence from BUILDER.
1411 pcp_sequence*
1412 pcp_sequence_builder_create_sequence(pcp_sequence_builder* builder)
1414 return builder->createSequence();
1417 // PCP Guard
1419 // Cast GUARD to objec.
1420 pcp_object*
1421 pcp_guard_to_object(pcp_guard* guard)
1423 return guard;
1426 // Cast GUARD to stmt.
1427 pcp_stmt*
1428 pcp_guard_to_stmt(pcp_guard* guard)
1430 return guard;
1433 // Get condition of GUARD.
1434 pcp_bool_expr*
1435 pcp_guard_get_condition(pcp_guard* guard)
1437 return guard->getCondition();
1440 // Get body of GUARD.
1441 pcp_stmt*
1442 pcp_guard_get_body(pcp_guard* guard)
1444 return guard->getBody();
1447 // Create guard with given CONDITION and BODY.
1448 pcp_guard*
1449 pcp_guard_create(pcp_bool_expr* condition, pcp_stmt* body)
1451 return new PcpGuard(condition, body);
1455 // PCP Loop
1457 // Cast LOOP to object.
1458 pcp_object*
1459 pcp_loop_to_object(pcp_loop* loop)
1461 return loop;
1464 // Cast LOOP to stmt.
1465 pcp_stmt*
1466 pcp_loop_to_stmt(pcp_loop* loop)
1468 return loop;
1471 // Get iv of LOOP.
1472 pcp_iv*
1473 pcp_loop_get_iv(pcp_loop* loop)
1475 return loop->getIv();
1478 // Get start of LOOP.
1479 pcp_expr*
1480 pcp_loop_get_start(pcp_loop* loop)
1482 return loop->getStart();
1485 // Get condition of LOOP.
1486 pcp_bool_expr*
1487 pcp_loop_get_condition(pcp_loop* loop)
1489 return loop->getCondition();
1492 // Get stride of LOOP.
1493 pcp_constant*
1494 pcp_loop_get_stride(pcp_loop* loop)
1496 return loop->getStride();
1499 // Get body of LOOP.
1500 pcp_stmt*
1501 pcp_loop_get_body(pcp_loop* loop)
1503 return loop->getBody();
1506 // Create loop as loop(IV, START, CONDITION, STRIDE) { BODY }.
1507 pcp_loop*
1508 pcp_loop_create(pcp_iv* iv, pcp_expr* start, pcp_bool_expr* condition,
1509 pcp_constant* stride, pcp_stmt* body)
1511 return new PcpLoop(iv, start, condition, stride, body);
1514 // PCP Scop
1516 // Cast SCOP to object.
1517 pcp_object*
1518 pcp_scop_to_object(pcp_scop* scop)
1520 return scop;
1523 // Get numer of variables of SCOP.
1525 pcp_scop_get_num_variables(pcp_scop* scop)
1527 return scop->getNumVariables();
1530 // Get variable of SCOP with given INDEX.
1531 pcp_variable*
1532 pcp_scop_get_variable(pcp_scop* scop, int index)
1534 return scop->getVariable(index);
1537 // Get number of paramters of SCOP.
1539 pcp_scop_get_num_parameters(pcp_scop* scop)
1541 return scop->getNumParameters();
1544 // Get parameter of SCOP with given INDEX.
1545 pcp_parameter*
1546 pcp_scop_get_parameter(pcp_scop* scop, int index)
1548 return scop->getParameter(index);
1551 // Get body of SCOP.
1552 pcp_stmt*
1553 pcp_scop_get_body(pcp_scop* scop)
1555 return scop->getBody();
1558 // PCP Scop Builder
1560 // Add VARIABLE to BUILDER.
1561 void
1562 pcp_scop_builder_add_variable(pcp_scop_builder* builder,
1563 pcp_variable* variable)
1565 builder->addVariable(variable);
1568 // Add PARAMETER to BUILDER.
1569 void
1570 pcp_scop_builder_add_parameter(pcp_scop_builder* builder,
1571 pcp_parameter* parameter)
1573 builder->addParameter(parameter);
1576 // Set body in BUILDER to BODY.
1577 void
1578 pcp_scop_builder_set_body(pcp_scop_builder* builder, pcp_stmt* body)
1580 builder->setBody(body);
1583 // Create new scop builder.
1584 pcp_scop_builder*
1585 pcp_scop_builder_create()
1587 return new PcpScopBuilder();
1590 // Create new scop from BUILDER.
1591 pcp_scop*
1592 pcp_scop_builder_create_scop(pcp_scop_builder* builder)
1594 return builder->createScop();