]>
Commit | Line | Data |
---|---|---|
9a4a3348 | 1 | /* Functions for high level gimple building routines. |
3aea1f79 | 2 | Copyright (C) 2013-2014 Free Software Foundation, Inc. |
9a4a3348 | 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 "tree.h" | |
9ed99284 | 24 | #include "stringpool.h" |
94ea8568 | 25 | #include "predict.h" |
26 | #include "vec.h" | |
27 | #include "hashtab.h" | |
28 | #include "hash-set.h" | |
29 | #include "machmode.h" | |
30 | #include "tm.h" | |
31 | #include "hard-reg-set.h" | |
32 | #include "input.h" | |
33 | #include "function.h" | |
bc61cadb | 34 | #include "basic-block.h" |
35 | #include "tree-ssa-alias.h" | |
36 | #include "internal-fn.h" | |
37 | #include "gimple-expr.h" | |
38 | #include "is-a.h" | |
9a4a3348 | 39 | #include "gimple.h" |
073c1fd5 | 40 | #include "tree-ssanames.h" |
9a4a3348 | 41 | |
42 | ||
43 | /* Return the expression type to use based on the CODE and type of | |
44 | the given operand OP. If the expression CODE is a comparison, | |
45 | the returned type is boolean_type_node. Otherwise, it returns | |
46 | the type of OP. */ | |
47 | ||
48 | static tree | |
49 | get_expr_type (enum tree_code code, tree op) | |
50 | { | |
51 | return (TREE_CODE_CLASS (code) == tcc_comparison) | |
52 | ? boolean_type_node | |
53 | : TREE_TYPE (op); | |
54 | } | |
55 | ||
56 | ||
57 | /* Build a new gimple assignment. The LHS of the assignment is a new | |
58 | temporary whose type matches the given expression. MODE indicates | |
59 | whether the LHS should be an SSA or a normal temporary. CODE is | |
60 | the expression code for the RHS. OP1 is the first operand and VAL | |
61 | is an integer value to be used as the second operand. */ | |
62 | ||
1a91d914 | 63 | gassign * |
9a4a3348 | 64 | build_assign (enum tree_code code, tree op1, int val, tree lhs) |
65 | { | |
66 | tree op2 = build_int_cst (TREE_TYPE (op1), val); | |
67 | if (lhs == NULL_TREE) | |
68 | lhs = make_ssa_name (get_expr_type (code, op1), NULL); | |
69 | return gimple_build_assign_with_ops (code, lhs, op1, op2); | |
70 | } | |
71 | ||
1a91d914 | 72 | gassign * |
9a4a3348 | 73 | build_assign (enum tree_code code, gimple g, int val, tree lhs ) |
74 | { | |
75 | return build_assign (code, gimple_assign_lhs (g), val, lhs); | |
76 | } | |
77 | ||
78 | ||
79 | /* Build and return a new GIMPLE assignment. The new assignment will | |
80 | have the opcode CODE and operands OP1 and OP2. The type of the | |
81 | expression on the RHS is inferred to be the type of OP1. | |
82 | ||
83 | The LHS of the statement will be an SSA name or a GIMPLE temporary | |
84 | in normal form depending on the type of builder invoking this | |
85 | function. */ | |
86 | ||
1a91d914 | 87 | gassign * |
9a4a3348 | 88 | build_assign (enum tree_code code, tree op1, tree op2, tree lhs) |
89 | { | |
90 | if (lhs == NULL_TREE) | |
91 | lhs = make_ssa_name (get_expr_type (code, op1), NULL); | |
92 | return gimple_build_assign_with_ops (code, lhs, op1, op2); | |
93 | } | |
94 | ||
1a91d914 | 95 | gassign * |
9a4a3348 | 96 | build_assign (enum tree_code code, gimple op1, tree op2, tree lhs) |
97 | { | |
98 | return build_assign (code, gimple_assign_lhs (op1), op2, lhs); | |
99 | } | |
100 | ||
1a91d914 | 101 | gassign * |
9a4a3348 | 102 | build_assign (enum tree_code code, tree op1, gimple op2, tree lhs) |
103 | { | |
104 | return build_assign (code, op1, gimple_assign_lhs (op2), lhs); | |
105 | } | |
106 | ||
1a91d914 | 107 | gassign * |
9a4a3348 | 108 | build_assign (enum tree_code code, gimple op1, gimple op2, tree lhs) |
109 | { | |
110 | return build_assign (code, gimple_assign_lhs (op1), gimple_assign_lhs (op2), | |
111 | lhs); | |
112 | } | |
113 | ||
114 | ||
115 | /* Create and return a type cast assignment. This creates a NOP_EXPR | |
116 | that converts OP to TO_TYPE. */ | |
117 | ||
1a91d914 | 118 | gassign * |
9a4a3348 | 119 | build_type_cast (tree to_type, tree op, tree lhs) |
120 | { | |
121 | if (lhs == NULL_TREE) | |
122 | lhs = make_ssa_name (to_type, NULL); | |
806413d2 | 123 | return gimple_build_assign_with_ops (NOP_EXPR, lhs, op); |
9a4a3348 | 124 | } |
125 | ||
1a91d914 | 126 | gassign * |
9a4a3348 | 127 | build_type_cast (tree to_type, gimple op, tree lhs) |
128 | { | |
129 | return build_type_cast (to_type, gimple_assign_lhs (op), lhs); | |
130 | } | |
131 | ||
132 | ||
133 |