+/* For a PHI node which sets SSA name N_I, VR_COUNTS[I] holds the
+ number of executable edges we saw the last time we visited the
+ node. */
+static int *vr_phi_edge_counts;
+
+
+/* Return whether TYPE should use an overflow infinity distinct from
+ TYPE_{MIN,MAX}_VALUE. We use an overflow infinity value to
+ represent a signed overflow during VRP computations. An infinity
+ is distinct from a half-range, which will go from some number to
+ TYPE_{MIN,MAX}_VALUE. */
+
+static inline bool
+needs_overflow_infinity (const_tree type)
+{
+ return INTEGRAL_TYPE_P (type) && !TYPE_OVERFLOW_WRAPS (type);
+}
+
+/* Return whether TYPE can support our overflow infinity
+ representation: we use the TREE_OVERFLOW flag, which only exists
+ for constants. If TYPE doesn't support this, we don't optimize
+ cases which would require signed overflow--we drop them to
+ VARYING. */
+
+static inline bool
+supports_overflow_infinity (const_tree type)
+{
+#ifdef ENABLE_CHECKING
+ gcc_assert (needs_overflow_infinity (type));
+#endif
+ return (TYPE_MIN_VALUE (type) != NULL_TREE
+ && CONSTANT_CLASS_P (TYPE_MIN_VALUE (type))
+ && TYPE_MAX_VALUE (type) != NULL_TREE
+ && CONSTANT_CLASS_P (TYPE_MAX_VALUE (type)));
+}
+
+/* VAL is the maximum or minimum value of a type. Return a
+ corresponding overflow infinity. */
+
+static inline tree
+make_overflow_infinity (tree val)
+{
+#ifdef ENABLE_CHECKING
+ gcc_assert (val != NULL_TREE && CONSTANT_CLASS_P (val));
+#endif
+ val = copy_node (val);
+ TREE_OVERFLOW (val) = 1;
+ return val;
+}
+
+/* Return a negative overflow infinity for TYPE. */
+
+static inline tree
+negative_overflow_infinity (tree type)
+{
+#ifdef ENABLE_CHECKING
+ gcc_assert (supports_overflow_infinity (type));
+#endif
+ return make_overflow_infinity (TYPE_MIN_VALUE (type));
+}
+
+/* Return a positive overflow infinity for TYPE. */
+
+static inline tree
+positive_overflow_infinity (tree type)
+{
+#ifdef ENABLE_CHECKING
+ gcc_assert (supports_overflow_infinity (type));
+#endif
+ return make_overflow_infinity (TYPE_MAX_VALUE (type));
+}
+
+/* Return whether VAL is a negative overflow infinity. */
+
+static inline bool
+is_negative_overflow_infinity (const_tree val)
+{
+ return (needs_overflow_infinity (TREE_TYPE (val))
+ && CONSTANT_CLASS_P (val)
+ && TREE_OVERFLOW (val)
+ && operand_equal_p (val, TYPE_MIN_VALUE (TREE_TYPE (val)), 0));
+}
+
+/* Return whether VAL is a positive overflow infinity. */
+
+static inline bool
+is_positive_overflow_infinity (const_tree val)
+{
+ return (needs_overflow_infinity (TREE_TYPE (val))
+ && CONSTANT_CLASS_P (val)
+ && TREE_OVERFLOW (val)
+ && operand_equal_p (val, TYPE_MAX_VALUE (TREE_TYPE (val)), 0));
+}
+
+/* Return whether VAL is a positive or negative overflow infinity. */
+
+static inline bool
+is_overflow_infinity (const_tree val)
+{
+ return (needs_overflow_infinity (TREE_TYPE (val))
+ && CONSTANT_CLASS_P (val)
+ && TREE_OVERFLOW (val)
+ && (operand_equal_p (val, TYPE_MAX_VALUE (TREE_TYPE (val)), 0)
+ || operand_equal_p (val, TYPE_MIN_VALUE (TREE_TYPE (val)), 0)));
+}
+
+/* If VAL is now an overflow infinity, return VAL. Otherwise, return
+ the same value with TREE_OVERFLOW clear. This can be used to avoid
+ confusing a regular value with an overflow value. */
+
+static inline tree
+avoid_overflow_infinity (tree val)
+{
+ if (!is_overflow_infinity (val))
+ return val;
+
+ if (operand_equal_p (val, TYPE_MAX_VALUE (TREE_TYPE (val)), 0))
+ return TYPE_MAX_VALUE (TREE_TYPE (val));
+ else
+ {
+#ifdef ENABLE_CHECKING
+ gcc_assert (operand_equal_p (val, TYPE_MIN_VALUE (TREE_TYPE (val)), 0));
+#endif
+ return TYPE_MIN_VALUE (TREE_TYPE (val));
+ }
+}
+
+
+/* Return whether VAL is equal to the maximum value of its type. This
+ will be true for a positive overflow infinity. We can't do a
+ simple equality comparison with TYPE_MAX_VALUE because C typedefs
+ and Ada subtypes can produce types whose TYPE_MAX_VALUE is not ==
+ to the integer constant with the same value in the type. */
+
+static inline bool
+vrp_val_is_max (const_tree val)
+{
+ tree type_max = TYPE_MAX_VALUE (TREE_TYPE (val));
+
+ return (val == type_max
+ || (type_max != NULL_TREE
+ && operand_equal_p (val, type_max, 0)));
+}
+
+/* Return whether VAL is equal to the minimum value of its type. This
+ will be true for a negative overflow infinity. */
+
+static inline bool
+vrp_val_is_min (const_tree val)
+{
+ tree type_min = TYPE_MIN_VALUE (TREE_TYPE (val));
+
+ return (val == type_min
+ || (type_min != NULL_TREE
+ && operand_equal_p (val, type_min, 0)));
+}
+