annotate gcc/tree-vectorizer.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1 /* Vectorizer
111
kono
parents: 67
diff changeset
2 Copyright (C) 2003-2017 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by Dorit Naishlos <dorit@il.ibm.com>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
21 /* Loop and basic block vectorizer.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
23 This file contains drivers for the three vectorizers:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
24 (1) loop vectorizer (inter-iteration parallelism),
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
25 (2) loop-aware SLP (intra-iteration parallelism) (invoked by the loop
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
26 vectorizer)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
27 (3) BB vectorizer (out-of-loops), aka SLP
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
29 The rest of the vectorizer's code is organized as follows:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
30 - tree-vect-loop.c - loop specific parts such as reductions, etc. These are
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
31 used by drivers (1) and (2).
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
32 - tree-vect-loop-manip.c - vectorizer's loop control-flow utilities, used by
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
33 drivers (1) and (2).
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
34 - tree-vect-slp.c - BB vectorization specific analysis and transformation,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
35 used by drivers (2) and (3).
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
36 - tree-vect-stmts.c - statements analysis and transformation (used by all).
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
37 - tree-vect-data-refs.c - vectorizer specific data-refs analysis and
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
38 manipulations (used by all).
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
39 - tree-vect-patterns.c - vectorizable code patterns detector (used by all)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
41 Here's a poor attempt at illustrating that:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
43 tree-vectorizer.c:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
44 loop_vect() loop_aware_slp() slp_vect()
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
45 | / \ /
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
46 | / \ /
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
47 tree-vect-loop.c tree-vect-slp.c
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
48 | \ \ / / |
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
49 | \ \/ / |
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
50 | \ /\ / |
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
51 | \ / \ / |
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
52 tree-vect-stmts.c tree-vect-data-refs.c
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
53 \ /
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
54 tree-vect-patterns.c
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 #include "coretypes.h"
111
kono
parents: 67
diff changeset
60 #include "backend.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 #include "tree.h"
111
kono
parents: 67
diff changeset
62 #include "gimple.h"
kono
parents: 67
diff changeset
63 #include "predict.h"
kono
parents: 67
diff changeset
64 #include "tree-pass.h"
kono
parents: 67
diff changeset
65 #include "ssa.h"
kono
parents: 67
diff changeset
66 #include "cgraph.h"
kono
parents: 67
diff changeset
67 #include "fold-const.h"
kono
parents: 67
diff changeset
68 #include "stor-layout.h"
kono
parents: 67
diff changeset
69 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
70 #include "gimple-walk.h"
kono
parents: 67
diff changeset
71 #include "tree-ssa-loop-manip.h"
kono
parents: 67
diff changeset
72 #include "tree-ssa-loop-niter.h"
kono
parents: 67
diff changeset
73 #include "tree-cfg.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
74 #include "cfgloop.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 #include "tree-vectorizer.h"
111
kono
parents: 67
diff changeset
76 #include "tree-ssa-propagate.h"
kono
parents: 67
diff changeset
77 #include "dbgcnt.h"
kono
parents: 67
diff changeset
78 #include "tree-scalar-evolution.h"
kono
parents: 67
diff changeset
79 #include "stringpool.h"
kono
parents: 67
diff changeset
80 #include "attribs.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
82
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
83 /* Loop or bb location. */
111
kono
parents: 67
diff changeset
84 source_location vect_location;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
85
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 /* Vector mapping GIMPLE stmt to stmt_vec_info. */
111
kono
parents: 67
diff changeset
87 vec<stmt_vec_info> stmt_vec_info_vec;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
88
111
kono
parents: 67
diff changeset
89 /* For mapping simduid to vectorization factor. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
90
111
kono
parents: 67
diff changeset
91 struct simduid_to_vf : free_ptr_hash<simduid_to_vf>
kono
parents: 67
diff changeset
92 {
kono
parents: 67
diff changeset
93 unsigned int simduid;
kono
parents: 67
diff changeset
94 int vf;
kono
parents: 67
diff changeset
95
kono
parents: 67
diff changeset
96 /* hash_table support. */
kono
parents: 67
diff changeset
97 static inline hashval_t hash (const simduid_to_vf *);
kono
parents: 67
diff changeset
98 static inline int equal (const simduid_to_vf *, const simduid_to_vf *);
kono
parents: 67
diff changeset
99 };
kono
parents: 67
diff changeset
100
kono
parents: 67
diff changeset
101 inline hashval_t
kono
parents: 67
diff changeset
102 simduid_to_vf::hash (const simduid_to_vf *p)
kono
parents: 67
diff changeset
103 {
kono
parents: 67
diff changeset
104 return p->simduid;
kono
parents: 67
diff changeset
105 }
kono
parents: 67
diff changeset
106
kono
parents: 67
diff changeset
107 inline int
kono
parents: 67
diff changeset
108 simduid_to_vf::equal (const simduid_to_vf *p1, const simduid_to_vf *p2)
kono
parents: 67
diff changeset
109 {
kono
parents: 67
diff changeset
110 return p1->simduid == p2->simduid;
kono
parents: 67
diff changeset
111 }
kono
parents: 67
diff changeset
112
kono
parents: 67
diff changeset
113 /* This hash maps the OMP simd array to the corresponding simduid used
kono
parents: 67
diff changeset
114 to index into it. Like thus,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
115
111
kono
parents: 67
diff changeset
116 _7 = GOMP_SIMD_LANE (simduid.0)
kono
parents: 67
diff changeset
117 ...
kono
parents: 67
diff changeset
118 ...
kono
parents: 67
diff changeset
119 D.1737[_7] = stuff;
kono
parents: 67
diff changeset
120
kono
parents: 67
diff changeset
121
kono
parents: 67
diff changeset
122 This hash maps from the OMP simd array (D.1737[]) to DECL_UID of
kono
parents: 67
diff changeset
123 simduid.0. */
kono
parents: 67
diff changeset
124
kono
parents: 67
diff changeset
125 struct simd_array_to_simduid : free_ptr_hash<simd_array_to_simduid>
kono
parents: 67
diff changeset
126 {
kono
parents: 67
diff changeset
127 tree decl;
kono
parents: 67
diff changeset
128 unsigned int simduid;
kono
parents: 67
diff changeset
129
kono
parents: 67
diff changeset
130 /* hash_table support. */
kono
parents: 67
diff changeset
131 static inline hashval_t hash (const simd_array_to_simduid *);
kono
parents: 67
diff changeset
132 static inline int equal (const simd_array_to_simduid *,
kono
parents: 67
diff changeset
133 const simd_array_to_simduid *);
kono
parents: 67
diff changeset
134 };
kono
parents: 67
diff changeset
135
kono
parents: 67
diff changeset
136 inline hashval_t
kono
parents: 67
diff changeset
137 simd_array_to_simduid::hash (const simd_array_to_simduid *p)
kono
parents: 67
diff changeset
138 {
kono
parents: 67
diff changeset
139 return DECL_UID (p->decl);
kono
parents: 67
diff changeset
140 }
kono
parents: 67
diff changeset
141
kono
parents: 67
diff changeset
142 inline int
kono
parents: 67
diff changeset
143 simd_array_to_simduid::equal (const simd_array_to_simduid *p1,
kono
parents: 67
diff changeset
144 const simd_array_to_simduid *p2)
kono
parents: 67
diff changeset
145 {
kono
parents: 67
diff changeset
146 return p1->decl == p2->decl;
kono
parents: 67
diff changeset
147 }
kono
parents: 67
diff changeset
148
kono
parents: 67
diff changeset
149 /* Fold IFN_GOMP_SIMD_LANE, IFN_GOMP_SIMD_VF, IFN_GOMP_SIMD_LAST_LANE,
kono
parents: 67
diff changeset
150 into their corresponding constants and remove
kono
parents: 67
diff changeset
151 IFN_GOMP_SIMD_ORDERED_{START,END}. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 static void
111
kono
parents: 67
diff changeset
154 adjust_simduid_builtins (hash_table<simduid_to_vf> *htab)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 {
111
kono
parents: 67
diff changeset
156 basic_block bb;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157
111
kono
parents: 67
diff changeset
158 FOR_EACH_BB_FN (bb, cfun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 {
111
kono
parents: 67
diff changeset
160 gimple_stmt_iterator i;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
161
111
kono
parents: 67
diff changeset
162 for (i = gsi_start_bb (bb); !gsi_end_p (i); )
kono
parents: 67
diff changeset
163 {
kono
parents: 67
diff changeset
164 unsigned int vf = 1;
kono
parents: 67
diff changeset
165 enum internal_fn ifn;
kono
parents: 67
diff changeset
166 gimple *stmt = gsi_stmt (i);
kono
parents: 67
diff changeset
167 tree t;
kono
parents: 67
diff changeset
168 if (!is_gimple_call (stmt)
kono
parents: 67
diff changeset
169 || !gimple_call_internal_p (stmt))
kono
parents: 67
diff changeset
170 {
kono
parents: 67
diff changeset
171 gsi_next (&i);
kono
parents: 67
diff changeset
172 continue;
kono
parents: 67
diff changeset
173 }
kono
parents: 67
diff changeset
174 ifn = gimple_call_internal_fn (stmt);
kono
parents: 67
diff changeset
175 switch (ifn)
kono
parents: 67
diff changeset
176 {
kono
parents: 67
diff changeset
177 case IFN_GOMP_SIMD_LANE:
kono
parents: 67
diff changeset
178 case IFN_GOMP_SIMD_VF:
kono
parents: 67
diff changeset
179 case IFN_GOMP_SIMD_LAST_LANE:
kono
parents: 67
diff changeset
180 break;
kono
parents: 67
diff changeset
181 case IFN_GOMP_SIMD_ORDERED_START:
kono
parents: 67
diff changeset
182 case IFN_GOMP_SIMD_ORDERED_END:
kono
parents: 67
diff changeset
183 if (integer_onep (gimple_call_arg (stmt, 0)))
kono
parents: 67
diff changeset
184 {
kono
parents: 67
diff changeset
185 enum built_in_function bcode
kono
parents: 67
diff changeset
186 = (ifn == IFN_GOMP_SIMD_ORDERED_START
kono
parents: 67
diff changeset
187 ? BUILT_IN_GOMP_ORDERED_START
kono
parents: 67
diff changeset
188 : BUILT_IN_GOMP_ORDERED_END);
kono
parents: 67
diff changeset
189 gimple *g
kono
parents: 67
diff changeset
190 = gimple_build_call (builtin_decl_explicit (bcode), 0);
kono
parents: 67
diff changeset
191 tree vdef = gimple_vdef (stmt);
kono
parents: 67
diff changeset
192 gimple_set_vdef (g, vdef);
kono
parents: 67
diff changeset
193 SSA_NAME_DEF_STMT (vdef) = g;
kono
parents: 67
diff changeset
194 gimple_set_vuse (g, gimple_vuse (stmt));
kono
parents: 67
diff changeset
195 gsi_replace (&i, g, true);
kono
parents: 67
diff changeset
196 continue;
kono
parents: 67
diff changeset
197 }
kono
parents: 67
diff changeset
198 gsi_remove (&i, true);
kono
parents: 67
diff changeset
199 unlink_stmt_vdef (stmt);
kono
parents: 67
diff changeset
200 continue;
kono
parents: 67
diff changeset
201 default:
kono
parents: 67
diff changeset
202 gsi_next (&i);
kono
parents: 67
diff changeset
203 continue;
kono
parents: 67
diff changeset
204 }
kono
parents: 67
diff changeset
205 tree arg = gimple_call_arg (stmt, 0);
kono
parents: 67
diff changeset
206 gcc_assert (arg != NULL_TREE);
kono
parents: 67
diff changeset
207 gcc_assert (TREE_CODE (arg) == SSA_NAME);
kono
parents: 67
diff changeset
208 simduid_to_vf *p = NULL, data;
kono
parents: 67
diff changeset
209 data.simduid = DECL_UID (SSA_NAME_VAR (arg));
kono
parents: 67
diff changeset
210 /* Need to nullify loop safelen field since it's value is not
kono
parents: 67
diff changeset
211 valid after transformation. */
kono
parents: 67
diff changeset
212 if (bb->loop_father && bb->loop_father->safelen > 0)
kono
parents: 67
diff changeset
213 bb->loop_father->safelen = 0;
kono
parents: 67
diff changeset
214 if (htab)
kono
parents: 67
diff changeset
215 {
kono
parents: 67
diff changeset
216 p = htab->find (&data);
kono
parents: 67
diff changeset
217 if (p)
kono
parents: 67
diff changeset
218 vf = p->vf;
kono
parents: 67
diff changeset
219 }
kono
parents: 67
diff changeset
220 switch (ifn)
kono
parents: 67
diff changeset
221 {
kono
parents: 67
diff changeset
222 case IFN_GOMP_SIMD_VF:
kono
parents: 67
diff changeset
223 t = build_int_cst (unsigned_type_node, vf);
kono
parents: 67
diff changeset
224 break;
kono
parents: 67
diff changeset
225 case IFN_GOMP_SIMD_LANE:
kono
parents: 67
diff changeset
226 t = build_int_cst (unsigned_type_node, 0);
kono
parents: 67
diff changeset
227 break;
kono
parents: 67
diff changeset
228 case IFN_GOMP_SIMD_LAST_LANE:
kono
parents: 67
diff changeset
229 t = gimple_call_arg (stmt, 1);
kono
parents: 67
diff changeset
230 break;
kono
parents: 67
diff changeset
231 default:
kono
parents: 67
diff changeset
232 gcc_unreachable ();
kono
parents: 67
diff changeset
233 }
kono
parents: 67
diff changeset
234 tree lhs = gimple_call_lhs (stmt);
kono
parents: 67
diff changeset
235 if (lhs)
kono
parents: 67
diff changeset
236 replace_uses_by (lhs, t);
kono
parents: 67
diff changeset
237 release_defs (stmt);
kono
parents: 67
diff changeset
238 gsi_remove (&i, true);
kono
parents: 67
diff changeset
239 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 }
111
kono
parents: 67
diff changeset
241 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
242
111
kono
parents: 67
diff changeset
243 /* Helper structure for note_simd_array_uses. */
kono
parents: 67
diff changeset
244
kono
parents: 67
diff changeset
245 struct note_simd_array_uses_struct
kono
parents: 67
diff changeset
246 {
kono
parents: 67
diff changeset
247 hash_table<simd_array_to_simduid> **htab;
kono
parents: 67
diff changeset
248 unsigned int simduid;
kono
parents: 67
diff changeset
249 };
kono
parents: 67
diff changeset
250
kono
parents: 67
diff changeset
251 /* Callback for note_simd_array_uses, called through walk_gimple_op. */
kono
parents: 67
diff changeset
252
kono
parents: 67
diff changeset
253 static tree
kono
parents: 67
diff changeset
254 note_simd_array_uses_cb (tree *tp, int *walk_subtrees, void *data)
kono
parents: 67
diff changeset
255 {
kono
parents: 67
diff changeset
256 struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
kono
parents: 67
diff changeset
257 struct note_simd_array_uses_struct *ns
kono
parents: 67
diff changeset
258 = (struct note_simd_array_uses_struct *) wi->info;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259
111
kono
parents: 67
diff changeset
260 if (TYPE_P (*tp))
kono
parents: 67
diff changeset
261 *walk_subtrees = 0;
kono
parents: 67
diff changeset
262 else if (VAR_P (*tp)
kono
parents: 67
diff changeset
263 && lookup_attribute ("omp simd array", DECL_ATTRIBUTES (*tp))
kono
parents: 67
diff changeset
264 && DECL_CONTEXT (*tp) == current_function_decl)
kono
parents: 67
diff changeset
265 {
kono
parents: 67
diff changeset
266 simd_array_to_simduid data;
kono
parents: 67
diff changeset
267 if (!*ns->htab)
kono
parents: 67
diff changeset
268 *ns->htab = new hash_table<simd_array_to_simduid> (15);
kono
parents: 67
diff changeset
269 data.decl = *tp;
kono
parents: 67
diff changeset
270 data.simduid = ns->simduid;
kono
parents: 67
diff changeset
271 simd_array_to_simduid **slot = (*ns->htab)->find_slot (&data, INSERT);
kono
parents: 67
diff changeset
272 if (*slot == NULL)
kono
parents: 67
diff changeset
273 {
kono
parents: 67
diff changeset
274 simd_array_to_simduid *p = XNEW (simd_array_to_simduid);
kono
parents: 67
diff changeset
275 *p = data;
kono
parents: 67
diff changeset
276 *slot = p;
kono
parents: 67
diff changeset
277 }
kono
parents: 67
diff changeset
278 else if ((*slot)->simduid != ns->simduid)
kono
parents: 67
diff changeset
279 (*slot)->simduid = -1U;
kono
parents: 67
diff changeset
280 *walk_subtrees = 0;
kono
parents: 67
diff changeset
281 }
kono
parents: 67
diff changeset
282 return NULL_TREE;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284
111
kono
parents: 67
diff changeset
285 /* Find "omp simd array" temporaries and map them to corresponding
kono
parents: 67
diff changeset
286 simduid. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287
111
kono
parents: 67
diff changeset
288 static void
kono
parents: 67
diff changeset
289 note_simd_array_uses (hash_table<simd_array_to_simduid> **htab)
kono
parents: 67
diff changeset
290 {
kono
parents: 67
diff changeset
291 basic_block bb;
kono
parents: 67
diff changeset
292 gimple_stmt_iterator gsi;
kono
parents: 67
diff changeset
293 struct walk_stmt_info wi;
kono
parents: 67
diff changeset
294 struct note_simd_array_uses_struct ns;
kono
parents: 67
diff changeset
295
kono
parents: 67
diff changeset
296 memset (&wi, 0, sizeof (wi));
kono
parents: 67
diff changeset
297 wi.info = &ns;
kono
parents: 67
diff changeset
298 ns.htab = htab;
kono
parents: 67
diff changeset
299
kono
parents: 67
diff changeset
300 FOR_EACH_BB_FN (bb, cfun)
kono
parents: 67
diff changeset
301 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
kono
parents: 67
diff changeset
302 {
kono
parents: 67
diff changeset
303 gimple *stmt = gsi_stmt (gsi);
kono
parents: 67
diff changeset
304 if (!is_gimple_call (stmt) || !gimple_call_internal_p (stmt))
kono
parents: 67
diff changeset
305 continue;
kono
parents: 67
diff changeset
306 switch (gimple_call_internal_fn (stmt))
kono
parents: 67
diff changeset
307 {
kono
parents: 67
diff changeset
308 case IFN_GOMP_SIMD_LANE:
kono
parents: 67
diff changeset
309 case IFN_GOMP_SIMD_VF:
kono
parents: 67
diff changeset
310 case IFN_GOMP_SIMD_LAST_LANE:
kono
parents: 67
diff changeset
311 break;
kono
parents: 67
diff changeset
312 default:
kono
parents: 67
diff changeset
313 continue;
kono
parents: 67
diff changeset
314 }
kono
parents: 67
diff changeset
315 tree lhs = gimple_call_lhs (stmt);
kono
parents: 67
diff changeset
316 if (lhs == NULL_TREE)
kono
parents: 67
diff changeset
317 continue;
kono
parents: 67
diff changeset
318 imm_use_iterator use_iter;
kono
parents: 67
diff changeset
319 gimple *use_stmt;
kono
parents: 67
diff changeset
320 ns.simduid = DECL_UID (SSA_NAME_VAR (gimple_call_arg (stmt, 0)));
kono
parents: 67
diff changeset
321 FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, lhs)
kono
parents: 67
diff changeset
322 if (!is_gimple_debug (use_stmt))
kono
parents: 67
diff changeset
323 walk_gimple_op (use_stmt, note_simd_array_uses_cb, &wi);
kono
parents: 67
diff changeset
324 }
kono
parents: 67
diff changeset
325 }
kono
parents: 67
diff changeset
326
kono
parents: 67
diff changeset
327 /* Shrink arrays with "omp simd array" attribute to the corresponding
kono
parents: 67
diff changeset
328 vectorization factor. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329
111
kono
parents: 67
diff changeset
330 static void
kono
parents: 67
diff changeset
331 shrink_simd_arrays
kono
parents: 67
diff changeset
332 (hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab,
kono
parents: 67
diff changeset
333 hash_table<simduid_to_vf> *simduid_to_vf_htab)
kono
parents: 67
diff changeset
334 {
kono
parents: 67
diff changeset
335 for (hash_table<simd_array_to_simduid>::iterator iter
kono
parents: 67
diff changeset
336 = simd_array_to_simduid_htab->begin ();
kono
parents: 67
diff changeset
337 iter != simd_array_to_simduid_htab->end (); ++iter)
kono
parents: 67
diff changeset
338 if ((*iter)->simduid != -1U)
kono
parents: 67
diff changeset
339 {
kono
parents: 67
diff changeset
340 tree decl = (*iter)->decl;
kono
parents: 67
diff changeset
341 int vf = 1;
kono
parents: 67
diff changeset
342 if (simduid_to_vf_htab)
kono
parents: 67
diff changeset
343 {
kono
parents: 67
diff changeset
344 simduid_to_vf *p = NULL, data;
kono
parents: 67
diff changeset
345 data.simduid = (*iter)->simduid;
kono
parents: 67
diff changeset
346 p = simduid_to_vf_htab->find (&data);
kono
parents: 67
diff changeset
347 if (p)
kono
parents: 67
diff changeset
348 vf = p->vf;
kono
parents: 67
diff changeset
349 }
kono
parents: 67
diff changeset
350 tree atype
kono
parents: 67
diff changeset
351 = build_array_type_nelts (TREE_TYPE (TREE_TYPE (decl)), vf);
kono
parents: 67
diff changeset
352 TREE_TYPE (decl) = atype;
kono
parents: 67
diff changeset
353 relayout_decl (decl);
kono
parents: 67
diff changeset
354 }
kono
parents: 67
diff changeset
355
kono
parents: 67
diff changeset
356 delete simd_array_to_simduid_htab;
kono
parents: 67
diff changeset
357 }
kono
parents: 67
diff changeset
358
kono
parents: 67
diff changeset
359 /* Initialize the vec_info with kind KIND_IN and target cost data
kono
parents: 67
diff changeset
360 TARGET_COST_DATA_IN. */
kono
parents: 67
diff changeset
361
kono
parents: 67
diff changeset
362 vec_info::vec_info (vec_info::vec_kind kind_in, void *target_cost_data_in)
kono
parents: 67
diff changeset
363 : kind (kind_in),
kono
parents: 67
diff changeset
364 datarefs (vNULL),
kono
parents: 67
diff changeset
365 ddrs (vNULL),
kono
parents: 67
diff changeset
366 target_cost_data (target_cost_data_in)
kono
parents: 67
diff changeset
367 {
kono
parents: 67
diff changeset
368 }
kono
parents: 67
diff changeset
369
kono
parents: 67
diff changeset
370 vec_info::~vec_info ()
kono
parents: 67
diff changeset
371 {
kono
parents: 67
diff changeset
372 slp_instance instance;
kono
parents: 67
diff changeset
373 struct data_reference *dr;
kono
parents: 67
diff changeset
374 unsigned int i;
kono
parents: 67
diff changeset
375
kono
parents: 67
diff changeset
376 FOR_EACH_VEC_ELT (datarefs, i, dr)
kono
parents: 67
diff changeset
377 if (dr->aux)
kono
parents: 67
diff changeset
378 {
kono
parents: 67
diff changeset
379 free (dr->aux);
kono
parents: 67
diff changeset
380 dr->aux = NULL;
kono
parents: 67
diff changeset
381 }
kono
parents: 67
diff changeset
382
kono
parents: 67
diff changeset
383 FOR_EACH_VEC_ELT (slp_instances, i, instance)
kono
parents: 67
diff changeset
384 vect_free_slp_instance (instance);
kono
parents: 67
diff changeset
385
kono
parents: 67
diff changeset
386 free_data_refs (datarefs);
kono
parents: 67
diff changeset
387 free_dependence_relations (ddrs);
kono
parents: 67
diff changeset
388 destroy_cost_data (target_cost_data);
kono
parents: 67
diff changeset
389 }
kono
parents: 67
diff changeset
390
kono
parents: 67
diff changeset
391 /* A helper function to free scev and LOOP niter information, as well as
kono
parents: 67
diff changeset
392 clear loop constraint LOOP_C_FINITE. */
kono
parents: 67
diff changeset
393
kono
parents: 67
diff changeset
394 void
kono
parents: 67
diff changeset
395 vect_free_loop_info_assumptions (struct loop *loop)
kono
parents: 67
diff changeset
396 {
kono
parents: 67
diff changeset
397 scev_reset_htab ();
kono
parents: 67
diff changeset
398 /* We need to explicitly reset upper bound information since they are
kono
parents: 67
diff changeset
399 used even after free_numbers_of_iterations_estimates. */
kono
parents: 67
diff changeset
400 loop->any_upper_bound = false;
kono
parents: 67
diff changeset
401 loop->any_likely_upper_bound = false;
kono
parents: 67
diff changeset
402 free_numbers_of_iterations_estimates (loop);
kono
parents: 67
diff changeset
403 loop_constraint_clear (loop, LOOP_C_FINITE);
kono
parents: 67
diff changeset
404 }
kono
parents: 67
diff changeset
405
kono
parents: 67
diff changeset
406 /* Return whether STMT is inside the region we try to vectorize. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
407
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 bool
111
kono
parents: 67
diff changeset
409 vect_stmt_in_region_p (vec_info *vinfo, gimple *stmt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410 {
111
kono
parents: 67
diff changeset
411 if (!gimple_bb (stmt))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413
111
kono
parents: 67
diff changeset
414 if (loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo))
kono
parents: 67
diff changeset
415 {
kono
parents: 67
diff changeset
416 struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
kono
parents: 67
diff changeset
417 if (!flow_bb_inside_loop_p (loop, gimple_bb (stmt)))
kono
parents: 67
diff changeset
418 return false;
kono
parents: 67
diff changeset
419 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 else
111
kono
parents: 67
diff changeset
421 {
kono
parents: 67
diff changeset
422 bb_vec_info bb_vinfo = as_a <bb_vec_info> (vinfo);
kono
parents: 67
diff changeset
423 if (gimple_bb (stmt) != BB_VINFO_BB (bb_vinfo)
kono
parents: 67
diff changeset
424 || gimple_uid (stmt) == -1U
kono
parents: 67
diff changeset
425 || gimple_code (stmt) == GIMPLE_PHI)
kono
parents: 67
diff changeset
426 return false;
kono
parents: 67
diff changeset
427 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
428
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432
111
kono
parents: 67
diff changeset
433 /* If LOOP has been versioned during ifcvt, return the internal call
kono
parents: 67
diff changeset
434 guarding it. */
kono
parents: 67
diff changeset
435
kono
parents: 67
diff changeset
436 static gimple *
kono
parents: 67
diff changeset
437 vect_loop_vectorized_call (struct loop *loop)
kono
parents: 67
diff changeset
438 {
kono
parents: 67
diff changeset
439 basic_block bb = loop_preheader_edge (loop)->src;
kono
parents: 67
diff changeset
440 gimple *g;
kono
parents: 67
diff changeset
441 do
kono
parents: 67
diff changeset
442 {
kono
parents: 67
diff changeset
443 g = last_stmt (bb);
kono
parents: 67
diff changeset
444 if (g)
kono
parents: 67
diff changeset
445 break;
kono
parents: 67
diff changeset
446 if (!single_pred_p (bb))
kono
parents: 67
diff changeset
447 break;
kono
parents: 67
diff changeset
448 bb = single_pred (bb);
kono
parents: 67
diff changeset
449 }
kono
parents: 67
diff changeset
450 while (1);
kono
parents: 67
diff changeset
451 if (g && gimple_code (g) == GIMPLE_COND)
kono
parents: 67
diff changeset
452 {
kono
parents: 67
diff changeset
453 gimple_stmt_iterator gsi = gsi_for_stmt (g);
kono
parents: 67
diff changeset
454 gsi_prev (&gsi);
kono
parents: 67
diff changeset
455 if (!gsi_end_p (gsi))
kono
parents: 67
diff changeset
456 {
kono
parents: 67
diff changeset
457 g = gsi_stmt (gsi);
kono
parents: 67
diff changeset
458 if (gimple_call_internal_p (g, IFN_LOOP_VECTORIZED)
kono
parents: 67
diff changeset
459 && (tree_to_shwi (gimple_call_arg (g, 0)) == loop->num
kono
parents: 67
diff changeset
460 || tree_to_shwi (gimple_call_arg (g, 1)) == loop->num))
kono
parents: 67
diff changeset
461 return g;
kono
parents: 67
diff changeset
462 }
kono
parents: 67
diff changeset
463 }
kono
parents: 67
diff changeset
464 return NULL;
kono
parents: 67
diff changeset
465 }
kono
parents: 67
diff changeset
466
kono
parents: 67
diff changeset
467 /* Fold loop internal call G like IFN_LOOP_VECTORIZED/IFN_LOOP_DIST_ALIAS
kono
parents: 67
diff changeset
468 to VALUE and update any immediate uses of it's LHS. */
kono
parents: 67
diff changeset
469
kono
parents: 67
diff changeset
470 static void
kono
parents: 67
diff changeset
471 fold_loop_internal_call (gimple *g, tree value)
kono
parents: 67
diff changeset
472 {
kono
parents: 67
diff changeset
473 tree lhs = gimple_call_lhs (g);
kono
parents: 67
diff changeset
474 use_operand_p use_p;
kono
parents: 67
diff changeset
475 imm_use_iterator iter;
kono
parents: 67
diff changeset
476 gimple *use_stmt;
kono
parents: 67
diff changeset
477 gimple_stmt_iterator gsi = gsi_for_stmt (g);
kono
parents: 67
diff changeset
478
kono
parents: 67
diff changeset
479 update_call_from_tree (&gsi, value);
kono
parents: 67
diff changeset
480 FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
kono
parents: 67
diff changeset
481 {
kono
parents: 67
diff changeset
482 FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
kono
parents: 67
diff changeset
483 SET_USE (use_p, value);
kono
parents: 67
diff changeset
484 update_stmt (use_stmt);
kono
parents: 67
diff changeset
485 }
kono
parents: 67
diff changeset
486 }
kono
parents: 67
diff changeset
487
kono
parents: 67
diff changeset
488 /* If LOOP has been versioned during loop distribution, return the gurading
kono
parents: 67
diff changeset
489 internal call. */
kono
parents: 67
diff changeset
490
kono
parents: 67
diff changeset
491 static gimple *
kono
parents: 67
diff changeset
492 vect_loop_dist_alias_call (struct loop *loop)
kono
parents: 67
diff changeset
493 {
kono
parents: 67
diff changeset
494 basic_block bb;
kono
parents: 67
diff changeset
495 basic_block entry;
kono
parents: 67
diff changeset
496 struct loop *outer, *orig;
kono
parents: 67
diff changeset
497 gimple_stmt_iterator gsi;
kono
parents: 67
diff changeset
498 gimple *g;
kono
parents: 67
diff changeset
499
kono
parents: 67
diff changeset
500 if (loop->orig_loop_num == 0)
kono
parents: 67
diff changeset
501 return NULL;
kono
parents: 67
diff changeset
502
kono
parents: 67
diff changeset
503 orig = get_loop (cfun, loop->orig_loop_num);
kono
parents: 67
diff changeset
504 if (orig == NULL)
kono
parents: 67
diff changeset
505 {
kono
parents: 67
diff changeset
506 /* The original loop is somehow destroyed. Clear the information. */
kono
parents: 67
diff changeset
507 loop->orig_loop_num = 0;
kono
parents: 67
diff changeset
508 return NULL;
kono
parents: 67
diff changeset
509 }
kono
parents: 67
diff changeset
510
kono
parents: 67
diff changeset
511 if (loop != orig)
kono
parents: 67
diff changeset
512 bb = nearest_common_dominator (CDI_DOMINATORS, loop->header, orig->header);
kono
parents: 67
diff changeset
513 else
kono
parents: 67
diff changeset
514 bb = loop_preheader_edge (loop)->src;
kono
parents: 67
diff changeset
515
kono
parents: 67
diff changeset
516 outer = bb->loop_father;
kono
parents: 67
diff changeset
517 entry = ENTRY_BLOCK_PTR_FOR_FN (cfun);
kono
parents: 67
diff changeset
518
kono
parents: 67
diff changeset
519 /* Look upward in dominance tree. */
kono
parents: 67
diff changeset
520 for (; bb != entry && flow_bb_inside_loop_p (outer, bb);
kono
parents: 67
diff changeset
521 bb = get_immediate_dominator (CDI_DOMINATORS, bb))
kono
parents: 67
diff changeset
522 {
kono
parents: 67
diff changeset
523 g = last_stmt (bb);
kono
parents: 67
diff changeset
524 if (g == NULL || gimple_code (g) != GIMPLE_COND)
kono
parents: 67
diff changeset
525 continue;
kono
parents: 67
diff changeset
526
kono
parents: 67
diff changeset
527 gsi = gsi_for_stmt (g);
kono
parents: 67
diff changeset
528 gsi_prev (&gsi);
kono
parents: 67
diff changeset
529 if (gsi_end_p (gsi))
kono
parents: 67
diff changeset
530 continue;
kono
parents: 67
diff changeset
531
kono
parents: 67
diff changeset
532 g = gsi_stmt (gsi);
kono
parents: 67
diff changeset
533 /* The guarding internal function call must have the same distribution
kono
parents: 67
diff changeset
534 alias id. */
kono
parents: 67
diff changeset
535 if (gimple_call_internal_p (g, IFN_LOOP_DIST_ALIAS)
kono
parents: 67
diff changeset
536 && (tree_to_shwi (gimple_call_arg (g, 0)) == loop->orig_loop_num))
kono
parents: 67
diff changeset
537 return g;
kono
parents: 67
diff changeset
538 }
kono
parents: 67
diff changeset
539 return NULL;
kono
parents: 67
diff changeset
540 }
kono
parents: 67
diff changeset
541
kono
parents: 67
diff changeset
542 /* Set the uids of all the statements in basic blocks inside loop
kono
parents: 67
diff changeset
543 represented by LOOP_VINFO. LOOP_VECTORIZED_CALL is the internal
kono
parents: 67
diff changeset
544 call guarding the loop which has been if converted. */
kono
parents: 67
diff changeset
545 static void
kono
parents: 67
diff changeset
546 set_uid_loop_bbs (loop_vec_info loop_vinfo, gimple *loop_vectorized_call)
kono
parents: 67
diff changeset
547 {
kono
parents: 67
diff changeset
548 tree arg = gimple_call_arg (loop_vectorized_call, 1);
kono
parents: 67
diff changeset
549 basic_block *bbs;
kono
parents: 67
diff changeset
550 unsigned int i;
kono
parents: 67
diff changeset
551 struct loop *scalar_loop = get_loop (cfun, tree_to_shwi (arg));
kono
parents: 67
diff changeset
552
kono
parents: 67
diff changeset
553 LOOP_VINFO_SCALAR_LOOP (loop_vinfo) = scalar_loop;
kono
parents: 67
diff changeset
554 gcc_checking_assert (vect_loop_vectorized_call (scalar_loop)
kono
parents: 67
diff changeset
555 == loop_vectorized_call);
kono
parents: 67
diff changeset
556 /* If we are going to vectorize outer loop, prevent vectorization
kono
parents: 67
diff changeset
557 of the inner loop in the scalar loop - either the scalar loop is
kono
parents: 67
diff changeset
558 thrown away, so it is a wasted work, or is used only for
kono
parents: 67
diff changeset
559 a few iterations. */
kono
parents: 67
diff changeset
560 if (scalar_loop->inner)
kono
parents: 67
diff changeset
561 {
kono
parents: 67
diff changeset
562 gimple *g = vect_loop_vectorized_call (scalar_loop->inner);
kono
parents: 67
diff changeset
563 if (g)
kono
parents: 67
diff changeset
564 {
kono
parents: 67
diff changeset
565 arg = gimple_call_arg (g, 0);
kono
parents: 67
diff changeset
566 get_loop (cfun, tree_to_shwi (arg))->dont_vectorize = true;
kono
parents: 67
diff changeset
567 fold_loop_internal_call (g, boolean_false_node);
kono
parents: 67
diff changeset
568 }
kono
parents: 67
diff changeset
569 }
kono
parents: 67
diff changeset
570 bbs = get_loop_body (scalar_loop);
kono
parents: 67
diff changeset
571 for (i = 0; i < scalar_loop->num_nodes; i++)
kono
parents: 67
diff changeset
572 {
kono
parents: 67
diff changeset
573 basic_block bb = bbs[i];
kono
parents: 67
diff changeset
574 gimple_stmt_iterator gsi;
kono
parents: 67
diff changeset
575 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
kono
parents: 67
diff changeset
576 {
kono
parents: 67
diff changeset
577 gimple *phi = gsi_stmt (gsi);
kono
parents: 67
diff changeset
578 gimple_set_uid (phi, 0);
kono
parents: 67
diff changeset
579 }
kono
parents: 67
diff changeset
580 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
kono
parents: 67
diff changeset
581 {
kono
parents: 67
diff changeset
582 gimple *stmt = gsi_stmt (gsi);
kono
parents: 67
diff changeset
583 gimple_set_uid (stmt, 0);
kono
parents: 67
diff changeset
584 }
kono
parents: 67
diff changeset
585 }
kono
parents: 67
diff changeset
586 free (bbs);
kono
parents: 67
diff changeset
587 }
kono
parents: 67
diff changeset
588
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 /* Function vectorize_loops.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
590
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
591 Entry point to loop vectorization phase. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 unsigned
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
594 vectorize_loops (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
596 unsigned int i;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597 unsigned int num_vectorized_loops = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 unsigned int vect_loops_num;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 struct loop *loop;
111
kono
parents: 67
diff changeset
600 hash_table<simduid_to_vf> *simduid_to_vf_htab = NULL;
kono
parents: 67
diff changeset
601 hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab = NULL;
kono
parents: 67
diff changeset
602 bool any_ifcvt_loops = false;
kono
parents: 67
diff changeset
603 unsigned ret = 0;
kono
parents: 67
diff changeset
604 struct loop *new_loop;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605
111
kono
parents: 67
diff changeset
606 vect_loops_num = number_of_loops (cfun);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608 /* Bail out if there are no loops. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 if (vect_loops_num <= 1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611
111
kono
parents: 67
diff changeset
612 if (cfun->has_simduid_loops)
kono
parents: 67
diff changeset
613 note_simd_array_uses (&simd_array_to_simduid_htab);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
614
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 init_stmt_vec_info_vec ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 /* ----------- Analyze loops. ----------- */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
618
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
619 /* If some loop was duplicated, it gets bigger number
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
620 than all previously defined loops. This fact allows us to run
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
621 only over initial loops skipping newly generated ones. */
111
kono
parents: 67
diff changeset
622 FOR_EACH_LOOP (loop, 0)
kono
parents: 67
diff changeset
623 if (loop->dont_vectorize)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
624 {
111
kono
parents: 67
diff changeset
625 any_ifcvt_loops = true;
kono
parents: 67
diff changeset
626 /* If-conversion sometimes versions both the outer loop
kono
parents: 67
diff changeset
627 (for the case when outer loop vectorization might be
kono
parents: 67
diff changeset
628 desirable) as well as the inner loop in the scalar version
kono
parents: 67
diff changeset
629 of the loop. So we have:
kono
parents: 67
diff changeset
630 if (LOOP_VECTORIZED (1, 3))
kono
parents: 67
diff changeset
631 {
kono
parents: 67
diff changeset
632 loop1
kono
parents: 67
diff changeset
633 loop2
kono
parents: 67
diff changeset
634 }
kono
parents: 67
diff changeset
635 else
kono
parents: 67
diff changeset
636 loop3 (copy of loop1)
kono
parents: 67
diff changeset
637 if (LOOP_VECTORIZED (4, 5))
kono
parents: 67
diff changeset
638 loop4 (copy of loop2)
kono
parents: 67
diff changeset
639 else
kono
parents: 67
diff changeset
640 loop5 (copy of loop4)
kono
parents: 67
diff changeset
641 If FOR_EACH_LOOP gives us loop3 first (which has
kono
parents: 67
diff changeset
642 dont_vectorize set), make sure to process loop1 before loop4;
kono
parents: 67
diff changeset
643 so that we can prevent vectorization of loop4 if loop1
kono
parents: 67
diff changeset
644 is successfully vectorized. */
kono
parents: 67
diff changeset
645 if (loop->inner)
kono
parents: 67
diff changeset
646 {
kono
parents: 67
diff changeset
647 gimple *loop_vectorized_call
kono
parents: 67
diff changeset
648 = vect_loop_vectorized_call (loop);
kono
parents: 67
diff changeset
649 if (loop_vectorized_call
kono
parents: 67
diff changeset
650 && vect_loop_vectorized_call (loop->inner))
kono
parents: 67
diff changeset
651 {
kono
parents: 67
diff changeset
652 tree arg = gimple_call_arg (loop_vectorized_call, 0);
kono
parents: 67
diff changeset
653 struct loop *vector_loop
kono
parents: 67
diff changeset
654 = get_loop (cfun, tree_to_shwi (arg));
kono
parents: 67
diff changeset
655 if (vector_loop && vector_loop != loop)
kono
parents: 67
diff changeset
656 {
kono
parents: 67
diff changeset
657 loop = vector_loop;
kono
parents: 67
diff changeset
658 /* Make sure we don't vectorize it twice. */
kono
parents: 67
diff changeset
659 loop->dont_vectorize = true;
kono
parents: 67
diff changeset
660 goto try_vectorize;
kono
parents: 67
diff changeset
661 }
kono
parents: 67
diff changeset
662 }
kono
parents: 67
diff changeset
663 }
kono
parents: 67
diff changeset
664 }
kono
parents: 67
diff changeset
665 else
kono
parents: 67
diff changeset
666 {
kono
parents: 67
diff changeset
667 loop_vec_info loop_vinfo, orig_loop_vinfo;
kono
parents: 67
diff changeset
668 gimple *loop_vectorized_call, *loop_dist_alias_call;
kono
parents: 67
diff changeset
669 try_vectorize:
kono
parents: 67
diff changeset
670 if (!((flag_tree_loop_vectorize
kono
parents: 67
diff changeset
671 && optimize_loop_nest_for_speed_p (loop))
kono
parents: 67
diff changeset
672 || loop->force_vectorize))
kono
parents: 67
diff changeset
673 continue;
kono
parents: 67
diff changeset
674 orig_loop_vinfo = NULL;
kono
parents: 67
diff changeset
675 loop_vectorized_call = vect_loop_vectorized_call (loop);
kono
parents: 67
diff changeset
676 loop_dist_alias_call = vect_loop_dist_alias_call (loop);
kono
parents: 67
diff changeset
677 vectorize_epilogue:
kono
parents: 67
diff changeset
678 vect_location = find_loop_location (loop);
kono
parents: 67
diff changeset
679 if (LOCATION_LOCUS (vect_location) != UNKNOWN_LOCATION
kono
parents: 67
diff changeset
680 && dump_enabled_p ())
kono
parents: 67
diff changeset
681 dump_printf (MSG_NOTE, "\nAnalyzing loop at %s:%d\n",
kono
parents: 67
diff changeset
682 LOCATION_FILE (vect_location),
kono
parents: 67
diff changeset
683 LOCATION_LINE (vect_location));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684
111
kono
parents: 67
diff changeset
685 loop_vinfo = vect_analyze_loop (loop, orig_loop_vinfo);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 loop->aux = loop_vinfo;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
687
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688 if (!loop_vinfo || !LOOP_VINFO_VECTORIZABLE_P (loop_vinfo))
111
kono
parents: 67
diff changeset
689 {
kono
parents: 67
diff changeset
690 /* Free existing information if loop is analyzed with some
kono
parents: 67
diff changeset
691 assumptions. */
kono
parents: 67
diff changeset
692 if (loop_constraint_set_p (loop, LOOP_C_FINITE))
kono
parents: 67
diff changeset
693 vect_free_loop_info_assumptions (loop);
kono
parents: 67
diff changeset
694
kono
parents: 67
diff changeset
695 /* If we applied if-conversion then try to vectorize the
kono
parents: 67
diff changeset
696 BB of innermost loops.
kono
parents: 67
diff changeset
697 ??? Ideally BB vectorization would learn to vectorize
kono
parents: 67
diff changeset
698 control flow by applying if-conversion on-the-fly, the
kono
parents: 67
diff changeset
699 following retains the if-converted loop body even when
kono
parents: 67
diff changeset
700 only non-if-converted parts took part in BB vectorization. */
kono
parents: 67
diff changeset
701 if (flag_tree_slp_vectorize != 0
kono
parents: 67
diff changeset
702 && loop_vectorized_call
kono
parents: 67
diff changeset
703 && ! loop->inner)
kono
parents: 67
diff changeset
704 {
kono
parents: 67
diff changeset
705 basic_block bb = loop->header;
kono
parents: 67
diff changeset
706 bool has_mask_load_store = false;
kono
parents: 67
diff changeset
707 for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
kono
parents: 67
diff changeset
708 !gsi_end_p (gsi); gsi_next (&gsi))
kono
parents: 67
diff changeset
709 {
kono
parents: 67
diff changeset
710 gimple *stmt = gsi_stmt (gsi);
kono
parents: 67
diff changeset
711 if (is_gimple_call (stmt)
kono
parents: 67
diff changeset
712 && gimple_call_internal_p (stmt)
kono
parents: 67
diff changeset
713 && (gimple_call_internal_fn (stmt) == IFN_MASK_LOAD
kono
parents: 67
diff changeset
714 || gimple_call_internal_fn (stmt) == IFN_MASK_STORE))
kono
parents: 67
diff changeset
715 {
kono
parents: 67
diff changeset
716 has_mask_load_store = true;
kono
parents: 67
diff changeset
717 break;
kono
parents: 67
diff changeset
718 }
kono
parents: 67
diff changeset
719 gimple_set_uid (stmt, -1);
kono
parents: 67
diff changeset
720 gimple_set_visited (stmt, false);
kono
parents: 67
diff changeset
721 }
kono
parents: 67
diff changeset
722 if (! has_mask_load_store && vect_slp_bb (bb))
kono
parents: 67
diff changeset
723 {
kono
parents: 67
diff changeset
724 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
kono
parents: 67
diff changeset
725 "basic block vectorized\n");
kono
parents: 67
diff changeset
726 fold_loop_internal_call (loop_vectorized_call,
kono
parents: 67
diff changeset
727 boolean_true_node);
kono
parents: 67
diff changeset
728 loop_vectorized_call = NULL;
kono
parents: 67
diff changeset
729 ret |= TODO_cleanup_cfg;
kono
parents: 67
diff changeset
730 }
kono
parents: 67
diff changeset
731 }
kono
parents: 67
diff changeset
732 /* If outer loop vectorization fails for LOOP_VECTORIZED guarded
kono
parents: 67
diff changeset
733 loop, don't vectorize its inner loop; we'll attempt to
kono
parents: 67
diff changeset
734 vectorize LOOP_VECTORIZED guarded inner loop of the scalar
kono
parents: 67
diff changeset
735 loop version. */
kono
parents: 67
diff changeset
736 if (loop_vectorized_call && loop->inner)
kono
parents: 67
diff changeset
737 loop->inner->dont_vectorize = true;
kono
parents: 67
diff changeset
738 continue;
kono
parents: 67
diff changeset
739 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740
111
kono
parents: 67
diff changeset
741 if (!dbg_cnt (vect_loop))
kono
parents: 67
diff changeset
742 {
kono
parents: 67
diff changeset
743 /* We may miss some if-converted loops due to
kono
parents: 67
diff changeset
744 debug counter. Set any_ifcvt_loops to visit
kono
parents: 67
diff changeset
745 them at finalization. */
kono
parents: 67
diff changeset
746 any_ifcvt_loops = true;
kono
parents: 67
diff changeset
747 /* Free existing information if loop is analyzed with some
kono
parents: 67
diff changeset
748 assumptions. */
kono
parents: 67
diff changeset
749 if (loop_constraint_set_p (loop, LOOP_C_FINITE))
kono
parents: 67
diff changeset
750 vect_free_loop_info_assumptions (loop);
kono
parents: 67
diff changeset
751
kono
parents: 67
diff changeset
752 break;
kono
parents: 67
diff changeset
753 }
kono
parents: 67
diff changeset
754
kono
parents: 67
diff changeset
755 if (loop_vectorized_call)
kono
parents: 67
diff changeset
756 set_uid_loop_bbs (loop_vinfo, loop_vectorized_call);
kono
parents: 67
diff changeset
757 if (LOCATION_LOCUS (vect_location) != UNKNOWN_LOCATION
kono
parents: 67
diff changeset
758 && dump_enabled_p ())
kono
parents: 67
diff changeset
759 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
kono
parents: 67
diff changeset
760 "loop vectorized\n");
kono
parents: 67
diff changeset
761 new_loop = vect_transform_loop (loop_vinfo);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 num_vectorized_loops++;
111
kono
parents: 67
diff changeset
763 /* Now that the loop has been vectorized, allow it to be unrolled
kono
parents: 67
diff changeset
764 etc. */
kono
parents: 67
diff changeset
765 loop->force_vectorize = false;
kono
parents: 67
diff changeset
766
kono
parents: 67
diff changeset
767 if (loop->simduid)
kono
parents: 67
diff changeset
768 {
kono
parents: 67
diff changeset
769 simduid_to_vf *simduid_to_vf_data = XNEW (simduid_to_vf);
kono
parents: 67
diff changeset
770 if (!simduid_to_vf_htab)
kono
parents: 67
diff changeset
771 simduid_to_vf_htab = new hash_table<simduid_to_vf> (15);
kono
parents: 67
diff changeset
772 simduid_to_vf_data->simduid = DECL_UID (loop->simduid);
kono
parents: 67
diff changeset
773 simduid_to_vf_data->vf = loop_vinfo->vectorization_factor;
kono
parents: 67
diff changeset
774 *simduid_to_vf_htab->find_slot (simduid_to_vf_data, INSERT)
kono
parents: 67
diff changeset
775 = simduid_to_vf_data;
kono
parents: 67
diff changeset
776 }
kono
parents: 67
diff changeset
777
kono
parents: 67
diff changeset
778 if (loop_vectorized_call)
kono
parents: 67
diff changeset
779 {
kono
parents: 67
diff changeset
780 fold_loop_internal_call (loop_vectorized_call, boolean_true_node);
kono
parents: 67
diff changeset
781 loop_vectorized_call = NULL;
kono
parents: 67
diff changeset
782 ret |= TODO_cleanup_cfg;
kono
parents: 67
diff changeset
783 }
kono
parents: 67
diff changeset
784 if (loop_dist_alias_call)
kono
parents: 67
diff changeset
785 {
kono
parents: 67
diff changeset
786 tree value = gimple_call_arg (loop_dist_alias_call, 1);
kono
parents: 67
diff changeset
787 fold_loop_internal_call (loop_dist_alias_call, value);
kono
parents: 67
diff changeset
788 loop_dist_alias_call = NULL;
kono
parents: 67
diff changeset
789 ret |= TODO_cleanup_cfg;
kono
parents: 67
diff changeset
790 }
kono
parents: 67
diff changeset
791
kono
parents: 67
diff changeset
792 if (new_loop)
kono
parents: 67
diff changeset
793 {
kono
parents: 67
diff changeset
794 /* Epilogue of vectorized loop must be vectorized too. */
kono
parents: 67
diff changeset
795 vect_loops_num = number_of_loops (cfun);
kono
parents: 67
diff changeset
796 loop = new_loop;
kono
parents: 67
diff changeset
797 orig_loop_vinfo = loop_vinfo; /* To pass vect_analyze_loop. */
kono
parents: 67
diff changeset
798 goto vectorize_epilogue;
kono
parents: 67
diff changeset
799 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
800 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
801
111
kono
parents: 67
diff changeset
802 vect_location = UNKNOWN_LOCATION;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
803
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
804 statistics_counter_event (cfun, "Vectorized loops", num_vectorized_loops);
111
kono
parents: 67
diff changeset
805 if (dump_enabled_p ()
kono
parents: 67
diff changeset
806 || (num_vectorized_loops > 0 && dump_enabled_p ()))
kono
parents: 67
diff changeset
807 dump_printf_loc (MSG_NOTE, vect_location,
kono
parents: 67
diff changeset
808 "vectorized %u loops in function.\n",
kono
parents: 67
diff changeset
809 num_vectorized_loops);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
810
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
811 /* ----------- Finalize. ----------- */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
812
111
kono
parents: 67
diff changeset
813 if (any_ifcvt_loops)
kono
parents: 67
diff changeset
814 for (i = 1; i < vect_loops_num; i++)
kono
parents: 67
diff changeset
815 {
kono
parents: 67
diff changeset
816 loop = get_loop (cfun, i);
kono
parents: 67
diff changeset
817 if (loop && loop->dont_vectorize)
kono
parents: 67
diff changeset
818 {
kono
parents: 67
diff changeset
819 gimple *g = vect_loop_vectorized_call (loop);
kono
parents: 67
diff changeset
820 if (g)
kono
parents: 67
diff changeset
821 {
kono
parents: 67
diff changeset
822 fold_loop_internal_call (g, boolean_false_node);
kono
parents: 67
diff changeset
823 ret |= TODO_cleanup_cfg;
kono
parents: 67
diff changeset
824 g = NULL;
kono
parents: 67
diff changeset
825 }
kono
parents: 67
diff changeset
826 else
kono
parents: 67
diff changeset
827 g = vect_loop_dist_alias_call (loop);
kono
parents: 67
diff changeset
828
kono
parents: 67
diff changeset
829 if (g)
kono
parents: 67
diff changeset
830 {
kono
parents: 67
diff changeset
831 fold_loop_internal_call (g, boolean_false_node);
kono
parents: 67
diff changeset
832 ret |= TODO_cleanup_cfg;
kono
parents: 67
diff changeset
833 }
kono
parents: 67
diff changeset
834 }
kono
parents: 67
diff changeset
835 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
837 for (i = 1; i < vect_loops_num; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
839 loop_vec_info loop_vinfo;
111
kono
parents: 67
diff changeset
840 bool has_mask_store;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
841
111
kono
parents: 67
diff changeset
842 loop = get_loop (cfun, i);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
843 if (!loop)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844 continue;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
845 loop_vinfo = (loop_vec_info) loop->aux;
111
kono
parents: 67
diff changeset
846 has_mask_store = false;
kono
parents: 67
diff changeset
847 if (loop_vinfo)
kono
parents: 67
diff changeset
848 has_mask_store = LOOP_VINFO_HAS_MASK_STORE (loop_vinfo);
kono
parents: 67
diff changeset
849 delete loop_vinfo;
kono
parents: 67
diff changeset
850 if (has_mask_store)
kono
parents: 67
diff changeset
851 optimize_mask_stores (loop);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
852 loop->aux = NULL;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
853 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
854
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
855 free_stmt_vec_info_vec ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
856
111
kono
parents: 67
diff changeset
857 /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE,ORDERED_{START,END}} builtins. */
kono
parents: 67
diff changeset
858 if (cfun->has_simduid_loops)
kono
parents: 67
diff changeset
859 adjust_simduid_builtins (simduid_to_vf_htab);
kono
parents: 67
diff changeset
860
kono
parents: 67
diff changeset
861 /* Shrink any "omp array simd" temporary arrays to the
kono
parents: 67
diff changeset
862 actual vectorization factors. */
kono
parents: 67
diff changeset
863 if (simd_array_to_simduid_htab)
kono
parents: 67
diff changeset
864 shrink_simd_arrays (simd_array_to_simduid_htab, simduid_to_vf_htab);
kono
parents: 67
diff changeset
865 delete simduid_to_vf_htab;
kono
parents: 67
diff changeset
866 cfun->has_simduid_loops = false;
kono
parents: 67
diff changeset
867
kono
parents: 67
diff changeset
868 if (num_vectorized_loops > 0)
kono
parents: 67
diff changeset
869 {
kono
parents: 67
diff changeset
870 /* If we vectorized any loop only virtual SSA form needs to be updated.
kono
parents: 67
diff changeset
871 ??? Also while we try hard to update loop-closed SSA form we fail
kono
parents: 67
diff changeset
872 to properly do this in some corner-cases (see PR56286). */
kono
parents: 67
diff changeset
873 rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa_only_virtuals);
kono
parents: 67
diff changeset
874 return TODO_cleanup_cfg;
kono
parents: 67
diff changeset
875 }
kono
parents: 67
diff changeset
876
kono
parents: 67
diff changeset
877 return ret;
kono
parents: 67
diff changeset
878 }
kono
parents: 67
diff changeset
879
kono
parents: 67
diff changeset
880
kono
parents: 67
diff changeset
881 /* Entry point to the simduid cleanup pass. */
kono
parents: 67
diff changeset
882
kono
parents: 67
diff changeset
883 namespace {
kono
parents: 67
diff changeset
884
kono
parents: 67
diff changeset
885 const pass_data pass_data_simduid_cleanup =
kono
parents: 67
diff changeset
886 {
kono
parents: 67
diff changeset
887 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
888 "simduid", /* name */
kono
parents: 67
diff changeset
889 OPTGROUP_NONE, /* optinfo_flags */
kono
parents: 67
diff changeset
890 TV_NONE, /* tv_id */
kono
parents: 67
diff changeset
891 ( PROP_ssa | PROP_cfg ), /* properties_required */
kono
parents: 67
diff changeset
892 0, /* properties_provided */
kono
parents: 67
diff changeset
893 0, /* properties_destroyed */
kono
parents: 67
diff changeset
894 0, /* todo_flags_start */
kono
parents: 67
diff changeset
895 0, /* todo_flags_finish */
kono
parents: 67
diff changeset
896 };
kono
parents: 67
diff changeset
897
kono
parents: 67
diff changeset
898 class pass_simduid_cleanup : public gimple_opt_pass
kono
parents: 67
diff changeset
899 {
kono
parents: 67
diff changeset
900 public:
kono
parents: 67
diff changeset
901 pass_simduid_cleanup (gcc::context *ctxt)
kono
parents: 67
diff changeset
902 : gimple_opt_pass (pass_data_simduid_cleanup, ctxt)
kono
parents: 67
diff changeset
903 {}
kono
parents: 67
diff changeset
904
kono
parents: 67
diff changeset
905 /* opt_pass methods: */
kono
parents: 67
diff changeset
906 opt_pass * clone () { return new pass_simduid_cleanup (m_ctxt); }
kono
parents: 67
diff changeset
907 virtual bool gate (function *fun) { return fun->has_simduid_loops; }
kono
parents: 67
diff changeset
908 virtual unsigned int execute (function *);
kono
parents: 67
diff changeset
909
kono
parents: 67
diff changeset
910 }; // class pass_simduid_cleanup
kono
parents: 67
diff changeset
911
kono
parents: 67
diff changeset
912 unsigned int
kono
parents: 67
diff changeset
913 pass_simduid_cleanup::execute (function *fun)
kono
parents: 67
diff changeset
914 {
kono
parents: 67
diff changeset
915 hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab = NULL;
kono
parents: 67
diff changeset
916
kono
parents: 67
diff changeset
917 note_simd_array_uses (&simd_array_to_simduid_htab);
kono
parents: 67
diff changeset
918
kono
parents: 67
diff changeset
919 /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE,ORDERED_{START,END}} builtins. */
kono
parents: 67
diff changeset
920 adjust_simduid_builtins (NULL);
kono
parents: 67
diff changeset
921
kono
parents: 67
diff changeset
922 /* Shrink any "omp array simd" temporary arrays to the
kono
parents: 67
diff changeset
923 actual vectorization factors. */
kono
parents: 67
diff changeset
924 if (simd_array_to_simduid_htab)
kono
parents: 67
diff changeset
925 shrink_simd_arrays (simd_array_to_simduid_htab, NULL);
kono
parents: 67
diff changeset
926 fun->has_simduid_loops = false;
kono
parents: 67
diff changeset
927 return 0;
kono
parents: 67
diff changeset
928 }
kono
parents: 67
diff changeset
929
kono
parents: 67
diff changeset
930 } // anon namespace
kono
parents: 67
diff changeset
931
kono
parents: 67
diff changeset
932 gimple_opt_pass *
kono
parents: 67
diff changeset
933 make_pass_simduid_cleanup (gcc::context *ctxt)
kono
parents: 67
diff changeset
934 {
kono
parents: 67
diff changeset
935 return new pass_simduid_cleanup (ctxt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
936 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
937
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
938
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
939 /* Entry point to basic block SLP phase. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
940
111
kono
parents: 67
diff changeset
941 namespace {
kono
parents: 67
diff changeset
942
kono
parents: 67
diff changeset
943 const pass_data pass_data_slp_vectorize =
kono
parents: 67
diff changeset
944 {
kono
parents: 67
diff changeset
945 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
946 "slp", /* name */
kono
parents: 67
diff changeset
947 OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */
kono
parents: 67
diff changeset
948 TV_TREE_SLP_VECTORIZATION, /* tv_id */
kono
parents: 67
diff changeset
949 ( PROP_ssa | PROP_cfg ), /* properties_required */
kono
parents: 67
diff changeset
950 0, /* properties_provided */
kono
parents: 67
diff changeset
951 0, /* properties_destroyed */
kono
parents: 67
diff changeset
952 0, /* todo_flags_start */
kono
parents: 67
diff changeset
953 TODO_update_ssa, /* todo_flags_finish */
kono
parents: 67
diff changeset
954 };
kono
parents: 67
diff changeset
955
kono
parents: 67
diff changeset
956 class pass_slp_vectorize : public gimple_opt_pass
kono
parents: 67
diff changeset
957 {
kono
parents: 67
diff changeset
958 public:
kono
parents: 67
diff changeset
959 pass_slp_vectorize (gcc::context *ctxt)
kono
parents: 67
diff changeset
960 : gimple_opt_pass (pass_data_slp_vectorize, ctxt)
kono
parents: 67
diff changeset
961 {}
kono
parents: 67
diff changeset
962
kono
parents: 67
diff changeset
963 /* opt_pass methods: */
kono
parents: 67
diff changeset
964 opt_pass * clone () { return new pass_slp_vectorize (m_ctxt); }
kono
parents: 67
diff changeset
965 virtual bool gate (function *) { return flag_tree_slp_vectorize != 0; }
kono
parents: 67
diff changeset
966 virtual unsigned int execute (function *);
kono
parents: 67
diff changeset
967
kono
parents: 67
diff changeset
968 }; // class pass_slp_vectorize
kono
parents: 67
diff changeset
969
kono
parents: 67
diff changeset
970 unsigned int
kono
parents: 67
diff changeset
971 pass_slp_vectorize::execute (function *fun)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
972 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
973 basic_block bb;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
974
111
kono
parents: 67
diff changeset
975 bool in_loop_pipeline = scev_initialized_p ();
kono
parents: 67
diff changeset
976 if (!in_loop_pipeline)
kono
parents: 67
diff changeset
977 {
kono
parents: 67
diff changeset
978 loop_optimizer_init (LOOPS_NORMAL);
kono
parents: 67
diff changeset
979 scev_initialize ();
kono
parents: 67
diff changeset
980 }
kono
parents: 67
diff changeset
981
kono
parents: 67
diff changeset
982 /* Mark all stmts as not belonging to the current region and unvisited. */
kono
parents: 67
diff changeset
983 FOR_EACH_BB_FN (bb, fun)
kono
parents: 67
diff changeset
984 {
kono
parents: 67
diff changeset
985 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
kono
parents: 67
diff changeset
986 gsi_next (&gsi))
kono
parents: 67
diff changeset
987 {
kono
parents: 67
diff changeset
988 gimple *stmt = gsi_stmt (gsi);
kono
parents: 67
diff changeset
989 gimple_set_uid (stmt, -1);
kono
parents: 67
diff changeset
990 gimple_set_visited (stmt, false);
kono
parents: 67
diff changeset
991 }
kono
parents: 67
diff changeset
992 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
993
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
994 init_stmt_vec_info_vec ();
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
995
111
kono
parents: 67
diff changeset
996 FOR_EACH_BB_FN (bb, fun)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
997 {
111
kono
parents: 67
diff changeset
998 if (vect_slp_bb (bb))
kono
parents: 67
diff changeset
999 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
kono
parents: 67
diff changeset
1000 "basic block vectorized\n");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1001 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1002
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1003 free_stmt_vec_info_vec ();
111
kono
parents: 67
diff changeset
1004
kono
parents: 67
diff changeset
1005 if (!in_loop_pipeline)
kono
parents: 67
diff changeset
1006 {
kono
parents: 67
diff changeset
1007 scev_finalize ();
kono
parents: 67
diff changeset
1008 loop_optimizer_finalize ();
kono
parents: 67
diff changeset
1009 }
kono
parents: 67
diff changeset
1010
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1011 return 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1012 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1013
111
kono
parents: 67
diff changeset
1014 } // anon namespace
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1015
111
kono
parents: 67
diff changeset
1016 gimple_opt_pass *
kono
parents: 67
diff changeset
1017 make_pass_slp_vectorize (gcc::context *ctxt)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1018 {
111
kono
parents: 67
diff changeset
1019 return new pass_slp_vectorize (ctxt);
kono
parents: 67
diff changeset
1020 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1021
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1022
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1023 /* Increase alignment of global arrays to improve vectorization potential.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024 TODO:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1025 - Consider also structs that have an array field.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1026 - Use ipa analysis to prune arrays that can't be vectorized?
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1027 This should involve global alignment analysis and in the future also
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1028 array padding. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1029
111
kono
parents: 67
diff changeset
1030 static unsigned get_vec_alignment_for_type (tree);
kono
parents: 67
diff changeset
1031 static hash_map<tree, unsigned> *type_align_map;
kono
parents: 67
diff changeset
1032
kono
parents: 67
diff changeset
1033 /* Return alignment of array's vector type corresponding to scalar type.
kono
parents: 67
diff changeset
1034 0 if no vector type exists. */
kono
parents: 67
diff changeset
1035 static unsigned
kono
parents: 67
diff changeset
1036 get_vec_alignment_for_array_type (tree type)
kono
parents: 67
diff changeset
1037 {
kono
parents: 67
diff changeset
1038 gcc_assert (TREE_CODE (type) == ARRAY_TYPE);
kono
parents: 67
diff changeset
1039
kono
parents: 67
diff changeset
1040 tree vectype = get_vectype_for_scalar_type (strip_array_types (type));
kono
parents: 67
diff changeset
1041 if (!vectype
kono
parents: 67
diff changeset
1042 || !TYPE_SIZE (type)
kono
parents: 67
diff changeset
1043 || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST
kono
parents: 67
diff changeset
1044 || tree_int_cst_lt (TYPE_SIZE (type), TYPE_SIZE (vectype)))
kono
parents: 67
diff changeset
1045 return 0;
kono
parents: 67
diff changeset
1046
kono
parents: 67
diff changeset
1047 return TYPE_ALIGN (vectype);
kono
parents: 67
diff changeset
1048 }
kono
parents: 67
diff changeset
1049
kono
parents: 67
diff changeset
1050 /* Return alignment of field having maximum alignment of vector type
kono
parents: 67
diff changeset
1051 corresponding to it's scalar type. For now, we only consider fields whose
kono
parents: 67
diff changeset
1052 offset is a multiple of it's vector alignment.
kono
parents: 67
diff changeset
1053 0 if no suitable field is found. */
kono
parents: 67
diff changeset
1054 static unsigned
kono
parents: 67
diff changeset
1055 get_vec_alignment_for_record_type (tree type)
kono
parents: 67
diff changeset
1056 {
kono
parents: 67
diff changeset
1057 gcc_assert (TREE_CODE (type) == RECORD_TYPE);
kono
parents: 67
diff changeset
1058
kono
parents: 67
diff changeset
1059 unsigned max_align = 0, alignment;
kono
parents: 67
diff changeset
1060 HOST_WIDE_INT offset;
kono
parents: 67
diff changeset
1061 tree offset_tree;
kono
parents: 67
diff changeset
1062
kono
parents: 67
diff changeset
1063 if (TYPE_PACKED (type))
kono
parents: 67
diff changeset
1064 return 0;
kono
parents: 67
diff changeset
1065
kono
parents: 67
diff changeset
1066 unsigned *slot = type_align_map->get (type);
kono
parents: 67
diff changeset
1067 if (slot)
kono
parents: 67
diff changeset
1068 return *slot;
kono
parents: 67
diff changeset
1069
kono
parents: 67
diff changeset
1070 for (tree field = first_field (type);
kono
parents: 67
diff changeset
1071 field != NULL_TREE;
kono
parents: 67
diff changeset
1072 field = DECL_CHAIN (field))
kono
parents: 67
diff changeset
1073 {
kono
parents: 67
diff changeset
1074 /* Skip if not FIELD_DECL or if alignment is set by user. */
kono
parents: 67
diff changeset
1075 if (TREE_CODE (field) != FIELD_DECL
kono
parents: 67
diff changeset
1076 || DECL_USER_ALIGN (field)
kono
parents: 67
diff changeset
1077 || DECL_ARTIFICIAL (field))
kono
parents: 67
diff changeset
1078 continue;
kono
parents: 67
diff changeset
1079
kono
parents: 67
diff changeset
1080 /* We don't need to process the type further if offset is variable,
kono
parents: 67
diff changeset
1081 since the offsets of remaining members will also be variable. */
kono
parents: 67
diff changeset
1082 if (TREE_CODE (DECL_FIELD_OFFSET (field)) != INTEGER_CST
kono
parents: 67
diff changeset
1083 || TREE_CODE (DECL_FIELD_BIT_OFFSET (field)) != INTEGER_CST)
kono
parents: 67
diff changeset
1084 break;
kono
parents: 67
diff changeset
1085
kono
parents: 67
diff changeset
1086 /* Similarly stop processing the type if offset_tree
kono
parents: 67
diff changeset
1087 does not fit in unsigned HOST_WIDE_INT. */
kono
parents: 67
diff changeset
1088 offset_tree = bit_position (field);
kono
parents: 67
diff changeset
1089 if (!tree_fits_uhwi_p (offset_tree))
kono
parents: 67
diff changeset
1090 break;
kono
parents: 67
diff changeset
1091
kono
parents: 67
diff changeset
1092 offset = tree_to_uhwi (offset_tree);
kono
parents: 67
diff changeset
1093 alignment = get_vec_alignment_for_type (TREE_TYPE (field));
kono
parents: 67
diff changeset
1094
kono
parents: 67
diff changeset
1095 /* Get maximum alignment of vectorized field/array among those members
kono
parents: 67
diff changeset
1096 whose offset is multiple of the vector alignment. */
kono
parents: 67
diff changeset
1097 if (alignment
kono
parents: 67
diff changeset
1098 && (offset % alignment == 0)
kono
parents: 67
diff changeset
1099 && (alignment > max_align))
kono
parents: 67
diff changeset
1100 max_align = alignment;
kono
parents: 67
diff changeset
1101 }
kono
parents: 67
diff changeset
1102
kono
parents: 67
diff changeset
1103 type_align_map->put (type, max_align);
kono
parents: 67
diff changeset
1104 return max_align;
kono
parents: 67
diff changeset
1105 }
kono
parents: 67
diff changeset
1106
kono
parents: 67
diff changeset
1107 /* Return alignment of vector type corresponding to decl's scalar type
kono
parents: 67
diff changeset
1108 or 0 if it doesn't exist or the vector alignment is lesser than
kono
parents: 67
diff changeset
1109 decl's alignment. */
kono
parents: 67
diff changeset
1110 static unsigned
kono
parents: 67
diff changeset
1111 get_vec_alignment_for_type (tree type)
kono
parents: 67
diff changeset
1112 {
kono
parents: 67
diff changeset
1113 if (type == NULL_TREE)
kono
parents: 67
diff changeset
1114 return 0;
kono
parents: 67
diff changeset
1115
kono
parents: 67
diff changeset
1116 gcc_assert (TYPE_P (type));
kono
parents: 67
diff changeset
1117
kono
parents: 67
diff changeset
1118 static unsigned alignment = 0;
kono
parents: 67
diff changeset
1119 switch (TREE_CODE (type))
kono
parents: 67
diff changeset
1120 {
kono
parents: 67
diff changeset
1121 case ARRAY_TYPE:
kono
parents: 67
diff changeset
1122 alignment = get_vec_alignment_for_array_type (type);
kono
parents: 67
diff changeset
1123 break;
kono
parents: 67
diff changeset
1124 case RECORD_TYPE:
kono
parents: 67
diff changeset
1125 alignment = get_vec_alignment_for_record_type (type);
kono
parents: 67
diff changeset
1126 break;
kono
parents: 67
diff changeset
1127 default:
kono
parents: 67
diff changeset
1128 alignment = 0;
kono
parents: 67
diff changeset
1129 break;
kono
parents: 67
diff changeset
1130 }
kono
parents: 67
diff changeset
1131
kono
parents: 67
diff changeset
1132 return (alignment > TYPE_ALIGN (type)) ? alignment : 0;
kono
parents: 67
diff changeset
1133 }
kono
parents: 67
diff changeset
1134
kono
parents: 67
diff changeset
1135 /* Entry point to increase_alignment pass. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1136 static unsigned int
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1137 increase_alignment (void)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1138 {
111
kono
parents: 67
diff changeset
1139 varpool_node *vnode;
kono
parents: 67
diff changeset
1140
kono
parents: 67
diff changeset
1141 vect_location = UNKNOWN_LOCATION;
kono
parents: 67
diff changeset
1142 type_align_map = new hash_map<tree, unsigned>;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1143
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1144 /* Increase the alignment of all global arrays for vectorization. */
111
kono
parents: 67
diff changeset
1145 FOR_EACH_DEFINED_VARIABLE (vnode)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1146 {
111
kono
parents: 67
diff changeset
1147 tree decl = vnode->decl;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1148 unsigned int alignment;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1149
111
kono
parents: 67
diff changeset
1150 if ((decl_in_symtab_p (decl)
kono
parents: 67
diff changeset
1151 && !symtab_node::get (decl)->can_increase_alignment_p ())
kono
parents: 67
diff changeset
1152 || DECL_USER_ALIGN (decl) || DECL_ARTIFICIAL (decl))
kono
parents: 67
diff changeset
1153 continue;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1154
111
kono
parents: 67
diff changeset
1155 alignment = get_vec_alignment_for_type (TREE_TYPE (decl));
kono
parents: 67
diff changeset
1156 if (alignment && vect_can_force_dr_alignment_p (decl, alignment))
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1157 {
111
kono
parents: 67
diff changeset
1158 vnode->increase_alignment (alignment);
kono
parents: 67
diff changeset
1159 dump_printf (MSG_NOTE, "Increasing alignment of decl: ");
kono
parents: 67
diff changeset
1160 dump_generic_expr (MSG_NOTE, TDF_SLIM, decl);
kono
parents: 67
diff changeset
1161 dump_printf (MSG_NOTE, "\n");
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1162 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163 }
111
kono
parents: 67
diff changeset
1164
kono
parents: 67
diff changeset
1165 delete type_align_map;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1169
111
kono
parents: 67
diff changeset
1170 namespace {
kono
parents: 67
diff changeset
1171
kono
parents: 67
diff changeset
1172 const pass_data pass_data_ipa_increase_alignment =
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173 {
111
kono
parents: 67
diff changeset
1174 SIMPLE_IPA_PASS, /* type */
kono
parents: 67
diff changeset
1175 "increase_alignment", /* name */
kono
parents: 67
diff changeset
1176 OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */
kono
parents: 67
diff changeset
1177 TV_IPA_OPT, /* tv_id */
kono
parents: 67
diff changeset
1178 0, /* properties_required */
kono
parents: 67
diff changeset
1179 0, /* properties_provided */
kono
parents: 67
diff changeset
1180 0, /* properties_destroyed */
kono
parents: 67
diff changeset
1181 0, /* todo_flags_start */
kono
parents: 67
diff changeset
1182 0, /* todo_flags_finish */
kono
parents: 67
diff changeset
1183 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1184
111
kono
parents: 67
diff changeset
1185 class pass_ipa_increase_alignment : public simple_ipa_opt_pass
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1186 {
111
kono
parents: 67
diff changeset
1187 public:
kono
parents: 67
diff changeset
1188 pass_ipa_increase_alignment (gcc::context *ctxt)
kono
parents: 67
diff changeset
1189 : simple_ipa_opt_pass (pass_data_ipa_increase_alignment, ctxt)
kono
parents: 67
diff changeset
1190 {}
kono
parents: 67
diff changeset
1191
kono
parents: 67
diff changeset
1192 /* opt_pass methods: */
kono
parents: 67
diff changeset
1193 virtual bool gate (function *)
kono
parents: 67
diff changeset
1194 {
kono
parents: 67
diff changeset
1195 return flag_section_anchors && flag_tree_loop_vectorize;
kono
parents: 67
diff changeset
1196 }
kono
parents: 67
diff changeset
1197
kono
parents: 67
diff changeset
1198 virtual unsigned int execute (function *) { return increase_alignment (); }
kono
parents: 67
diff changeset
1199
kono
parents: 67
diff changeset
1200 }; // class pass_ipa_increase_alignment
kono
parents: 67
diff changeset
1201
kono
parents: 67
diff changeset
1202 } // anon namespace
kono
parents: 67
diff changeset
1203
kono
parents: 67
diff changeset
1204 simple_ipa_opt_pass *
kono
parents: 67
diff changeset
1205 make_pass_ipa_increase_alignment (gcc::context *ctxt)
kono
parents: 67
diff changeset
1206 {
kono
parents: 67
diff changeset
1207 return new pass_ipa_increase_alignment (ctxt);
kono
parents: 67
diff changeset
1208 }