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.
33 // Set name of OBJECT to NAME.
35 pcp_object_set_name(pcp_object
* object
, const char* name
)
37 object
->setName(name
);
40 // Get name of OBJECT.
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
,
65 return object
->getAnnotWithTag(tag
);
69 // Returns true if an annotation with given TAG exists in OBJECT.
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.
85 pcp_object_get_annots(pcp_object
* object
)
87 return object
->getAnnots();
91 // Return true if OBJECT is an array type.
93 pcp_object_is_array_type(pcp_object
* object
)
95 return object
->isArrayType();
98 // Return true if OBJECT is an expr.
100 pcp_object_is_expr(pcp_object
* object
)
102 return object
->isExpr();
105 // Return true if OBJECT is an iv.
107 pcp_object_is_iv(pcp_object
* object
)
109 return object
->isIv();
112 // Return true if OBJECT is a parameter.
114 pcp_object_is_parameter(pcp_object
* object
)
117 return object
->isParameter();
120 // Return true if OBJECT is a bool_expr.
122 pcp_object_is_bool_expr(pcp_object
* object
)
124 return object
->isBoolExpr();
127 // Return true if OBJECT is a variable.
129 pcp_object_is_variable(pcp_object
* object
)
131 return object
->isVariable();
134 // Return true if OBJECT is an array access.
136 pcp_object_is_array_access(pcp_object
* object
)
138 return object
->isArrayAccess();
141 // Return true if OBJECT is a stmt.
143 pcp_object_is_stmt(pcp_object
* object
)
145 return object
->isStmt();
148 // Return true if OBJECT is a scop.
150 pcp_object_is_scop(pcp_object
* object
)
152 return object
->isScop();
155 // Cast OBJECT to array type.
157 pcp_object_to_array_type(pcp_object
* object
)
159 return object
->toArrayType();
162 // Cast OBJECT to expr.
164 pcp_object_to_expr(pcp_object
* object
)
166 return object
->toExpr();
169 // Cast OBJECT to parameter.
171 pcp_object_to_parameter(pcp_object
* object
)
173 return object
->toParameter();
176 // Cast OBJECT to IV.
178 pcp_object_to_iv(pcp_object
* object
)
180 return object
->toIv();
183 // Cast OBJECT to bool expr.
185 pcp_object_to_bool_expr(pcp_object
* object
)
187 return object
->toBoolExpr();
190 // Cast OBJECT to variable.
192 pcp_object_to_variable(pcp_object
* object
)
194 return object
->toVariable();
197 // Cast OBJECT to array access.
199 pcp_object_to_array_access(pcp_object
* object
)
201 return object
->toArrayAccess();
204 // Cast OBJECT to stmt.
206 pcp_object_to_stmt(pcp_object
* object
)
208 return object
->toStmt();
211 // Cast OBJECT to 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
,
236 return annot_set
->getAnnotWithTag(tag
);
239 // Add ANNOT to ANNOT_SET. Assert that no previous annotation with the
241 void pcp_annot_set_add_annot(pcp_annot_set
* annot_set
, pcp_annot_term
* annot
)
243 annot_set
->addAnnot(annot
);
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.
259 pcp_annot_is_annot_int(pcp_annot
* annot
)
261 return annot
->isAnnotInt();
264 // Return true if ANNOT is a string.
266 pcp_annot_is_annot_string(pcp_annot
* annot
)
268 return annot
->isAnnotString();
271 // Return true if ANNOT is an object.
273 pcp_annot_is_annot_object(pcp_annot
* annot
)
275 return annot
->isAnnotObject();
278 // Return true if ANNOT is a term.
280 pcp_annot_is_annot_term(pcp_annot
* annot
)
282 return annot
->isAnnotTerm();
285 // Cast ANNOT to int.
287 pcp_annot_to_annot_int(pcp_annot
* annot
)
289 return annot
->toAnnotInt();
292 // Cast ANNOT to string.
294 pcp_annot_to_annot_string(pcp_annot
* annot
)
296 return annot
->toAnnotString();
299 // Cast ANNOT to object.
301 pcp_annot_to_annot_object(pcp_annot
* annot
)
303 return annot
->toAnnotObject();
306 // Cast ANNOT to term.
308 pcp_annot_to_annot_term(pcp_annot
* annot
)
310 return annot
->toAnnotTerm();
315 // Cast ANNOT_INT to annot.
317 pcp_annot_int_to_annot(pcp_annot_int
* 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.
331 pcp_annot_int_create(int value
)
333 return new PcpAnnotInt(value
);
338 // Cast ANNOT_STRING to annot.
340 pcp_annot_string_to_annot(pcp_annot_string
* annot_string
)
345 // Get string of ANNOT_STRING.
347 pcp_annot_string_get_string(pcp_annot_string
* annot_string
)
349 return annot_string
->getString();
352 // Create annot string with given STRING.
354 pcp_annot_string_create(const char* string
)
356 return new PcpAnnotString(string
);
361 // Cast ANNOT_OBJECT to annot.
363 pcp_annot_object_to_annot(pcp_annot_object
* annot_object
)
368 // Get object of ANNOT_OBJECT.
370 pcp_annot_object_get_object(pcp_annot_object
* annot_object
)
372 return annot_object
->getObject();
375 // Create annot object with given OBJECT.
377 pcp_annot_object_create(pcp_object
* object
)
379 return new PcpAnnotObject(object
);
384 // Cast ANNOT_TERM to annot.
386 pcp_annot_term_to_annot(pcp_annot_term
* annot_term
)
391 // Get tag of ANNOT_TERM.
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.
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.
422 pcp_annot_term_builder_set_tag(pcp_annot_term_builder
* builder
,
425 builder
->setTag(tag
);
428 // Add ARGUMENT to BUILDER.
430 pcp_annot_term_builder_add_argument(pcp_annot_term_builder
* builder
,
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.
445 pcp_annot_term_builder_create_annot(pcp_annot_term_builder
* builder
)
447 return builder
->createAnnot();
452 // Cast ARRAY_TYPE to object.
454 pcp_array_type_to_object(pcp_array_type
* 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.
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.
484 pcp_array_type_builder_add_dimension(pcp_array_type_builder
* builder
,
487 builder
->addDimension(size
);
490 void pcp_array_type_builder_add_int_dimension(pcp_array_type_builder
* builder
,
493 builder
->addIntDimension(size
);
496 // Create new array type from BUIDER.
498 pcp_array_type_builder_create_type(pcp_array_type_builder
* builder
)
500 return builder
->createType();
505 // Cast EXPR to object.
507 pcp_expr_to_object(pcp_expr
* expr
)
512 // Get expression 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
:
522 // Return true if EXPR is a pcp_parameter, otherwise return false.
524 pcp_expr_is_parameter(pcp_expr
* expr
)
526 return expr
->isParameter();
529 // Return true if EXPR is a pcp_arith, otherwise return false.
531 pcp_expr_is_arith(pcp_expr
* expr
)
533 return expr
->isArith();
536 // Return true if EXPR is a pcp_constant, otherwise return false.
538 pcp_expr_is_constant(pcp_expr
* expr
)
540 return expr
->isConstant();
543 // Return true if EXPR is a pcp_iv, otherwise return false.
545 pcp_expr_is_iv(pcp_expr
* expr
)
550 // Cast EXPR to pcp_parameter.
552 pcp_expr_to_parameter(pcp_expr
* expr
)
554 return expr
->toParameter();
557 // Cast EXPR to pcp_arith.
559 pcp_expr_to_arith(pcp_expr
* expr
)
561 return expr
->toArith();
564 // Cast EXPR to pcp_constant.
566 pcp_expr_to_constant(pcp_expr
* expr
)
568 return expr
->toConstant();
571 // Cast EXPR to pcp_iv.
573 pcp_expr_to_iv(pcp_expr
* expr
)
580 // Cast BOOL_EXPR to object.
582 pcp_bool_expr_to_object(pcp_bool_expr
* bool_expr
)
587 // Get kind of BOOL_EXPR.
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.
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.
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.
617 pcp_bool_expr_to_bool_arith(pcp_bool_expr
* bool_expr
)
619 return bool_expr
->toBoolArith();
624 pcp_compare_to_bool_expr(pcp_compare
* compare
)
629 // Convert OPER to a PcpCompareOperator.
630 static PcpCompareOperator
631 pcp_compare_operator_to_class(pcp_compare_operator oper
)
635 case pcp_compare_operator_equal
:
636 return PcpCompareOperator::equal();
637 case pcp_compare_operator_greater_equal
:
638 return PcpCompareOperator::greaterEqual();
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
)
649 return pcp_compare_operator_equal
;
650 else if(oper
.isGreaterEqual())
651 return pcp_compare_operator_greater_equal
;
653 return pcp_compare_operator_unknown
;
656 // Get pcp_compare_operator of COMPARE.
658 pcp_compare_get_operator(pcp_compare
* compare
)
660 return pcp_compare_operator_from_class(compare
->getOperator());
663 // Get lhs of COMPARE.
665 pcp_compare_get_lhs(pcp_compare
* compare
)
667 return compare
->getLhs();
670 // Get rhs of COMPARE.
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
,
682 PcpCompareOperator operClass
= pcp_compare_operator_to_class(oper
);
683 return new PcpCompare(operClass
, lhs
, rhs
);
687 static PcpBoolArithOperator
688 pcp_bool_arith_operator_to_class(pcp_bool_arith_operator oper
)
692 case pcp_bool_arith_operator_and
:
693 return PcpBoolArithOperator::boolAnd();
694 case pcp_bool_arith_operator_or
:
695 return PcpBoolArithOperator::boolOr();
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
)
706 return pcp_bool_arith_operator_and
;
708 return pcp_bool_arith_operator_or
;
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.
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.
736 pcp_bool_arith_to_object(pcp_bool_arith
* bool_arith
)
741 // Cast BOOL_ARITH to bool_expr.
743 pcp_bool_arith_to_bool_expr(pcp_bool_arith
* bool_arith
)
748 // PCP Bool Arith Builder.
749 // Set operator in BUILDER to OPERATOR.
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.
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.
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.
781 pcp_bool_arith_binary_create(pcp_bool_arith_operator oper
,
786 return PcpBoolArith::pcpBoolArithBinaryCreate(pcp_bool_arith_operator_to_class(oper
), lhs
, rhs
);
791 // Convert oper enum to PcpArithOperator class
792 static PcpArithOperator
793 pcp_arith_operator_to_class(pcp_arith_operator 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();
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
)
836 // Cast ARITH to expr.
837 pcp_expr
* pcp_arith_to_expr(pcp_arith
* 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.
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.
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.
873 pcp_arith_builder_add_operand(pcp_arith_builder
* builder
,
876 builder
->addOperand(operand
);
879 // Create new arithmetic operation from BUILDER.
881 pcp_arith_builder_create_arith(pcp_arith_builder
* builder
)
883 return builder
->createArith();
886 // Create new arithmetic operation builder.
888 pcp_arith_builder_create()
890 return new PcpArithBuilder();
895 // Cast CONSTANT to object.
897 pcp_constant_to_object(pcp_constant
* constant
)
902 // Cast CONSTANT to pcp_expr.
904 pcp_constant_to_expr(pcp_constant
* constant
)
909 // Get value of CONSTANT.
911 pcp_constant_get_value(pcp_constant
* constant
)
913 return constant
->getValue();
916 // Create constant with VALUE.
918 pcp_constant_create(int value
)
920 return new PcpConstant(value
);
923 // PCP Induction Variable
925 // Cast IV to object.
927 pcp_iv_to_object(pcp_iv
* iv
)
932 // Cast IV to pcp_expr.
934 pcp_iv_to_expr(pcp_iv
* iv
)
941 pcp_iv_get_name(pcp_iv
* iv
)
943 return iv
->getName();
946 // Create iv with NAME.
948 pcp_iv_create(const char* name
)
950 return new PcpIv(name
);
955 // Cast VAR to object.
957 pcp_variable_to_object(pcp_variable
* var
)
962 // Set is input of VAR to IS_INPUT.
964 pcp_variable_set_is_input(pcp_variable
* var
, bool is_input
)
966 var
->setIsInput(is_input
);
969 // Get is input of VAR.
971 pcp_variable_get_is_input(pcp_variable
* var
)
973 return var
->getIsInput();
976 // Set is output of VAR to IS_OUTPUT.
978 pcp_variable_set_is_output(pcp_variable
* var
, bool is_output
)
980 var
->setIsOutput(is_output
);
983 // Get is output of VAR.
985 pcp_variable_get_is_output(pcp_variable
* var
)
987 return var
->getIsOutput();
992 pcp_variable_get_type(pcp_variable
* var
)
994 return var
->getType();
999 pcp_variable_get_name(pcp_variable
* var
)
1001 return var
->getName();
1004 // Create variable given TYPE and NAME.
1006 pcp_variable_create(pcp_array_type
* type
, const char* name
)
1008 return new PcpVariable(type
, name
);
1013 // Cast PARAMETER to pcp_object.
1015 pcp_parameter_to_object(pcp_parameter
* parameter
)
1020 // Cast PARAMETER to pcp_expr.
1022 pcp_parameter_to_expr(pcp_parameter
* parameter
)
1027 // Get name of PARAMETER.
1029 pcp_parameter_get_name(pcp_parameter
* parameter
)
1031 return parameter
->getName();
1034 // Create parameter with the given NAME.
1036 pcp_parameter_create(const char* name
)
1038 return new PcpParameter(name
);
1041 // Create binary arithmetic operation with OPERATOR, LHS, RHS.
1043 pcp_arith_binary_create(pcp_arith_operator oper
,
1047 return PcpArith::pcpArithBinaryCreate(pcp_arith_operator_to_class(oper
),
1053 // Convert oper enum to PcpArrayOperator object
1054 static PcpArrayOperator
1055 pcp_array_operator_to_class(pcp_array_operator 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();
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.
1082 pcp_array_access_to_object(pcp_array_access
* access
)
1087 // Get operator enum from ACCESS.
1089 pcp_array_access_get_operator(pcp_array_access
* access
)
1091 return pcp_array_operator_from_class(access
->getOperator());
1094 // Get base of ACCESS.
1096 pcp_array_access_get_base(pcp_array_access
* access
)
1098 return access
->getBase();
1101 // Get ACCESS subscript at INDEX.
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.
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.
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.
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.
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.
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.
1163 pcp_array_access_builder_create_access(pcp_array_access_builder
* builder
)
1165 return builder
->createAccess();
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.
1183 pcp_stmt_to_object(pcp_stmt
* stmt
)
1188 // Get kind of STMT.
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.
1197 pcp_stmt_is_copy(pcp_stmt
* stmt
)
1199 return stmt
->isCopy();
1202 // Returns true if STMT is a user stmt.
1204 pcp_stmt_is_user_stmt(pcp_stmt
* stmt
)
1206 return stmt
->isUserStmt();
1209 // Returns true if STMT is a loop stmt.
1211 pcp_stmt_is_loop(pcp_stmt
* stmt
)
1213 return stmt
->isLoop();
1216 // Returns true if STMT is a guard stmt.
1218 pcp_stmt_is_guard(pcp_stmt
* stmt
)
1220 return stmt
->isGuard();
1223 // Returns true if STMT is a sequence stmt.
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.
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.
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.
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.
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.
1260 pcp_stmt_to_sequence(pcp_stmt
* stmt
)
1262 return stmt
->toSequence();
1267 // Cast COPY to object.
1269 pcp_copy_to_object(pcp_copy
* copy
)
1274 // Cast COPU to stmt.
1276 pcp_copy_to_stmt(pcp_copy
* copy
)
1281 // Get source of COPY.
1283 pcp_copy_get_src(pcp_copy
* copy
)
1285 return copy
->getSrc();
1288 // Get destination of COPY.
1290 pcp_copy_get_dest(pcp_copy
* copy
)
1292 return copy
->getDest();
1295 // Create new copy statement given DEST and SRC.
1297 pcp_copy_create(pcp_array_access
* dest
, pcp_array_access
* src
)
1299 return new PcpCopy(dest
, src
);
1304 // Cast USER_STMT to object.
1306 pcp_user_stmt_to_object(pcp_user_stmt
* user_stmt
)
1311 // Cast USER_STMT to stmt.
1313 pcp_user_stmt_to_stmt(pcp_user_stmt
* user_stmt
)
1318 // Get name of USER_STMT.
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.
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.
1343 pcp_user_stmt_builder_set_name(pcp_user_stmt_builder
* builder
,
1346 builder
->setName(name
);
1349 // Add ACCESS to BUILDER.
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.
1366 pcp_user_stmt_builder_create_user_stmt(pcp_user_stmt_builder
* builder
)
1368 return builder
->createUserStmt();
1373 // Cast SEQUENCE to stmt.
1375 pcp_sequence_to_stmt(pcp_sequence
* 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.
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.
1398 pcp_sequence_builder_add(pcp_sequence_builder
* builder
, pcp_stmt
* stmt
)
1403 // Create sequence builder.
1404 pcp_sequence_builder
*
1405 pcp_sequence_builder_create()
1407 return new PcpSequenceBuilder();
1410 // Create sequence from BUILDER.
1412 pcp_sequence_builder_create_sequence(pcp_sequence_builder
* builder
)
1414 return builder
->createSequence();
1419 // Cast GUARD to objec.
1421 pcp_guard_to_object(pcp_guard
* guard
)
1426 // Cast GUARD to stmt.
1428 pcp_guard_to_stmt(pcp_guard
* guard
)
1433 // Get condition of GUARD.
1435 pcp_guard_get_condition(pcp_guard
* guard
)
1437 return guard
->getCondition();
1440 // Get body of GUARD.
1442 pcp_guard_get_body(pcp_guard
* guard
)
1444 return guard
->getBody();
1447 // Create guard with given CONDITION and BODY.
1449 pcp_guard_create(pcp_bool_expr
* condition
, pcp_stmt
* body
)
1451 return new PcpGuard(condition
, body
);
1457 // Cast LOOP to object.
1459 pcp_loop_to_object(pcp_loop
* loop
)
1464 // Cast LOOP to stmt.
1466 pcp_loop_to_stmt(pcp_loop
* loop
)
1473 pcp_loop_get_iv(pcp_loop
* loop
)
1475 return loop
->getIv();
1478 // Get start of LOOP.
1480 pcp_loop_get_start(pcp_loop
* loop
)
1482 return loop
->getStart();
1485 // Get condition of LOOP.
1487 pcp_loop_get_condition(pcp_loop
* loop
)
1489 return loop
->getCondition();
1492 // Get stride of LOOP.
1494 pcp_loop_get_stride(pcp_loop
* loop
)
1496 return loop
->getStride();
1499 // Get body of LOOP.
1501 pcp_loop_get_body(pcp_loop
* loop
)
1503 return loop
->getBody();
1506 // Create loop as loop(IV, START, CONDITION, STRIDE) { BODY }.
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
);
1516 // Cast SCOP to object.
1518 pcp_scop_to_object(pcp_scop
* 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.
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.
1546 pcp_scop_get_parameter(pcp_scop
* scop
, int index
)
1548 return scop
->getParameter(index
);
1551 // Get body of SCOP.
1553 pcp_scop_get_body(pcp_scop
* scop
)
1555 return scop
->getBody();
1560 // Add VARIABLE to BUILDER.
1562 pcp_scop_builder_add_variable(pcp_scop_builder
* builder
,
1563 pcp_variable
* variable
)
1565 builder
->addVariable(variable
);
1568 // Add PARAMETER to BUILDER.
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.
1578 pcp_scop_builder_set_body(pcp_scop_builder
* builder
, pcp_stmt
* body
)
1580 builder
->setBody(body
);
1583 // Create new scop builder.
1585 pcp_scop_builder_create()
1587 return new PcpScopBuilder();
1590 // Create new scop from BUILDER.
1592 pcp_scop_builder_create_scop(pcp_scop_builder
* builder
)
1594 return builder
->createScop();