1*38fd1498Szrj /* Header file for gimple decl, type and expressions.
2*38fd1498Szrj Copyright (C) 2013-2018 Free Software Foundation, Inc.
3*38fd1498Szrj
4*38fd1498Szrj This file is part of GCC.
5*38fd1498Szrj
6*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
7*38fd1498Szrj the terms of the GNU General Public License as published by the Free
8*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
9*38fd1498Szrj version.
10*38fd1498Szrj
11*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
13*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14*38fd1498Szrj for more details.
15*38fd1498Szrj
16*38fd1498Szrj You should have received a copy of the GNU General Public License
17*38fd1498Szrj along with GCC; see the file COPYING3. If not see
18*38fd1498Szrj <http://www.gnu.org/licenses/>. */
19*38fd1498Szrj
20*38fd1498Szrj #ifndef GCC_GIMPLE_EXPR_H
21*38fd1498Szrj #define GCC_GIMPLE_EXPR_H
22*38fd1498Szrj
23*38fd1498Szrj extern bool useless_type_conversion_p (tree, tree);
24*38fd1498Szrj
25*38fd1498Szrj
26*38fd1498Szrj extern void gimple_set_body (tree, gimple_seq);
27*38fd1498Szrj extern gimple_seq gimple_body (tree);
28*38fd1498Szrj extern bool gimple_has_body_p (tree);
29*38fd1498Szrj extern const char *gimple_decl_printable_name (tree, int);
30*38fd1498Szrj extern tree copy_var_decl (tree, tree, tree);
31*38fd1498Szrj extern tree create_tmp_var_name (const char *);
32*38fd1498Szrj extern tree create_tmp_var_raw (tree, const char * = NULL);
33*38fd1498Szrj extern tree create_tmp_var (tree, const char * = NULL);
34*38fd1498Szrj extern tree create_tmp_reg (tree, const char * = NULL);
35*38fd1498Szrj extern tree create_tmp_reg_fn (struct function *, tree, const char *);
36*38fd1498Szrj
37*38fd1498Szrj
38*38fd1498Szrj extern void extract_ops_from_tree (tree, enum tree_code *, tree *, tree *,
39*38fd1498Szrj tree *);
40*38fd1498Szrj extern void gimple_cond_get_ops_from_tree (tree, enum tree_code *, tree *,
41*38fd1498Szrj tree *);
42*38fd1498Szrj extern bool is_gimple_lvalue (tree);
43*38fd1498Szrj extern bool is_gimple_condexpr (tree);
44*38fd1498Szrj extern bool is_gimple_address (const_tree);
45*38fd1498Szrj extern bool is_gimple_invariant_address (const_tree);
46*38fd1498Szrj extern bool is_gimple_ip_invariant_address (const_tree);
47*38fd1498Szrj extern bool is_gimple_min_invariant (const_tree);
48*38fd1498Szrj extern bool is_gimple_ip_invariant (const_tree);
49*38fd1498Szrj extern bool is_gimple_reg (tree);
50*38fd1498Szrj extern bool is_gimple_val (tree);
51*38fd1498Szrj extern bool is_gimple_asm_val (tree);
52*38fd1498Szrj extern bool is_gimple_min_lval (tree);
53*38fd1498Szrj extern bool is_gimple_call_addr (tree);
54*38fd1498Szrj extern bool is_gimple_mem_ref_addr (tree);
55*38fd1498Szrj extern void flush_mark_addressable_queue (void);
56*38fd1498Szrj extern void mark_addressable (tree);
57*38fd1498Szrj extern bool is_gimple_reg_rhs (tree);
58*38fd1498Szrj
59*38fd1498Szrj /* Return true if a conversion from either type of TYPE1 and TYPE2
60*38fd1498Szrj to the other is not required. Otherwise return false. */
61*38fd1498Szrj
62*38fd1498Szrj static inline bool
types_compatible_p(tree type1,tree type2)63*38fd1498Szrj types_compatible_p (tree type1, tree type2)
64*38fd1498Szrj {
65*38fd1498Szrj return (type1 == type2
66*38fd1498Szrj || (useless_type_conversion_p (type1, type2)
67*38fd1498Szrj && useless_type_conversion_p (type2, type1)));
68*38fd1498Szrj }
69*38fd1498Szrj
70*38fd1498Szrj /* Return true if TYPE is a suitable type for a scalar register variable. */
71*38fd1498Szrj
72*38fd1498Szrj static inline bool
is_gimple_reg_type(tree type)73*38fd1498Szrj is_gimple_reg_type (tree type)
74*38fd1498Szrj {
75*38fd1498Szrj return !AGGREGATE_TYPE_P (type);
76*38fd1498Szrj }
77*38fd1498Szrj
78*38fd1498Szrj /* Return true if T is a variable. */
79*38fd1498Szrj
80*38fd1498Szrj static inline bool
is_gimple_variable(tree t)81*38fd1498Szrj is_gimple_variable (tree t)
82*38fd1498Szrj {
83*38fd1498Szrj return (TREE_CODE (t) == VAR_DECL
84*38fd1498Szrj || TREE_CODE (t) == PARM_DECL
85*38fd1498Szrj || TREE_CODE (t) == RESULT_DECL
86*38fd1498Szrj || TREE_CODE (t) == SSA_NAME);
87*38fd1498Szrj }
88*38fd1498Szrj
89*38fd1498Szrj /* Return true if T is a GIMPLE identifier (something with an address). */
90*38fd1498Szrj
91*38fd1498Szrj static inline bool
is_gimple_id(tree t)92*38fd1498Szrj is_gimple_id (tree t)
93*38fd1498Szrj {
94*38fd1498Szrj return (is_gimple_variable (t)
95*38fd1498Szrj || TREE_CODE (t) == FUNCTION_DECL
96*38fd1498Szrj || TREE_CODE (t) == LABEL_DECL
97*38fd1498Szrj || TREE_CODE (t) == CONST_DECL
98*38fd1498Szrj /* Allow string constants, since they are addressable. */
99*38fd1498Szrj || TREE_CODE (t) == STRING_CST);
100*38fd1498Szrj }
101*38fd1498Szrj
102*38fd1498Szrj /* Return true if OP, an SSA name or a DECL is a virtual operand. */
103*38fd1498Szrj
104*38fd1498Szrj static inline bool
virtual_operand_p(tree op)105*38fd1498Szrj virtual_operand_p (tree op)
106*38fd1498Szrj {
107*38fd1498Szrj if (TREE_CODE (op) == SSA_NAME)
108*38fd1498Szrj return SSA_NAME_IS_VIRTUAL_OPERAND (op);
109*38fd1498Szrj
110*38fd1498Szrj if (TREE_CODE (op) == VAR_DECL)
111*38fd1498Szrj return VAR_DECL_IS_VIRTUAL_OPERAND (op);
112*38fd1498Szrj
113*38fd1498Szrj return false;
114*38fd1498Szrj }
115*38fd1498Szrj
116*38fd1498Szrj /* Return true if T is something whose address can be taken. */
117*38fd1498Szrj
118*38fd1498Szrj static inline bool
is_gimple_addressable(tree t)119*38fd1498Szrj is_gimple_addressable (tree t)
120*38fd1498Szrj {
121*38fd1498Szrj return (is_gimple_id (t) || handled_component_p (t)
122*38fd1498Szrj || TREE_CODE (t) == TARGET_MEM_REF
123*38fd1498Szrj || TREE_CODE (t) == MEM_REF);
124*38fd1498Szrj }
125*38fd1498Szrj
126*38fd1498Szrj /* Return true if T is a valid gimple constant. */
127*38fd1498Szrj
128*38fd1498Szrj static inline bool
is_gimple_constant(const_tree t)129*38fd1498Szrj is_gimple_constant (const_tree t)
130*38fd1498Szrj {
131*38fd1498Szrj switch (TREE_CODE (t))
132*38fd1498Szrj {
133*38fd1498Szrj case INTEGER_CST:
134*38fd1498Szrj case POLY_INT_CST:
135*38fd1498Szrj case REAL_CST:
136*38fd1498Szrj case FIXED_CST:
137*38fd1498Szrj case COMPLEX_CST:
138*38fd1498Szrj case VECTOR_CST:
139*38fd1498Szrj case STRING_CST:
140*38fd1498Szrj return true;
141*38fd1498Szrj
142*38fd1498Szrj default:
143*38fd1498Szrj return false;
144*38fd1498Szrj }
145*38fd1498Szrj }
146*38fd1498Szrj
147*38fd1498Szrj /* A wrapper around extract_ops_from_tree with 3 ops, for callers which
148*38fd1498Szrj expect to see only a maximum of two operands. */
149*38fd1498Szrj
150*38fd1498Szrj static inline void
extract_ops_from_tree(tree expr,enum tree_code * code,tree * op0,tree * op1)151*38fd1498Szrj extract_ops_from_tree (tree expr, enum tree_code *code, tree *op0,
152*38fd1498Szrj tree *op1)
153*38fd1498Szrj {
154*38fd1498Szrj tree op2;
155*38fd1498Szrj extract_ops_from_tree (expr, code, op0, op1, &op2);
156*38fd1498Szrj gcc_assert (op2 == NULL_TREE);
157*38fd1498Szrj }
158*38fd1498Szrj
159*38fd1498Szrj /* Given a valid GIMPLE_CALL function address return the FUNCTION_DECL
160*38fd1498Szrj associated with the callee if known. Otherwise return NULL_TREE. */
161*38fd1498Szrj
162*38fd1498Szrj static inline tree
gimple_call_addr_fndecl(const_tree fn)163*38fd1498Szrj gimple_call_addr_fndecl (const_tree fn)
164*38fd1498Szrj {
165*38fd1498Szrj if (fn && TREE_CODE (fn) == ADDR_EXPR)
166*38fd1498Szrj {
167*38fd1498Szrj tree fndecl = TREE_OPERAND (fn, 0);
168*38fd1498Szrj if (TREE_CODE (fndecl) == MEM_REF
169*38fd1498Szrj && TREE_CODE (TREE_OPERAND (fndecl, 0)) == ADDR_EXPR
170*38fd1498Szrj && integer_zerop (TREE_OPERAND (fndecl, 1)))
171*38fd1498Szrj fndecl = TREE_OPERAND (TREE_OPERAND (fndecl, 0), 0);
172*38fd1498Szrj if (TREE_CODE (fndecl) == FUNCTION_DECL)
173*38fd1498Szrj return fndecl;
174*38fd1498Szrj }
175*38fd1498Szrj return NULL_TREE;
176*38fd1498Szrj }
177*38fd1498Szrj
178*38fd1498Szrj #endif /* GCC_GIMPLE_EXPR_H */
179