Mercurial > hg > CbC > CbC_gcc
annotate gcc/tree-ssa-operands.c @ 158:494b0b89df80 default tip
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 18:13:55 +0900 |
parents | 351920fa3827 |
children |
rev | line source |
---|---|
0 | 1 /* SSA operands management for trees. |
145 | 2 Copyright (C) 2003-2020 Free Software Foundation, Inc. |
0 | 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" | |
111 | 23 #include "backend.h" |
0 | 24 #include "tree.h" |
111 | 25 #include "gimple.h" |
26 #include "timevar.h" | |
27 #include "ssa.h" | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
28 #include "gimple-pretty-print.h" |
111 | 29 #include "diagnostic-core.h" |
30 #include "stmt.h" | |
31 #include "print-tree.h" | |
32 #include "dumpfile.h" | |
33 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
34 /* This file contains the code required to manage the operands cache of the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
35 SSA optimizer. For every stmt, we maintain an operand cache in the stmt |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
36 annotation. This cache contains operands that will be of interest to |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
37 optimizers and other passes wishing to manipulate the IL. |
0 | 38 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
39 The operand type are broken up into REAL and VIRTUAL operands. The real |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
40 operands are represented as pointers into the stmt's operand tree. Thus |
0 | 41 any manipulation of the real operands will be reflected in the actual tree. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
42 Virtual operands are represented solely in the cache, although the base |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
43 variable for the SSA_NAME may, or may not occur in the stmt's tree. |
0 | 44 Manipulation of the virtual operands will not be reflected in the stmt tree. |
45 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
46 The routines in this file are concerned with creating this operand cache |
0 | 47 from a stmt tree. |
48 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
49 The operand tree is the parsed by the various get_* routines which look |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
50 through the stmt tree for the occurrence of operands which may be of |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
51 interest, and calls are made to the append_* routines whenever one is |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
52 found. There are 4 of these routines, each representing one of the |
0 | 53 4 types of operands. Defs, Uses, Virtual Uses, and Virtual May Defs. |
54 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
55 The append_* routines check for duplication, and simply keep a list of |
0 | 56 unique objects for each operand type in the build_* extendable vectors. |
57 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
58 Once the stmt tree is completely parsed, the finalize_ssa_operands() |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
59 routine is called, which proceeds to perform the finalization routine |
0 | 60 on each of the 4 operand vectors which have been built up. |
61 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
62 If the stmt had a previous operand cache, the finalization routines |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
63 attempt to match up the new operands with the old ones. If it's a perfect |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
64 match, the old vector is simply reused. If it isn't a perfect match, then |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
65 a new vector is created and the new operands are placed there. For |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
66 virtual operands, if the previous cache had SSA_NAME version of a |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
67 variable, and that same variable occurs in the same operands cache, then |
0 | 68 the new cache vector will also get the same SSA_NAME. |
69 | |
70 i.e., if a stmt had a VUSE of 'a_5', and 'a' occurs in the new | |
71 operand vector for VUSE, then the new vector will also be modified | |
72 such that it contains 'a_5' rather than 'a'. */ | |
73 | |
74 | |
75 /* Flags to describe operand properties in helpers. */ | |
76 | |
77 /* By default, operands are loaded. */ | |
78 #define opf_use 0 | |
79 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
80 /* Operand is the target of an assignment expression or a |
0 | 81 call-clobbered variable. */ |
82 #define opf_def (1 << 0) | |
83 | |
84 /* No virtual operands should be created in the expression. This is used | |
85 when traversing ADDR_EXPR nodes which have different semantics than | |
86 other expressions. Inside an ADDR_EXPR node, the only operands that we | |
87 need to consider are indices into arrays. For instance, &a.b[i] should | |
88 generate a USE of 'i' but it should not generate a VUSE for 'a' nor a | |
89 VUSE for 'b'. */ | |
90 #define opf_no_vops (1 << 1) | |
91 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
92 /* Operand is in a place where address-taken does not imply addressable. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
93 #define opf_non_addressable (1 << 3) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
94 |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
95 /* Operand is in a place where opf_non_addressable does not apply. */ |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
96 #define opf_not_non_addressable (1 << 4) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
97 |
111 | 98 /* Operand is having its address taken. */ |
99 #define opf_address_taken (1 << 5) | |
0 | 100 |
101 /* Array for building all the use operands. */ | |
111 | 102 static vec<tree *> build_uses; |
0 | 103 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
104 /* The built VDEF operand. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
105 static tree build_vdef; |
0 | 106 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
107 /* The built VUSE operand. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
108 static tree build_vuse; |
0 | 109 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
110 /* Bitmap obstack for our datastructures that needs to survive across |
0 | 111 compilations of multiple functions. */ |
112 static bitmap_obstack operands_bitmap_obstack; | |
113 | |
111 | 114 static void get_expr_operands (struct function *, gimple *, tree *, int); |
0 | 115 |
116 /* Number of functions with initialized ssa_operands. */ | |
117 static int n_initialized = 0; | |
118 | |
111 | 119 /* Accessor to tree-ssa-operands.c caches. */ |
120 static inline struct ssa_operands * | |
121 gimple_ssa_operands (const struct function *fun) | |
0 | 122 { |
111 | 123 return &fun->gimple_df->ssa_operands; |
0 | 124 } |
125 | |
126 | |
127 /* Return true if the SSA operands cache is active. */ | |
128 | |
129 bool | |
111 | 130 ssa_operands_active (struct function *fun) |
0 | 131 { |
111 | 132 if (fun == NULL) |
0 | 133 return false; |
134 | |
111 | 135 return fun->gimple_df && gimple_ssa_operands (fun)->ops_active; |
0 | 136 } |
137 | |
138 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
139 /* Create the VOP variable, an artificial global variable to act as a |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
140 representative of all of the virtual operands FUD chain. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
141 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
142 static void |
111 | 143 create_vop_var (struct function *fn) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
144 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
145 tree global_var; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
146 |
111 | 147 gcc_assert (fn->gimple_df->vop == NULL_TREE); |
0 | 148 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
149 global_var = build_decl (BUILTINS_LOCATION, VAR_DECL, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
150 get_identifier (".MEM"), |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
151 void_type_node); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
152 DECL_ARTIFICIAL (global_var) = 1; |
111 | 153 DECL_IGNORED_P (global_var) = 1; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
154 TREE_READONLY (global_var) = 0; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
155 DECL_EXTERNAL (global_var) = 1; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
156 TREE_STATIC (global_var) = 1; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
157 TREE_USED (global_var) = 1; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
158 DECL_CONTEXT (global_var) = NULL_TREE; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
159 TREE_THIS_VOLATILE (global_var) = 0; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
160 TREE_ADDRESSABLE (global_var) = 0; |
111 | 161 VAR_DECL_IS_VIRTUAL_OPERAND (global_var) = 1; |
0 | 162 |
111 | 163 fn->gimple_df->vop = global_var; |
0 | 164 } |
165 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
166 /* These are the sizes of the operand memory buffer in bytes which gets |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
167 allocated each time more operands space is required. The final value is |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
168 the amount that is allocated every time after that. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
169 In 1k we can fit 25 use operands (or 63 def operands) on a host with |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
170 8 byte pointers, that would be 10 statements each with 1 def and 2 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
171 uses. */ |
0 | 172 |
173 #define OP_SIZE_INIT 0 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
174 #define OP_SIZE_1 (1024 - sizeof (void *)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
175 #define OP_SIZE_2 (1024 * 4 - sizeof (void *)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
176 #define OP_SIZE_3 (1024 * 16 - sizeof (void *)) |
0 | 177 |
178 /* Initialize the operand cache routines. */ | |
179 | |
180 void | |
111 | 181 init_ssa_operands (struct function *fn) |
0 | 182 { |
183 if (!n_initialized++) | |
184 { | |
111 | 185 build_uses.create (10); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
186 build_vuse = NULL_TREE; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
187 build_vdef = NULL_TREE; |
0 | 188 bitmap_obstack_initialize (&operands_bitmap_obstack); |
189 } | |
190 | |
111 | 191 gcc_assert (gimple_ssa_operands (fn)->operand_memory == NULL); |
192 gimple_ssa_operands (fn)->operand_memory_index | |
193 = gimple_ssa_operands (fn)->ssa_operand_mem_size; | |
194 gimple_ssa_operands (fn)->ops_active = true; | |
195 gimple_ssa_operands (fn)->ssa_operand_mem_size = OP_SIZE_INIT; | |
196 create_vop_var (fn); | |
0 | 197 } |
198 | |
199 | |
200 /* Dispose of anything required by the operand routines. */ | |
201 | |
202 void | |
111 | 203 fini_ssa_operands (struct function *fn) |
0 | 204 { |
205 struct ssa_operand_memory_d *ptr; | |
206 | |
207 if (!--n_initialized) | |
208 { | |
111 | 209 build_uses.release (); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
210 build_vdef = NULL_TREE; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
211 build_vuse = NULL_TREE; |
0 | 212 } |
213 | |
111 | 214 gimple_ssa_operands (fn)->free_uses = NULL; |
0 | 215 |
111 | 216 while ((ptr = gimple_ssa_operands (fn)->operand_memory) != NULL) |
0 | 217 { |
111 | 218 gimple_ssa_operands (fn)->operand_memory |
219 = gimple_ssa_operands (fn)->operand_memory->next; | |
0 | 220 ggc_free (ptr); |
221 } | |
222 | |
111 | 223 gimple_ssa_operands (fn)->ops_active = false; |
0 | 224 |
225 if (!n_initialized) | |
226 bitmap_obstack_release (&operands_bitmap_obstack); | |
227 | |
111 | 228 fn->gimple_df->vop = NULL_TREE; |
0 | 229 } |
230 | |
231 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
232 /* Return memory for an operand of size SIZE. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
233 |
0 | 234 static inline void * |
111 | 235 ssa_operand_alloc (struct function *fn, unsigned size) |
0 | 236 { |
237 char *ptr; | |
238 | |
111 | 239 gcc_assert (size == sizeof (struct use_optype_d)); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
240 |
111 | 241 if (gimple_ssa_operands (fn)->operand_memory_index + size |
242 >= gimple_ssa_operands (fn)->ssa_operand_mem_size) | |
0 | 243 { |
244 struct ssa_operand_memory_d *ptr; | |
245 | |
111 | 246 switch (gimple_ssa_operands (fn)->ssa_operand_mem_size) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
247 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
248 case OP_SIZE_INIT: |
111 | 249 gimple_ssa_operands (fn)->ssa_operand_mem_size = OP_SIZE_1; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
250 break; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
251 case OP_SIZE_1: |
111 | 252 gimple_ssa_operands (fn)->ssa_operand_mem_size = OP_SIZE_2; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
253 break; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
254 case OP_SIZE_2: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
255 case OP_SIZE_3: |
111 | 256 gimple_ssa_operands (fn)->ssa_operand_mem_size = OP_SIZE_3; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
257 break; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
258 default: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
259 gcc_unreachable (); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
260 } |
0 | 261 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
262 |
111 | 263 ptr = (ssa_operand_memory_d *) ggc_internal_alloc |
264 (sizeof (void *) + gimple_ssa_operands (fn)->ssa_operand_mem_size); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
265 |
111 | 266 ptr->next = gimple_ssa_operands (fn)->operand_memory; |
267 gimple_ssa_operands (fn)->operand_memory = ptr; | |
268 gimple_ssa_operands (fn)->operand_memory_index = 0; | |
0 | 269 } |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
270 |
111 | 271 ptr = &(gimple_ssa_operands (fn)->operand_memory |
272 ->mem[gimple_ssa_operands (fn)->operand_memory_index]); | |
273 gimple_ssa_operands (fn)->operand_memory_index += size; | |
0 | 274 return ptr; |
275 } | |
276 | |
277 | |
278 /* Allocate a USE operand. */ | |
279 | |
280 static inline struct use_optype_d * | |
111 | 281 alloc_use (struct function *fn) |
0 | 282 { |
283 struct use_optype_d *ret; | |
111 | 284 if (gimple_ssa_operands (fn)->free_uses) |
0 | 285 { |
111 | 286 ret = gimple_ssa_operands (fn)->free_uses; |
287 gimple_ssa_operands (fn)->free_uses | |
288 = gimple_ssa_operands (fn)->free_uses->next; | |
0 | 289 } |
290 else | |
291 ret = (struct use_optype_d *) | |
111 | 292 ssa_operand_alloc (fn, sizeof (struct use_optype_d)); |
0 | 293 return ret; |
294 } | |
295 | |
296 | |
297 /* Adds OP to the list of uses of statement STMT after LAST. */ | |
298 | |
299 static inline use_optype_p | |
111 | 300 add_use_op (struct function *fn, gimple *stmt, tree *op, use_optype_p last) |
0 | 301 { |
302 use_optype_p new_use; | |
303 | |
111 | 304 new_use = alloc_use (fn); |
0 | 305 USE_OP_PTR (new_use)->use = op; |
306 link_imm_use_stmt (USE_OP_PTR (new_use), *op, stmt); | |
307 last->next = new_use; | |
308 new_use->next = NULL; | |
309 return new_use; | |
310 } | |
311 | |
312 | |
313 | |
314 /* Takes elements from build_defs and turns them into def operands of STMT. | |
111 | 315 TODO -- Make build_defs vec of tree *. */ |
0 | 316 |
317 static inline void | |
111 | 318 finalize_ssa_defs (struct function *fn, gimple *stmt) |
0 | 319 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
320 /* Pre-pend the vdef we may have built. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
321 if (build_vdef != NULL_TREE) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
322 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
323 tree oldvdef = gimple_vdef (stmt); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
324 if (oldvdef |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
325 && TREE_CODE (oldvdef) == SSA_NAME) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
326 oldvdef = SSA_NAME_VAR (oldvdef); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
327 if (oldvdef != build_vdef) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
328 gimple_set_vdef (stmt, build_vdef); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
329 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
330 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
331 /* Clear and unlink a no longer necessary VDEF. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
332 if (build_vdef == NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
333 && gimple_vdef (stmt) != NULL_TREE) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
334 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
335 if (TREE_CODE (gimple_vdef (stmt)) == SSA_NAME) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
336 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
337 unlink_stmt_vdef (stmt); |
111 | 338 release_ssa_name_fn (fn, gimple_vdef (stmt)); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
339 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
340 gimple_set_vdef (stmt, NULL_TREE); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
341 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
342 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
343 /* If we have a non-SSA_NAME VDEF, mark it for renaming. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
344 if (gimple_vdef (stmt) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
345 && TREE_CODE (gimple_vdef (stmt)) != SSA_NAME) |
0 | 346 { |
111 | 347 fn->gimple_df->rename_vops = 1; |
348 fn->gimple_df->ssa_renaming_needed = 1; | |
0 | 349 } |
350 } | |
351 | |
352 | |
111 | 353 /* Takes elements from build_uses and turns them into use operands of STMT. */ |
0 | 354 |
355 static inline void | |
111 | 356 finalize_ssa_uses (struct function *fn, gimple *stmt) |
0 | 357 { |
358 unsigned new_i; | |
359 struct use_optype_d new_list; | |
360 use_optype_p old_ops, ptr, last; | |
361 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
362 /* Pre-pend the VUSE we may have built. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
363 if (build_vuse != NULL_TREE) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
364 { |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
365 tree oldvuse = gimple_vuse (stmt); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
366 if (oldvuse |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
367 && TREE_CODE (oldvuse) == SSA_NAME) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
368 oldvuse = SSA_NAME_VAR (oldvuse); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
369 if (oldvuse != (build_vuse != NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
370 ? build_vuse : build_vdef)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
371 gimple_set_vuse (stmt, NULL_TREE); |
111 | 372 build_uses.safe_insert (0, gimple_vuse_ptr (stmt)); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
373 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
374 |
0 | 375 new_list.next = NULL; |
376 last = &new_list; | |
377 | |
378 old_ops = gimple_use_ops (stmt); | |
379 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
380 /* Clear a no longer necessary VUSE. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
381 if (build_vuse == NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
382 && gimple_vuse (stmt) != NULL_TREE) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
383 gimple_set_vuse (stmt, NULL_TREE); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
384 |
0 | 385 /* If there is anything in the old list, free it. */ |
386 if (old_ops) | |
387 { | |
111 | 388 for (ptr = old_ops; ptr->next; ptr = ptr->next) |
0 | 389 delink_imm_use (USE_OP_PTR (ptr)); |
111 | 390 delink_imm_use (USE_OP_PTR (ptr)); |
391 ptr->next = gimple_ssa_operands (fn)->free_uses; | |
392 gimple_ssa_operands (fn)->free_uses = old_ops; | |
0 | 393 } |
394 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
395 /* If we added a VUSE, make sure to set the operand if it is not already |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
396 present and mark it for renaming. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
397 if (build_vuse != NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
398 && gimple_vuse (stmt) == NULL_TREE) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
399 { |
111 | 400 gimple_set_vuse (stmt, gimple_vop (fn)); |
401 fn->gimple_df->rename_vops = 1; | |
402 fn->gimple_df->ssa_renaming_needed = 1; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
403 } |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
404 |
0 | 405 /* Now create nodes for all the new nodes. */ |
111 | 406 for (new_i = 0; new_i < build_uses.length (); new_i++) |
407 { | |
408 tree *op = build_uses[new_i]; | |
409 last = add_use_op (fn, stmt, op, last); | |
410 } | |
0 | 411 |
412 /* Now set the stmt's operands. */ | |
413 gimple_set_use_ops (stmt, new_list.next); | |
414 } | |
415 | |
416 | |
417 /* Clear the in_list bits and empty the build array for VDEFs and | |
418 VUSEs. */ | |
419 | |
420 static inline void | |
421 cleanup_build_arrays (void) | |
422 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
423 build_vdef = NULL_TREE; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
424 build_vuse = NULL_TREE; |
111 | 425 build_uses.truncate (0); |
0 | 426 } |
427 | |
428 | |
429 /* Finalize all the build vectors, fill the new ones into INFO. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
430 |
0 | 431 static inline void |
111 | 432 finalize_ssa_stmt_operands (struct function *fn, gimple *stmt) |
0 | 433 { |
111 | 434 finalize_ssa_defs (fn, stmt); |
435 finalize_ssa_uses (fn, stmt); | |
0 | 436 cleanup_build_arrays (); |
437 } | |
438 | |
439 | |
440 /* Start the process of building up operands vectors in INFO. */ | |
441 | |
442 static inline void | |
443 start_ssa_stmt_operands (void) | |
444 { | |
111 | 445 gcc_assert (build_uses.length () == 0); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
446 gcc_assert (build_vuse == NULL_TREE); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
447 gcc_assert (build_vdef == NULL_TREE); |
0 | 448 } |
449 | |
450 | |
451 /* Add USE_P to the list of pointers to operands. */ | |
452 | |
453 static inline void | |
454 append_use (tree *use_p) | |
455 { | |
111 | 456 build_uses.safe_push (use_p); |
0 | 457 } |
458 | |
459 | |
460 /* Add VAR to the set of variables that require a VDEF operator. */ | |
461 | |
462 static inline void | |
463 append_vdef (tree var) | |
464 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
465 gcc_assert ((build_vdef == NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
466 || build_vdef == var) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
467 && (build_vuse == NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
468 || build_vuse == var)); |
0 | 469 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
470 build_vdef = var; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
471 build_vuse = var; |
0 | 472 } |
473 | |
474 | |
475 /* Add VAR to the set of variables that require a VUSE operator. */ | |
476 | |
477 static inline void | |
478 append_vuse (tree var) | |
479 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
480 gcc_assert (build_vuse == NULL_TREE |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
481 || build_vuse == var); |
0 | 482 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
483 build_vuse = var; |
0 | 484 } |
485 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
486 /* Add virtual operands for STMT. FLAGS is as in get_expr_operands. */ |
0 | 487 |
488 static void | |
111 | 489 add_virtual_operand (struct function *fn, |
490 gimple *stmt ATTRIBUTE_UNUSED, int flags) | |
0 | 491 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
492 /* Add virtual operands to the stmt, unless the caller has specifically |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
493 requested not to do that (used when adding operands inside an |
0 | 494 ADDR_EXPR expression). */ |
495 if (flags & opf_no_vops) | |
496 return; | |
497 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
498 gcc_assert (!is_gimple_debug (stmt)); |
0 | 499 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
500 if (flags & opf_def) |
111 | 501 append_vdef (gimple_vop (fn)); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
502 else |
111 | 503 append_vuse (gimple_vop (fn)); |
0 | 504 } |
505 | |
506 | |
507 /* Add *VAR_P to the appropriate operand array for statement STMT. | |
508 FLAGS is as in get_expr_operands. If *VAR_P is a GIMPLE register, | |
509 it will be added to the statement's real operands, otherwise it is | |
510 added to virtual operands. */ | |
511 | |
512 static void | |
111 | 513 add_stmt_operand (struct function *fn, tree *var_p, gimple *stmt, int flags) |
0 | 514 { |
111 | 515 tree var = *var_p; |
0 | 516 |
145 | 517 gcc_assert (SSA_VAR_P (*var_p) |
518 || TREE_CODE (*var_p) == STRING_CST | |
519 || TREE_CODE (*var_p) == CONST_DECL); | |
0 | 520 |
111 | 521 if (is_gimple_reg (var)) |
0 | 522 { |
523 /* The variable is a GIMPLE register. Add it to real operands. */ | |
524 if (flags & opf_def) | |
111 | 525 ; |
0 | 526 else |
527 append_use (var_p); | |
111 | 528 if (DECL_P (*var_p)) |
529 fn->gimple_df->ssa_renaming_needed = 1; | |
0 | 530 } |
531 else | |
111 | 532 { |
533 /* Mark statements with volatile operands. */ | |
534 if (!(flags & opf_no_vops) | |
535 && TREE_THIS_VOLATILE (var)) | |
536 gimple_set_has_volatile_ops (stmt, true); | |
537 | |
538 /* The variable is a memory access. Add virtual operands. */ | |
539 add_virtual_operand (fn, stmt, flags); | |
540 } | |
0 | 541 } |
542 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
543 /* Mark the base address of REF as having its address taken. |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
544 REF may be a single variable whose address has been taken or any |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
545 other valid GIMPLE memory reference (structure reference, array, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
546 etc). */ |
0 | 547 |
548 static void | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
549 mark_address_taken (tree ref) |
0 | 550 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
551 tree var; |
0 | 552 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
553 /* Note that it is *NOT OKAY* to use the target of a COMPONENT_REF |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
554 as the only thing we take the address of. If VAR is a structure, |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
555 taking the address of a field means that the whole structure may |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
556 be referenced using pointer arithmetic. See PR 21407 and the |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
557 ensuing mailing list discussion. */ |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
558 var = get_base_address (ref); |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
559 if (var) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
560 { |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
561 if (DECL_P (var)) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
562 TREE_ADDRESSABLE (var) = 1; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
563 else if (TREE_CODE (var) == MEM_REF |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
564 && TREE_CODE (TREE_OPERAND (var, 0)) == ADDR_EXPR |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
565 && DECL_P (TREE_OPERAND (TREE_OPERAND (var, 0), 0))) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
566 TREE_ADDRESSABLE (TREE_OPERAND (TREE_OPERAND (var, 0), 0)) = 1; |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
567 } |
0 | 568 } |
569 | |
570 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
571 /* A subroutine of get_expr_operands to handle MEM_REF. |
0 | 572 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
573 STMT is the statement being processed, EXPR is the MEM_REF |
0 | 574 that got us here. |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
575 |
111 | 576 FLAGS is as in get_expr_operands. */ |
0 | 577 |
578 static void | |
111 | 579 get_mem_ref_operands (struct function *fn, |
580 gimple *stmt, tree expr, int flags) | |
0 | 581 { |
582 tree *pptr = &TREE_OPERAND (expr, 0); | |
583 | |
111 | 584 if (!(flags & opf_no_vops) |
585 && TREE_THIS_VOLATILE (expr)) | |
0 | 586 gimple_set_has_volatile_ops (stmt, true); |
587 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
588 /* Add the VOP. */ |
111 | 589 add_virtual_operand (fn, stmt, flags); |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
590 |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
591 /* If requested, add a USE operand for the base pointer. */ |
111 | 592 get_expr_operands (fn, stmt, pptr, |
593 opf_non_addressable | opf_use | |
594 | (flags & (opf_no_vops|opf_not_non_addressable))); | |
0 | 595 } |
596 | |
597 | |
598 /* A subroutine of get_expr_operands to handle TARGET_MEM_REF. */ | |
599 | |
600 static void | |
111 | 601 get_tmr_operands (struct function *fn, gimple *stmt, tree expr, int flags) |
0 | 602 { |
111 | 603 if (!(flags & opf_no_vops) |
604 && TREE_THIS_VOLATILE (expr)) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
605 gimple_set_has_volatile_ops (stmt, true); |
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
606 |
0 | 607 /* First record the real operands. */ |
111 | 608 get_expr_operands (fn, stmt, |
609 &TMR_BASE (expr), opf_use | (flags & opf_no_vops)); | |
610 get_expr_operands (fn, stmt, | |
611 &TMR_INDEX (expr), opf_use | (flags & opf_no_vops)); | |
612 get_expr_operands (fn, stmt, | |
613 &TMR_INDEX2 (expr), opf_use | (flags & opf_no_vops)); | |
0 | 614 |
111 | 615 add_virtual_operand (fn, stmt, flags); |
0 | 616 } |
617 | |
618 | |
619 /* If STMT is a call that may clobber globals and other symbols that | |
620 escape, add them to the VDEF/VUSE lists for it. */ | |
621 | |
622 static void | |
111 | 623 maybe_add_call_vops (struct function *fn, gcall *stmt) |
0 | 624 { |
625 int call_flags = gimple_call_flags (stmt); | |
626 | |
627 /* If aliases have been computed already, add VDEF or VUSE | |
628 operands for all the symbols that have been found to be | |
629 call-clobbered. */ | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
630 if (!(call_flags & ECF_NOVOPS)) |
0 | 631 { |
111 | 632 /* A 'pure' or a 'const' function never call-clobbers anything. */ |
633 if (!(call_flags & (ECF_PURE | ECF_CONST))) | |
634 add_virtual_operand (fn, stmt, opf_def); | |
0 | 635 else if (!(call_flags & ECF_CONST)) |
111 | 636 add_virtual_operand (fn, stmt, opf_use); |
0 | 637 } |
638 } | |
639 | |
640 | |
641 /* Scan operands in the ASM_EXPR stmt referred to in INFO. */ | |
642 | |
643 static void | |
111 | 644 get_asm_stmt_operands (struct function *fn, gasm *stmt) |
0 | 645 { |
646 size_t i, noutputs; | |
647 const char **oconstraints; | |
648 const char *constraint; | |
649 bool allows_mem, allows_reg, is_inout; | |
650 | |
651 noutputs = gimple_asm_noutputs (stmt); | |
652 oconstraints = (const char **) alloca ((noutputs) * sizeof (const char *)); | |
653 | |
654 /* Gather all output operands. */ | |
655 for (i = 0; i < gimple_asm_noutputs (stmt); i++) | |
656 { | |
657 tree link = gimple_asm_output_op (stmt, i); | |
658 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link))); | |
659 oconstraints[i] = constraint; | |
660 parse_output_constraint (&constraint, i, 0, 0, &allows_mem, | |
661 &allows_reg, &is_inout); | |
662 | |
663 /* This should have been split in gimplify_asm_expr. */ | |
664 gcc_assert (!allows_reg || !is_inout); | |
665 | |
666 /* Memory operands are addressable. Note that STMT needs the | |
667 address of this operand. */ | |
668 if (!allows_reg && allows_mem) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
669 mark_address_taken (TREE_VALUE (link)); |
0 | 670 |
111 | 671 get_expr_operands (fn, stmt, |
672 &TREE_VALUE (link), opf_def | opf_not_non_addressable); | |
0 | 673 } |
674 | |
675 /* Gather all input operands. */ | |
676 for (i = 0; i < gimple_asm_ninputs (stmt); i++) | |
677 { | |
678 tree link = gimple_asm_input_op (stmt, i); | |
679 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (link))); | |
680 parse_input_constraint (&constraint, 0, 0, noutputs, 0, oconstraints, | |
681 &allows_mem, &allows_reg); | |
682 | |
683 /* Memory operands are addressable. Note that STMT needs the | |
684 address of this operand. */ | |
685 if (!allows_reg && allows_mem) | |
63
b7f97abdc517
update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
55
diff
changeset
|
686 mark_address_taken (TREE_VALUE (link)); |
0 | 687 |
111 | 688 get_expr_operands (fn, stmt, &TREE_VALUE (link), opf_not_non_addressable); |
0 | 689 } |
690 | |
691 /* Clobber all memory and addressable symbols for asm ("" : : : "memory"); */ | |
111 | 692 if (gimple_asm_clobbers_memory_p (stmt)) |
693 add_virtual_operand (fn, stmt, opf_def); | |
0 | 694 } |
695 | |
696 | |
697 /* Recursively scan the expression pointed to by EXPR_P in statement | |
698 STMT. FLAGS is one of the OPF_* constants modifying how to | |
699 interpret the operands found. */ | |
700 | |
701 static void | |
111 | 702 get_expr_operands (struct function *fn, gimple *stmt, tree *expr_p, int flags) |
0 | 703 { |
704 enum tree_code code; | |
705 enum tree_code_class codeclass; | |
706 tree expr = *expr_p; | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
707 int uflags = opf_use; |
0 | 708 |
709 if (expr == NULL) | |
710 return; | |
711 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
712 if (is_gimple_debug (stmt)) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
713 uflags |= (flags & opf_no_vops); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
714 |
0 | 715 code = TREE_CODE (expr); |
716 codeclass = TREE_CODE_CLASS (code); | |
717 | |
718 switch (code) | |
719 { | |
720 case ADDR_EXPR: | |
721 /* Taking the address of a variable does not represent a | |
722 reference to it, but the fact that the statement takes its | |
723 address will be of interest to some passes (e.g. alias | |
724 resolution). */ | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
725 if ((!(flags & opf_non_addressable) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
726 || (flags & opf_not_non_addressable)) |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
727 && !is_gimple_debug (stmt)) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
728 mark_address_taken (TREE_OPERAND (expr, 0)); |
0 | 729 |
730 /* Otherwise, there may be variables referenced inside but there | |
731 should be no VUSEs created, since the referenced objects are | |
732 not really accessed. The only operands that we should find | |
733 here are ARRAY_REF indices which will always be real operands | |
734 (GIMPLE does not allow non-registers as array indices). */ | |
735 flags |= opf_no_vops; | |
111 | 736 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), |
737 flags | opf_not_non_addressable | opf_address_taken); | |
0 | 738 return; |
739 | |
740 case SSA_NAME: | |
741 case VAR_DECL: | |
742 case PARM_DECL: | |
743 case RESULT_DECL: | |
131 | 744 case STRING_CST: |
145 | 745 case CONST_DECL: |
111 | 746 if (!(flags & opf_address_taken)) |
747 add_stmt_operand (fn, expr_p, stmt, flags); | |
0 | 748 return; |
749 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
750 case DEBUG_EXPR_DECL: |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
751 gcc_assert (gimple_debug_bind_p (stmt)); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
752 return; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
753 |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
754 case MEM_REF: |
111 | 755 get_mem_ref_operands (fn, stmt, expr, flags); |
0 | 756 return; |
757 | |
758 case TARGET_MEM_REF: | |
111 | 759 get_tmr_operands (fn, stmt, expr, flags); |
0 | 760 return; |
761 | |
762 case ARRAY_REF: | |
763 case ARRAY_RANGE_REF: | |
764 case COMPONENT_REF: | |
765 case REALPART_EXPR: | |
766 case IMAGPART_EXPR: | |
767 { | |
111 | 768 if (!(flags & opf_no_vops) |
769 && TREE_THIS_VOLATILE (expr)) | |
0 | 770 gimple_set_has_volatile_ops (stmt, true); |
771 | |
111 | 772 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), flags); |
0 | 773 |
774 if (code == COMPONENT_REF) | |
775 { | |
111 | 776 if (!(flags & opf_no_vops) |
777 && TREE_THIS_VOLATILE (TREE_OPERAND (expr, 1))) | |
0 | 778 gimple_set_has_volatile_ops (stmt, true); |
111 | 779 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 2), uflags); |
0 | 780 } |
781 else if (code == ARRAY_REF || code == ARRAY_RANGE_REF) | |
782 { | |
111 | 783 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 1), uflags); |
784 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 2), uflags); | |
785 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 3), uflags); | |
0 | 786 } |
787 | |
788 return; | |
789 } | |
790 | |
791 case WITH_SIZE_EXPR: | |
792 /* WITH_SIZE_EXPR is a pass-through reference to its first argument, | |
793 and an rvalue reference to its second argument. */ | |
111 | 794 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 1), uflags); |
795 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), flags); | |
0 | 796 return; |
797 | |
798 case COND_EXPR: | |
799 case VEC_COND_EXPR: | |
111 | 800 case VEC_PERM_EXPR: |
801 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), uflags); | |
802 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 1), uflags); | |
803 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 2), uflags); | |
0 | 804 return; |
805 | |
806 case CONSTRUCTOR: | |
807 { | |
808 /* General aggregate CONSTRUCTORs have been decomposed, but they | |
809 are still in use as the COMPLEX_EXPR equivalent for vectors. */ | |
810 constructor_elt *ce; | |
811 unsigned HOST_WIDE_INT idx; | |
812 | |
111 | 813 /* A volatile constructor is actually TREE_CLOBBER_P, transfer |
814 the volatility to the statement, don't use TREE_CLOBBER_P for | |
815 mirroring the other uses of THIS_VOLATILE in this file. */ | |
816 if (!(flags & opf_no_vops) | |
817 && TREE_THIS_VOLATILE (expr)) | |
818 gimple_set_has_volatile_ops (stmt, true); | |
819 | |
0 | 820 for (idx = 0; |
111 | 821 vec_safe_iterate (CONSTRUCTOR_ELTS (expr), idx, &ce); |
0 | 822 idx++) |
111 | 823 get_expr_operands (fn, stmt, &ce->value, uflags); |
0 | 824 |
825 return; | |
826 } | |
827 | |
828 case BIT_FIELD_REF: | |
111 | 829 if (!(flags & opf_no_vops) |
830 && TREE_THIS_VOLATILE (expr)) | |
0 | 831 gimple_set_has_volatile_ops (stmt, true); |
832 /* FALLTHRU */ | |
833 | |
834 case VIEW_CONVERT_EXPR: | |
835 do_unary: | |
111 | 836 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), flags); |
0 | 837 return; |
838 | |
111 | 839 case BIT_INSERT_EXPR: |
0 | 840 case COMPOUND_EXPR: |
841 case OBJ_TYPE_REF: | |
842 case ASSERT_EXPR: | |
843 do_binary: | |
844 { | |
111 | 845 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), flags); |
846 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 1), flags); | |
0 | 847 return; |
848 } | |
849 | |
850 case DOT_PROD_EXPR: | |
111 | 851 case SAD_EXPR: |
0 | 852 case REALIGN_LOAD_EXPR: |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
853 case WIDEN_MULT_PLUS_EXPR: |
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
854 case WIDEN_MULT_MINUS_EXPR: |
0 | 855 { |
111 | 856 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 0), flags); |
857 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 1), flags); | |
858 get_expr_operands (fn, stmt, &TREE_OPERAND (expr, 2), flags); | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
859 return; |
0 | 860 } |
861 | |
862 case FUNCTION_DECL: | |
863 case LABEL_DECL: | |
864 case CASE_LABEL_EXPR: | |
865 /* Expressions that make no memory references. */ | |
866 return; | |
867 | |
868 default: | |
869 if (codeclass == tcc_unary) | |
870 goto do_unary; | |
871 if (codeclass == tcc_binary || codeclass == tcc_comparison) | |
872 goto do_binary; | |
873 if (codeclass == tcc_constant || codeclass == tcc_type) | |
874 return; | |
875 } | |
876 | |
877 /* If we get here, something has gone wrong. */ | |
111 | 878 if (flag_checking) |
879 { | |
880 fprintf (stderr, "unhandled expression in get_expr_operands():\n"); | |
881 debug_tree (expr); | |
882 fputs ("\n", stderr); | |
883 gcc_unreachable (); | |
884 } | |
0 | 885 } |
886 | |
887 | |
888 /* Parse STMT looking for operands. When finished, the various | |
889 build_* operand vectors will have potential operands in them. */ | |
890 | |
891 static void | |
111 | 892 parse_ssa_operands (struct function *fn, gimple *stmt) |
0 | 893 { |
894 enum gimple_code code = gimple_code (stmt); | |
111 | 895 size_t i, n, start = 0; |
0 | 896 |
111 | 897 switch (code) |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
898 { |
111 | 899 case GIMPLE_ASM: |
900 get_asm_stmt_operands (fn, as_a <gasm *> (stmt)); | |
901 break; | |
902 | |
903 case GIMPLE_TRANSACTION: | |
904 /* The start of a transaction is a memory barrier. */ | |
905 add_virtual_operand (fn, stmt, opf_def | opf_use); | |
906 break; | |
907 | |
908 case GIMPLE_DEBUG: | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
909 if (gimple_debug_bind_p (stmt) |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
910 && gimple_debug_bind_has_value_p (stmt)) |
111 | 911 get_expr_operands (fn, stmt, gimple_debug_bind_get_value_ptr (stmt), |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
912 opf_use | opf_no_vops); |
111 | 913 break; |
914 | |
915 case GIMPLE_RETURN: | |
916 append_vuse (gimple_vop (fn)); | |
917 goto do_default; | |
0 | 918 |
111 | 919 case GIMPLE_CALL: |
920 /* Add call-clobbered operands, if needed. */ | |
921 maybe_add_call_vops (fn, as_a <gcall *> (stmt)); | |
922 /* FALLTHRU */ | |
0 | 923 |
111 | 924 case GIMPLE_ASSIGN: |
925 get_expr_operands (fn, stmt, gimple_op_ptr (stmt, 0), opf_def); | |
926 start = 1; | |
927 /* FALLTHRU */ | |
0 | 928 |
111 | 929 default: |
930 do_default: | |
931 n = gimple_num_ops (stmt); | |
932 for (i = start; i < n; i++) | |
933 get_expr_operands (fn, stmt, gimple_op_ptr (stmt, i), opf_use); | |
934 break; | |
0 | 935 } |
936 } | |
937 | |
938 | |
939 /* Create an operands cache for STMT. */ | |
940 | |
941 static void | |
111 | 942 build_ssa_operands (struct function *fn, gimple *stmt) |
0 | 943 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
944 /* Initially assume that the statement has no volatile operands. */ |
0 | 945 gimple_set_has_volatile_ops (stmt, false); |
946 | |
947 start_ssa_stmt_operands (); | |
111 | 948 parse_ssa_operands (fn, stmt); |
949 finalize_ssa_stmt_operands (fn, stmt); | |
950 } | |
951 | |
952 /* Verifies SSA statement operands. */ | |
953 | |
954 DEBUG_FUNCTION bool | |
955 verify_ssa_operands (struct function *fn, gimple *stmt) | |
956 { | |
957 use_operand_p use_p; | |
958 def_operand_p def_p; | |
959 ssa_op_iter iter; | |
960 unsigned i; | |
961 tree def; | |
962 bool volatile_p = gimple_has_volatile_ops (stmt); | |
963 | |
964 /* build_ssa_operands w/o finalizing them. */ | |
965 gimple_set_has_volatile_ops (stmt, false); | |
966 start_ssa_stmt_operands (); | |
967 parse_ssa_operands (fn, stmt); | |
968 | |
969 /* Now verify the built operands are the same as present in STMT. */ | |
970 def = gimple_vdef (stmt); | |
971 if (def | |
972 && TREE_CODE (def) == SSA_NAME) | |
973 def = SSA_NAME_VAR (def); | |
974 if (build_vdef != def) | |
975 { | |
145 | 976 error ("virtual definition of statement not up to date"); |
111 | 977 return true; |
978 } | |
979 if (gimple_vdef (stmt) | |
980 && ((def_p = gimple_vdef_op (stmt)) == NULL_DEF_OPERAND_P | |
981 || DEF_FROM_PTR (def_p) != gimple_vdef (stmt))) | |
982 { | |
145 | 983 error ("virtual def operand missing for statement"); |
111 | 984 return true; |
985 } | |
986 | |
987 tree use = gimple_vuse (stmt); | |
988 if (use | |
989 && TREE_CODE (use) == SSA_NAME) | |
990 use = SSA_NAME_VAR (use); | |
991 if (build_vuse != use) | |
992 { | |
145 | 993 error ("virtual use of statement not up to date"); |
111 | 994 return true; |
995 } | |
996 if (gimple_vuse (stmt) | |
997 && ((use_p = gimple_vuse_op (stmt)) == NULL_USE_OPERAND_P | |
998 || USE_FROM_PTR (use_p) != gimple_vuse (stmt))) | |
999 { | |
145 | 1000 error ("virtual use operand missing for statement"); |
111 | 1001 return true; |
1002 } | |
1003 | |
1004 FOR_EACH_SSA_USE_OPERAND (use_p, stmt, iter, SSA_OP_USE) | |
1005 { | |
1006 tree *op; | |
1007 FOR_EACH_VEC_ELT (build_uses, i, op) | |
1008 { | |
1009 if (use_p->use == op) | |
1010 { | |
1011 build_uses[i] = NULL; | |
1012 break; | |
1013 } | |
1014 } | |
1015 if (i == build_uses.length ()) | |
1016 { | |
145 | 1017 error ("excess use operand for statement"); |
111 | 1018 debug_generic_expr (USE_FROM_PTR (use_p)); |
1019 return true; | |
1020 } | |
1021 } | |
1022 | |
1023 tree *op; | |
1024 FOR_EACH_VEC_ELT (build_uses, i, op) | |
1025 if (op != NULL) | |
1026 { | |
145 | 1027 error ("use operand missing for statement"); |
111 | 1028 debug_generic_expr (*op); |
1029 return true; | |
1030 } | |
1031 | |
1032 if (gimple_has_volatile_ops (stmt) != volatile_p) | |
1033 { | |
145 | 1034 error ("statement volatile flag not up to date"); |
111 | 1035 return true; |
1036 } | |
1037 | |
1038 cleanup_build_arrays (); | |
1039 return false; | |
0 | 1040 } |
1041 | |
1042 | |
1043 /* Releases the operands of STMT back to their freelists, and clears | |
1044 the stmt operand lists. */ | |
1045 | |
1046 void | |
111 | 1047 free_stmt_operands (struct function *fn, gimple *stmt) |
0 | 1048 { |
1049 use_optype_p uses = gimple_use_ops (stmt), last_use; | |
1050 | |
1051 if (uses) | |
1052 { | |
1053 for (last_use = uses; last_use->next; last_use = last_use->next) | |
1054 delink_imm_use (USE_OP_PTR (last_use)); | |
1055 delink_imm_use (USE_OP_PTR (last_use)); | |
111 | 1056 last_use->next = gimple_ssa_operands (fn)->free_uses; |
1057 gimple_ssa_operands (fn)->free_uses = uses; | |
0 | 1058 gimple_set_use_ops (stmt, NULL); |
1059 } | |
1060 | |
1061 if (gimple_has_mem_ops (stmt)) | |
1062 { | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1063 gimple_set_vuse (stmt, NULL_TREE); |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1064 gimple_set_vdef (stmt, NULL_TREE); |
0 | 1065 } |
1066 } | |
1067 | |
1068 | |
1069 /* Get the operands of statement STMT. */ | |
1070 | |
1071 void | |
111 | 1072 update_stmt_operands (struct function *fn, gimple *stmt) |
0 | 1073 { |
1074 /* If update_stmt_operands is called before SSA is initialized, do | |
1075 nothing. */ | |
111 | 1076 if (!ssa_operands_active (fn)) |
0 | 1077 return; |
1078 | |
1079 timevar_push (TV_TREE_OPS); | |
1080 | |
1081 gcc_assert (gimple_modified_p (stmt)); | |
111 | 1082 build_ssa_operands (fn, stmt); |
0 | 1083 gimple_set_modified (stmt, false); |
1084 | |
1085 timevar_pop (TV_TREE_OPS); | |
1086 } | |
1087 | |
1088 | |
1089 /* Swap operands EXP0 and EXP1 in statement STMT. No attempt is done | |
1090 to test the validity of the swap operation. */ | |
1091 | |
1092 void | |
111 | 1093 swap_ssa_operands (gimple *stmt, tree *exp0, tree *exp1) |
0 | 1094 { |
1095 tree op0, op1; | |
1096 op0 = *exp0; | |
1097 op1 = *exp1; | |
1098 | |
111 | 1099 if (op0 != op1) |
0 | 1100 { |
111 | 1101 /* Attempt to preserve the relative positions of these two operands in |
1102 their * respective immediate use lists by adjusting their use pointer | |
1103 to point to the new operand position. */ | |
0 | 1104 use_optype_p use0, use1, ptr; |
1105 use0 = use1 = NULL; | |
1106 | |
1107 /* Find the 2 operands in the cache, if they are there. */ | |
1108 for (ptr = gimple_use_ops (stmt); ptr; ptr = ptr->next) | |
1109 if (USE_OP_PTR (ptr)->use == exp0) | |
1110 { | |
1111 use0 = ptr; | |
1112 break; | |
1113 } | |
1114 | |
1115 for (ptr = gimple_use_ops (stmt); ptr; ptr = ptr->next) | |
1116 if (USE_OP_PTR (ptr)->use == exp1) | |
1117 { | |
1118 use1 = ptr; | |
1119 break; | |
1120 } | |
1121 | |
111 | 1122 /* And adjust their location to point to the new position of the |
1123 operand. */ | |
1124 if (use0) | |
1125 USE_OP_PTR (use0)->use = exp1; | |
1126 if (use1) | |
1127 USE_OP_PTR (use1)->use = exp0; | |
1128 | |
1129 /* Now swap the data. */ | |
1130 *exp0 = op1; | |
1131 *exp1 = op0; | |
0 | 1132 } |
1133 } | |
1134 | |
1135 | |
1136 /* Scan the immediate_use list for VAR making sure its linked properly. | |
1137 Return TRUE if there is a problem and emit an error message to F. */ | |
1138 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1139 DEBUG_FUNCTION bool |
0 | 1140 verify_imm_links (FILE *f, tree var) |
1141 { | |
1142 use_operand_p ptr, prev, list; | |
111 | 1143 unsigned int count; |
0 | 1144 |
1145 gcc_assert (TREE_CODE (var) == SSA_NAME); | |
1146 | |
1147 list = &(SSA_NAME_IMM_USE_NODE (var)); | |
1148 gcc_assert (list->use == NULL); | |
1149 | |
1150 if (list->prev == NULL) | |
1151 { | |
1152 gcc_assert (list->next == NULL); | |
1153 return false; | |
1154 } | |
1155 | |
1156 prev = list; | |
1157 count = 0; | |
1158 for (ptr = list->next; ptr != list; ) | |
1159 { | |
1160 if (prev != ptr->prev) | |
111 | 1161 { |
1162 fprintf (f, "prev != ptr->prev\n"); | |
1163 goto error; | |
1164 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1165 |
0 | 1166 if (ptr->use == NULL) |
111 | 1167 { |
1168 fprintf (f, "ptr->use == NULL\n"); | |
1169 goto error; /* 2 roots, or SAFE guard node. */ | |
1170 } | |
0 | 1171 else if (*(ptr->use) != var) |
111 | 1172 { |
1173 fprintf (f, "*(ptr->use) != var\n"); | |
1174 goto error; | |
1175 } | |
0 | 1176 |
1177 prev = ptr; | |
1178 ptr = ptr->next; | |
1179 | |
111 | 1180 count++; |
1181 if (count == 0) | |
1182 { | |
1183 fprintf (f, "number of immediate uses doesn't fit unsigned int\n"); | |
1184 goto error; | |
1185 } | |
0 | 1186 } |
1187 | |
1188 /* Verify list in the other direction. */ | |
1189 prev = list; | |
1190 for (ptr = list->prev; ptr != list; ) | |
1191 { | |
1192 if (prev != ptr->next) | |
111 | 1193 { |
1194 fprintf (f, "prev != ptr->next\n"); | |
1195 goto error; | |
1196 } | |
0 | 1197 prev = ptr; |
1198 ptr = ptr->prev; | |
111 | 1199 if (count == 0) |
1200 { | |
1201 fprintf (f, "count-- < 0\n"); | |
1202 goto error; | |
1203 } | |
1204 count--; | |
0 | 1205 } |
1206 | |
1207 if (count != 0) | |
111 | 1208 { |
1209 fprintf (f, "count != 0\n"); | |
1210 goto error; | |
1211 } | |
0 | 1212 |
1213 return false; | |
1214 | |
1215 error: | |
1216 if (ptr->loc.stmt && gimple_modified_p (ptr->loc.stmt)) | |
1217 { | |
1218 fprintf (f, " STMT MODIFIED. - <%p> ", (void *)ptr->loc.stmt); | |
1219 print_gimple_stmt (f, ptr->loc.stmt, 0, TDF_SLIM); | |
1220 } | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1221 fprintf (f, " IMM ERROR : (use_p : tree - %p:%p)", (void *)ptr, |
0 | 1222 (void *)ptr->use); |
1223 print_generic_expr (f, USE_FROM_PTR (ptr), TDF_SLIM); | |
111 | 1224 fprintf (f, "\n"); |
0 | 1225 return true; |
1226 } | |
1227 | |
1228 | |
1229 /* Dump all the immediate uses to FILE. */ | |
1230 | |
1231 void | |
1232 dump_immediate_uses_for (FILE *file, tree var) | |
1233 { | |
1234 imm_use_iterator iter; | |
1235 use_operand_p use_p; | |
1236 | |
1237 gcc_assert (var && TREE_CODE (var) == SSA_NAME); | |
1238 | |
1239 print_generic_expr (file, var, TDF_SLIM); | |
1240 fprintf (file, " : -->"); | |
1241 if (has_zero_uses (var)) | |
1242 fprintf (file, " no uses.\n"); | |
1243 else | |
1244 if (has_single_use (var)) | |
1245 fprintf (file, " single use.\n"); | |
1246 else | |
1247 fprintf (file, "%d uses.\n", num_imm_uses (var)); | |
1248 | |
1249 FOR_EACH_IMM_USE_FAST (use_p, iter, var) | |
1250 { | |
1251 if (use_p->loc.stmt == NULL && use_p->use == NULL) | |
1252 fprintf (file, "***end of stmt iterator marker***\n"); | |
1253 else | |
1254 if (!is_gimple_reg (USE_FROM_PTR (use_p))) | |
1255 print_gimple_stmt (file, USE_STMT (use_p), 0, TDF_VOPS|TDF_MEMSYMS); | |
1256 else | |
1257 print_gimple_stmt (file, USE_STMT (use_p), 0, TDF_SLIM); | |
1258 } | |
111 | 1259 fprintf (file, "\n"); |
0 | 1260 } |
1261 | |
1262 | |
1263 /* Dump all the immediate uses to FILE. */ | |
1264 | |
1265 void | |
1266 dump_immediate_uses (FILE *file) | |
1267 { | |
1268 tree var; | |
1269 unsigned int x; | |
1270 | |
1271 fprintf (file, "Immediate_uses: \n\n"); | |
111 | 1272 FOR_EACH_SSA_NAME (x, var, cfun) |
0 | 1273 { |
1274 dump_immediate_uses_for (file, var); | |
1275 } | |
1276 } | |
1277 | |
1278 | |
1279 /* Dump def-use edges on stderr. */ | |
1280 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1281 DEBUG_FUNCTION void |
0 | 1282 debug_immediate_uses (void) |
1283 { | |
1284 dump_immediate_uses (stderr); | |
1285 } | |
1286 | |
1287 | |
1288 /* Dump def-use edges on stderr. */ | |
1289 | |
67
f6334be47118
update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents:
63
diff
changeset
|
1290 DEBUG_FUNCTION void |
0 | 1291 debug_immediate_uses_for (tree var) |
1292 { | |
1293 dump_immediate_uses_for (stderr, var); | |
1294 } | |
1295 | |
1296 | |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1297 /* Unlink STMTs virtual definition from the IL by propagating its use. */ |
0 | 1298 |
1299 void | |
111 | 1300 unlink_stmt_vdef (gimple *stmt) |
0 | 1301 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1302 use_operand_p use_p; |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1303 imm_use_iterator iter; |
111 | 1304 gimple *use_stmt; |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1305 tree vdef = gimple_vdef (stmt); |
111 | 1306 tree vuse = gimple_vuse (stmt); |
0 | 1307 |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1308 if (!vdef |
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1309 || TREE_CODE (vdef) != SSA_NAME) |
0 | 1310 return; |
1311 | |
111 | 1312 FOR_EACH_IMM_USE_STMT (use_stmt, iter, vdef) |
0 | 1313 { |
55
77e2b8dfacca
update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents:
19
diff
changeset
|
1314 FOR_EACH_IMM_USE_ON_STMT (use_p, iter) |
111 | 1315 SET_USE (use_p, vuse); |
0 | 1316 } |
1317 | |
111 | 1318 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (vdef)) |
1319 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (vuse) = 1; | |
0 | 1320 } |
1321 | |
111 | 1322 /* Return true if the var whose chain of uses starts at PTR has a |
1323 single nondebug use. Set USE_P and STMT to that single nondebug | |
1324 use, if so, or to NULL otherwise. */ | |
1325 bool | |
1326 single_imm_use_1 (const ssa_use_operand_t *head, | |
1327 use_operand_p *use_p, gimple **stmt) | |
1328 { | |
1329 ssa_use_operand_t *ptr, *single_use = 0; | |
1330 | |
1331 for (ptr = head->next; ptr != head; ptr = ptr->next) | |
1332 if (USE_STMT(ptr) && !is_gimple_debug (USE_STMT (ptr))) | |
1333 { | |
1334 if (single_use) | |
1335 { | |
1336 single_use = NULL; | |
1337 break; | |
1338 } | |
1339 single_use = ptr; | |
1340 } | |
1341 | |
1342 if (use_p) | |
1343 *use_p = single_use; | |
1344 | |
1345 if (stmt) | |
1346 *stmt = single_use ? single_use->loc.stmt : NULL; | |
1347 | |
1348 return single_use; | |
1349 } | |
1350 |