fold-const.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* Fold a constant sub-tree into a single node for C-compiler
  2. Copyright (C) 1987-2019 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef GCC_FOLD_CONST_H
  16. #define GCC_FOLD_CONST_H
  17. /* Non-zero if we are folding constants inside an initializer; zero
  18. otherwise. */
  19. extern int folding_initializer;
  20. /* Convert between trees and native memory representation. */
  21. extern int native_encode_expr (const_tree, unsigned char *, int, int off = -1);
  22. extern tree native_interpret_expr (tree, const unsigned char *, int);
  23. /* Fold constants as much as possible in an expression.
  24. Returns the simplified expression.
  25. Acts only on the top level of the expression;
  26. if the argument itself cannot be simplified, its
  27. subexpressions are not changed. */
  28. extern tree fold (tree);
  29. #define fold_unary(CODE,T1,T2)\
  30. fold_unary_loc (UNKNOWN_LOCATION, CODE, T1, T2)
  31. extern tree fold_unary_loc (location_t, enum tree_code, tree, tree);
  32. #define fold_unary_ignore_overflow(CODE,T1,T2)\
  33. fold_unary_ignore_overflow_loc (UNKNOWN_LOCATION, CODE, T1, T2)
  34. extern tree fold_unary_ignore_overflow_loc (location_t, enum tree_code, tree, tree);
  35. #define fold_binary(CODE,T1,T2,T3)\
  36. fold_binary_loc (UNKNOWN_LOCATION, CODE, T1, T2, T3)
  37. extern tree fold_binary_loc (location_t, enum tree_code, tree, tree, tree);
  38. #define fold_ternary(CODE,T1,T2,T3,T4)\
  39. fold_ternary_loc (UNKNOWN_LOCATION, CODE, T1, T2, T3, T4)
  40. extern tree fold_ternary_loc (location_t, enum tree_code, tree, tree, tree, tree);
  41. #define fold_build1(c,t1,t2)\
  42. fold_build1_loc (UNKNOWN_LOCATION, c, t1, t2 MEM_STAT_INFO)
  43. extern tree fold_build1_loc (location_t, enum tree_code, tree,
  44. tree CXX_MEM_STAT_INFO);
  45. #define fold_build2(c,t1,t2,t3)\
  46. fold_build2_loc (UNKNOWN_LOCATION, c, t1, t2, t3 MEM_STAT_INFO)
  47. extern tree fold_build2_loc (location_t, enum tree_code, tree, tree,
  48. tree CXX_MEM_STAT_INFO);
  49. #define fold_build3(c,t1,t2,t3,t4)\
  50. fold_build3_loc (UNKNOWN_LOCATION, c, t1, t2, t3, t4 MEM_STAT_INFO)
  51. extern tree fold_build3_loc (location_t, enum tree_code, tree, tree, tree,
  52. tree CXX_MEM_STAT_INFO);
  53. extern tree fold_build1_initializer_loc (location_t, enum tree_code, tree, tree);
  54. extern tree fold_build2_initializer_loc (location_t, enum tree_code, tree, tree, tree);
  55. #define fold_build_call_array(T1,T2,N,T4)\
  56. fold_build_call_array_loc (UNKNOWN_LOCATION, T1, T2, N, T4)
  57. extern tree fold_build_call_array_loc (location_t, tree, tree, int, tree *);
  58. #define fold_build_call_array_initializer(T1,T2,N,T4)\
  59. fold_build_call_array_initializer_loc (UNKNOWN_LOCATION, T1, T2, N, T4)
  60. extern tree fold_build_call_array_initializer_loc (location_t, tree, tree, int, tree *);
  61. extern tree get_array_ctor_element_at_index (tree, offset_int);
  62. extern bool fold_convertible_p (const_tree, const_tree);
  63. #define fold_convert(T1,T2)\
  64. fold_convert_loc (UNKNOWN_LOCATION, T1, T2)
  65. extern tree fold_convert_loc (location_t, tree, tree);
  66. extern tree fold_single_bit_test (location_t, enum tree_code, tree, tree, tree);
  67. extern tree fold_ignored_result (tree);
  68. extern tree fold_abs_const (tree, tree);
  69. extern tree fold_indirect_ref_1 (location_t, tree, tree);
  70. extern void fold_defer_overflow_warnings (void);
  71. extern void fold_undefer_overflow_warnings (bool, const gimple *, int);
  72. extern void fold_undefer_and_ignore_overflow_warnings (void);
  73. extern bool fold_deferring_overflow_warnings_p (void);
  74. extern void fold_overflow_warning (const char*, enum warn_strict_overflow_code);
  75. extern enum tree_code fold_div_compare (enum tree_code, tree, tree,
  76. tree *, tree *, bool *);
  77. extern int operand_equal_p (const_tree, const_tree, unsigned int);
  78. extern int multiple_of_p (tree, const_tree, const_tree);
  79. #define omit_one_operand(T1,T2,T3)\
  80. omit_one_operand_loc (UNKNOWN_LOCATION, T1, T2, T3)
  81. extern tree omit_one_operand_loc (location_t, tree, tree, tree);
  82. #define omit_two_operands(T1,T2,T3,T4)\
  83. omit_two_operands_loc (UNKNOWN_LOCATION, T1, T2, T3, T4)
  84. extern tree omit_two_operands_loc (location_t, tree, tree, tree, tree);
  85. #define invert_truthvalue(T)\
  86. invert_truthvalue_loc (UNKNOWN_LOCATION, T)
  87. extern tree invert_truthvalue_loc (location_t, tree);
  88. extern tree fold_unary_to_constant (enum tree_code, tree, tree);
  89. extern tree fold_binary_to_constant (enum tree_code, tree, tree, tree);
  90. extern tree fold_bit_and_mask (tree, tree, enum tree_code,
  91. tree, enum tree_code, tree, tree,
  92. tree, enum tree_code, tree, tree, tree *);
  93. extern tree fold_read_from_constant_string (tree);
  94. extern bool wide_int_binop (wide_int &res, enum tree_code,
  95. const wide_int &arg1, const wide_int &arg2,
  96. signop, wi::overflow_type *);
  97. extern tree int_const_binop (enum tree_code, const_tree, const_tree, int = 1);
  98. #define build_fold_addr_expr(T)\
  99. build_fold_addr_expr_loc (UNKNOWN_LOCATION, (T))
  100. extern tree build_fold_addr_expr_loc (location_t, tree);
  101. #define build_fold_addr_expr_with_type(T,TYPE)\
  102. build_fold_addr_expr_with_type_loc (UNKNOWN_LOCATION, (T), TYPE)
  103. extern tree build_fold_addr_expr_with_type_loc (location_t, tree, tree);
  104. extern tree fold_build_cleanup_point_expr (tree type, tree expr);
  105. #define build_fold_indirect_ref(T)\
  106. build_fold_indirect_ref_loc (UNKNOWN_LOCATION, T)
  107. extern tree build_fold_indirect_ref_loc (location_t, tree);
  108. #define fold_indirect_ref(T)\
  109. fold_indirect_ref_loc (UNKNOWN_LOCATION, T)
  110. extern tree fold_indirect_ref_loc (location_t, tree);
  111. extern tree build_simple_mem_ref_loc (location_t, tree);
  112. #define build_simple_mem_ref(T)\
  113. build_simple_mem_ref_loc (UNKNOWN_LOCATION, T)
  114. extern poly_offset_int mem_ref_offset (const_tree);
  115. extern tree build_invariant_address (tree, tree, poly_int64);
  116. extern tree constant_boolean_node (bool, tree);
  117. extern tree div_if_zero_remainder (const_tree, const_tree);
  118. extern bool tree_swap_operands_p (const_tree, const_tree);
  119. extern enum tree_code swap_tree_comparison (enum tree_code);
  120. extern bool ptr_difference_const (tree, tree, poly_int64_pod *);
  121. extern enum tree_code invert_tree_comparison (enum tree_code, bool);
  122. extern bool inverse_conditions_p (const_tree, const_tree);
  123. extern bool tree_unary_nonzero_warnv_p (enum tree_code, tree, tree, bool *);
  124. extern bool tree_binary_nonzero_warnv_p (enum tree_code, tree, tree, tree op1,
  125. bool *);
  126. extern bool tree_single_nonzero_warnv_p (tree, bool *);
  127. extern bool tree_unary_nonnegative_warnv_p (enum tree_code, tree, tree,
  128. bool *, int);
  129. extern bool tree_binary_nonnegative_warnv_p (enum tree_code, tree, tree, tree,
  130. bool *, int);
  131. extern bool tree_single_nonnegative_warnv_p (tree, bool *, int);
  132. extern bool tree_call_nonnegative_warnv_p (tree, combined_fn, tree, tree,
  133. bool *, int);
  134. extern bool integer_valued_real_unary_p (tree_code, tree, int);
  135. extern bool integer_valued_real_binary_p (tree_code, tree, tree, int);
  136. extern bool integer_valued_real_call_p (combined_fn, tree, tree, int);
  137. extern bool integer_valued_real_single_p (tree, int);
  138. extern bool integer_valued_real_p (tree, int = 0);
  139. extern bool fold_real_zero_addition_p (const_tree, const_tree, int);
  140. extern tree combine_comparisons (location_t, enum tree_code, enum tree_code,
  141. enum tree_code, tree, tree, tree);
  142. extern void debug_fold_checksum (const_tree);
  143. extern bool may_negate_without_overflow_p (const_tree);
  144. #define round_up(T,N) round_up_loc (UNKNOWN_LOCATION, T, N)
  145. extern tree round_up_loc (location_t, tree, unsigned int);
  146. #define round_down(T,N) round_down_loc (UNKNOWN_LOCATION, T, N)
  147. extern tree round_down_loc (location_t, tree, int);
  148. extern tree size_int_kind (poly_int64, enum size_type_kind);
  149. #define size_binop(CODE,T1,T2)\
  150. size_binop_loc (UNKNOWN_LOCATION, CODE, T1, T2)
  151. extern tree size_binop_loc (location_t, enum tree_code, tree, tree);
  152. #define size_diffop(T1,T2)\
  153. size_diffop_loc (UNKNOWN_LOCATION, T1, T2)
  154. extern tree size_diffop_loc (location_t, tree, tree);
  155. /* Return an expr equal to X but certainly not valid as an lvalue. */
  156. #define non_lvalue(T) non_lvalue_loc (UNKNOWN_LOCATION, T)
  157. extern tree non_lvalue_loc (location_t, tree);
  158. extern bool tree_expr_nonzero_p (tree);
  159. extern bool tree_expr_nonnegative_p (tree);
  160. extern bool tree_expr_nonnegative_warnv_p (tree, bool *, int = 0);
  161. extern tree make_range (tree, int *, tree *, tree *, bool *);
  162. extern tree make_range_step (location_t, enum tree_code, tree, tree, tree,
  163. tree *, tree *, int *, bool *);
  164. extern tree range_check_type (tree);
  165. extern tree build_range_check (location_t, tree, tree, int, tree, tree);
  166. extern bool merge_ranges (int *, tree *, tree *, int, tree, tree, int,
  167. tree, tree);
  168. extern tree sign_bit_p (tree, const_tree);
  169. extern tree exact_inverse (tree, tree);
  170. extern bool expr_not_equal_to (tree t, const wide_int &);
  171. extern tree const_unop (enum tree_code, tree, tree);
  172. extern tree const_binop (enum tree_code, tree, tree, tree);
  173. extern bool negate_mathfn_p (combined_fn);
  174. extern const char *c_getstr (tree, unsigned HOST_WIDE_INT * = NULL);
  175. extern wide_int tree_nonzero_bits (const_tree);
  176. /* Return OFF converted to a pointer offset type suitable as offset for
  177. POINTER_PLUS_EXPR. Use location LOC for this conversion. */
  178. extern tree convert_to_ptrofftype_loc (location_t loc, tree off);
  179. #define convert_to_ptrofftype(t) convert_to_ptrofftype_loc (UNKNOWN_LOCATION, t)
  180. /* Build and fold a POINTER_PLUS_EXPR at LOC offsetting PTR by OFF. */
  181. extern tree fold_build_pointer_plus_loc (location_t loc, tree ptr, tree off);
  182. #define fold_build_pointer_plus(p,o) \
  183. fold_build_pointer_plus_loc (UNKNOWN_LOCATION, p, o)
  184. /* Build and fold a POINTER_PLUS_EXPR at LOC offsetting PTR by OFF. */
  185. extern tree fold_build_pointer_plus_hwi_loc (location_t loc, tree ptr, HOST_WIDE_INT off);
  186. #define fold_build_pointer_plus_hwi(p,o) \
  187. fold_build_pointer_plus_hwi_loc (UNKNOWN_LOCATION, p, o)
  188. #endif // GCC_FOLD_CONST_H