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