fold-const.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /* Fold a constant sub-tree into a single node for C-compiler
  2. Copyright (C) 1987-2018 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_read_from_constant_string (tree);
  91. extern tree int_const_binop (enum tree_code, const_tree, const_tree);
  92. #define build_fold_addr_expr(T)\
  93. build_fold_addr_expr_loc (UNKNOWN_LOCATION, (T))
  94. extern tree build_fold_addr_expr_loc (location_t, tree);
  95. #define build_fold_addr_expr_with_type(T,TYPE)\
  96. build_fold_addr_expr_with_type_loc (UNKNOWN_LOCATION, (T), TYPE)
  97. extern tree build_fold_addr_expr_with_type_loc (location_t, tree, tree);
  98. extern tree fold_build_cleanup_point_expr (tree type, tree expr);
  99. #define build_fold_indirect_ref(T)\
  100. build_fold_indirect_ref_loc (UNKNOWN_LOCATION, T)
  101. extern tree build_fold_indirect_ref_loc (location_t, tree);
  102. #define fold_indirect_ref(T)\
  103. fold_indirect_ref_loc (UNKNOWN_LOCATION, T)
  104. extern tree fold_indirect_ref_loc (location_t, tree);
  105. extern tree build_simple_mem_ref_loc (location_t, tree);
  106. #define build_simple_mem_ref(T)\
  107. build_simple_mem_ref_loc (UNKNOWN_LOCATION, T)
  108. extern poly_offset_int mem_ref_offset (const_tree);
  109. extern tree build_invariant_address (tree, tree, poly_int64);
  110. extern tree constant_boolean_node (bool, tree);
  111. extern tree div_if_zero_remainder (const_tree, const_tree);
  112. extern bool tree_swap_operands_p (const_tree, const_tree);
  113. extern enum tree_code swap_tree_comparison (enum tree_code);
  114. extern bool ptr_difference_const (tree, tree, poly_int64_pod *);
  115. extern enum tree_code invert_tree_comparison (enum tree_code, bool);
  116. extern bool tree_unary_nonzero_warnv_p (enum tree_code, tree, tree, bool *);
  117. extern bool tree_binary_nonzero_warnv_p (enum tree_code, tree, tree, tree op1,
  118. bool *);
  119. extern bool tree_single_nonzero_warnv_p (tree, bool *);
  120. extern bool tree_unary_nonnegative_warnv_p (enum tree_code, tree, tree,
  121. bool *, int);
  122. extern bool tree_binary_nonnegative_warnv_p (enum tree_code, tree, tree, tree,
  123. bool *, int);
  124. extern bool tree_single_nonnegative_warnv_p (tree, bool *, int);
  125. extern bool tree_call_nonnegative_warnv_p (tree, combined_fn, tree, tree,
  126. bool *, int);
  127. extern bool integer_valued_real_unary_p (tree_code, tree, int);
  128. extern bool integer_valued_real_binary_p (tree_code, tree, tree, int);
  129. extern bool integer_valued_real_call_p (combined_fn, tree, tree, int);
  130. extern bool integer_valued_real_single_p (tree, int);
  131. extern bool integer_valued_real_p (tree, int = 0);
  132. extern bool fold_real_zero_addition_p (const_tree, const_tree, int);
  133. extern tree combine_comparisons (location_t, enum tree_code, enum tree_code,
  134. enum tree_code, tree, tree, tree);
  135. extern void debug_fold_checksum (const_tree);
  136. extern bool may_negate_without_overflow_p (const_tree);
  137. #define round_up(T,N) round_up_loc (UNKNOWN_LOCATION, T, N)
  138. extern tree round_up_loc (location_t, tree, unsigned int);
  139. #define round_down(T,N) round_down_loc (UNKNOWN_LOCATION, T, N)
  140. extern tree round_down_loc (location_t, tree, int);
  141. extern tree size_int_kind (poly_int64, enum size_type_kind);
  142. #define size_binop(CODE,T1,T2)\
  143. size_binop_loc (UNKNOWN_LOCATION, CODE, T1, T2)
  144. extern tree size_binop_loc (location_t, enum tree_code, tree, tree);
  145. #define size_diffop(T1,T2)\
  146. size_diffop_loc (UNKNOWN_LOCATION, T1, T2)
  147. extern tree size_diffop_loc (location_t, tree, tree);
  148. /* Return an expr equal to X but certainly not valid as an lvalue. */
  149. #define non_lvalue(T) non_lvalue_loc (UNKNOWN_LOCATION, T)
  150. extern tree non_lvalue_loc (location_t, tree);
  151. extern bool tree_expr_nonzero_p (tree);
  152. extern bool tree_expr_nonnegative_p (tree);
  153. extern bool tree_expr_nonnegative_warnv_p (tree, bool *, int = 0);
  154. extern tree make_range (tree, int *, tree *, tree *, bool *);
  155. extern tree make_range_step (location_t, enum tree_code, tree, tree, tree,
  156. tree *, tree *, int *, bool *);
  157. extern tree range_check_type (tree);
  158. extern tree build_range_check (location_t, tree, tree, int, tree, tree);
  159. extern bool merge_ranges (int *, tree *, tree *, int, tree, tree, int,
  160. tree, tree);
  161. extern tree sign_bit_p (tree, const_tree);
  162. extern tree exact_inverse (tree, tree);
  163. extern bool expr_not_equal_to (tree t, const wide_int &);
  164. extern tree const_unop (enum tree_code, tree, tree);
  165. extern tree const_binop (enum tree_code, tree, tree, tree);
  166. extern bool negate_mathfn_p (combined_fn);
  167. extern const char *c_getstr (tree, unsigned HOST_WIDE_INT *strlen = NULL);
  168. /* Return OFF converted to a pointer offset type suitable as offset for
  169. POINTER_PLUS_EXPR. Use location LOC for this conversion. */
  170. extern tree convert_to_ptrofftype_loc (location_t loc, tree off);
  171. #define convert_to_ptrofftype(t) convert_to_ptrofftype_loc (UNKNOWN_LOCATION, t)
  172. /* Build and fold a POINTER_PLUS_EXPR at LOC offsetting PTR by OFF. */
  173. extern tree fold_build_pointer_plus_loc (location_t loc, tree ptr, tree off);
  174. #define fold_build_pointer_plus(p,o) \
  175. fold_build_pointer_plus_loc (UNKNOWN_LOCATION, p, o)
  176. /* Build and fold a POINTER_PLUS_EXPR at LOC offsetting PTR by OFF. */
  177. extern tree fold_build_pointer_plus_hwi_loc (location_t loc, tree ptr, HOST_WIDE_INT off);
  178. #define fold_build_pointer_plus_hwi(p,o) \
  179. fold_build_pointer_plus_hwi_loc (UNKNOWN_LOCATION, p, o)
  180. #endif // GCC_FOLD_CONST_H