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