[AArch64] PR target/68129: Define TARGET_SUPPORTS_WIDE_INT
[official-gcc.git] / gcc / tree-vectorizer.c
blob41e87a8d9bd25dc64eb6a50239bb4f603bd28926
1 /* Vectorizer
2 Copyright (C) 2003-2015 Free Software Foundation, Inc.
3 Contributed by Dorit Naishlos <dorit@il.ibm.com>
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* Loop and basic block vectorizer.
23 This file contains drivers for the three vectorizers:
24 (1) loop vectorizer (inter-iteration parallelism),
25 (2) loop-aware SLP (intra-iteration parallelism) (invoked by the loop
26 vectorizer)
27 (3) BB vectorizer (out-of-loops), aka SLP
29 The rest of the vectorizer's code is organized as follows:
30 - tree-vect-loop.c - loop specific parts such as reductions, etc. These are
31 used by drivers (1) and (2).
32 - tree-vect-loop-manip.c - vectorizer's loop control-flow utilities, used by
33 drivers (1) and (2).
34 - tree-vect-slp.c - BB vectorization specific analysis and transformation,
35 used by drivers (2) and (3).
36 - tree-vect-stmts.c - statements analysis and transformation (used by all).
37 - tree-vect-data-refs.c - vectorizer specific data-refs analysis and
38 manipulations (used by all).
39 - tree-vect-patterns.c - vectorizable code patterns detector (used by all)
41 Here's a poor attempt at illustrating that:
43 tree-vectorizer.c:
44 loop_vect() loop_aware_slp() slp_vect()
45 | / \ /
46 | / \ /
47 tree-vect-loop.c tree-vect-slp.c
48 | \ \ / / |
49 | \ \/ / |
50 | \ /\ / |
51 | \ / \ / |
52 tree-vect-stmts.c tree-vect-data-refs.c
53 \ /
54 tree-vect-patterns.c
57 #include "config.h"
58 #include "system.h"
59 #include "coretypes.h"
60 #include "backend.h"
61 #include "tree.h"
62 #include "gimple.h"
63 #include "predict.h"
64 #include "tree-pass.h"
65 #include "ssa.h"
66 #include "cgraph.h"
67 #include "fold-const.h"
68 #include "stor-layout.h"
69 #include "gimple-iterator.h"
70 #include "gimple-walk.h"
71 #include "tree-ssa-loop-manip.h"
72 #include "tree-cfg.h"
73 #include "cfgloop.h"
74 #include "tree-vectorizer.h"
75 #include "tree-ssa-propagate.h"
76 #include "dbgcnt.h"
77 #include "tree-scalar-evolution.h"
80 /* Loop or bb location. */
81 source_location vect_location;
83 /* Vector mapping GIMPLE stmt to stmt_vec_info. */
84 vec<stmt_vec_info> stmt_vec_info_vec;
86 /* For mapping simduid to vectorization factor. */
88 struct simduid_to_vf : free_ptr_hash<simduid_to_vf>
90 unsigned int simduid;
91 int vf;
93 /* hash_table support. */
94 static inline hashval_t hash (const simduid_to_vf *);
95 static inline int equal (const simduid_to_vf *, const simduid_to_vf *);
98 inline hashval_t
99 simduid_to_vf::hash (const simduid_to_vf *p)
101 return p->simduid;
104 inline int
105 simduid_to_vf::equal (const simduid_to_vf *p1, const simduid_to_vf *p2)
107 return p1->simduid == p2->simduid;
110 /* This hash maps the OMP simd array to the corresponding simduid used
111 to index into it. Like thus,
113 _7 = GOMP_SIMD_LANE (simduid.0)
116 D.1737[_7] = stuff;
119 This hash maps from the OMP simd array (D.1737[]) to DECL_UID of
120 simduid.0. */
122 struct simd_array_to_simduid : free_ptr_hash<simd_array_to_simduid>
124 tree decl;
125 unsigned int simduid;
127 /* hash_table support. */
128 static inline hashval_t hash (const simd_array_to_simduid *);
129 static inline int equal (const simd_array_to_simduid *,
130 const simd_array_to_simduid *);
133 inline hashval_t
134 simd_array_to_simduid::hash (const simd_array_to_simduid *p)
136 return DECL_UID (p->decl);
139 inline int
140 simd_array_to_simduid::equal (const simd_array_to_simduid *p1,
141 const simd_array_to_simduid *p2)
143 return p1->decl == p2->decl;
146 /* Fold IFN_GOMP_SIMD_LANE, IFN_GOMP_SIMD_VF, IFN_GOMP_SIMD_LAST_LANE,
147 into their corresponding constants and remove
148 IFN_GOMP_SIMD_ORDERED_{START,END}. */
150 static void
151 adjust_simduid_builtins (hash_table<simduid_to_vf> *htab)
153 basic_block bb;
155 FOR_EACH_BB_FN (bb, cfun)
157 gimple_stmt_iterator i;
159 for (i = gsi_start_bb (bb); !gsi_end_p (i); )
161 unsigned int vf = 1;
162 enum internal_fn ifn;
163 gimple *stmt = gsi_stmt (i);
164 tree t;
165 if (!is_gimple_call (stmt)
166 || !gimple_call_internal_p (stmt))
168 gsi_next (&i);
169 continue;
171 ifn = gimple_call_internal_fn (stmt);
172 switch (ifn)
174 case IFN_GOMP_SIMD_LANE:
175 case IFN_GOMP_SIMD_VF:
176 case IFN_GOMP_SIMD_LAST_LANE:
177 break;
178 case IFN_GOMP_SIMD_ORDERED_START:
179 case IFN_GOMP_SIMD_ORDERED_END:
180 gsi_remove (&i, true);
181 unlink_stmt_vdef (stmt);
182 continue;
183 default:
184 gsi_next (&i);
185 continue;
187 tree arg = gimple_call_arg (stmt, 0);
188 gcc_assert (arg != NULL_TREE);
189 gcc_assert (TREE_CODE (arg) == SSA_NAME);
190 simduid_to_vf *p = NULL, data;
191 data.simduid = DECL_UID (SSA_NAME_VAR (arg));
192 if (htab)
194 p = htab->find (&data);
195 if (p)
196 vf = p->vf;
198 switch (ifn)
200 case IFN_GOMP_SIMD_VF:
201 t = build_int_cst (unsigned_type_node, vf);
202 break;
203 case IFN_GOMP_SIMD_LANE:
204 t = build_int_cst (unsigned_type_node, 0);
205 break;
206 case IFN_GOMP_SIMD_LAST_LANE:
207 t = gimple_call_arg (stmt, 1);
208 break;
209 default:
210 gcc_unreachable ();
212 update_call_from_tree (&i, t);
213 gsi_next (&i);
218 /* Helper structure for note_simd_array_uses. */
220 struct note_simd_array_uses_struct
222 hash_table<simd_array_to_simduid> **htab;
223 unsigned int simduid;
226 /* Callback for note_simd_array_uses, called through walk_gimple_op. */
228 static tree
229 note_simd_array_uses_cb (tree *tp, int *walk_subtrees, void *data)
231 struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
232 struct note_simd_array_uses_struct *ns
233 = (struct note_simd_array_uses_struct *) wi->info;
235 if (TYPE_P (*tp))
236 *walk_subtrees = 0;
237 else if (VAR_P (*tp)
238 && lookup_attribute ("omp simd array", DECL_ATTRIBUTES (*tp))
239 && DECL_CONTEXT (*tp) == current_function_decl)
241 simd_array_to_simduid data;
242 if (!*ns->htab)
243 *ns->htab = new hash_table<simd_array_to_simduid> (15);
244 data.decl = *tp;
245 data.simduid = ns->simduid;
246 simd_array_to_simduid **slot = (*ns->htab)->find_slot (&data, INSERT);
247 if (*slot == NULL)
249 simd_array_to_simduid *p = XNEW (simd_array_to_simduid);
250 *p = data;
251 *slot = p;
253 else if ((*slot)->simduid != ns->simduid)
254 (*slot)->simduid = -1U;
255 *walk_subtrees = 0;
257 return NULL_TREE;
260 /* Find "omp simd array" temporaries and map them to corresponding
261 simduid. */
263 static void
264 note_simd_array_uses (hash_table<simd_array_to_simduid> **htab)
266 basic_block bb;
267 gimple_stmt_iterator gsi;
268 struct walk_stmt_info wi;
269 struct note_simd_array_uses_struct ns;
271 memset (&wi, 0, sizeof (wi));
272 wi.info = &ns;
273 ns.htab = htab;
275 FOR_EACH_BB_FN (bb, cfun)
276 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
278 gimple *stmt = gsi_stmt (gsi);
279 if (!is_gimple_call (stmt) || !gimple_call_internal_p (stmt))
280 continue;
281 switch (gimple_call_internal_fn (stmt))
283 case IFN_GOMP_SIMD_LANE:
284 case IFN_GOMP_SIMD_VF:
285 case IFN_GOMP_SIMD_LAST_LANE:
286 break;
287 default:
288 continue;
290 tree lhs = gimple_call_lhs (stmt);
291 if (lhs == NULL_TREE)
292 continue;
293 imm_use_iterator use_iter;
294 gimple *use_stmt;
295 ns.simduid = DECL_UID (SSA_NAME_VAR (gimple_call_arg (stmt, 0)));
296 FOR_EACH_IMM_USE_STMT (use_stmt, use_iter, lhs)
297 if (!is_gimple_debug (use_stmt))
298 walk_gimple_op (use_stmt, note_simd_array_uses_cb, &wi);
302 /* Shrink arrays with "omp simd array" attribute to the corresponding
303 vectorization factor. */
305 static void
306 shrink_simd_arrays
307 (hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab,
308 hash_table<simduid_to_vf> *simduid_to_vf_htab)
310 for (hash_table<simd_array_to_simduid>::iterator iter
311 = simd_array_to_simduid_htab->begin ();
312 iter != simd_array_to_simduid_htab->end (); ++iter)
313 if ((*iter)->simduid != -1U)
315 tree decl = (*iter)->decl;
316 int vf = 1;
317 if (simduid_to_vf_htab)
319 simduid_to_vf *p = NULL, data;
320 data.simduid = (*iter)->simduid;
321 p = simduid_to_vf_htab->find (&data);
322 if (p)
323 vf = p->vf;
325 tree atype
326 = build_array_type_nelts (TREE_TYPE (TREE_TYPE (decl)), vf);
327 TREE_TYPE (decl) = atype;
328 relayout_decl (decl);
331 delete simd_array_to_simduid_htab;
334 /* A helper function to free data refs. */
336 void
337 vect_destroy_datarefs (vec_info *vinfo)
339 struct data_reference *dr;
340 unsigned int i;
342 FOR_EACH_VEC_ELT (vinfo->datarefs, i, dr)
343 if (dr->aux)
345 free (dr->aux);
346 dr->aux = NULL;
349 free_data_refs (vinfo->datarefs);
353 /* Return whether STMT is inside the region we try to vectorize. */
355 bool
356 vect_stmt_in_region_p (vec_info *vinfo, gimple *stmt)
358 if (!gimple_bb (stmt))
359 return false;
361 if (loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (vinfo))
363 struct loop *loop = LOOP_VINFO_LOOP (loop_vinfo);
364 if (!flow_bb_inside_loop_p (loop, gimple_bb (stmt)))
365 return false;
367 else
369 bb_vec_info bb_vinfo = as_a <bb_vec_info> (vinfo);
370 if (gimple_bb (stmt) != BB_VINFO_BB (bb_vinfo)
371 || gimple_uid (stmt) == -1U
372 || gimple_code (stmt) == GIMPLE_PHI)
373 return false;
376 return true;
380 /* If LOOP has been versioned during ifcvt, return the internal call
381 guarding it. */
383 static gimple *
384 vect_loop_vectorized_call (struct loop *loop)
386 basic_block bb = loop_preheader_edge (loop)->src;
387 gimple *g;
390 g = last_stmt (bb);
391 if (g)
392 break;
393 if (!single_pred_p (bb))
394 break;
395 bb = single_pred (bb);
397 while (1);
398 if (g && gimple_code (g) == GIMPLE_COND)
400 gimple_stmt_iterator gsi = gsi_for_stmt (g);
401 gsi_prev (&gsi);
402 if (!gsi_end_p (gsi))
404 g = gsi_stmt (gsi);
405 if (is_gimple_call (g)
406 && gimple_call_internal_p (g)
407 && gimple_call_internal_fn (g) == IFN_LOOP_VECTORIZED
408 && (tree_to_shwi (gimple_call_arg (g, 0)) == loop->num
409 || tree_to_shwi (gimple_call_arg (g, 1)) == loop->num))
410 return g;
413 return NULL;
416 /* Fold LOOP_VECTORIZED internal call G to VALUE and
417 update any immediate uses of it's LHS. */
419 static void
420 fold_loop_vectorized_call (gimple *g, tree value)
422 tree lhs = gimple_call_lhs (g);
423 use_operand_p use_p;
424 imm_use_iterator iter;
425 gimple *use_stmt;
426 gimple_stmt_iterator gsi = gsi_for_stmt (g);
428 update_call_from_tree (&gsi, value);
429 FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
431 FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
432 SET_USE (use_p, value);
433 update_stmt (use_stmt);
436 /* Set the uids of all the statements in basic blocks inside loop
437 represented by LOOP_VINFO. LOOP_VECTORIZED_CALL is the internal
438 call guarding the loop which has been if converted. */
439 static void
440 set_uid_loop_bbs (loop_vec_info loop_vinfo, gimple *loop_vectorized_call)
442 tree arg = gimple_call_arg (loop_vectorized_call, 1);
443 basic_block *bbs;
444 unsigned int i;
445 struct loop *scalar_loop = get_loop (cfun, tree_to_shwi (arg));
447 LOOP_VINFO_SCALAR_LOOP (loop_vinfo) = scalar_loop;
448 gcc_checking_assert (vect_loop_vectorized_call
449 (LOOP_VINFO_SCALAR_LOOP (loop_vinfo))
450 == loop_vectorized_call);
451 bbs = get_loop_body (scalar_loop);
452 for (i = 0; i < scalar_loop->num_nodes; i++)
454 basic_block bb = bbs[i];
455 gimple_stmt_iterator gsi;
456 for (gsi = gsi_start_phis (bb); !gsi_end_p (gsi); gsi_next (&gsi))
458 gimple *phi = gsi_stmt (gsi);
459 gimple_set_uid (phi, 0);
461 for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
463 gimple *stmt = gsi_stmt (gsi);
464 gimple_set_uid (stmt, 0);
467 free (bbs);
470 /* Function vectorize_loops.
472 Entry point to loop vectorization phase. */
474 unsigned
475 vectorize_loops (void)
477 unsigned int i;
478 unsigned int num_vectorized_loops = 0;
479 unsigned int vect_loops_num;
480 struct loop *loop;
481 hash_table<simduid_to_vf> *simduid_to_vf_htab = NULL;
482 hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab = NULL;
483 bool any_ifcvt_loops = false;
484 unsigned ret = 0;
486 vect_loops_num = number_of_loops (cfun);
488 /* Bail out if there are no loops. */
489 if (vect_loops_num <= 1)
490 return 0;
492 if (cfun->has_simduid_loops)
493 note_simd_array_uses (&simd_array_to_simduid_htab);
495 init_stmt_vec_info_vec ();
497 /* ----------- Analyze loops. ----------- */
499 /* If some loop was duplicated, it gets bigger number
500 than all previously defined loops. This fact allows us to run
501 only over initial loops skipping newly generated ones. */
502 FOR_EACH_LOOP (loop, 0)
503 if (loop->dont_vectorize)
504 any_ifcvt_loops = true;
505 else if ((flag_tree_loop_vectorize
506 && optimize_loop_nest_for_speed_p (loop))
507 || loop->force_vectorize)
509 loop_vec_info loop_vinfo;
510 vect_location = find_loop_location (loop);
511 if (LOCATION_LOCUS (vect_location) != UNKNOWN_LOCATION
512 && dump_enabled_p ())
513 dump_printf (MSG_NOTE, "\nAnalyzing loop at %s:%d\n",
514 LOCATION_FILE (vect_location),
515 LOCATION_LINE (vect_location));
517 loop_vinfo = vect_analyze_loop (loop);
518 loop->aux = loop_vinfo;
520 if (!loop_vinfo || !LOOP_VINFO_VECTORIZABLE_P (loop_vinfo))
521 continue;
523 if (!dbg_cnt (vect_loop))
524 break;
526 gimple *loop_vectorized_call = vect_loop_vectorized_call (loop);
527 if (loop_vectorized_call)
528 set_uid_loop_bbs (loop_vinfo, loop_vectorized_call);
529 if (LOCATION_LOCUS (vect_location) != UNKNOWN_LOCATION
530 && dump_enabled_p ())
531 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
532 "loop vectorized\n");
533 vect_transform_loop (loop_vinfo);
534 num_vectorized_loops++;
535 /* Now that the loop has been vectorized, allow it to be unrolled
536 etc. */
537 loop->force_vectorize = false;
539 if (loop->simduid)
541 simduid_to_vf *simduid_to_vf_data = XNEW (simduid_to_vf);
542 if (!simduid_to_vf_htab)
543 simduid_to_vf_htab = new hash_table<simduid_to_vf> (15);
544 simduid_to_vf_data->simduid = DECL_UID (loop->simduid);
545 simduid_to_vf_data->vf = loop_vinfo->vectorization_factor;
546 *simduid_to_vf_htab->find_slot (simduid_to_vf_data, INSERT)
547 = simduid_to_vf_data;
550 if (loop_vectorized_call)
552 fold_loop_vectorized_call (loop_vectorized_call, boolean_true_node);
553 ret |= TODO_cleanup_cfg;
557 vect_location = UNKNOWN_LOCATION;
559 statistics_counter_event (cfun, "Vectorized loops", num_vectorized_loops);
560 if (dump_enabled_p ()
561 || (num_vectorized_loops > 0 && dump_enabled_p ()))
562 dump_printf_loc (MSG_NOTE, vect_location,
563 "vectorized %u loops in function.\n",
564 num_vectorized_loops);
566 /* ----------- Finalize. ----------- */
568 if (any_ifcvt_loops)
569 for (i = 1; i < vect_loops_num; i++)
571 loop = get_loop (cfun, i);
572 if (loop && loop->dont_vectorize)
574 gimple *g = vect_loop_vectorized_call (loop);
575 if (g)
577 fold_loop_vectorized_call (g, boolean_false_node);
578 ret |= TODO_cleanup_cfg;
583 for (i = 1; i < vect_loops_num; i++)
585 loop_vec_info loop_vinfo;
587 loop = get_loop (cfun, i);
588 if (!loop)
589 continue;
590 loop_vinfo = (loop_vec_info) loop->aux;
591 destroy_loop_vec_info (loop_vinfo, true);
592 loop->aux = NULL;
595 free_stmt_vec_info_vec ();
597 /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE,ORDERED_{START,END}} builtins. */
598 if (cfun->has_simduid_loops)
599 adjust_simduid_builtins (simduid_to_vf_htab);
601 /* Shrink any "omp array simd" temporary arrays to the
602 actual vectorization factors. */
603 if (simd_array_to_simduid_htab)
604 shrink_simd_arrays (simd_array_to_simduid_htab, simduid_to_vf_htab);
605 delete simduid_to_vf_htab;
606 cfun->has_simduid_loops = false;
608 if (num_vectorized_loops > 0)
610 /* If we vectorized any loop only virtual SSA form needs to be updated.
611 ??? Also while we try hard to update loop-closed SSA form we fail
612 to properly do this in some corner-cases (see PR56286). */
613 rewrite_into_loop_closed_ssa (NULL, TODO_update_ssa_only_virtuals);
614 return TODO_cleanup_cfg;
617 return ret;
621 /* Entry point to the simduid cleanup pass. */
623 namespace {
625 const pass_data pass_data_simduid_cleanup =
627 GIMPLE_PASS, /* type */
628 "simduid", /* name */
629 OPTGROUP_NONE, /* optinfo_flags */
630 TV_NONE, /* tv_id */
631 ( PROP_ssa | PROP_cfg ), /* properties_required */
632 0, /* properties_provided */
633 0, /* properties_destroyed */
634 0, /* todo_flags_start */
635 0, /* todo_flags_finish */
638 class pass_simduid_cleanup : public gimple_opt_pass
640 public:
641 pass_simduid_cleanup (gcc::context *ctxt)
642 : gimple_opt_pass (pass_data_simduid_cleanup, ctxt)
645 /* opt_pass methods: */
646 opt_pass * clone () { return new pass_simduid_cleanup (m_ctxt); }
647 virtual bool gate (function *fun) { return fun->has_simduid_loops; }
648 virtual unsigned int execute (function *);
650 }; // class pass_simduid_cleanup
652 unsigned int
653 pass_simduid_cleanup::execute (function *fun)
655 hash_table<simd_array_to_simduid> *simd_array_to_simduid_htab = NULL;
657 note_simd_array_uses (&simd_array_to_simduid_htab);
659 /* Fold IFN_GOMP_SIMD_{VF,LANE,LAST_LANE,ORDERED_{START,END}} builtins. */
660 adjust_simduid_builtins (NULL);
662 /* Shrink any "omp array simd" temporary arrays to the
663 actual vectorization factors. */
664 if (simd_array_to_simduid_htab)
665 shrink_simd_arrays (simd_array_to_simduid_htab, NULL);
666 fun->has_simduid_loops = false;
667 return 0;
670 } // anon namespace
672 gimple_opt_pass *
673 make_pass_simduid_cleanup (gcc::context *ctxt)
675 return new pass_simduid_cleanup (ctxt);
679 /* Entry point to basic block SLP phase. */
681 namespace {
683 const pass_data pass_data_slp_vectorize =
685 GIMPLE_PASS, /* type */
686 "slp", /* name */
687 OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */
688 TV_TREE_SLP_VECTORIZATION, /* tv_id */
689 ( PROP_ssa | PROP_cfg ), /* properties_required */
690 0, /* properties_provided */
691 0, /* properties_destroyed */
692 0, /* todo_flags_start */
693 TODO_update_ssa, /* todo_flags_finish */
696 class pass_slp_vectorize : public gimple_opt_pass
698 public:
699 pass_slp_vectorize (gcc::context *ctxt)
700 : gimple_opt_pass (pass_data_slp_vectorize, ctxt)
703 /* opt_pass methods: */
704 opt_pass * clone () { return new pass_slp_vectorize (m_ctxt); }
705 virtual bool gate (function *) { return flag_tree_slp_vectorize != 0; }
706 virtual unsigned int execute (function *);
708 }; // class pass_slp_vectorize
710 unsigned int
711 pass_slp_vectorize::execute (function *fun)
713 basic_block bb;
715 bool in_loop_pipeline = scev_initialized_p ();
716 if (!in_loop_pipeline)
718 loop_optimizer_init (LOOPS_NORMAL);
719 scev_initialize ();
722 /* Mark all stmts as not belonging to the current region. */
723 FOR_EACH_BB_FN (bb, fun)
725 for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
726 gsi_next (&gsi))
727 gimple_set_uid (gsi_stmt (gsi), -1);
730 init_stmt_vec_info_vec ();
732 FOR_EACH_BB_FN (bb, fun)
734 if (vect_slp_bb (bb))
735 dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, vect_location,
736 "basic block vectorized\n");
739 free_stmt_vec_info_vec ();
741 if (!in_loop_pipeline)
743 scev_finalize ();
744 loop_optimizer_finalize ();
747 return 0;
750 } // anon namespace
752 gimple_opt_pass *
753 make_pass_slp_vectorize (gcc::context *ctxt)
755 return new pass_slp_vectorize (ctxt);
759 /* Increase alignment of global arrays to improve vectorization potential.
760 TODO:
761 - Consider also structs that have an array field.
762 - Use ipa analysis to prune arrays that can't be vectorized?
763 This should involve global alignment analysis and in the future also
764 array padding. */
766 static unsigned int
767 increase_alignment (void)
769 varpool_node *vnode;
771 vect_location = UNKNOWN_LOCATION;
773 /* Increase the alignment of all global arrays for vectorization. */
774 FOR_EACH_DEFINED_VARIABLE (vnode)
776 tree vectype, decl = vnode->decl;
777 tree t;
778 unsigned int alignment;
780 t = TREE_TYPE (decl);
781 if (TREE_CODE (t) != ARRAY_TYPE)
782 continue;
783 vectype = get_vectype_for_scalar_type (strip_array_types (t));
784 if (!vectype)
785 continue;
786 alignment = TYPE_ALIGN (vectype);
787 if (DECL_ALIGN (decl) >= alignment)
788 continue;
790 if (vect_can_force_dr_alignment_p (decl, alignment))
792 vnode->increase_alignment (TYPE_ALIGN (vectype));
793 dump_printf (MSG_NOTE, "Increasing alignment of decl: ");
794 dump_generic_expr (MSG_NOTE, TDF_SLIM, decl);
795 dump_printf (MSG_NOTE, "\n");
798 return 0;
802 namespace {
804 const pass_data pass_data_ipa_increase_alignment =
806 SIMPLE_IPA_PASS, /* type */
807 "increase_alignment", /* name */
808 OPTGROUP_LOOP | OPTGROUP_VEC, /* optinfo_flags */
809 TV_IPA_OPT, /* tv_id */
810 0, /* properties_required */
811 0, /* properties_provided */
812 0, /* properties_destroyed */
813 0, /* todo_flags_start */
814 0, /* todo_flags_finish */
817 class pass_ipa_increase_alignment : public simple_ipa_opt_pass
819 public:
820 pass_ipa_increase_alignment (gcc::context *ctxt)
821 : simple_ipa_opt_pass (pass_data_ipa_increase_alignment, ctxt)
824 /* opt_pass methods: */
825 virtual bool gate (function *)
827 return flag_section_anchors && flag_tree_loop_vectorize;
830 virtual unsigned int execute (function *) { return increase_alignment (); }
832 }; // class pass_ipa_increase_alignment
834 } // anon namespace
836 simple_ipa_opt_pass *
837 make_pass_ipa_increase_alignment (gcc::context *ctxt)
839 return new pass_ipa_increase_alignment (ctxt);