1*e4b17023SJohn Marino /* Vectorizer 2*e4b17023SJohn Marino Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 3*e4b17023SJohn Marino Free Software Foundation, Inc. 4*e4b17023SJohn Marino Contributed by Dorit Naishlos <dorit@il.ibm.com> 5*e4b17023SJohn Marino 6*e4b17023SJohn Marino This file is part of GCC. 7*e4b17023SJohn Marino 8*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under 9*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free 10*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later 11*e4b17023SJohn Marino version. 12*e4b17023SJohn Marino 13*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY 14*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or 15*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16*e4b17023SJohn Marino for more details. 17*e4b17023SJohn Marino 18*e4b17023SJohn Marino You should have received a copy of the GNU General Public License 19*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see 20*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */ 21*e4b17023SJohn Marino 22*e4b17023SJohn Marino #ifndef GCC_TREE_VECTORIZER_H 23*e4b17023SJohn Marino #define GCC_TREE_VECTORIZER_H 24*e4b17023SJohn Marino 25*e4b17023SJohn Marino #include "tree-data-ref.h" 26*e4b17023SJohn Marino 27*e4b17023SJohn Marino typedef source_location LOC; 28*e4b17023SJohn Marino #define UNKNOWN_LOC UNKNOWN_LOCATION 29*e4b17023SJohn Marino #define EXPR_LOC(e) EXPR_LOCATION(e) 30*e4b17023SJohn Marino #define LOC_FILE(l) LOCATION_FILE (l) 31*e4b17023SJohn Marino #define LOC_LINE(l) LOCATION_LINE (l) 32*e4b17023SJohn Marino 33*e4b17023SJohn Marino /* Used for naming of new temporaries. */ 34*e4b17023SJohn Marino enum vect_var_kind { 35*e4b17023SJohn Marino vect_simple_var, 36*e4b17023SJohn Marino vect_pointer_var, 37*e4b17023SJohn Marino vect_scalar_var 38*e4b17023SJohn Marino }; 39*e4b17023SJohn Marino 40*e4b17023SJohn Marino /* Defines type of operation. */ 41*e4b17023SJohn Marino enum operation_type { 42*e4b17023SJohn Marino unary_op = 1, 43*e4b17023SJohn Marino binary_op, 44*e4b17023SJohn Marino ternary_op 45*e4b17023SJohn Marino }; 46*e4b17023SJohn Marino 47*e4b17023SJohn Marino /* Define type of available alignment support. */ 48*e4b17023SJohn Marino enum dr_alignment_support { 49*e4b17023SJohn Marino dr_unaligned_unsupported, 50*e4b17023SJohn Marino dr_unaligned_supported, 51*e4b17023SJohn Marino dr_explicit_realign, 52*e4b17023SJohn Marino dr_explicit_realign_optimized, 53*e4b17023SJohn Marino dr_aligned 54*e4b17023SJohn Marino }; 55*e4b17023SJohn Marino 56*e4b17023SJohn Marino /* Define type of def-use cross-iteration cycle. */ 57*e4b17023SJohn Marino enum vect_def_type { 58*e4b17023SJohn Marino vect_uninitialized_def = 0, 59*e4b17023SJohn Marino vect_constant_def = 1, 60*e4b17023SJohn Marino vect_external_def, 61*e4b17023SJohn Marino vect_internal_def, 62*e4b17023SJohn Marino vect_induction_def, 63*e4b17023SJohn Marino vect_reduction_def, 64*e4b17023SJohn Marino vect_double_reduction_def, 65*e4b17023SJohn Marino vect_nested_cycle, 66*e4b17023SJohn Marino vect_unknown_def_type 67*e4b17023SJohn Marino }; 68*e4b17023SJohn Marino 69*e4b17023SJohn Marino #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \ 70*e4b17023SJohn Marino || ((D) == vect_double_reduction_def) \ 71*e4b17023SJohn Marino || ((D) == vect_nested_cycle)) 72*e4b17023SJohn Marino 73*e4b17023SJohn Marino /************************************************************************ 74*e4b17023SJohn Marino SLP 75*e4b17023SJohn Marino ************************************************************************/ 76*e4b17023SJohn Marino typedef void *slp_void_p; 77*e4b17023SJohn Marino DEF_VEC_P (slp_void_p); 78*e4b17023SJohn Marino DEF_VEC_ALLOC_P (slp_void_p, heap); 79*e4b17023SJohn Marino 80*e4b17023SJohn Marino /* A computation tree of an SLP instance. Each node corresponds to a group of 81*e4b17023SJohn Marino stmts to be packed in a SIMD stmt. */ 82*e4b17023SJohn Marino typedef struct _slp_tree { 83*e4b17023SJohn Marino /* Nodes that contain def-stmts of this node statements operands. */ 84*e4b17023SJohn Marino VEC (slp_void_p, heap) *children; 85*e4b17023SJohn Marino /* A group of scalar stmts to be vectorized together. */ 86*e4b17023SJohn Marino VEC (gimple, heap) *stmts; 87*e4b17023SJohn Marino /* Vectorized stmt/s. */ 88*e4b17023SJohn Marino VEC (gimple, heap) *vec_stmts; 89*e4b17023SJohn Marino /* Number of vector stmts that are created to replace the group of scalar 90*e4b17023SJohn Marino stmts. It is calculated during the transformation phase as the number of 91*e4b17023SJohn Marino scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF 92*e4b17023SJohn Marino divided by vector size. */ 93*e4b17023SJohn Marino unsigned int vec_stmts_size; 94*e4b17023SJohn Marino /* Vectorization costs associated with SLP node. */ 95*e4b17023SJohn Marino struct 96*e4b17023SJohn Marino { 97*e4b17023SJohn Marino int outside_of_loop; /* Statements generated outside loop. */ 98*e4b17023SJohn Marino int inside_of_loop; /* Statements generated inside loop. */ 99*e4b17023SJohn Marino } cost; 100*e4b17023SJohn Marino } *slp_tree; 101*e4b17023SJohn Marino 102*e4b17023SJohn Marino DEF_VEC_P(slp_tree); 103*e4b17023SJohn Marino DEF_VEC_ALLOC_P(slp_tree, heap); 104*e4b17023SJohn Marino 105*e4b17023SJohn Marino /* SLP instance is a sequence of stmts in a loop that can be packed into 106*e4b17023SJohn Marino SIMD stmts. */ 107*e4b17023SJohn Marino typedef struct _slp_instance { 108*e4b17023SJohn Marino /* The root of SLP tree. */ 109*e4b17023SJohn Marino slp_tree root; 110*e4b17023SJohn Marino 111*e4b17023SJohn Marino /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */ 112*e4b17023SJohn Marino unsigned int group_size; 113*e4b17023SJohn Marino 114*e4b17023SJohn Marino /* The unrolling factor required to vectorized this SLP instance. */ 115*e4b17023SJohn Marino unsigned int unrolling_factor; 116*e4b17023SJohn Marino 117*e4b17023SJohn Marino /* Vectorization costs associated with SLP instance. */ 118*e4b17023SJohn Marino struct 119*e4b17023SJohn Marino { 120*e4b17023SJohn Marino int outside_of_loop; /* Statements generated outside loop. */ 121*e4b17023SJohn Marino int inside_of_loop; /* Statements generated inside loop. */ 122*e4b17023SJohn Marino } cost; 123*e4b17023SJohn Marino 124*e4b17023SJohn Marino /* Loads permutation relatively to the stores, NULL if there is no 125*e4b17023SJohn Marino permutation. */ 126*e4b17023SJohn Marino VEC (int, heap) *load_permutation; 127*e4b17023SJohn Marino 128*e4b17023SJohn Marino /* The group of nodes that contain loads of this SLP instance. */ 129*e4b17023SJohn Marino VEC (slp_tree, heap) *loads; 130*e4b17023SJohn Marino 131*e4b17023SJohn Marino /* The first scalar load of the instance. The created vector loads will be 132*e4b17023SJohn Marino inserted before this statement. */ 133*e4b17023SJohn Marino gimple first_load; 134*e4b17023SJohn Marino } *slp_instance; 135*e4b17023SJohn Marino 136*e4b17023SJohn Marino DEF_VEC_P(slp_instance); 137*e4b17023SJohn Marino DEF_VEC_ALLOC_P(slp_instance, heap); 138*e4b17023SJohn Marino 139*e4b17023SJohn Marino /* Access Functions. */ 140*e4b17023SJohn Marino #define SLP_INSTANCE_TREE(S) (S)->root 141*e4b17023SJohn Marino #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size 142*e4b17023SJohn Marino #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor 143*e4b17023SJohn Marino #define SLP_INSTANCE_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop 144*e4b17023SJohn Marino #define SLP_INSTANCE_INSIDE_OF_LOOP_COST(S) (S)->cost.inside_of_loop 145*e4b17023SJohn Marino #define SLP_INSTANCE_LOAD_PERMUTATION(S) (S)->load_permutation 146*e4b17023SJohn Marino #define SLP_INSTANCE_LOADS(S) (S)->loads 147*e4b17023SJohn Marino #define SLP_INSTANCE_FIRST_LOAD_STMT(S) (S)->first_load 148*e4b17023SJohn Marino 149*e4b17023SJohn Marino #define SLP_TREE_CHILDREN(S) (S)->children 150*e4b17023SJohn Marino #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts 151*e4b17023SJohn Marino #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts 152*e4b17023SJohn Marino #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size 153*e4b17023SJohn Marino #define SLP_TREE_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop 154*e4b17023SJohn Marino #define SLP_TREE_INSIDE_OF_LOOP_COST(S) (S)->cost.inside_of_loop 155*e4b17023SJohn Marino 156*e4b17023SJohn Marino /* This structure is used in creation of an SLP tree. Each instance 157*e4b17023SJohn Marino corresponds to the same operand in a group of scalar stmts in an SLP 158*e4b17023SJohn Marino node. */ 159*e4b17023SJohn Marino typedef struct _slp_oprnd_info 160*e4b17023SJohn Marino { 161*e4b17023SJohn Marino /* Def-stmts for the operands. */ 162*e4b17023SJohn Marino VEC (gimple, heap) *def_stmts; 163*e4b17023SJohn Marino /* Information about the first statement, its vector def-type, type, the 164*e4b17023SJohn Marino operand itself in case it's constant, and an indication if it's a pattern 165*e4b17023SJohn Marino stmt. */ 166*e4b17023SJohn Marino enum vect_def_type first_dt; 167*e4b17023SJohn Marino tree first_def_type; 168*e4b17023SJohn Marino tree first_const_oprnd; 169*e4b17023SJohn Marino bool first_pattern; 170*e4b17023SJohn Marino } *slp_oprnd_info; 171*e4b17023SJohn Marino 172*e4b17023SJohn Marino DEF_VEC_P(slp_oprnd_info); 173*e4b17023SJohn Marino DEF_VEC_ALLOC_P(slp_oprnd_info, heap); 174*e4b17023SJohn Marino 175*e4b17023SJohn Marino 176*e4b17023SJohn Marino typedef struct _vect_peel_info 177*e4b17023SJohn Marino { 178*e4b17023SJohn Marino int npeel; 179*e4b17023SJohn Marino struct data_reference *dr; 180*e4b17023SJohn Marino unsigned int count; 181*e4b17023SJohn Marino } *vect_peel_info; 182*e4b17023SJohn Marino 183*e4b17023SJohn Marino typedef struct _vect_peel_extended_info 184*e4b17023SJohn Marino { 185*e4b17023SJohn Marino struct _vect_peel_info peel_info; 186*e4b17023SJohn Marino unsigned int inside_cost; 187*e4b17023SJohn Marino unsigned int outside_cost; 188*e4b17023SJohn Marino } *vect_peel_extended_info; 189*e4b17023SJohn Marino 190*e4b17023SJohn Marino /*-----------------------------------------------------------------*/ 191*e4b17023SJohn Marino /* Info on vectorized loops. */ 192*e4b17023SJohn Marino /*-----------------------------------------------------------------*/ 193*e4b17023SJohn Marino typedef struct _loop_vec_info { 194*e4b17023SJohn Marino 195*e4b17023SJohn Marino /* The loop to which this info struct refers to. */ 196*e4b17023SJohn Marino struct loop *loop; 197*e4b17023SJohn Marino 198*e4b17023SJohn Marino /* The loop basic blocks. */ 199*e4b17023SJohn Marino basic_block *bbs; 200*e4b17023SJohn Marino 201*e4b17023SJohn Marino /* Number of iterations. */ 202*e4b17023SJohn Marino tree num_iters; 203*e4b17023SJohn Marino tree num_iters_unchanged; 204*e4b17023SJohn Marino 205*e4b17023SJohn Marino /* Minimum number of iterations below which vectorization is expected to 206*e4b17023SJohn Marino not be profitable (as estimated by the cost model). 207*e4b17023SJohn Marino -1 indicates that vectorization will not be profitable. 208*e4b17023SJohn Marino FORNOW: This field is an int. Will be a tree in the future, to represent 209*e4b17023SJohn Marino values unknown at compile time. */ 210*e4b17023SJohn Marino int min_profitable_iters; 211*e4b17023SJohn Marino 212*e4b17023SJohn Marino /* Is the loop vectorizable? */ 213*e4b17023SJohn Marino bool vectorizable; 214*e4b17023SJohn Marino 215*e4b17023SJohn Marino /* Unrolling factor */ 216*e4b17023SJohn Marino int vectorization_factor; 217*e4b17023SJohn Marino 218*e4b17023SJohn Marino /* The loop location in the source. */ 219*e4b17023SJohn Marino LOC loop_line_number; 220*e4b17023SJohn Marino 221*e4b17023SJohn Marino /* Unknown DRs according to which loop was peeled. */ 222*e4b17023SJohn Marino struct data_reference *unaligned_dr; 223*e4b17023SJohn Marino 224*e4b17023SJohn Marino /* peeling_for_alignment indicates whether peeling for alignment will take 225*e4b17023SJohn Marino place, and what the peeling factor should be: 226*e4b17023SJohn Marino peeling_for_alignment = X means: 227*e4b17023SJohn Marino If X=0: Peeling for alignment will not be applied. 228*e4b17023SJohn Marino If X>0: Peel first X iterations. 229*e4b17023SJohn Marino If X=-1: Generate a runtime test to calculate the number of iterations 230*e4b17023SJohn Marino to be peeled, using the dataref recorded in the field 231*e4b17023SJohn Marino unaligned_dr. */ 232*e4b17023SJohn Marino int peeling_for_alignment; 233*e4b17023SJohn Marino 234*e4b17023SJohn Marino /* The mask used to check the alignment of pointers or arrays. */ 235*e4b17023SJohn Marino int ptr_mask; 236*e4b17023SJohn Marino 237*e4b17023SJohn Marino /* The loop nest in which the data dependences are computed. */ 238*e4b17023SJohn Marino VEC (loop_p, heap) *loop_nest; 239*e4b17023SJohn Marino 240*e4b17023SJohn Marino /* All data references in the loop. */ 241*e4b17023SJohn Marino VEC (data_reference_p, heap) *datarefs; 242*e4b17023SJohn Marino 243*e4b17023SJohn Marino /* All data dependences in the loop. */ 244*e4b17023SJohn Marino VEC (ddr_p, heap) *ddrs; 245*e4b17023SJohn Marino 246*e4b17023SJohn Marino /* Data Dependence Relations defining address ranges that are candidates 247*e4b17023SJohn Marino for a run-time aliasing check. */ 248*e4b17023SJohn Marino VEC (ddr_p, heap) *may_alias_ddrs; 249*e4b17023SJohn Marino 250*e4b17023SJohn Marino /* Statements in the loop that have data references that are candidates for a 251*e4b17023SJohn Marino runtime (loop versioning) misalignment check. */ 252*e4b17023SJohn Marino VEC(gimple,heap) *may_misalign_stmts; 253*e4b17023SJohn Marino 254*e4b17023SJohn Marino /* All interleaving chains of stores in the loop, represented by the first 255*e4b17023SJohn Marino stmt in the chain. */ 256*e4b17023SJohn Marino VEC(gimple, heap) *strided_stores; 257*e4b17023SJohn Marino 258*e4b17023SJohn Marino /* All SLP instances in the loop. This is a subset of the set of STRIDED_STORES 259*e4b17023SJohn Marino of the loop. */ 260*e4b17023SJohn Marino VEC(slp_instance, heap) *slp_instances; 261*e4b17023SJohn Marino 262*e4b17023SJohn Marino /* The unrolling factor needed to SLP the loop. In case of that pure SLP is 263*e4b17023SJohn Marino applied to the loop, i.e., no unrolling is needed, this is 1. */ 264*e4b17023SJohn Marino unsigned slp_unrolling_factor; 265*e4b17023SJohn Marino 266*e4b17023SJohn Marino /* Reduction cycles detected in the loop. Used in loop-aware SLP. */ 267*e4b17023SJohn Marino VEC (gimple, heap) *reductions; 268*e4b17023SJohn Marino 269*e4b17023SJohn Marino /* All reduction chains in the loop, represented by the first 270*e4b17023SJohn Marino stmt in the chain. */ 271*e4b17023SJohn Marino VEC (gimple, heap) *reduction_chains; 272*e4b17023SJohn Marino 273*e4b17023SJohn Marino /* Hash table used to choose the best peeling option. */ 274*e4b17023SJohn Marino htab_t peeling_htab; 275*e4b17023SJohn Marino 276*e4b17023SJohn Marino /* When we have strided data accesses with gaps, we may introduce invalid 277*e4b17023SJohn Marino memory accesses. We peel the last iteration of the loop to prevent 278*e4b17023SJohn Marino this. */ 279*e4b17023SJohn Marino bool peeling_for_gaps; 280*e4b17023SJohn Marino 281*e4b17023SJohn Marino } *loop_vec_info; 282*e4b17023SJohn Marino 283*e4b17023SJohn Marino /* Access Functions. */ 284*e4b17023SJohn Marino #define LOOP_VINFO_LOOP(L) (L)->loop 285*e4b17023SJohn Marino #define LOOP_VINFO_BBS(L) (L)->bbs 286*e4b17023SJohn Marino #define LOOP_VINFO_NITERS(L) (L)->num_iters 287*e4b17023SJohn Marino /* Since LOOP_VINFO_NITERS can change after prologue peeling 288*e4b17023SJohn Marino retain total unchanged scalar loop iterations for cost model. */ 289*e4b17023SJohn Marino #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged 290*e4b17023SJohn Marino #define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters 291*e4b17023SJohn Marino #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable 292*e4b17023SJohn Marino #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor 293*e4b17023SJohn Marino #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask 294*e4b17023SJohn Marino #define LOOP_VINFO_LOOP_NEST(L) (L)->loop_nest 295*e4b17023SJohn Marino #define LOOP_VINFO_DATAREFS(L) (L)->datarefs 296*e4b17023SJohn Marino #define LOOP_VINFO_DDRS(L) (L)->ddrs 297*e4b17023SJohn Marino #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters)) 298*e4b17023SJohn Marino #define LOOP_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment 299*e4b17023SJohn Marino #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr 300*e4b17023SJohn Marino #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts 301*e4b17023SJohn Marino #define LOOP_VINFO_LOC(L) (L)->loop_line_number 302*e4b17023SJohn Marino #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs 303*e4b17023SJohn Marino #define LOOP_VINFO_STRIDED_STORES(L) (L)->strided_stores 304*e4b17023SJohn Marino #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances 305*e4b17023SJohn Marino #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor 306*e4b17023SJohn Marino #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions 307*e4b17023SJohn Marino #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains 308*e4b17023SJohn Marino #define LOOP_VINFO_PEELING_HTAB(L) (L)->peeling_htab 309*e4b17023SJohn Marino #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps 310*e4b17023SJohn Marino 311*e4b17023SJohn Marino #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \ 312*e4b17023SJohn Marino VEC_length (gimple, (L)->may_misalign_stmts) > 0 313*e4b17023SJohn Marino #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \ 314*e4b17023SJohn Marino VEC_length (ddr_p, (L)->may_alias_ddrs) > 0 315*e4b17023SJohn Marino 316*e4b17023SJohn Marino #define NITERS_KNOWN_P(n) \ 317*e4b17023SJohn Marino (host_integerp ((n),0) \ 318*e4b17023SJohn Marino && TREE_INT_CST_LOW ((n)) > 0) 319*e4b17023SJohn Marino 320*e4b17023SJohn Marino #define LOOP_VINFO_NITERS_KNOWN_P(L) \ 321*e4b17023SJohn Marino NITERS_KNOWN_P((L)->num_iters) 322*e4b17023SJohn Marino 323*e4b17023SJohn Marino static inline loop_vec_info 324*e4b17023SJohn Marino loop_vec_info_for_loop (struct loop *loop) 325*e4b17023SJohn Marino { 326*e4b17023SJohn Marino return (loop_vec_info) loop->aux; 327*e4b17023SJohn Marino } 328*e4b17023SJohn Marino 329*e4b17023SJohn Marino static inline bool 330*e4b17023SJohn Marino nested_in_vect_loop_p (struct loop *loop, gimple stmt) 331*e4b17023SJohn Marino { 332*e4b17023SJohn Marino return (loop->inner 333*e4b17023SJohn Marino && (loop->inner == (gimple_bb (stmt))->loop_father)); 334*e4b17023SJohn Marino } 335*e4b17023SJohn Marino 336*e4b17023SJohn Marino typedef struct _bb_vec_info { 337*e4b17023SJohn Marino 338*e4b17023SJohn Marino basic_block bb; 339*e4b17023SJohn Marino /* All interleaving chains of stores in the basic block, represented by the 340*e4b17023SJohn Marino first stmt in the chain. */ 341*e4b17023SJohn Marino VEC(gimple, heap) *strided_stores; 342*e4b17023SJohn Marino 343*e4b17023SJohn Marino /* All SLP instances in the basic block. This is a subset of the set of 344*e4b17023SJohn Marino STRIDED_STORES of the basic block. */ 345*e4b17023SJohn Marino VEC(slp_instance, heap) *slp_instances; 346*e4b17023SJohn Marino 347*e4b17023SJohn Marino /* All data references in the basic block. */ 348*e4b17023SJohn Marino VEC (data_reference_p, heap) *datarefs; 349*e4b17023SJohn Marino 350*e4b17023SJohn Marino /* All data dependences in the basic block. */ 351*e4b17023SJohn Marino VEC (ddr_p, heap) *ddrs; 352*e4b17023SJohn Marino } *bb_vec_info; 353*e4b17023SJohn Marino 354*e4b17023SJohn Marino #define BB_VINFO_BB(B) (B)->bb 355*e4b17023SJohn Marino #define BB_VINFO_STRIDED_STORES(B) (B)->strided_stores 356*e4b17023SJohn Marino #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances 357*e4b17023SJohn Marino #define BB_VINFO_DATAREFS(B) (B)->datarefs 358*e4b17023SJohn Marino #define BB_VINFO_DDRS(B) (B)->ddrs 359*e4b17023SJohn Marino 360*e4b17023SJohn Marino static inline bb_vec_info 361*e4b17023SJohn Marino vec_info_for_bb (basic_block bb) 362*e4b17023SJohn Marino { 363*e4b17023SJohn Marino return (bb_vec_info) bb->aux; 364*e4b17023SJohn Marino } 365*e4b17023SJohn Marino 366*e4b17023SJohn Marino /*-----------------------------------------------------------------*/ 367*e4b17023SJohn Marino /* Info on vectorized defs. */ 368*e4b17023SJohn Marino /*-----------------------------------------------------------------*/ 369*e4b17023SJohn Marino enum stmt_vec_info_type { 370*e4b17023SJohn Marino undef_vec_info_type = 0, 371*e4b17023SJohn Marino load_vec_info_type, 372*e4b17023SJohn Marino store_vec_info_type, 373*e4b17023SJohn Marino shift_vec_info_type, 374*e4b17023SJohn Marino op_vec_info_type, 375*e4b17023SJohn Marino call_vec_info_type, 376*e4b17023SJohn Marino assignment_vec_info_type, 377*e4b17023SJohn Marino condition_vec_info_type, 378*e4b17023SJohn Marino reduc_vec_info_type, 379*e4b17023SJohn Marino induc_vec_info_type, 380*e4b17023SJohn Marino type_promotion_vec_info_type, 381*e4b17023SJohn Marino type_demotion_vec_info_type, 382*e4b17023SJohn Marino type_conversion_vec_info_type, 383*e4b17023SJohn Marino loop_exit_ctrl_vec_info_type 384*e4b17023SJohn Marino }; 385*e4b17023SJohn Marino 386*e4b17023SJohn Marino /* Indicates whether/how a variable is used in the scope of loop/basic 387*e4b17023SJohn Marino block. */ 388*e4b17023SJohn Marino enum vect_relevant { 389*e4b17023SJohn Marino vect_unused_in_scope = 0, 390*e4b17023SJohn Marino /* The def is in the inner loop, and the use is in the outer loop, and the 391*e4b17023SJohn Marino use is a reduction stmt. */ 392*e4b17023SJohn Marino vect_used_in_outer_by_reduction, 393*e4b17023SJohn Marino /* The def is in the inner loop, and the use is in the outer loop (and is 394*e4b17023SJohn Marino not part of reduction). */ 395*e4b17023SJohn Marino vect_used_in_outer, 396*e4b17023SJohn Marino 397*e4b17023SJohn Marino /* defs that feed computations that end up (only) in a reduction. These 398*e4b17023SJohn Marino defs may be used by non-reduction stmts, but eventually, any 399*e4b17023SJohn Marino computations/values that are affected by these defs are used to compute 400*e4b17023SJohn Marino a reduction (i.e. don't get stored to memory, for example). We use this 401*e4b17023SJohn Marino to identify computations that we can change the order in which they are 402*e4b17023SJohn Marino computed. */ 403*e4b17023SJohn Marino vect_used_by_reduction, 404*e4b17023SJohn Marino 405*e4b17023SJohn Marino vect_used_in_scope 406*e4b17023SJohn Marino }; 407*e4b17023SJohn Marino 408*e4b17023SJohn Marino /* The type of vectorization that can be applied to the stmt: regular loop-based 409*e4b17023SJohn Marino vectorization; pure SLP - the stmt is a part of SLP instances and does not 410*e4b17023SJohn Marino have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is 411*e4b17023SJohn Marino a part of SLP instance and also must be loop-based vectorized, since it has 412*e4b17023SJohn Marino uses outside SLP sequences. 413*e4b17023SJohn Marino 414*e4b17023SJohn Marino In the loop context the meanings of pure and hybrid SLP are slightly 415*e4b17023SJohn Marino different. By saying that pure SLP is applied to the loop, we mean that we 416*e4b17023SJohn Marino exploit only intra-iteration parallelism in the loop; i.e., the loop can be 417*e4b17023SJohn Marino vectorized without doing any conceptual unrolling, cause we don't pack 418*e4b17023SJohn Marino together stmts from different iterations, only within a single iteration. 419*e4b17023SJohn Marino Loop hybrid SLP means that we exploit both intra-iteration and 420*e4b17023SJohn Marino inter-iteration parallelism (e.g., number of elements in the vector is 4 421*e4b17023SJohn Marino and the slp-group-size is 2, in which case we don't have enough parallelism 422*e4b17023SJohn Marino within an iteration, so we obtain the rest of the parallelism from subsequent 423*e4b17023SJohn Marino iterations by unrolling the loop by 2). */ 424*e4b17023SJohn Marino enum slp_vect_type { 425*e4b17023SJohn Marino loop_vect = 0, 426*e4b17023SJohn Marino pure_slp, 427*e4b17023SJohn Marino hybrid 428*e4b17023SJohn Marino }; 429*e4b17023SJohn Marino 430*e4b17023SJohn Marino 431*e4b17023SJohn Marino typedef struct data_reference *dr_p; 432*e4b17023SJohn Marino DEF_VEC_P(dr_p); 433*e4b17023SJohn Marino DEF_VEC_ALLOC_P(dr_p,heap); 434*e4b17023SJohn Marino 435*e4b17023SJohn Marino typedef struct _stmt_vec_info { 436*e4b17023SJohn Marino 437*e4b17023SJohn Marino enum stmt_vec_info_type type; 438*e4b17023SJohn Marino 439*e4b17023SJohn Marino /* Indicates whether this stmts is part of a computation whose result is 440*e4b17023SJohn Marino used outside the loop. */ 441*e4b17023SJohn Marino bool live; 442*e4b17023SJohn Marino 443*e4b17023SJohn Marino /* Stmt is part of some pattern (computation idiom) */ 444*e4b17023SJohn Marino bool in_pattern_p; 445*e4b17023SJohn Marino 446*e4b17023SJohn Marino /* For loads only, if there is a store with the same location, this field is 447*e4b17023SJohn Marino TRUE. */ 448*e4b17023SJohn Marino bool read_write_dep; 449*e4b17023SJohn Marino 450*e4b17023SJohn Marino /* The stmt to which this info struct refers to. */ 451*e4b17023SJohn Marino gimple stmt; 452*e4b17023SJohn Marino 453*e4b17023SJohn Marino /* The loop_vec_info with respect to which STMT is vectorized. */ 454*e4b17023SJohn Marino loop_vec_info loop_vinfo; 455*e4b17023SJohn Marino 456*e4b17023SJohn Marino /* The vector type to be used for the LHS of this statement. */ 457*e4b17023SJohn Marino tree vectype; 458*e4b17023SJohn Marino 459*e4b17023SJohn Marino /* The vectorized version of the stmt. */ 460*e4b17023SJohn Marino gimple vectorized_stmt; 461*e4b17023SJohn Marino 462*e4b17023SJohn Marino 463*e4b17023SJohn Marino /** The following is relevant only for stmts that contain a non-scalar 464*e4b17023SJohn Marino data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have 465*e4b17023SJohn Marino at most one such data-ref. **/ 466*e4b17023SJohn Marino 467*e4b17023SJohn Marino /* Information about the data-ref (access function, etc), 468*e4b17023SJohn Marino relative to the inner-most containing loop. */ 469*e4b17023SJohn Marino struct data_reference *data_ref_info; 470*e4b17023SJohn Marino 471*e4b17023SJohn Marino /* Information about the data-ref relative to this loop 472*e4b17023SJohn Marino nest (the loop that is being considered for vectorization). */ 473*e4b17023SJohn Marino tree dr_base_address; 474*e4b17023SJohn Marino tree dr_init; 475*e4b17023SJohn Marino tree dr_offset; 476*e4b17023SJohn Marino tree dr_step; 477*e4b17023SJohn Marino tree dr_aligned_to; 478*e4b17023SJohn Marino 479*e4b17023SJohn Marino /* For loop PHI nodes, the evolution part of it. This makes sure 480*e4b17023SJohn Marino this information is still available in vect_update_ivs_after_vectorizer 481*e4b17023SJohn Marino where we may not be able to re-analyze the PHI nodes evolution as 482*e4b17023SJohn Marino peeling for the prologue loop can make it unanalyzable. The evolution 483*e4b17023SJohn Marino part is still correct though. */ 484*e4b17023SJohn Marino tree loop_phi_evolution_part; 485*e4b17023SJohn Marino 486*e4b17023SJohn Marino /* Used for various bookkeeping purposes, generally holding a pointer to 487*e4b17023SJohn Marino some other stmt S that is in some way "related" to this stmt. 488*e4b17023SJohn Marino Current use of this field is: 489*e4b17023SJohn Marino If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is 490*e4b17023SJohn Marino true): S is the "pattern stmt" that represents (and replaces) the 491*e4b17023SJohn Marino sequence of stmts that constitutes the pattern. Similarly, the 492*e4b17023SJohn Marino related_stmt of the "pattern stmt" points back to this stmt (which is 493*e4b17023SJohn Marino the last stmt in the original sequence of stmts that constitutes the 494*e4b17023SJohn Marino pattern). */ 495*e4b17023SJohn Marino gimple related_stmt; 496*e4b17023SJohn Marino 497*e4b17023SJohn Marino /* Used to keep a sequence of def stmts of a pattern stmt if such exists. */ 498*e4b17023SJohn Marino gimple_seq pattern_def_seq; 499*e4b17023SJohn Marino 500*e4b17023SJohn Marino /* List of datarefs that are known to have the same alignment as the dataref 501*e4b17023SJohn Marino of this stmt. */ 502*e4b17023SJohn Marino VEC(dr_p,heap) *same_align_refs; 503*e4b17023SJohn Marino 504*e4b17023SJohn Marino /* Classify the def of this stmt. */ 505*e4b17023SJohn Marino enum vect_def_type def_type; 506*e4b17023SJohn Marino 507*e4b17023SJohn Marino /* Whether the stmt is SLPed, loop-based vectorized, or both. */ 508*e4b17023SJohn Marino enum slp_vect_type slp_type; 509*e4b17023SJohn Marino 510*e4b17023SJohn Marino /* Interleaving and reduction chains info. */ 511*e4b17023SJohn Marino /* First element in the group. */ 512*e4b17023SJohn Marino gimple first_element; 513*e4b17023SJohn Marino /* Pointer to the next element in the group. */ 514*e4b17023SJohn Marino gimple next_element; 515*e4b17023SJohn Marino /* For data-refs, in case that two or more stmts share data-ref, this is the 516*e4b17023SJohn Marino pointer to the previously detected stmt with the same dr. */ 517*e4b17023SJohn Marino gimple same_dr_stmt; 518*e4b17023SJohn Marino /* The size of the group. */ 519*e4b17023SJohn Marino unsigned int size; 520*e4b17023SJohn Marino /* For stores, number of stores from this group seen. We vectorize the last 521*e4b17023SJohn Marino one. */ 522*e4b17023SJohn Marino unsigned int store_count; 523*e4b17023SJohn Marino /* For loads only, the gap from the previous load. For consecutive loads, GAP 524*e4b17023SJohn Marino is 1. */ 525*e4b17023SJohn Marino unsigned int gap; 526*e4b17023SJohn Marino 527*e4b17023SJohn Marino /* Not all stmts in the loop need to be vectorized. e.g, the increment 528*e4b17023SJohn Marino of the loop induction variable and computation of array indexes. relevant 529*e4b17023SJohn Marino indicates whether the stmt needs to be vectorized. */ 530*e4b17023SJohn Marino enum vect_relevant relevant; 531*e4b17023SJohn Marino 532*e4b17023SJohn Marino /* Vectorization costs associated with statement. */ 533*e4b17023SJohn Marino struct 534*e4b17023SJohn Marino { 535*e4b17023SJohn Marino int outside_of_loop; /* Statements generated outside loop. */ 536*e4b17023SJohn Marino int inside_of_loop; /* Statements generated inside loop. */ 537*e4b17023SJohn Marino } cost; 538*e4b17023SJohn Marino 539*e4b17023SJohn Marino /* The bb_vec_info with respect to which STMT is vectorized. */ 540*e4b17023SJohn Marino bb_vec_info bb_vinfo; 541*e4b17023SJohn Marino 542*e4b17023SJohn Marino /* Is this statement vectorizable or should it be skipped in (partial) 543*e4b17023SJohn Marino vectorization. */ 544*e4b17023SJohn Marino bool vectorizable; 545*e4b17023SJohn Marino 546*e4b17023SJohn Marino /* For loads only, true if this is a gather load. */ 547*e4b17023SJohn Marino bool gather_p; 548*e4b17023SJohn Marino } *stmt_vec_info; 549*e4b17023SJohn Marino 550*e4b17023SJohn Marino /* Access Functions. */ 551*e4b17023SJohn Marino #define STMT_VINFO_TYPE(S) (S)->type 552*e4b17023SJohn Marino #define STMT_VINFO_STMT(S) (S)->stmt 553*e4b17023SJohn Marino #define STMT_VINFO_LOOP_VINFO(S) (S)->loop_vinfo 554*e4b17023SJohn Marino #define STMT_VINFO_BB_VINFO(S) (S)->bb_vinfo 555*e4b17023SJohn Marino #define STMT_VINFO_RELEVANT(S) (S)->relevant 556*e4b17023SJohn Marino #define STMT_VINFO_LIVE_P(S) (S)->live 557*e4b17023SJohn Marino #define STMT_VINFO_VECTYPE(S) (S)->vectype 558*e4b17023SJohn Marino #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt 559*e4b17023SJohn Marino #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable 560*e4b17023SJohn Marino #define STMT_VINFO_DATA_REF(S) (S)->data_ref_info 561*e4b17023SJohn Marino #define STMT_VINFO_GATHER_P(S) (S)->gather_p 562*e4b17023SJohn Marino 563*e4b17023SJohn Marino #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_base_address 564*e4b17023SJohn Marino #define STMT_VINFO_DR_INIT(S) (S)->dr_init 565*e4b17023SJohn Marino #define STMT_VINFO_DR_OFFSET(S) (S)->dr_offset 566*e4b17023SJohn Marino #define STMT_VINFO_DR_STEP(S) (S)->dr_step 567*e4b17023SJohn Marino #define STMT_VINFO_DR_ALIGNED_TO(S) (S)->dr_aligned_to 568*e4b17023SJohn Marino 569*e4b17023SJohn Marino #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p 570*e4b17023SJohn Marino #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt 571*e4b17023SJohn Marino #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq 572*e4b17023SJohn Marino #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs 573*e4b17023SJohn Marino #define STMT_VINFO_DEF_TYPE(S) (S)->def_type 574*e4b17023SJohn Marino #define STMT_VINFO_GROUP_FIRST_ELEMENT(S) (S)->first_element 575*e4b17023SJohn Marino #define STMT_VINFO_GROUP_NEXT_ELEMENT(S) (S)->next_element 576*e4b17023SJohn Marino #define STMT_VINFO_GROUP_SIZE(S) (S)->size 577*e4b17023SJohn Marino #define STMT_VINFO_GROUP_STORE_COUNT(S) (S)->store_count 578*e4b17023SJohn Marino #define STMT_VINFO_GROUP_GAP(S) (S)->gap 579*e4b17023SJohn Marino #define STMT_VINFO_GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt 580*e4b17023SJohn Marino #define STMT_VINFO_GROUP_READ_WRITE_DEPENDENCE(S) (S)->read_write_dep 581*e4b17023SJohn Marino #define STMT_VINFO_STRIDED_ACCESS(S) ((S)->first_element != NULL && (S)->data_ref_info) 582*e4b17023SJohn Marino #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part 583*e4b17023SJohn Marino 584*e4b17023SJohn Marino #define GROUP_FIRST_ELEMENT(S) (S)->first_element 585*e4b17023SJohn Marino #define GROUP_NEXT_ELEMENT(S) (S)->next_element 586*e4b17023SJohn Marino #define GROUP_SIZE(S) (S)->size 587*e4b17023SJohn Marino #define GROUP_STORE_COUNT(S) (S)->store_count 588*e4b17023SJohn Marino #define GROUP_GAP(S) (S)->gap 589*e4b17023SJohn Marino #define GROUP_SAME_DR_STMT(S) (S)->same_dr_stmt 590*e4b17023SJohn Marino #define GROUP_READ_WRITE_DEPENDENCE(S) (S)->read_write_dep 591*e4b17023SJohn Marino 592*e4b17023SJohn Marino #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope) 593*e4b17023SJohn Marino #define STMT_VINFO_OUTSIDE_OF_LOOP_COST(S) (S)->cost.outside_of_loop 594*e4b17023SJohn Marino #define STMT_VINFO_INSIDE_OF_LOOP_COST(S) (S)->cost.inside_of_loop 595*e4b17023SJohn Marino 596*e4b17023SJohn Marino #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid) 597*e4b17023SJohn Marino #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp) 598*e4b17023SJohn Marino #define STMT_SLP_TYPE(S) (S)->slp_type 599*e4b17023SJohn Marino 600*e4b17023SJohn Marino #define VECT_MAX_COST 1000 601*e4b17023SJohn Marino 602*e4b17023SJohn Marino /* The maximum number of intermediate steps required in multi-step type 603*e4b17023SJohn Marino conversion. */ 604*e4b17023SJohn Marino #define MAX_INTERM_CVT_STEPS 3 605*e4b17023SJohn Marino 606*e4b17023SJohn Marino /* The maximum vectorization factor supported by any target (V32QI). */ 607*e4b17023SJohn Marino #define MAX_VECTORIZATION_FACTOR 32 608*e4b17023SJohn Marino 609*e4b17023SJohn Marino /* Avoid GTY(()) on stmt_vec_info. */ 610*e4b17023SJohn Marino typedef void *vec_void_p; 611*e4b17023SJohn Marino DEF_VEC_P (vec_void_p); 612*e4b17023SJohn Marino DEF_VEC_ALLOC_P (vec_void_p, heap); 613*e4b17023SJohn Marino 614*e4b17023SJohn Marino extern VEC(vec_void_p,heap) *stmt_vec_info_vec; 615*e4b17023SJohn Marino 616*e4b17023SJohn Marino void init_stmt_vec_info_vec (void); 617*e4b17023SJohn Marino void free_stmt_vec_info_vec (void); 618*e4b17023SJohn Marino 619*e4b17023SJohn Marino /* Return a stmt_vec_info corresponding to STMT. */ 620*e4b17023SJohn Marino 621*e4b17023SJohn Marino static inline stmt_vec_info 622*e4b17023SJohn Marino vinfo_for_stmt (gimple stmt) 623*e4b17023SJohn Marino { 624*e4b17023SJohn Marino unsigned int uid = gimple_uid (stmt); 625*e4b17023SJohn Marino if (uid == 0) 626*e4b17023SJohn Marino return NULL; 627*e4b17023SJohn Marino 628*e4b17023SJohn Marino return (stmt_vec_info) VEC_index (vec_void_p, stmt_vec_info_vec, uid - 1); 629*e4b17023SJohn Marino } 630*e4b17023SJohn Marino 631*e4b17023SJohn Marino /* Set vectorizer information INFO for STMT. */ 632*e4b17023SJohn Marino 633*e4b17023SJohn Marino static inline void 634*e4b17023SJohn Marino set_vinfo_for_stmt (gimple stmt, stmt_vec_info info) 635*e4b17023SJohn Marino { 636*e4b17023SJohn Marino unsigned int uid = gimple_uid (stmt); 637*e4b17023SJohn Marino if (uid == 0) 638*e4b17023SJohn Marino { 639*e4b17023SJohn Marino gcc_checking_assert (info); 640*e4b17023SJohn Marino uid = VEC_length (vec_void_p, stmt_vec_info_vec) + 1; 641*e4b17023SJohn Marino gimple_set_uid (stmt, uid); 642*e4b17023SJohn Marino VEC_safe_push (vec_void_p, heap, stmt_vec_info_vec, (vec_void_p) info); 643*e4b17023SJohn Marino } 644*e4b17023SJohn Marino else 645*e4b17023SJohn Marino VEC_replace (vec_void_p, stmt_vec_info_vec, uid - 1, (vec_void_p) info); 646*e4b17023SJohn Marino } 647*e4b17023SJohn Marino 648*e4b17023SJohn Marino /* Return the earlier statement between STMT1 and STMT2. */ 649*e4b17023SJohn Marino 650*e4b17023SJohn Marino static inline gimple 651*e4b17023SJohn Marino get_earlier_stmt (gimple stmt1, gimple stmt2) 652*e4b17023SJohn Marino { 653*e4b17023SJohn Marino unsigned int uid1, uid2; 654*e4b17023SJohn Marino 655*e4b17023SJohn Marino if (stmt1 == NULL) 656*e4b17023SJohn Marino return stmt2; 657*e4b17023SJohn Marino 658*e4b17023SJohn Marino if (stmt2 == NULL) 659*e4b17023SJohn Marino return stmt1; 660*e4b17023SJohn Marino 661*e4b17023SJohn Marino uid1 = gimple_uid (stmt1); 662*e4b17023SJohn Marino uid2 = gimple_uid (stmt2); 663*e4b17023SJohn Marino 664*e4b17023SJohn Marino if (uid1 == 0 || uid2 == 0) 665*e4b17023SJohn Marino return NULL; 666*e4b17023SJohn Marino 667*e4b17023SJohn Marino gcc_checking_assert (uid1 <= VEC_length (vec_void_p, stmt_vec_info_vec) 668*e4b17023SJohn Marino && uid2 <= VEC_length (vec_void_p, stmt_vec_info_vec)); 669*e4b17023SJohn Marino 670*e4b17023SJohn Marino if (uid1 < uid2) 671*e4b17023SJohn Marino return stmt1; 672*e4b17023SJohn Marino else 673*e4b17023SJohn Marino return stmt2; 674*e4b17023SJohn Marino } 675*e4b17023SJohn Marino 676*e4b17023SJohn Marino /* Return the later statement between STMT1 and STMT2. */ 677*e4b17023SJohn Marino 678*e4b17023SJohn Marino static inline gimple 679*e4b17023SJohn Marino get_later_stmt (gimple stmt1, gimple stmt2) 680*e4b17023SJohn Marino { 681*e4b17023SJohn Marino unsigned int uid1, uid2; 682*e4b17023SJohn Marino 683*e4b17023SJohn Marino if (stmt1 == NULL) 684*e4b17023SJohn Marino return stmt2; 685*e4b17023SJohn Marino 686*e4b17023SJohn Marino if (stmt2 == NULL) 687*e4b17023SJohn Marino return stmt1; 688*e4b17023SJohn Marino 689*e4b17023SJohn Marino uid1 = gimple_uid (stmt1); 690*e4b17023SJohn Marino uid2 = gimple_uid (stmt2); 691*e4b17023SJohn Marino 692*e4b17023SJohn Marino if (uid1 == 0 || uid2 == 0) 693*e4b17023SJohn Marino return NULL; 694*e4b17023SJohn Marino 695*e4b17023SJohn Marino gcc_assert (uid1 <= VEC_length (vec_void_p, stmt_vec_info_vec)); 696*e4b17023SJohn Marino gcc_assert (uid2 <= VEC_length (vec_void_p, stmt_vec_info_vec)); 697*e4b17023SJohn Marino 698*e4b17023SJohn Marino if (uid1 > uid2) 699*e4b17023SJohn Marino return stmt1; 700*e4b17023SJohn Marino else 701*e4b17023SJohn Marino return stmt2; 702*e4b17023SJohn Marino } 703*e4b17023SJohn Marino 704*e4b17023SJohn Marino /* Return TRUE if a statement represented by STMT_INFO is a part of a 705*e4b17023SJohn Marino pattern. */ 706*e4b17023SJohn Marino 707*e4b17023SJohn Marino static inline bool 708*e4b17023SJohn Marino is_pattern_stmt_p (stmt_vec_info stmt_info) 709*e4b17023SJohn Marino { 710*e4b17023SJohn Marino gimple related_stmt; 711*e4b17023SJohn Marino stmt_vec_info related_stmt_info; 712*e4b17023SJohn Marino 713*e4b17023SJohn Marino related_stmt = STMT_VINFO_RELATED_STMT (stmt_info); 714*e4b17023SJohn Marino if (related_stmt 715*e4b17023SJohn Marino && (related_stmt_info = vinfo_for_stmt (related_stmt)) 716*e4b17023SJohn Marino && STMT_VINFO_IN_PATTERN_P (related_stmt_info)) 717*e4b17023SJohn Marino return true; 718*e4b17023SJohn Marino 719*e4b17023SJohn Marino return false; 720*e4b17023SJohn Marino } 721*e4b17023SJohn Marino 722*e4b17023SJohn Marino /* Return true if BB is a loop header. */ 723*e4b17023SJohn Marino 724*e4b17023SJohn Marino static inline bool 725*e4b17023SJohn Marino is_loop_header_bb_p (basic_block bb) 726*e4b17023SJohn Marino { 727*e4b17023SJohn Marino if (bb == (bb->loop_father)->header) 728*e4b17023SJohn Marino return true; 729*e4b17023SJohn Marino gcc_checking_assert (EDGE_COUNT (bb->preds) == 1); 730*e4b17023SJohn Marino return false; 731*e4b17023SJohn Marino } 732*e4b17023SJohn Marino 733*e4b17023SJohn Marino /* Set inside loop vectorization cost. */ 734*e4b17023SJohn Marino 735*e4b17023SJohn Marino static inline void 736*e4b17023SJohn Marino stmt_vinfo_set_inside_of_loop_cost (stmt_vec_info stmt_info, slp_tree slp_node, 737*e4b17023SJohn Marino int cost) 738*e4b17023SJohn Marino { 739*e4b17023SJohn Marino if (slp_node) 740*e4b17023SJohn Marino SLP_TREE_INSIDE_OF_LOOP_COST (slp_node) = cost; 741*e4b17023SJohn Marino else 742*e4b17023SJohn Marino STMT_VINFO_INSIDE_OF_LOOP_COST (stmt_info) = cost; 743*e4b17023SJohn Marino } 744*e4b17023SJohn Marino 745*e4b17023SJohn Marino /* Set inside loop vectorization cost. */ 746*e4b17023SJohn Marino 747*e4b17023SJohn Marino static inline void 748*e4b17023SJohn Marino stmt_vinfo_set_outside_of_loop_cost (stmt_vec_info stmt_info, slp_tree slp_node, 749*e4b17023SJohn Marino int cost) 750*e4b17023SJohn Marino { 751*e4b17023SJohn Marino if (slp_node) 752*e4b17023SJohn Marino SLP_TREE_OUTSIDE_OF_LOOP_COST (slp_node) = cost; 753*e4b17023SJohn Marino else 754*e4b17023SJohn Marino STMT_VINFO_OUTSIDE_OF_LOOP_COST (stmt_info) = cost; 755*e4b17023SJohn Marino } 756*e4b17023SJohn Marino 757*e4b17023SJohn Marino /* Return pow2 (X). */ 758*e4b17023SJohn Marino 759*e4b17023SJohn Marino static inline int 760*e4b17023SJohn Marino vect_pow2 (int x) 761*e4b17023SJohn Marino { 762*e4b17023SJohn Marino int i, res = 1; 763*e4b17023SJohn Marino 764*e4b17023SJohn Marino for (i = 0; i < x; i++) 765*e4b17023SJohn Marino res *= 2; 766*e4b17023SJohn Marino 767*e4b17023SJohn Marino return res; 768*e4b17023SJohn Marino } 769*e4b17023SJohn Marino 770*e4b17023SJohn Marino /*-----------------------------------------------------------------*/ 771*e4b17023SJohn Marino /* Info on data references alignment. */ 772*e4b17023SJohn Marino /*-----------------------------------------------------------------*/ 773*e4b17023SJohn Marino 774*e4b17023SJohn Marino /* Reflects actual alignment of first access in the vectorized loop, 775*e4b17023SJohn Marino taking into account peeling/versioning if applied. */ 776*e4b17023SJohn Marino #define DR_MISALIGNMENT(DR) ((int) (size_t) (DR)->aux) 777*e4b17023SJohn Marino #define SET_DR_MISALIGNMENT(DR, VAL) ((DR)->aux = (void *) (size_t) (VAL)) 778*e4b17023SJohn Marino 779*e4b17023SJohn Marino /* Return TRUE if the data access is aligned, and FALSE otherwise. */ 780*e4b17023SJohn Marino 781*e4b17023SJohn Marino static inline bool 782*e4b17023SJohn Marino aligned_access_p (struct data_reference *data_ref_info) 783*e4b17023SJohn Marino { 784*e4b17023SJohn Marino return (DR_MISALIGNMENT (data_ref_info) == 0); 785*e4b17023SJohn Marino } 786*e4b17023SJohn Marino 787*e4b17023SJohn Marino /* Return TRUE if the alignment of the data access is known, and FALSE 788*e4b17023SJohn Marino otherwise. */ 789*e4b17023SJohn Marino 790*e4b17023SJohn Marino static inline bool 791*e4b17023SJohn Marino known_alignment_for_access_p (struct data_reference *data_ref_info) 792*e4b17023SJohn Marino { 793*e4b17023SJohn Marino return (DR_MISALIGNMENT (data_ref_info) != -1); 794*e4b17023SJohn Marino } 795*e4b17023SJohn Marino 796*e4b17023SJohn Marino /* vect_dump will be set to stderr or dump_file if exist. */ 797*e4b17023SJohn Marino extern FILE *vect_dump; 798*e4b17023SJohn Marino extern LOC vect_loop_location; 799*e4b17023SJohn Marino 800*e4b17023SJohn Marino /*-----------------------------------------------------------------*/ 801*e4b17023SJohn Marino /* Function prototypes. */ 802*e4b17023SJohn Marino /*-----------------------------------------------------------------*/ 803*e4b17023SJohn Marino 804*e4b17023SJohn Marino /* Simple loop peeling and versioning utilities for vectorizer's purposes - 805*e4b17023SJohn Marino in tree-vect-loop-manip.c. */ 806*e4b17023SJohn Marino extern void slpeel_make_loop_iterate_ntimes (struct loop *, tree); 807*e4b17023SJohn Marino extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge); 808*e4b17023SJohn Marino extern void vect_loop_versioning (loop_vec_info, bool, tree *, gimple_seq *); 809*e4b17023SJohn Marino extern void vect_do_peeling_for_loop_bound (loop_vec_info, tree *, 810*e4b17023SJohn Marino tree, gimple_seq); 811*e4b17023SJohn Marino extern void vect_do_peeling_for_alignment (loop_vec_info); 812*e4b17023SJohn Marino extern LOC find_loop_location (struct loop *); 813*e4b17023SJohn Marino extern bool vect_can_advance_ivs_p (loop_vec_info); 814*e4b17023SJohn Marino 815*e4b17023SJohn Marino /* In tree-vect-stmts.c. */ 816*e4b17023SJohn Marino extern unsigned int current_vector_size; 817*e4b17023SJohn Marino extern tree get_vectype_for_scalar_type (tree); 818*e4b17023SJohn Marino extern tree get_same_sized_vectype (tree, tree); 819*e4b17023SJohn Marino extern bool vect_is_simple_use (tree, gimple, loop_vec_info, 820*e4b17023SJohn Marino bb_vec_info, gimple *, 821*e4b17023SJohn Marino tree *, enum vect_def_type *); 822*e4b17023SJohn Marino extern bool vect_is_simple_use_1 (tree, gimple, loop_vec_info, 823*e4b17023SJohn Marino bb_vec_info, gimple *, 824*e4b17023SJohn Marino tree *, enum vect_def_type *, tree *); 825*e4b17023SJohn Marino extern bool supportable_widening_operation (enum tree_code, gimple, tree, tree, 826*e4b17023SJohn Marino tree *, tree *, enum tree_code *, 827*e4b17023SJohn Marino enum tree_code *, int *, 828*e4b17023SJohn Marino VEC (tree, heap) **); 829*e4b17023SJohn Marino extern bool supportable_narrowing_operation (enum tree_code, tree, tree, 830*e4b17023SJohn Marino enum tree_code *, 831*e4b17023SJohn Marino int *, VEC (tree, heap) **); 832*e4b17023SJohn Marino extern stmt_vec_info new_stmt_vec_info (gimple stmt, loop_vec_info, 833*e4b17023SJohn Marino bb_vec_info); 834*e4b17023SJohn Marino extern void free_stmt_vec_info (gimple stmt); 835*e4b17023SJohn Marino extern tree vectorizable_function (gimple, tree, tree); 836*e4b17023SJohn Marino extern void vect_model_simple_cost (stmt_vec_info, int, enum vect_def_type *, 837*e4b17023SJohn Marino slp_tree); 838*e4b17023SJohn Marino extern void vect_model_store_cost (stmt_vec_info, int, bool, 839*e4b17023SJohn Marino enum vect_def_type, slp_tree); 840*e4b17023SJohn Marino extern void vect_model_load_cost (stmt_vec_info, int, bool, slp_tree); 841*e4b17023SJohn Marino extern void vect_finish_stmt_generation (gimple, gimple, 842*e4b17023SJohn Marino gimple_stmt_iterator *); 843*e4b17023SJohn Marino extern bool vect_mark_stmts_to_be_vectorized (loop_vec_info); 844*e4b17023SJohn Marino extern int cost_for_stmt (gimple); 845*e4b17023SJohn Marino extern tree vect_get_vec_def_for_operand (tree, gimple, tree *); 846*e4b17023SJohn Marino extern tree vect_init_vector (gimple, tree, tree, 847*e4b17023SJohn Marino gimple_stmt_iterator *); 848*e4b17023SJohn Marino extern tree vect_get_vec_def_for_stmt_copy (enum vect_def_type, tree); 849*e4b17023SJohn Marino extern bool vect_transform_stmt (gimple, gimple_stmt_iterator *, 850*e4b17023SJohn Marino bool *, slp_tree, slp_instance); 851*e4b17023SJohn Marino extern void vect_remove_stores (gimple); 852*e4b17023SJohn Marino extern bool vect_analyze_stmt (gimple, bool *, slp_tree); 853*e4b17023SJohn Marino extern bool vectorizable_condition (gimple, gimple_stmt_iterator *, gimple *, 854*e4b17023SJohn Marino tree, int, slp_tree); 855*e4b17023SJohn Marino extern void vect_get_load_cost (struct data_reference *, int, bool, 856*e4b17023SJohn Marino unsigned int *, unsigned int *); 857*e4b17023SJohn Marino extern void vect_get_store_cost (struct data_reference *, int, unsigned int *); 858*e4b17023SJohn Marino extern bool vect_supportable_shift (enum tree_code, tree); 859*e4b17023SJohn Marino extern void vect_get_vec_defs (tree, tree, gimple, VEC (tree, heap) **, 860*e4b17023SJohn Marino VEC (tree, heap) **, slp_tree, int); 861*e4b17023SJohn Marino extern tree vect_gen_perm_mask (tree, unsigned char *); 862*e4b17023SJohn Marino 863*e4b17023SJohn Marino /* In tree-vect-data-refs.c. */ 864*e4b17023SJohn Marino extern bool vect_can_force_dr_alignment_p (const_tree, unsigned int); 865*e4b17023SJohn Marino extern enum dr_alignment_support vect_supportable_dr_alignment 866*e4b17023SJohn Marino (struct data_reference *, bool); 867*e4b17023SJohn Marino extern tree vect_get_smallest_scalar_type (gimple, HOST_WIDE_INT *, 868*e4b17023SJohn Marino HOST_WIDE_INT *); 869*e4b17023SJohn Marino extern bool vect_analyze_data_ref_dependences (loop_vec_info, bb_vec_info, 870*e4b17023SJohn Marino int *); 871*e4b17023SJohn Marino extern bool vect_enhance_data_refs_alignment (loop_vec_info); 872*e4b17023SJohn Marino extern bool vect_analyze_data_refs_alignment (loop_vec_info, bb_vec_info); 873*e4b17023SJohn Marino extern bool vect_verify_datarefs_alignment (loop_vec_info, bb_vec_info); 874*e4b17023SJohn Marino extern bool vect_analyze_data_ref_accesses (loop_vec_info, bb_vec_info); 875*e4b17023SJohn Marino extern bool vect_prune_runtime_alias_test_list (loop_vec_info); 876*e4b17023SJohn Marino extern tree vect_check_gather (gimple, loop_vec_info, tree *, tree *, 877*e4b17023SJohn Marino int *); 878*e4b17023SJohn Marino extern bool vect_analyze_data_refs (loop_vec_info, bb_vec_info, int *); 879*e4b17023SJohn Marino extern tree vect_create_data_ref_ptr (gimple, tree, struct loop *, tree, 880*e4b17023SJohn Marino tree *, gimple_stmt_iterator *, 881*e4b17023SJohn Marino gimple *, bool, bool *); 882*e4b17023SJohn Marino extern tree bump_vector_ptr (tree, gimple, gimple_stmt_iterator *, gimple, tree); 883*e4b17023SJohn Marino extern tree vect_create_destination_var (tree, tree); 884*e4b17023SJohn Marino extern bool vect_strided_store_supported (tree, unsigned HOST_WIDE_INT); 885*e4b17023SJohn Marino extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT); 886*e4b17023SJohn Marino extern bool vect_strided_load_supported (tree, unsigned HOST_WIDE_INT); 887*e4b17023SJohn Marino extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT); 888*e4b17023SJohn Marino extern void vect_permute_store_chain (VEC(tree,heap) *,unsigned int, gimple, 889*e4b17023SJohn Marino gimple_stmt_iterator *, VEC(tree,heap) **); 890*e4b17023SJohn Marino extern tree vect_setup_realignment (gimple, gimple_stmt_iterator *, tree *, 891*e4b17023SJohn Marino enum dr_alignment_support, tree, 892*e4b17023SJohn Marino struct loop **); 893*e4b17023SJohn Marino extern void vect_transform_strided_load (gimple, VEC(tree,heap) *, int, 894*e4b17023SJohn Marino gimple_stmt_iterator *); 895*e4b17023SJohn Marino extern void vect_record_strided_load_vectors (gimple, VEC(tree,heap) *); 896*e4b17023SJohn Marino extern int vect_get_place_in_interleaving_chain (gimple, gimple); 897*e4b17023SJohn Marino extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *); 898*e4b17023SJohn Marino extern tree vect_create_addr_base_for_vector_ref (gimple, gimple_seq *, 899*e4b17023SJohn Marino tree, struct loop *); 900*e4b17023SJohn Marino 901*e4b17023SJohn Marino /* In tree-vect-loop.c. */ 902*e4b17023SJohn Marino /* FORNOW: Used in tree-parloops.c. */ 903*e4b17023SJohn Marino extern void destroy_loop_vec_info (loop_vec_info, bool); 904*e4b17023SJohn Marino extern gimple vect_force_simple_reduction (loop_vec_info, gimple, bool, bool *); 905*e4b17023SJohn Marino /* Drive for loop analysis stage. */ 906*e4b17023SJohn Marino extern loop_vec_info vect_analyze_loop (struct loop *); 907*e4b17023SJohn Marino /* Drive for loop transformation stage. */ 908*e4b17023SJohn Marino extern void vect_transform_loop (loop_vec_info); 909*e4b17023SJohn Marino extern loop_vec_info vect_analyze_loop_form (struct loop *); 910*e4b17023SJohn Marino extern bool vectorizable_live_operation (gimple, gimple_stmt_iterator *, 911*e4b17023SJohn Marino gimple *); 912*e4b17023SJohn Marino extern bool vectorizable_reduction (gimple, gimple_stmt_iterator *, gimple *, 913*e4b17023SJohn Marino slp_tree); 914*e4b17023SJohn Marino extern bool vectorizable_induction (gimple, gimple_stmt_iterator *, gimple *); 915*e4b17023SJohn Marino extern int vect_estimate_min_profitable_iters (loop_vec_info); 916*e4b17023SJohn Marino extern tree get_initial_def_for_reduction (gimple, tree, tree *); 917*e4b17023SJohn Marino extern int vect_min_worthwhile_factor (enum tree_code); 918*e4b17023SJohn Marino extern int vect_get_known_peeling_cost (loop_vec_info, int, int *, int); 919*e4b17023SJohn Marino extern int vect_get_single_scalar_iteraion_cost (loop_vec_info); 920*e4b17023SJohn Marino 921*e4b17023SJohn Marino /* In tree-vect-slp.c. */ 922*e4b17023SJohn Marino extern void vect_free_slp_instance (slp_instance); 923*e4b17023SJohn Marino extern bool vect_transform_slp_perm_load (gimple, VEC (tree, heap) *, 924*e4b17023SJohn Marino gimple_stmt_iterator *, int, 925*e4b17023SJohn Marino slp_instance, bool); 926*e4b17023SJohn Marino extern bool vect_schedule_slp (loop_vec_info, bb_vec_info); 927*e4b17023SJohn Marino extern void vect_update_slp_costs_according_to_vf (loop_vec_info); 928*e4b17023SJohn Marino extern bool vect_analyze_slp (loop_vec_info, bb_vec_info); 929*e4b17023SJohn Marino extern bool vect_make_slp_decision (loop_vec_info); 930*e4b17023SJohn Marino extern void vect_detect_hybrid_slp (loop_vec_info); 931*e4b17023SJohn Marino extern void vect_get_slp_defs (VEC (tree, heap) *, slp_tree, 932*e4b17023SJohn Marino VEC (slp_void_p, heap) **, int); 933*e4b17023SJohn Marino 934*e4b17023SJohn Marino extern LOC find_bb_location (basic_block); 935*e4b17023SJohn Marino extern bb_vec_info vect_slp_analyze_bb (basic_block); 936*e4b17023SJohn Marino extern void vect_slp_transform_bb (basic_block); 937*e4b17023SJohn Marino 938*e4b17023SJohn Marino /* In tree-vect-patterns.c. */ 939*e4b17023SJohn Marino /* Pattern recognition functions. 940*e4b17023SJohn Marino Additional pattern recognition functions can (and will) be added 941*e4b17023SJohn Marino in the future. */ 942*e4b17023SJohn Marino typedef gimple (* vect_recog_func_ptr) (VEC (gimple, heap) **, tree *, tree *); 943*e4b17023SJohn Marino #define NUM_PATTERNS 10 944*e4b17023SJohn Marino void vect_pattern_recog (loop_vec_info); 945*e4b17023SJohn Marino 946*e4b17023SJohn Marino /* In tree-vectorizer.c. */ 947*e4b17023SJohn Marino unsigned vectorize_loops (void); 948*e4b17023SJohn Marino /* Vectorization debug information */ 949*e4b17023SJohn Marino extern bool vect_print_dump_info (enum vect_verbosity_levels); 950*e4b17023SJohn Marino 951*e4b17023SJohn Marino #endif /* GCC_TREE_VECTORIZER_H */ 952