int
tree_int_cst_compare (const_tree t1, const_tree t2)
{
- if (tree_int_cst_lt (t1, t2))
- return -1;
- else if (tree_int_cst_lt (t2, t1))
- return 1;
- else
- return 0;
+ return wi::cmps (wi::to_widest (t1), wi::to_widest (t2));
}
- && ((TREE_INT_CST_HIGH (t) == 0
- && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) >= 0)
- || (TREE_INT_CST_HIGH (t) == -1
- && (HOST_WIDE_INT) TREE_INT_CST_LOW (t) < 0
- && !TYPE_UNSIGNED (TREE_TYPE (t)))));
+ /* Return true if T is an INTEGER_CST whose numerical value (extended
+ according to TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. */
+
+ bool
+ tree_fits_shwi_p (const_tree t)
+ {
+ return (t != NULL_TREE
+ && TREE_CODE (t) == INTEGER_CST
- && TREE_INT_CST_HIGH (t) == 0);
++ && wi::fits_shwi_p (wi::to_widest (t)));
+ }
+
+ /* Return true if T is an INTEGER_CST whose numerical value (extended
+ according to TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. */
+
+ bool
+ tree_fits_uhwi_p (const_tree t)
+ {
+ return (t != NULL_TREE
+ && TREE_CODE (t) == INTEGER_CST
- return TREE_INT_CST_LOW (t);
++ && wi::fits_uhwi_p (wi::to_widest (t)));
+ }
+
+ /* T is an INTEGER_CST whose numerical value (extended according to
+ TYPE_UNSIGNED) fits in a signed HOST_WIDE_INT. Return that
+ HOST_WIDE_INT. */
+
+ HOST_WIDE_INT
+ tree_to_shwi (const_tree t)
+ {
+ gcc_assert (tree_fits_shwi_p (t));
- return TREE_INT_CST_LOW (t);
++ return TREE_INT_CST_ELT (t, 0);
+ }
+
+ /* T is an INTEGER_CST whose numerical value (extended according to
+ TYPE_UNSIGNED) fits in an unsigned HOST_WIDE_INT. Return that
+ HOST_WIDE_INT. */
+
+ unsigned HOST_WIDE_INT
+ tree_to_uhwi (const_tree t)
+ {
+ gcc_assert (tree_fits_uhwi_p (t));
++ return TREE_INT_CST_ELT (t, 0);
+ }
+
/* Return the most significant (sign) bit of T. */
int
#endif
- /* Return true if T is an INTEGER_CST whose value must be non-negative
- and can be represented in a single unsigned HOST_WIDE_INT. This
- function differs from the cst_fits versions in that the signedness
- of the type of cst is considered. */
-
- static inline bool
- tree_fits_uhwi_p (const_tree cst)
- {
- tree type;
- if (cst == NULL_TREE)
- return false;
-
- type = TREE_TYPE (cst);
-
- if (TREE_CODE (cst) != INTEGER_CST)
- return false;
-
- if (TREE_INT_CST_NUNITS (cst) == 1)
- {
- if ((TYPE_SIGN (type) == UNSIGNED)
- && (TYPE_PRECISION (type) <= HOST_BITS_PER_WIDE_INT))
- return true;
-
- /* For numbers of unsigned type that are longer than a HWI, if
- the top bit of the bottom word is set, and there is not
- another element, then this is too large to fit in a single
- hwi. For signed numbers, negative values are not allowed. */
- if (TREE_INT_CST_ELT (cst, 0) >= 0)
- return true;
- }
- else if (TREE_INT_CST_NUNITS (cst) == 2)
- {
- if (TREE_INT_CST_ELT (cst, 1) == 0)
- return true;
- }
- return false;
- }
-
- /* Return true if CST is an INTEGER_CST whose value can be represented
- in a single HOST_WIDE_INT. This function differs from the cst_fits
- versions in that the signedness of the type of cst is
- considered. */
-
- static inline bool
- tree_fits_shwi_p (const_tree cst)
- {
- if (cst == NULL_TREE)
- return false;
-
- if (TREE_CODE (cst) != INTEGER_CST)
- return false;
-
- if (TREE_INT_CST_NUNITS (cst) != 1)
- return false;
-
- if (TYPE_SIGN (TREE_TYPE (cst)) == SIGNED)
- return true;
-
- if (TREE_INT_CST_ELT (cst, 0) >= 0)
- return true;
-
- return false;
- }
-
- /* Return true if T is an INTEGER_CST that can be manipulated
- efficiently on the host. If SIGN is SIGNED, the value can be
- represented in a single HOST_WIDE_INT. If SIGN is UNSIGNED, the
- value must be non-negative and can be represented in a single
- unsigned HOST_WIDE_INT. */
-
- static inline bool
- tree_fits_hwi_p (const_tree cst, signop sign)
- {
- return sign ? tree_fits_uhwi_p (cst) : tree_fits_shwi_p (cst);
- }
-
- /* Return true if T is an INTEGER_CST that can be manipulated
- efficiently on the host. If the sign of CST is SIGNED, the value
- can be represented in a single HOST_WIDE_INT. If the sign of CST
- is UNSIGNED, the value must be non-negative and can be represented
- in a single unsigned HOST_WIDE_INT. */
-
- static inline bool
- tree_fits_hwi_p (const_tree cst)
- {
- if (cst == NULL_TREE)
- return false;
-
- if (TREE_CODE (cst) != INTEGER_CST)
- return false;
-
- return TYPE_UNSIGNED (TREE_TYPE (cst))
- ? tree_fits_uhwi_p (cst) : tree_fits_shwi_p (cst);
- }
-
- /* Return the unsigned HOST_WIDE_INT least significant bits of CST.
- If checking is enabled, this ices if the value does not fit. */
-
- static inline unsigned HOST_WIDE_INT
- tree_to_uhwi (const_tree cst)
- {
- gcc_checking_assert (tree_fits_uhwi_p (cst));
-
- return (unsigned HOST_WIDE_INT)TREE_INT_CST_ELT (cst, 0);
- }
-
- /* Return the HOST_WIDE_INT least significant bits of CST. If
- checking is enabled, this ices if the value does not fit. */
-
- static inline HOST_WIDE_INT
- tree_to_shwi (const_tree cst)
- {
- gcc_checking_assert (tree_fits_shwi_p (cst));
-
- return (HOST_WIDE_INT)TREE_INT_CST_ELT (cst, 0);
- }
-
+/* Checks that X is an integer constant that can be expressed in a signed
+ HOST_WIDE_INT without loss of precision. This function differs from
+ the tree_fits_* versions in that the signedness of the type of X is
+ not considered. */
+
+static inline bool
+cst_fits_shwi_p (const_tree x)
+{
+ if (TREE_CODE (x) != INTEGER_CST)
+ return false;
+
+ return TREE_INT_CST_NUNITS (x) == 1;
+}
+
+/* Checks that X is an integer constant that can be expressed in an unsigned
+ HOST_WIDE_INT without loss of precision. This function differs from
+ the tree_fits_* versions in that the signedness of the type of X is
+ not considered. */
+
+static inline bool
+cst_fits_uhwi_p (const_tree x)
+{
+ if (TREE_CODE (x) != INTEGER_CST)
+ return false;
+
+ return TREE_INT_CST_NUNITS (x) == 1 && TREE_INT_CST_ELT (x, 0) >= 0;
+}
+
- /* Return the HOST_WIDE_INT least significant bits of CST. The sign
- of the checking is based on SIGNOP. */
-
- static inline HOST_WIDE_INT
- tree_to_hwi (const_tree cst, signop sgn)
- {
- if (sgn == SIGNED)
- return tree_to_shwi (cst);
- else
- return tree_to_uhwi (cst);
- }
-
-
+/* Return the HOST_WIDE_INT least significant bits of CST. No
+ checking is done to assure that it fits. It is assumed that one of
+ tree_fits_uhwi_p or tree_fits_shwi_p was done before this call. */
+
+static inline HOST_WIDE_INT
+tree_to_hwi (const_tree cst)
+{
+ return TREE_INT_CST_ELT (cst, 0);
+}
+
/* Compute the number of operands in an expression node NODE. For
tcc_vl_exp nodes like CALL_EXPRs, this is stored in the node itself,
otherwise it is looked up from the node's code. */
extern int tree_int_cst_equal (const_tree, const_tree);
extern int tree_int_cst_lt (const_tree, const_tree);
extern int tree_int_cst_compare (const_tree, const_tree);
- return TREE_INT_CST_LOW (t);
+ extern bool tree_fits_shwi_p (const_tree)
+ #ifndef ENABLE_TREE_CHECKING
+ ATTRIBUTE_PURE /* tree_fits_shwi_p is pure only when checking is disabled. */
+ #endif
+ ;
+ extern bool tree_fits_uhwi_p (const_tree)
+ #ifndef ENABLE_TREE_CHECKING
+ ATTRIBUTE_PURE /* tree_fits_uhwi_p is pure only when checking is disabled. */
+ #endif
+ ;
+ extern HOST_WIDE_INT tree_to_shwi (const_tree);
+ extern unsigned HOST_WIDE_INT tree_to_uhwi (const_tree);
+ #if !defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 4003)
+ extern inline __attribute__ ((__gnu_inline__)) HOST_WIDE_INT
+ tree_to_shwi (const_tree t)
+ {
+ gcc_assert (tree_fits_shwi_p (t));
- return TREE_INT_CST_LOW (t);
++ return TREE_INT_CST_ELT (t, 0);
+ }
+
+ extern inline __attribute__ ((__gnu_inline__)) unsigned HOST_WIDE_INT
+ tree_to_uhwi (const_tree t)
+ {
+ gcc_assert (tree_fits_uhwi_p (t));
++ return TREE_INT_CST_ELT (t, 0);
+ }
+ #endif
extern int tree_int_cst_sgn (const_tree);
extern int tree_int_cst_sign_bit (const_tree);
-extern unsigned int tree_int_cst_min_precision (tree, bool);
+extern unsigned int tree_int_cst_min_precision (tree, signop);
extern bool tree_expr_nonnegative_p (tree);
extern bool tree_expr_nonnegative_warnv_p (tree, bool *);
extern bool may_negate_without_overflow_p (const_tree);
extern bool valid_constant_size_p (const_tree);
extern unsigned int element_precision (const_tree);
++/* Return true if T is an INTEGER_CST that can be manipulated
++ efficiently on the host. If SIGN is SIGNED, the value can be
++ represented in a single HOST_WIDE_INT. If SIGN is UNSIGNED, the
++ value must be non-negative and can be represented in a single
++ unsigned HOST_WIDE_INT. */
++
++static inline bool
++tree_fits_hwi_p (const_tree cst, signop sign)
++{
++ return sign ? tree_fits_uhwi_p (cst) : tree_fits_shwi_p (cst);
++}
++
++/* Return true if T is an INTEGER_CST that can be manipulated
++ efficiently on the host. If the sign of CST is SIGNED, the value
++ can be represented in a single HOST_WIDE_INT. If the sign of CST
++ is UNSIGNED, the value must be non-negative and can be represented
++ in a single unsigned HOST_WIDE_INT. */
++
++static inline bool
++tree_fits_hwi_p (const_tree cst)
++{
++ if (cst == NULL_TREE)
++ return false;
++
++ if (TREE_CODE (cst) != INTEGER_CST)
++ return false;
++
++ return TYPE_UNSIGNED (TREE_TYPE (cst))
++ ? tree_fits_uhwi_p (cst) : tree_fits_shwi_p (cst);
++}
++
++/* Return the HOST_WIDE_INT least significant bits of CST. The sign
++ of the checking is based on SIGNOP. */
++
++static inline HOST_WIDE_INT
++tree_to_hwi (const_tree cst, signop sgn)
++{
++ if (sgn == SIGNED)
++ return tree_to_shwi (cst);
++ else
++ return tree_to_uhwi (cst);
++}
++
++
/* Construct various nodes representing fract or accum data types. */
extern tree make_fract_type (int, int, int);