{
tree name = clast_name_to_gcc (t->var, region, newivs,
newivs_index, params_index);
- return fold_convert (type, name);
+
+ if (POINTER_TYPE_P (TREE_TYPE (name)) != POINTER_TYPE_P (type))
+ name = fold_convert (sizetype, name);
+
+ name = fold_convert (type, name);
+ return name;
}
else if (value_mone_p (t->val))
{
tree name = clast_name_to_gcc (t->var, region, newivs,
newivs_index, params_index);
+
+ if (POINTER_TYPE_P (TREE_TYPE (name)) != POINTER_TYPE_P (type))
+ name = fold_convert (sizetype, name);
+
name = fold_convert (type, name);
+
return fold_build1 (NEGATE_EXPR, type, name);
}
else
tree name = clast_name_to_gcc (t->var, region, newivs,
newivs_index, params_index);
tree cst = gmp_cst_to_tree (type, t->val);
+
+ if (POINTER_TYPE_P (TREE_TYPE (name)) != POINTER_TYPE_P (type))
+ name = fold_convert (sizetype, name);
+
name = fold_convert (type, name);
+
if (!POINTER_TYPE_P (type))
return fold_build2 (MULT_EXPR, type, cst, name);
gcc_unreachable ();
}
-/* Given a CLOOG_IV, returns the type that it should have in GCC land.
- If the information is not available, i.e. in the case one of the
- transforms created the loop, just return integer_type_node. */
+/* Given a CLOOG_IV, return the type that CLOOG_IV should have in GCC
+ land. The selected type is big enough to include the original loop
+ iteration variable, but signed to work with the subtractions CLooG
+ may have introduced. If such a type is not available, we fail.
+
+ TODO: Do not always return long_long, but the smallest possible
+ type, that still holds the original type.
+
+ TODO: Get the types using CLooG instead. This enables further
+ optimizations, but needs CLooG support. */
static tree
gcc_type_for_cloog_iv (const char *cloog_iv, gimple_bb_p gbb)
slot = htab_find_slot (GBB_CLOOG_IV_TYPES (gbb), &tmp, NO_INSERT);
if (slot && *slot)
- return ((ivtype_map_elt) *slot)->type;
+ {
+ tree type = ((ivtype_map_elt) *slot)->type;
+ int type_precision = TYPE_PRECISION (type);
+
+ /* Find the smallest signed type possible. */
+ if (!TYPE_UNSIGNED (type))
+ {
+ if (type_precision <= TYPE_PRECISION (integer_type_node))
+ return integer_type_node;
+
+ if (type_precision <= TYPE_PRECISION (long_integer_type_node))
+ return long_integer_type_node;
+
+ if (type_precision <= TYPE_PRECISION (long_long_integer_type_node))
+ return long_long_integer_type_node;
+
+ gcc_unreachable ();
+ }
+
+ if (type_precision < TYPE_PRECISION (integer_type_node))
+ return integer_type_node;
+
+ if (type_precision < TYPE_PRECISION (long_integer_type_node))
+ return long_integer_type_node;
+
+ if (type_precision < TYPE_PRECISION (long_long_integer_type_node))
+ return long_long_integer_type_node;
+
+ /* There is no signed type available, that is large enough to hold the
+ original value. */
+ gcc_unreachable ();
+ }
- return integer_type_node;
+ return long_long_integer_type_node;
}
/* Returns the induction variable for the loop that gets translated to
if (slot && !*slot)
{
tree oldiv = pbb_to_depth_to_oldiv (pbb, index);
- tree type = oldiv ? TREE_TYPE (oldiv) : integer_type_node;
+ tree type = TREE_TYPE (oldiv);
*slot = new_ivtype_map_elt (tmp.cloog_iv, type);
}
}
graphite_loop_normal_form (loop);
}
+/* Can all ivs be represented by a signed integer?
+ As CLooG might generate negative values in its expressions, signed loop ivs
+ are required in the backend. */
+static bool
+scop_ivs_can_be_represented (scop_p scop)
+{
+ loop_iterator li;
+ loop_p loop;
+
+ FOR_EACH_LOOP (li, loop, 0)
+ {
+ tree type;
+ int precision;
+
+ if (!loop_in_sese_p (loop, SCOP_REGION (scop)))
+ continue;
+
+ if (!loop->single_iv)
+ continue;
+
+ type = TREE_TYPE(loop->single_iv);
+ precision = TYPE_PRECISION (type);
+
+ if (TYPE_UNSIGNED (type)
+ && precision >= TYPE_PRECISION (long_long_integer_type_node))
+ return false;
+ }
+
+ return true;
+}
+
+
/* Builds the polyhedral representation for a SESE region. */
bool
return false;
scop_canonicalize_loops (scop);
+
+ if (!scop_ivs_can_be_represented (scop))
+ return false;
+
build_sese_loop_nests (region);
build_sese_conditions (region);
find_scop_parameters (scop);