gimple-expr.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* Header file for gimple decl, type and expressions.
  2. Copyright (C) 2013-2015 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_GIMPLE_EXPR_H
  16. #define GCC_GIMPLE_EXPR_H
  17. extern bool useless_type_conversion_p (tree, tree);
  18. extern void gimple_set_body (tree, gimple_seq);
  19. extern gimple_seq gimple_body (tree);
  20. extern bool gimple_has_body_p (tree);
  21. extern const char *gimple_decl_printable_name (tree, int);
  22. extern tree copy_var_decl (tree, tree, tree);
  23. extern bool gimple_can_coalesce_p (tree, tree);
  24. extern tree create_tmp_var_name (const char *);
  25. extern tree create_tmp_var_raw (tree, const char * = NULL);
  26. extern tree create_tmp_var (tree, const char * = NULL);
  27. extern tree create_tmp_reg (tree, const char * = NULL);
  28. extern tree create_tmp_reg_fn (struct function *, tree, const char *);
  29. extern void extract_ops_from_tree_1 (tree, enum tree_code *, tree *, tree *,
  30. tree *);
  31. extern void gimple_cond_get_ops_from_tree (tree, enum tree_code *, tree *,
  32. tree *);
  33. extern bool is_gimple_lvalue (tree);
  34. extern bool is_gimple_condexpr (tree);
  35. extern bool is_gimple_address (const_tree);
  36. extern bool is_gimple_invariant_address (const_tree);
  37. extern bool is_gimple_ip_invariant_address (const_tree);
  38. extern bool is_gimple_min_invariant (const_tree);
  39. extern bool is_gimple_ip_invariant (const_tree);
  40. extern bool is_gimple_reg (tree);
  41. extern bool is_gimple_val (tree);
  42. extern bool is_gimple_asm_val (tree);
  43. extern bool is_gimple_min_lval (tree);
  44. extern bool is_gimple_call_addr (tree);
  45. extern bool is_gimple_mem_ref_addr (tree);
  46. extern void mark_addressable (tree);
  47. extern bool is_gimple_reg_rhs (tree);
  48. /* Return true if a conversion from either type of TYPE1 and TYPE2
  49. to the other is not required. Otherwise return false. */
  50. static inline bool
  51. types_compatible_p (tree type1, tree type2)
  52. {
  53. return (type1 == type2
  54. || (useless_type_conversion_p (type1, type2)
  55. && useless_type_conversion_p (type2, type1)));
  56. }
  57. /* Return true if TYPE is a suitable type for a scalar register variable. */
  58. static inline bool
  59. is_gimple_reg_type (tree type)
  60. {
  61. return !AGGREGATE_TYPE_P (type);
  62. }
  63. /* Return true if T is a variable. */
  64. static inline bool
  65. is_gimple_variable (tree t)
  66. {
  67. return (TREE_CODE (t) == VAR_DECL
  68. || TREE_CODE (t) == PARM_DECL
  69. || TREE_CODE (t) == RESULT_DECL
  70. || TREE_CODE (t) == SSA_NAME);
  71. }
  72. /* Return true if T is a GIMPLE identifier (something with an address). */
  73. static inline bool
  74. is_gimple_id (tree t)
  75. {
  76. return (is_gimple_variable (t)
  77. || TREE_CODE (t) == FUNCTION_DECL
  78. || TREE_CODE (t) == LABEL_DECL
  79. || TREE_CODE (t) == CONST_DECL
  80. /* Allow string constants, since they are addressable. */
  81. || TREE_CODE (t) == STRING_CST);
  82. }
  83. /* Return true if OP, an SSA name or a DECL is a virtual operand. */
  84. static inline bool
  85. virtual_operand_p (tree op)
  86. {
  87. if (TREE_CODE (op) == SSA_NAME)
  88. {
  89. op = SSA_NAME_VAR (op);
  90. if (!op)
  91. return false;
  92. }
  93. if (TREE_CODE (op) == VAR_DECL)
  94. return VAR_DECL_IS_VIRTUAL_OPERAND (op);
  95. return false;
  96. }
  97. /* Return true if T is something whose address can be taken. */
  98. static inline bool
  99. is_gimple_addressable (tree t)
  100. {
  101. return (is_gimple_id (t) || handled_component_p (t)
  102. || TREE_CODE (t) == MEM_REF);
  103. }
  104. /* Return true if T is a valid gimple constant. */
  105. static inline bool
  106. is_gimple_constant (const_tree t)
  107. {
  108. switch (TREE_CODE (t))
  109. {
  110. case INTEGER_CST:
  111. case REAL_CST:
  112. case FIXED_CST:
  113. case STRING_CST:
  114. case COMPLEX_CST:
  115. case VECTOR_CST:
  116. return true;
  117. default:
  118. return false;
  119. }
  120. }
  121. /* A wrapper around extract_ops_from_tree_1, for callers which expect
  122. to see only a maximum of two operands. */
  123. static inline void
  124. extract_ops_from_tree (tree expr, enum tree_code *code, tree *op0,
  125. tree *op1)
  126. {
  127. tree op2;
  128. extract_ops_from_tree_1 (expr, code, op0, op1, &op2);
  129. gcc_assert (op2 == NULL_TREE);
  130. }
  131. /* Given a valid GIMPLE_CALL function address return the FUNCTION_DECL
  132. associated with the callee if known. Otherwise return NULL_TREE. */
  133. static inline tree
  134. gimple_call_addr_fndecl (const_tree fn)
  135. {
  136. if (fn && TREE_CODE (fn) == ADDR_EXPR)
  137. {
  138. tree fndecl = TREE_OPERAND (fn, 0);
  139. if (TREE_CODE (fndecl) == MEM_REF
  140. && TREE_CODE (TREE_OPERAND (fndecl, 0)) == ADDR_EXPR
  141. && integer_zerop (TREE_OPERAND (fndecl, 1)))
  142. fndecl = TREE_OPERAND (TREE_OPERAND (fndecl, 0), 0);
  143. if (TREE_CODE (fndecl) == FUNCTION_DECL)
  144. return fndecl;
  145. }
  146. return NULL_TREE;
  147. }
  148. #endif /* GCC_GIMPLE_EXPR_H */