]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/gimple-builder.c
2015-06-04 Andrew MacLeod <amacleod@redhat.com>
[thirdparty/gcc.git] / gcc / gimple-builder.c
1 /* Functions for high level gimple building routines.
2 Copyright (C) 2013-2015 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
10
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
19
20 #include "config.h"
21 #include "system.h"
22 #include "coretypes.h"
23 #include "hash-set.h"
24 #include "vec.h"
25 #include "input.h"
26 #include "alias.h"
27 #include "symtab.h"
28 #include "options.h"
29 #include "inchash.h"
30 #include "tree.h"
31 #include "fold-const.h"
32 #include "stringpool.h"
33 #include "predict.h"
34 #include "tm.h"
35 #include "hard-reg-set.h"
36 #include "input.h"
37 #include "function.h"
38 #include "basic-block.h"
39 #include "tree-ssa-alias.h"
40 #include "internal-fn.h"
41 #include "gimple-expr.h"
42 #include "is-a.h"
43 #include "gimple.h"
44 #include "tree-ssanames.h"
45
46
47 /* Return the expression type to use based on the CODE and type of
48 the given operand OP. If the expression CODE is a comparison,
49 the returned type is boolean_type_node. Otherwise, it returns
50 the type of OP. */
51
52 static tree
53 get_expr_type (enum tree_code code, tree op)
54 {
55 return (TREE_CODE_CLASS (code) == tcc_comparison)
56 ? boolean_type_node
57 : TREE_TYPE (op);
58 }
59
60
61 /* Build a new gimple assignment. The LHS of the assignment is a new
62 temporary whose type matches the given expression. MODE indicates
63 whether the LHS should be an SSA or a normal temporary. CODE is
64 the expression code for the RHS. OP1 is the first operand and VAL
65 is an integer value to be used as the second operand. */
66
67 gassign *
68 build_assign (enum tree_code code, tree op1, int val, tree lhs)
69 {
70 tree op2 = build_int_cst (TREE_TYPE (op1), val);
71 if (lhs == NULL_TREE)
72 lhs = make_ssa_name (get_expr_type (code, op1));
73 return gimple_build_assign (lhs, code, op1, op2);
74 }
75
76 gassign *
77 build_assign (enum tree_code code, gimple g, int val, tree lhs )
78 {
79 return build_assign (code, gimple_assign_lhs (g), val, lhs);
80 }
81
82
83 /* Build and return a new GIMPLE assignment. The new assignment will
84 have the opcode CODE and operands OP1 and OP2. The type of the
85 expression on the RHS is inferred to be the type of OP1.
86
87 The LHS of the statement will be an SSA name or a GIMPLE temporary
88 in normal form depending on the type of builder invoking this
89 function. */
90
91 gassign *
92 build_assign (enum tree_code code, tree op1, tree op2, tree lhs)
93 {
94 if (lhs == NULL_TREE)
95 lhs = make_ssa_name (get_expr_type (code, op1));
96 return gimple_build_assign (lhs, code, op1, op2);
97 }
98
99 gassign *
100 build_assign (enum tree_code code, gimple op1, tree op2, tree lhs)
101 {
102 return build_assign (code, gimple_assign_lhs (op1), op2, lhs);
103 }
104
105 gassign *
106 build_assign (enum tree_code code, tree op1, gimple op2, tree lhs)
107 {
108 return build_assign (code, op1, gimple_assign_lhs (op2), lhs);
109 }
110
111 gassign *
112 build_assign (enum tree_code code, gimple op1, gimple op2, tree lhs)
113 {
114 return build_assign (code, gimple_assign_lhs (op1), gimple_assign_lhs (op2),
115 lhs);
116 }
117
118
119 /* Create and return a type cast assignment. This creates a NOP_EXPR
120 that converts OP to TO_TYPE. */
121
122 gassign *
123 build_type_cast (tree to_type, tree op, tree lhs)
124 {
125 if (lhs == NULL_TREE)
126 lhs = make_ssa_name (to_type);
127 return gimple_build_assign (lhs, NOP_EXPR, op);
128 }
129
130 gassign *
131 build_type_cast (tree to_type, gimple op, tree lhs)
132 {
133 return build_type_cast (to_type, gimple_assign_lhs (op), lhs);
134 }
135
136
137