1*38fd1498Szrj /* Functions for high level gimple building routines.
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
7*38fd1498Szrj it under the terms of the GNU General Public License as published by
8*38fd1498Szrj the Free Software Foundation; either version 3, or (at your option)
9*38fd1498Szrj any later version.
10*38fd1498Szrj 
11*38fd1498Szrj GCC is distributed in the hope that it will be useful,
12*38fd1498Szrj but WITHOUT ANY WARRANTY; without even the implied warranty of
13*38fd1498Szrj MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*38fd1498Szrj GNU General Public License 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 #include "config.h"
21*38fd1498Szrj #include "system.h"
22*38fd1498Szrj #include "coretypes.h"
23*38fd1498Szrj #include "backend.h"
24*38fd1498Szrj #include "tree.h"
25*38fd1498Szrj #include "gimple.h"
26*38fd1498Szrj #include "stringpool.h"
27*38fd1498Szrj #include "tree-vrp.h"
28*38fd1498Szrj #include "tree-ssanames.h"
29*38fd1498Szrj 
30*38fd1498Szrj 
31*38fd1498Szrj /* Return the expression type to use based on the CODE and type of
32*38fd1498Szrj    the given operand OP.  If the expression CODE is a comparison,
33*38fd1498Szrj    the returned type is boolean_type_node.  Otherwise, it returns
34*38fd1498Szrj    the type of OP.  */
35*38fd1498Szrj 
36*38fd1498Szrj static tree
get_expr_type(enum tree_code code,tree op)37*38fd1498Szrj get_expr_type (enum tree_code code, tree op)
38*38fd1498Szrj {
39*38fd1498Szrj   return (TREE_CODE_CLASS (code) == tcc_comparison)
40*38fd1498Szrj 	 ? boolean_type_node
41*38fd1498Szrj 	 : TREE_TYPE (op);
42*38fd1498Szrj }
43*38fd1498Szrj 
44*38fd1498Szrj 
45*38fd1498Szrj /* Build a new gimple assignment.  The LHS of the assignment is a new
46*38fd1498Szrj    temporary whose type matches the given expression.  MODE indicates
47*38fd1498Szrj    whether the LHS should be an SSA or a normal temporary.  CODE is
48*38fd1498Szrj    the expression code for the RHS.  OP1 is the first operand and VAL
49*38fd1498Szrj    is an integer value to be used as the second operand.  */
50*38fd1498Szrj 
51*38fd1498Szrj gassign *
build_assign(enum tree_code code,tree op1,int val,tree lhs)52*38fd1498Szrj build_assign (enum tree_code code, tree op1, int val, tree lhs)
53*38fd1498Szrj {
54*38fd1498Szrj   tree op2 = build_int_cst (TREE_TYPE (op1), val);
55*38fd1498Szrj   if (lhs == NULL_TREE)
56*38fd1498Szrj     lhs = make_ssa_name (get_expr_type (code, op1));
57*38fd1498Szrj   return gimple_build_assign (lhs, code, op1, op2);
58*38fd1498Szrj }
59*38fd1498Szrj 
60*38fd1498Szrj gassign *
build_assign(enum tree_code code,gimple * g,int val,tree lhs)61*38fd1498Szrj build_assign (enum tree_code code, gimple *g, int val, tree lhs )
62*38fd1498Szrj {
63*38fd1498Szrj   return build_assign (code, gimple_assign_lhs (g), val, lhs);
64*38fd1498Szrj }
65*38fd1498Szrj 
66*38fd1498Szrj 
67*38fd1498Szrj /* Build and return a new GIMPLE assignment.  The new assignment will
68*38fd1498Szrj    have the opcode CODE and operands OP1 and OP2.  The type of the
69*38fd1498Szrj    expression on the RHS is inferred to be the type of OP1.
70*38fd1498Szrj 
71*38fd1498Szrj    The LHS of the statement will be an SSA name or a GIMPLE temporary
72*38fd1498Szrj    in normal form depending on the type of builder invoking this
73*38fd1498Szrj    function.  */
74*38fd1498Szrj 
75*38fd1498Szrj gassign *
build_assign(enum tree_code code,tree op1,tree op2,tree lhs)76*38fd1498Szrj build_assign (enum tree_code code, tree op1, tree op2, tree lhs)
77*38fd1498Szrj {
78*38fd1498Szrj   if (lhs == NULL_TREE)
79*38fd1498Szrj     lhs = make_ssa_name (get_expr_type (code, op1));
80*38fd1498Szrj   return gimple_build_assign (lhs, code, op1, op2);
81*38fd1498Szrj }
82*38fd1498Szrj 
83*38fd1498Szrj gassign *
build_assign(enum tree_code code,gimple * op1,tree op2,tree lhs)84*38fd1498Szrj build_assign (enum tree_code code, gimple *op1, tree op2, tree lhs)
85*38fd1498Szrj {
86*38fd1498Szrj   return build_assign (code, gimple_assign_lhs (op1), op2, lhs);
87*38fd1498Szrj }
88*38fd1498Szrj 
89*38fd1498Szrj gassign *
build_assign(enum tree_code code,tree op1,gimple * op2,tree lhs)90*38fd1498Szrj build_assign (enum tree_code code, tree op1, gimple *op2, tree lhs)
91*38fd1498Szrj {
92*38fd1498Szrj   return build_assign (code, op1, gimple_assign_lhs (op2), lhs);
93*38fd1498Szrj }
94*38fd1498Szrj 
95*38fd1498Szrj gassign *
build_assign(enum tree_code code,gimple * op1,gimple * op2,tree lhs)96*38fd1498Szrj build_assign (enum tree_code code, gimple *op1, gimple *op2, tree lhs)
97*38fd1498Szrj {
98*38fd1498Szrj   return build_assign (code, gimple_assign_lhs (op1), gimple_assign_lhs (op2),
99*38fd1498Szrj                        lhs);
100*38fd1498Szrj }
101*38fd1498Szrj 
102*38fd1498Szrj 
103*38fd1498Szrj /* Create and return a type cast assignment. This creates a NOP_EXPR
104*38fd1498Szrj    that converts OP to TO_TYPE.  */
105*38fd1498Szrj 
106*38fd1498Szrj gassign *
build_type_cast(tree to_type,tree op,tree lhs)107*38fd1498Szrj build_type_cast (tree to_type, tree op, tree lhs)
108*38fd1498Szrj {
109*38fd1498Szrj   if (lhs == NULL_TREE)
110*38fd1498Szrj     lhs = make_ssa_name (to_type);
111*38fd1498Szrj   return gimple_build_assign (lhs, NOP_EXPR, op);
112*38fd1498Szrj }
113*38fd1498Szrj 
114*38fd1498Szrj gassign *
build_type_cast(tree to_type,gimple * op,tree lhs)115*38fd1498Szrj build_type_cast (tree to_type, gimple *op, tree lhs)
116*38fd1498Szrj {
117*38fd1498Szrj   return build_type_cast (to_type, gimple_assign_lhs (op), lhs);
118*38fd1498Szrj }
119*38fd1498Szrj 
120*38fd1498Szrj 
121*38fd1498Szrj 
122