+/* Applies operation OP on affine functions FNA and FNB, and returns the
+ result. */
+
+static affine_fn
+affine_fn_op (enum tree_code op, affine_fn fna, affine_fn fnb)
+{
+ unsigned i, n, m;
+ affine_fn ret;
+ tree coef;
+
+ if (VEC_length (tree, fnb) > VEC_length (tree, fna))
+ {
+ n = VEC_length (tree, fna);
+ m = VEC_length (tree, fnb);
+ }
+ else
+ {
+ n = VEC_length (tree, fnb);
+ m = VEC_length (tree, fna);
+ }
+
+ ret = VEC_alloc (tree, heap, m);
+ for (i = 0; i < n; i++)
+ VEC_quick_push (tree, ret,
+ fold_build2 (op, integer_type_node,
+ VEC_index (tree, fna, i),
+ VEC_index (tree, fnb, i)));
+
+ for (; VEC_iterate (tree, fna, i, coef); i++)
+ VEC_quick_push (tree, ret,
+ fold_build2 (op, integer_type_node,
+ coef, integer_zero_node));
+ for (; VEC_iterate (tree, fnb, i, coef); i++)
+ VEC_quick_push (tree, ret,
+ fold_build2 (op, integer_type_node,
+ integer_zero_node, coef));
+
+ return ret;
+}
+
+/* Returns the sum of affine functions FNA and FNB. */
+
+static affine_fn
+affine_fn_plus (affine_fn fna, affine_fn fnb)
+{
+ return affine_fn_op (PLUS_EXPR, fna, fnb);
+}
+
+/* Returns the difference of affine functions FNA and FNB. */
+
+static affine_fn
+affine_fn_minus (affine_fn fna, affine_fn fnb)
+{
+ return affine_fn_op (MINUS_EXPR, fna, fnb);
+}
+
+/* Frees affine function FN. */
+
+static void
+affine_fn_free (affine_fn fn)
+{
+ VEC_free (tree, heap, fn);
+}
+