You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
5.1KB

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