tree-vectorizer.h 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661
  1. /* Vectorizer
  2. Copyright (C) 2003-2019 Free Software Foundation, Inc.
  3. Contributed by Dorit Naishlos <dorit@il.ibm.com>
  4. This file is part of GCC.
  5. GCC is free software; you can redistribute it and/or modify it under
  6. the terms of the GNU General Public License as published by the Free
  7. Software Foundation; either version 3, or (at your option) any later
  8. version.
  9. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GCC; see the file COPYING3. If not see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef GCC_TREE_VECTORIZER_H
  17. #define GCC_TREE_VECTORIZER_H
  18. typedef struct _stmt_vec_info *stmt_vec_info;
  19. #include "tree-data-ref.h"
  20. #include "tree-hash-traits.h"
  21. #include "target.h"
  22. /* Used for naming of new temporaries. */
  23. enum vect_var_kind {
  24. vect_simple_var,
  25. vect_pointer_var,
  26. vect_scalar_var,
  27. vect_mask_var
  28. };
  29. /* Defines type of operation. */
  30. enum operation_type {
  31. unary_op = 1,
  32. binary_op,
  33. ternary_op
  34. };
  35. /* Define type of available alignment support. */
  36. enum dr_alignment_support {
  37. dr_unaligned_unsupported,
  38. dr_unaligned_supported,
  39. dr_explicit_realign,
  40. dr_explicit_realign_optimized,
  41. dr_aligned
  42. };
  43. /* Define type of def-use cross-iteration cycle. */
  44. enum vect_def_type {
  45. vect_uninitialized_def = 0,
  46. vect_constant_def = 1,
  47. vect_external_def,
  48. vect_internal_def,
  49. vect_induction_def,
  50. vect_reduction_def,
  51. vect_double_reduction_def,
  52. vect_nested_cycle,
  53. vect_unknown_def_type
  54. };
  55. /* Define type of reduction. */
  56. enum vect_reduction_type {
  57. TREE_CODE_REDUCTION,
  58. COND_REDUCTION,
  59. INTEGER_INDUC_COND_REDUCTION,
  60. CONST_COND_REDUCTION,
  61. /* Retain a scalar phi and use a FOLD_EXTRACT_LAST within the loop
  62. to implement:
  63. for (int i = 0; i < VF; ++i)
  64. res = cond[i] ? val[i] : res; */
  65. EXTRACT_LAST_REDUCTION,
  66. /* Use a folding reduction within the loop to implement:
  67. for (int i = 0; i < VF; ++i)
  68. res = res OP val[i];
  69. (with no reassocation). */
  70. FOLD_LEFT_REDUCTION
  71. };
  72. #define VECTORIZABLE_CYCLE_DEF(D) (((D) == vect_reduction_def) \
  73. || ((D) == vect_double_reduction_def) \
  74. || ((D) == vect_nested_cycle))
  75. /* Structure to encapsulate information about a group of like
  76. instructions to be presented to the target cost model. */
  77. struct stmt_info_for_cost {
  78. int count;
  79. enum vect_cost_for_stmt kind;
  80. enum vect_cost_model_location where;
  81. stmt_vec_info stmt_info;
  82. int misalign;
  83. };
  84. typedef vec<stmt_info_for_cost> stmt_vector_for_cost;
  85. /* Maps base addresses to an innermost_loop_behavior that gives the maximum
  86. known alignment for that base. */
  87. typedef hash_map<tree_operand_hash,
  88. innermost_loop_behavior *> vec_base_alignments;
  89. /************************************************************************
  90. SLP
  91. ************************************************************************/
  92. typedef struct _slp_tree *slp_tree;
  93. /* A computation tree of an SLP instance. Each node corresponds to a group of
  94. stmts to be packed in a SIMD stmt. */
  95. struct _slp_tree {
  96. /* Nodes that contain def-stmts of this node statements operands. */
  97. vec<slp_tree> children;
  98. /* A group of scalar stmts to be vectorized together. */
  99. vec<stmt_vec_info> stmts;
  100. /* Load permutation relative to the stores, NULL if there is no
  101. permutation. */
  102. vec<unsigned> load_permutation;
  103. /* Vectorized stmt/s. */
  104. vec<stmt_vec_info> vec_stmts;
  105. /* Number of vector stmts that are created to replace the group of scalar
  106. stmts. It is calculated during the transformation phase as the number of
  107. scalar elements in one scalar iteration (GROUP_SIZE) multiplied by VF
  108. divided by vector size. */
  109. unsigned int vec_stmts_size;
  110. /* Reference count in the SLP graph. */
  111. unsigned int refcnt;
  112. /* The maximum number of vector elements for the subtree rooted
  113. at this node. */
  114. poly_uint64 max_nunits;
  115. /* Whether the scalar computations use two different operators. */
  116. bool two_operators;
  117. /* The DEF type of this node. */
  118. enum vect_def_type def_type;
  119. };
  120. /* SLP instance is a sequence of stmts in a loop that can be packed into
  121. SIMD stmts. */
  122. typedef struct _slp_instance {
  123. /* The root of SLP tree. */
  124. slp_tree root;
  125. /* Size of groups of scalar stmts that will be replaced by SIMD stmt/s. */
  126. unsigned int group_size;
  127. /* The unrolling factor required to vectorized this SLP instance. */
  128. poly_uint64 unrolling_factor;
  129. /* The group of nodes that contain loads of this SLP instance. */
  130. vec<slp_tree> loads;
  131. /* The SLP node containing the reduction PHIs. */
  132. slp_tree reduc_phis;
  133. } *slp_instance;
  134. /* Access Functions. */
  135. #define SLP_INSTANCE_TREE(S) (S)->root
  136. #define SLP_INSTANCE_GROUP_SIZE(S) (S)->group_size
  137. #define SLP_INSTANCE_UNROLLING_FACTOR(S) (S)->unrolling_factor
  138. #define SLP_INSTANCE_LOADS(S) (S)->loads
  139. #define SLP_TREE_CHILDREN(S) (S)->children
  140. #define SLP_TREE_SCALAR_STMTS(S) (S)->stmts
  141. #define SLP_TREE_VEC_STMTS(S) (S)->vec_stmts
  142. #define SLP_TREE_NUMBER_OF_VEC_STMTS(S) (S)->vec_stmts_size
  143. #define SLP_TREE_LOAD_PERMUTATION(S) (S)->load_permutation
  144. #define SLP_TREE_TWO_OPERATORS(S) (S)->two_operators
  145. #define SLP_TREE_DEF_TYPE(S) (S)->def_type
  146. /* Describes two objects whose addresses must be unequal for the vectorized
  147. loop to be valid. */
  148. typedef std::pair<tree, tree> vec_object_pair;
  149. /* Records that vectorization is only possible if abs (EXPR) >= MIN_VALUE.
  150. UNSIGNED_P is true if we can assume that abs (EXPR) == EXPR. */
  151. struct vec_lower_bound {
  152. vec_lower_bound () {}
  153. vec_lower_bound (tree e, bool u, poly_uint64 m)
  154. : expr (e), unsigned_p (u), min_value (m) {}
  155. tree expr;
  156. bool unsigned_p;
  157. poly_uint64 min_value;
  158. };
  159. /* Vectorizer state shared between different analyses like vector sizes
  160. of the same CFG region. */
  161. struct vec_info_shared {
  162. vec_info_shared();
  163. ~vec_info_shared();
  164. void save_datarefs();
  165. void check_datarefs();
  166. /* All data references. Freed by free_data_refs, so not an auto_vec. */
  167. vec<data_reference_p> datarefs;
  168. vec<data_reference> datarefs_copy;
  169. /* The loop nest in which the data dependences are computed. */
  170. auto_vec<loop_p> loop_nest;
  171. /* All data dependences. Freed by free_dependence_relations, so not
  172. an auto_vec. */
  173. vec<ddr_p> ddrs;
  174. };
  175. /* Vectorizer state common between loop and basic-block vectorization. */
  176. struct vec_info {
  177. enum vec_kind { bb, loop };
  178. vec_info (vec_kind, void *, vec_info_shared *);
  179. ~vec_info ();
  180. stmt_vec_info add_stmt (gimple *);
  181. stmt_vec_info lookup_stmt (gimple *);
  182. stmt_vec_info lookup_def (tree);
  183. stmt_vec_info lookup_single_use (tree);
  184. struct dr_vec_info *lookup_dr (data_reference *);
  185. void move_dr (stmt_vec_info, stmt_vec_info);
  186. void remove_stmt (stmt_vec_info);
  187. void replace_stmt (gimple_stmt_iterator *, stmt_vec_info, gimple *);
  188. /* The type of vectorization. */
  189. vec_kind kind;
  190. /* Shared vectorizer state. */
  191. vec_info_shared *shared;
  192. /* The mapping of GIMPLE UID to stmt_vec_info. */
  193. vec<stmt_vec_info> stmt_vec_infos;
  194. /* All SLP instances. */
  195. auto_vec<slp_instance> slp_instances;
  196. /* Maps base addresses to an innermost_loop_behavior that gives the maximum
  197. known alignment for that base. */
  198. vec_base_alignments base_alignments;
  199. /* All interleaving chains of stores, represented by the first
  200. stmt in the chain. */
  201. auto_vec<stmt_vec_info> grouped_stores;
  202. /* Cost data used by the target cost model. */
  203. void *target_cost_data;
  204. private:
  205. stmt_vec_info new_stmt_vec_info (gimple *stmt);
  206. void set_vinfo_for_stmt (gimple *, stmt_vec_info);
  207. void free_stmt_vec_infos ();
  208. void free_stmt_vec_info (stmt_vec_info);
  209. };
  210. struct _loop_vec_info;
  211. struct _bb_vec_info;
  212. template<>
  213. template<>
  214. inline bool
  215. is_a_helper <_loop_vec_info *>::test (vec_info *i)
  216. {
  217. return i->kind == vec_info::loop;
  218. }
  219. template<>
  220. template<>
  221. inline bool
  222. is_a_helper <_bb_vec_info *>::test (vec_info *i)
  223. {
  224. return i->kind == vec_info::bb;
  225. }
  226. /* In general, we can divide the vector statements in a vectorized loop
  227. into related groups ("rgroups") and say that for each rgroup there is
  228. some nS such that the rgroup operates on nS values from one scalar
  229. iteration followed by nS values from the next. That is, if VF is the
  230. vectorization factor of the loop, the rgroup operates on a sequence:
  231. (1,1) (1,2) ... (1,nS) (2,1) ... (2,nS) ... (VF,1) ... (VF,nS)
  232. where (i,j) represents a scalar value with index j in a scalar
  233. iteration with index i.
  234. [ We use the term "rgroup" to emphasise that this grouping isn't
  235. necessarily the same as the grouping of statements used elsewhere.
  236. For example, if we implement a group of scalar loads using gather
  237. loads, we'll use a separate gather load for each scalar load, and
  238. thus each gather load will belong to its own rgroup. ]
  239. In general this sequence will occupy nV vectors concatenated
  240. together. If these vectors have nL lanes each, the total number
  241. of scalar values N is given by:
  242. N = nS * VF = nV * nL
  243. None of nS, VF, nV and nL are required to be a power of 2. nS and nV
  244. are compile-time constants but VF and nL can be variable (if the target
  245. supports variable-length vectors).
  246. In classical vectorization, each iteration of the vector loop would
  247. handle exactly VF iterations of the original scalar loop. However,
  248. in a fully-masked loop, a particular iteration of the vector loop
  249. might handle fewer than VF iterations of the scalar loop. The vector
  250. lanes that correspond to iterations of the scalar loop are said to be
  251. "active" and the other lanes are said to be "inactive".
  252. In a fully-masked loop, many rgroups need to be masked to ensure that
  253. they have no effect for the inactive lanes. Each such rgroup needs a
  254. sequence of booleans in the same order as above, but with each (i,j)
  255. replaced by a boolean that indicates whether iteration i is active.
  256. This sequence occupies nV vector masks that again have nL lanes each.
  257. Thus the mask sequence as a whole consists of VF independent booleans
  258. that are each repeated nS times.
  259. We make the simplifying assumption that if a sequence of nV masks is
  260. suitable for one (nS,nL) pair, we can reuse it for (nS/2,nL/2) by
  261. VIEW_CONVERTing it. This holds for all current targets that support
  262. fully-masked loops. For example, suppose the scalar loop is:
  263. float *f;
  264. double *d;
  265. for (int i = 0; i < n; ++i)
  266. {
  267. f[i * 2 + 0] += 1.0f;
  268. f[i * 2 + 1] += 2.0f;
  269. d[i] += 3.0;
  270. }
  271. and suppose that vectors have 256 bits. The vectorized f accesses
  272. will belong to one rgroup and the vectorized d access to another:
  273. f rgroup: nS = 2, nV = 1, nL = 8
  274. d rgroup: nS = 1, nV = 1, nL = 4
  275. VF = 4
  276. [ In this simple example the rgroups do correspond to the normal
  277. SLP grouping scheme. ]
  278. If only the first three lanes are active, the masks we need are:
  279. f rgroup: 1 1 | 1 1 | 1 1 | 0 0
  280. d rgroup: 1 | 1 | 1 | 0
  281. Here we can use a mask calculated for f's rgroup for d's, but not
  282. vice versa.
  283. Thus for each value of nV, it is enough to provide nV masks, with the
  284. mask being calculated based on the highest nL (or, equivalently, based
  285. on the highest nS) required by any rgroup with that nV. We therefore
  286. represent the entire collection of masks as a two-level table, with the
  287. first level being indexed by nV - 1 (since nV == 0 doesn't exist) and
  288. the second being indexed by the mask index 0 <= i < nV. */
  289. /* The masks needed by rgroups with nV vectors, according to the
  290. description above. */
  291. struct rgroup_masks {
  292. /* The largest nS for all rgroups that use these masks. */
  293. unsigned int max_nscalars_per_iter;
  294. /* The type of mask to use, based on the highest nS recorded above. */
  295. tree mask_type;
  296. /* A vector of nV masks, in iteration order. */
  297. vec<tree> masks;
  298. };
  299. typedef auto_vec<rgroup_masks> vec_loop_masks;
  300. /*-----------------------------------------------------------------*/
  301. /* Info on vectorized loops. */
  302. /*-----------------------------------------------------------------*/
  303. typedef struct _loop_vec_info : public vec_info {
  304. _loop_vec_info (struct loop *, vec_info_shared *);
  305. ~_loop_vec_info ();
  306. /* The loop to which this info struct refers to. */
  307. struct loop *loop;
  308. /* The loop basic blocks. */
  309. basic_block *bbs;
  310. /* Number of latch executions. */
  311. tree num_itersm1;
  312. /* Number of iterations. */
  313. tree num_iters;
  314. /* Number of iterations of the original loop. */
  315. tree num_iters_unchanged;
  316. /* Condition under which this loop is analyzed and versioned. */
  317. tree num_iters_assumptions;
  318. /* Threshold of number of iterations below which vectorzation will not be
  319. performed. It is calculated from MIN_PROFITABLE_ITERS and
  320. PARAM_MIN_VECT_LOOP_BOUND. */
  321. unsigned int th;
  322. /* When applying loop versioning, the vector form should only be used
  323. if the number of scalar iterations is >= this value, on top of all
  324. the other requirements. Ignored when loop versioning is not being
  325. used. */
  326. poly_uint64 versioning_threshold;
  327. /* Unrolling factor */
  328. poly_uint64 vectorization_factor;
  329. /* Maximum runtime vectorization factor, or MAX_VECTORIZATION_FACTOR
  330. if there is no particular limit. */
  331. unsigned HOST_WIDE_INT max_vectorization_factor;
  332. /* The masks that a fully-masked loop should use to avoid operating
  333. on inactive scalars. */
  334. vec_loop_masks masks;
  335. /* If we are using a loop mask to align memory addresses, this variable
  336. contains the number of vector elements that we should skip in the
  337. first iteration of the vector loop (i.e. the number of leading
  338. elements that should be false in the first mask). */
  339. tree mask_skip_niters;
  340. /* Type of the variables to use in the WHILE_ULT call for fully-masked
  341. loops. */
  342. tree mask_compare_type;
  343. /* For #pragma omp simd if (x) loops the x expression. If constant 0,
  344. the loop should not be vectorized, if constant non-zero, simd_if_cond
  345. shouldn't be set and loop vectorized normally, if SSA_NAME, the loop
  346. should be versioned on that condition, using scalar loop if the condition
  347. is false and vectorized loop otherwise. */
  348. tree simd_if_cond;
  349. /* Unknown DRs according to which loop was peeled. */
  350. struct dr_vec_info *unaligned_dr;
  351. /* peeling_for_alignment indicates whether peeling for alignment will take
  352. place, and what the peeling factor should be:
  353. peeling_for_alignment = X means:
  354. If X=0: Peeling for alignment will not be applied.
  355. If X>0: Peel first X iterations.
  356. If X=-1: Generate a runtime test to calculate the number of iterations
  357. to be peeled, using the dataref recorded in the field
  358. unaligned_dr. */
  359. int peeling_for_alignment;
  360. /* The mask used to check the alignment of pointers or arrays. */
  361. int ptr_mask;
  362. /* Data Dependence Relations defining address ranges that are candidates
  363. for a run-time aliasing check. */
  364. auto_vec<ddr_p> may_alias_ddrs;
  365. /* Data Dependence Relations defining address ranges together with segment
  366. lengths from which the run-time aliasing check is built. */
  367. auto_vec<dr_with_seg_len_pair_t> comp_alias_ddrs;
  368. /* Check that the addresses of each pair of objects is unequal. */
  369. auto_vec<vec_object_pair> check_unequal_addrs;
  370. /* List of values that are required to be nonzero. This is used to check
  371. whether things like "x[i * n] += 1;" are safe and eventually gets added
  372. to the checks for lower bounds below. */
  373. auto_vec<tree> check_nonzero;
  374. /* List of values that need to be checked for a minimum value. */
  375. auto_vec<vec_lower_bound> lower_bounds;
  376. /* Statements in the loop that have data references that are candidates for a
  377. runtime (loop versioning) misalignment check. */
  378. auto_vec<stmt_vec_info> may_misalign_stmts;
  379. /* Reduction cycles detected in the loop. Used in loop-aware SLP. */
  380. auto_vec<stmt_vec_info> reductions;
  381. /* All reduction chains in the loop, represented by the first
  382. stmt in the chain. */
  383. auto_vec<stmt_vec_info> reduction_chains;
  384. /* Cost vector for a single scalar iteration. */
  385. auto_vec<stmt_info_for_cost> scalar_cost_vec;
  386. /* Map of IV base/step expressions to inserted name in the preheader. */
  387. hash_map<tree_operand_hash, tree> *ivexpr_map;
  388. /* The unrolling factor needed to SLP the loop. In case of that pure SLP is
  389. applied to the loop, i.e., no unrolling is needed, this is 1. */
  390. poly_uint64 slp_unrolling_factor;
  391. /* Cost of a single scalar iteration. */
  392. int single_scalar_iteration_cost;
  393. /* Is the loop vectorizable? */
  394. bool vectorizable;
  395. /* Records whether we still have the option of using a fully-masked loop. */
  396. bool can_fully_mask_p;
  397. /* True if have decided to use a fully-masked loop. */
  398. bool fully_masked_p;
  399. /* When we have grouped data accesses with gaps, we may introduce invalid
  400. memory accesses. We peel the last iteration of the loop to prevent
  401. this. */
  402. bool peeling_for_gaps;
  403. /* When the number of iterations is not a multiple of the vector size
  404. we need to peel off iterations at the end to form an epilogue loop. */
  405. bool peeling_for_niter;
  406. /* Reductions are canonicalized so that the last operand is the reduction
  407. operand. If this places a constant into RHS1, this decanonicalizes
  408. GIMPLE for other phases, so we must track when this has occurred and
  409. fix it up. */
  410. bool operands_swapped;
  411. /* True if there are no loop carried data dependencies in the loop.
  412. If loop->safelen <= 1, then this is always true, either the loop
  413. didn't have any loop carried data dependencies, or the loop is being
  414. vectorized guarded with some runtime alias checks, or couldn't
  415. be vectorized at all, but then this field shouldn't be used.
  416. For loop->safelen >= 2, the user has asserted that there are no
  417. backward dependencies, but there still could be loop carried forward
  418. dependencies in such loops. This flag will be false if normal
  419. vectorizer data dependency analysis would fail or require versioning
  420. for alias, but because of loop->safelen >= 2 it has been vectorized
  421. even without versioning for alias. E.g. in:
  422. #pragma omp simd
  423. for (int i = 0; i < m; i++)
  424. a[i] = a[i + k] * c;
  425. (or #pragma simd or #pragma ivdep) we can vectorize this and it will
  426. DTRT even for k > 0 && k < m, but without safelen we would not
  427. vectorize this, so this field would be false. */
  428. bool no_data_dependencies;
  429. /* Mark loops having masked stores. */
  430. bool has_mask_store;
  431. /* If if-conversion versioned this loop before conversion, this is the
  432. loop version without if-conversion. */
  433. struct loop *scalar_loop;
  434. /* For loops being epilogues of already vectorized loops
  435. this points to the original vectorized loop. Otherwise NULL. */
  436. _loop_vec_info *orig_loop_info;
  437. } *loop_vec_info;
  438. /* Access Functions. */
  439. #define LOOP_VINFO_LOOP(L) (L)->loop
  440. #define LOOP_VINFO_BBS(L) (L)->bbs
  441. #define LOOP_VINFO_NITERSM1(L) (L)->num_itersm1
  442. #define LOOP_VINFO_NITERS(L) (L)->num_iters
  443. /* Since LOOP_VINFO_NITERS and LOOP_VINFO_NITERSM1 can change after
  444. prologue peeling retain total unchanged scalar loop iterations for
  445. cost model. */
  446. #define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
  447. #define LOOP_VINFO_NITERS_ASSUMPTIONS(L) (L)->num_iters_assumptions
  448. #define LOOP_VINFO_COST_MODEL_THRESHOLD(L) (L)->th
  449. #define LOOP_VINFO_VERSIONING_THRESHOLD(L) (L)->versioning_threshold
  450. #define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
  451. #define LOOP_VINFO_CAN_FULLY_MASK_P(L) (L)->can_fully_mask_p
  452. #define LOOP_VINFO_FULLY_MASKED_P(L) (L)->fully_masked_p
  453. #define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
  454. #define LOOP_VINFO_MAX_VECT_FACTOR(L) (L)->max_vectorization_factor
  455. #define LOOP_VINFO_MASKS(L) (L)->masks
  456. #define LOOP_VINFO_MASK_SKIP_NITERS(L) (L)->mask_skip_niters
  457. #define LOOP_VINFO_MASK_COMPARE_TYPE(L) (L)->mask_compare_type
  458. #define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask
  459. #define LOOP_VINFO_LOOP_NEST(L) (L)->shared->loop_nest
  460. #define LOOP_VINFO_DATAREFS(L) (L)->shared->datarefs
  461. #define LOOP_VINFO_DDRS(L) (L)->shared->ddrs
  462. #define LOOP_VINFO_INT_NITERS(L) (TREE_INT_CST_LOW ((L)->num_iters))
  463. #define LOOP_VINFO_PEELING_FOR_ALIGNMENT(L) (L)->peeling_for_alignment
  464. #define LOOP_VINFO_UNALIGNED_DR(L) (L)->unaligned_dr
  465. #define LOOP_VINFO_MAY_MISALIGN_STMTS(L) (L)->may_misalign_stmts
  466. #define LOOP_VINFO_MAY_ALIAS_DDRS(L) (L)->may_alias_ddrs
  467. #define LOOP_VINFO_COMP_ALIAS_DDRS(L) (L)->comp_alias_ddrs
  468. #define LOOP_VINFO_CHECK_UNEQUAL_ADDRS(L) (L)->check_unequal_addrs
  469. #define LOOP_VINFO_CHECK_NONZERO(L) (L)->check_nonzero
  470. #define LOOP_VINFO_LOWER_BOUNDS(L) (L)->lower_bounds
  471. #define LOOP_VINFO_GROUPED_STORES(L) (L)->grouped_stores
  472. #define LOOP_VINFO_SLP_INSTANCES(L) (L)->slp_instances
  473. #define LOOP_VINFO_SLP_UNROLLING_FACTOR(L) (L)->slp_unrolling_factor
  474. #define LOOP_VINFO_REDUCTIONS(L) (L)->reductions
  475. #define LOOP_VINFO_REDUCTION_CHAINS(L) (L)->reduction_chains
  476. #define LOOP_VINFO_TARGET_COST_DATA(L) (L)->target_cost_data
  477. #define LOOP_VINFO_PEELING_FOR_GAPS(L) (L)->peeling_for_gaps
  478. #define LOOP_VINFO_OPERANDS_SWAPPED(L) (L)->operands_swapped
  479. #define LOOP_VINFO_PEELING_FOR_NITER(L) (L)->peeling_for_niter
  480. #define LOOP_VINFO_NO_DATA_DEPENDENCIES(L) (L)->no_data_dependencies
  481. #define LOOP_VINFO_SCALAR_LOOP(L) (L)->scalar_loop
  482. #define LOOP_VINFO_HAS_MASK_STORE(L) (L)->has_mask_store
  483. #define LOOP_VINFO_SCALAR_ITERATION_COST(L) (L)->scalar_cost_vec
  484. #define LOOP_VINFO_SINGLE_SCALAR_ITERATION_COST(L) (L)->single_scalar_iteration_cost
  485. #define LOOP_VINFO_ORIG_LOOP_INFO(L) (L)->orig_loop_info
  486. #define LOOP_VINFO_SIMD_IF_COND(L) (L)->simd_if_cond
  487. #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
  488. ((L)->may_misalign_stmts.length () > 0)
  489. #define LOOP_REQUIRES_VERSIONING_FOR_ALIAS(L) \
  490. ((L)->comp_alias_ddrs.length () > 0 \
  491. || (L)->check_unequal_addrs.length () > 0 \
  492. || (L)->lower_bounds.length () > 0)
  493. #define LOOP_REQUIRES_VERSIONING_FOR_NITERS(L) \
  494. (LOOP_VINFO_NITERS_ASSUMPTIONS (L))
  495. #define LOOP_REQUIRES_VERSIONING_FOR_SIMD_IF_COND(L) \
  496. (LOOP_VINFO_SIMD_IF_COND (L))
  497. #define LOOP_REQUIRES_VERSIONING(L) \
  498. (LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT (L) \
  499. || LOOP_REQUIRES_VERSIONING_FOR_ALIAS (L) \
  500. || LOOP_REQUIRES_VERSIONING_FOR_NITERS (L) \
  501. || LOOP_REQUIRES_VERSIONING_FOR_SIMD_IF_COND (L))
  502. #define LOOP_VINFO_NITERS_KNOWN_P(L) \
  503. (tree_fits_shwi_p ((L)->num_iters) && tree_to_shwi ((L)->num_iters) > 0)
  504. #define LOOP_VINFO_EPILOGUE_P(L) \
  505. (LOOP_VINFO_ORIG_LOOP_INFO (L) != NULL)
  506. #define LOOP_VINFO_ORIG_MAX_VECT_FACTOR(L) \
  507. (LOOP_VINFO_MAX_VECT_FACTOR (LOOP_VINFO_ORIG_LOOP_INFO (L)))
  508. /* Wrapper for loop_vec_info, for tracking success/failure, where a non-NULL
  509. value signifies success, and a NULL value signifies failure, supporting
  510. propagating an opt_problem * describing the failure back up the call
  511. stack. */
  512. typedef opt_pointer_wrapper <loop_vec_info> opt_loop_vec_info;
  513. static inline loop_vec_info
  514. loop_vec_info_for_loop (struct loop *loop)
  515. {
  516. return (loop_vec_info) loop->aux;
  517. }
  518. typedef struct _bb_vec_info : public vec_info
  519. {
  520. _bb_vec_info (gimple_stmt_iterator, gimple_stmt_iterator, vec_info_shared *);
  521. ~_bb_vec_info ();
  522. basic_block bb;
  523. gimple_stmt_iterator region_begin;
  524. gimple_stmt_iterator region_end;
  525. } *bb_vec_info;
  526. #define BB_VINFO_BB(B) (B)->bb
  527. #define BB_VINFO_GROUPED_STORES(B) (B)->grouped_stores
  528. #define BB_VINFO_SLP_INSTANCES(B) (B)->slp_instances
  529. #define BB_VINFO_DATAREFS(B) (B)->shared->datarefs
  530. #define BB_VINFO_DDRS(B) (B)->shared->ddrs
  531. #define BB_VINFO_TARGET_COST_DATA(B) (B)->target_cost_data
  532. static inline bb_vec_info
  533. vec_info_for_bb (basic_block bb)
  534. {
  535. return (bb_vec_info) bb->aux;
  536. }
  537. /*-----------------------------------------------------------------*/
  538. /* Info on vectorized defs. */
  539. /*-----------------------------------------------------------------*/
  540. enum stmt_vec_info_type {
  541. undef_vec_info_type = 0,
  542. load_vec_info_type,
  543. store_vec_info_type,
  544. shift_vec_info_type,
  545. op_vec_info_type,
  546. call_vec_info_type,
  547. call_simd_clone_vec_info_type,
  548. assignment_vec_info_type,
  549. condition_vec_info_type,
  550. comparison_vec_info_type,
  551. reduc_vec_info_type,
  552. induc_vec_info_type,
  553. type_promotion_vec_info_type,
  554. type_demotion_vec_info_type,
  555. type_conversion_vec_info_type,
  556. loop_exit_ctrl_vec_info_type
  557. };
  558. /* Indicates whether/how a variable is used in the scope of loop/basic
  559. block. */
  560. enum vect_relevant {
  561. vect_unused_in_scope = 0,
  562. /* The def is only used outside the loop. */
  563. vect_used_only_live,
  564. /* The def is in the inner loop, and the use is in the outer loop, and the
  565. use is a reduction stmt. */
  566. vect_used_in_outer_by_reduction,
  567. /* The def is in the inner loop, and the use is in the outer loop (and is
  568. not part of reduction). */
  569. vect_used_in_outer,
  570. /* defs that feed computations that end up (only) in a reduction. These
  571. defs may be used by non-reduction stmts, but eventually, any
  572. computations/values that are affected by these defs are used to compute
  573. a reduction (i.e. don't get stored to memory, for example). We use this
  574. to identify computations that we can change the order in which they are
  575. computed. */
  576. vect_used_by_reduction,
  577. vect_used_in_scope
  578. };
  579. /* The type of vectorization that can be applied to the stmt: regular loop-based
  580. vectorization; pure SLP - the stmt is a part of SLP instances and does not
  581. have uses outside SLP instances; or hybrid SLP and loop-based - the stmt is
  582. a part of SLP instance and also must be loop-based vectorized, since it has
  583. uses outside SLP sequences.
  584. In the loop context the meanings of pure and hybrid SLP are slightly
  585. different. By saying that pure SLP is applied to the loop, we mean that we
  586. exploit only intra-iteration parallelism in the loop; i.e., the loop can be
  587. vectorized without doing any conceptual unrolling, cause we don't pack
  588. together stmts from different iterations, only within a single iteration.
  589. Loop hybrid SLP means that we exploit both intra-iteration and
  590. inter-iteration parallelism (e.g., number of elements in the vector is 4
  591. and the slp-group-size is 2, in which case we don't have enough parallelism
  592. within an iteration, so we obtain the rest of the parallelism from subsequent
  593. iterations by unrolling the loop by 2). */
  594. enum slp_vect_type {
  595. loop_vect = 0,
  596. pure_slp,
  597. hybrid
  598. };
  599. /* Says whether a statement is a load, a store of a vectorized statement
  600. result, or a store of an invariant value. */
  601. enum vec_load_store_type {
  602. VLS_LOAD,
  603. VLS_STORE,
  604. VLS_STORE_INVARIANT
  605. };
  606. /* Describes how we're going to vectorize an individual load or store,
  607. or a group of loads or stores. */
  608. enum vect_memory_access_type {
  609. /* An access to an invariant address. This is used only for loads. */
  610. VMAT_INVARIANT,
  611. /* A simple contiguous access. */
  612. VMAT_CONTIGUOUS,
  613. /* A contiguous access that goes down in memory rather than up,
  614. with no additional permutation. This is used only for stores
  615. of invariants. */
  616. VMAT_CONTIGUOUS_DOWN,
  617. /* A simple contiguous access in which the elements need to be permuted
  618. after loading or before storing. Only used for loop vectorization;
  619. SLP uses separate permutes. */
  620. VMAT_CONTIGUOUS_PERMUTE,
  621. /* A simple contiguous access in which the elements need to be reversed
  622. after loading or before storing. */
  623. VMAT_CONTIGUOUS_REVERSE,
  624. /* An access that uses IFN_LOAD_LANES or IFN_STORE_LANES. */
  625. VMAT_LOAD_STORE_LANES,
  626. /* An access in which each scalar element is loaded or stored
  627. individually. */
  628. VMAT_ELEMENTWISE,
  629. /* A hybrid of VMAT_CONTIGUOUS and VMAT_ELEMENTWISE, used for grouped
  630. SLP accesses. Each unrolled iteration uses a contiguous load
  631. or store for the whole group, but the groups from separate iterations
  632. are combined in the same way as for VMAT_ELEMENTWISE. */
  633. VMAT_STRIDED_SLP,
  634. /* The access uses gather loads or scatter stores. */
  635. VMAT_GATHER_SCATTER
  636. };
  637. struct dr_vec_info {
  638. /* The data reference itself. */
  639. data_reference *dr;
  640. /* The statement that contains the data reference. */
  641. stmt_vec_info stmt;
  642. /* The misalignment in bytes of the reference, or -1 if not known. */
  643. int misalignment;
  644. /* The byte alignment that we'd ideally like the reference to have,
  645. and the value that misalignment is measured against. */
  646. poly_uint64 target_alignment;
  647. /* If true the alignment of base_decl needs to be increased. */
  648. bool base_misaligned;
  649. tree base_decl;
  650. };
  651. typedef struct data_reference *dr_p;
  652. struct _stmt_vec_info {
  653. enum stmt_vec_info_type type;
  654. /* Indicates whether this stmts is part of a computation whose result is
  655. used outside the loop. */
  656. bool live;
  657. /* Stmt is part of some pattern (computation idiom) */
  658. bool in_pattern_p;
  659. /* True if the statement was created during pattern recognition as
  660. part of the replacement for RELATED_STMT. This implies that the
  661. statement isn't part of any basic block, although for convenience
  662. its gimple_bb is the same as for RELATED_STMT. */
  663. bool pattern_stmt_p;
  664. /* Is this statement vectorizable or should it be skipped in (partial)
  665. vectorization. */
  666. bool vectorizable;
  667. /* The stmt to which this info struct refers to. */
  668. gimple *stmt;
  669. /* The vec_info with respect to which STMT is vectorized. */
  670. vec_info *vinfo;
  671. /* The vector type to be used for the LHS of this statement. */
  672. tree vectype;
  673. /* The vectorized version of the stmt. */
  674. stmt_vec_info vectorized_stmt;
  675. /* The following is relevant only for stmts that contain a non-scalar
  676. data-ref (array/pointer/struct access). A GIMPLE stmt is expected to have
  677. at most one such data-ref. */
  678. dr_vec_info dr_aux;
  679. /* Information about the data-ref relative to this loop
  680. nest (the loop that is being considered for vectorization). */
  681. innermost_loop_behavior dr_wrt_vec_loop;
  682. /* For loop PHI nodes, the base and evolution part of it. This makes sure
  683. this information is still available in vect_update_ivs_after_vectorizer
  684. where we may not be able to re-analyze the PHI nodes evolution as
  685. peeling for the prologue loop can make it unanalyzable. The evolution
  686. part is still correct after peeling, but the base may have changed from
  687. the version here. */
  688. tree loop_phi_evolution_base_unchanged;
  689. tree loop_phi_evolution_part;
  690. /* Used for various bookkeeping purposes, generally holding a pointer to
  691. some other stmt S that is in some way "related" to this stmt.
  692. Current use of this field is:
  693. If this stmt is part of a pattern (i.e. the field 'in_pattern_p' is
  694. true): S is the "pattern stmt" that represents (and replaces) the
  695. sequence of stmts that constitutes the pattern. Similarly, the
  696. related_stmt of the "pattern stmt" points back to this stmt (which is
  697. the last stmt in the original sequence of stmts that constitutes the
  698. pattern). */
  699. stmt_vec_info related_stmt;
  700. /* Used to keep a sequence of def stmts of a pattern stmt if such exists.
  701. The sequence is attached to the original statement rather than the
  702. pattern statement. */
  703. gimple_seq pattern_def_seq;
  704. /* List of datarefs that are known to have the same alignment as the dataref
  705. of this stmt. */
  706. vec<dr_p> same_align_refs;
  707. /* Selected SIMD clone's function info. First vector element
  708. is SIMD clone's function decl, followed by a pair of trees (base + step)
  709. for linear arguments (pair of NULLs for other arguments). */
  710. vec<tree> simd_clone_info;
  711. /* Classify the def of this stmt. */
  712. enum vect_def_type def_type;
  713. /* Whether the stmt is SLPed, loop-based vectorized, or both. */
  714. enum slp_vect_type slp_type;
  715. /* Interleaving and reduction chains info. */
  716. /* First element in the group. */
  717. stmt_vec_info first_element;
  718. /* Pointer to the next element in the group. */
  719. stmt_vec_info next_element;
  720. /* The size of the group. */
  721. unsigned int size;
  722. /* For stores, number of stores from this group seen. We vectorize the last
  723. one. */
  724. unsigned int store_count;
  725. /* For loads only, the gap from the previous load. For consecutive loads, GAP
  726. is 1. */
  727. unsigned int gap;
  728. /* The minimum negative dependence distance this stmt participates in
  729. or zero if none. */
  730. unsigned int min_neg_dist;
  731. /* Not all stmts in the loop need to be vectorized. e.g, the increment
  732. of the loop induction variable and computation of array indexes. relevant
  733. indicates whether the stmt needs to be vectorized. */
  734. enum vect_relevant relevant;
  735. /* For loads if this is a gather, for stores if this is a scatter. */
  736. bool gather_scatter_p;
  737. /* True if this is an access with loop-invariant stride. */
  738. bool strided_p;
  739. /* For both loads and stores. */
  740. bool simd_lane_access_p;
  741. /* Classifies how the load or store is going to be implemented
  742. for loop vectorization. */
  743. vect_memory_access_type memory_access_type;
  744. /* For reduction loops, this is the type of reduction. */
  745. enum vect_reduction_type v_reduc_type;
  746. /* For CONST_COND_REDUCTION, record the reduc code. */
  747. enum tree_code const_cond_reduc_code;
  748. /* On a reduction PHI the reduction type as detected by
  749. vect_force_simple_reduction. */
  750. enum vect_reduction_type reduc_type;
  751. /* On a reduction PHI the def returned by vect_force_simple_reduction.
  752. On the def returned by vect_force_simple_reduction the
  753. corresponding PHI. */
  754. stmt_vec_info reduc_def;
  755. /* The number of scalar stmt references from active SLP instances. */
  756. unsigned int num_slp_uses;
  757. /* If nonzero, the lhs of the statement could be truncated to this
  758. many bits without affecting any users of the result. */
  759. unsigned int min_output_precision;
  760. /* If nonzero, all non-boolean input operands have the same precision,
  761. and they could each be truncated to this many bits without changing
  762. the result. */
  763. unsigned int min_input_precision;
  764. /* If OPERATION_BITS is nonzero, the statement could be performed on
  765. an integer with the sign and number of bits given by OPERATION_SIGN
  766. and OPERATION_BITS without changing the result. */
  767. unsigned int operation_precision;
  768. signop operation_sign;
  769. };
  770. /* Information about a gather/scatter call. */
  771. struct gather_scatter_info {
  772. /* The internal function to use for the gather/scatter operation,
  773. or IFN_LAST if a built-in function should be used instead. */
  774. internal_fn ifn;
  775. /* The FUNCTION_DECL for the built-in gather/scatter function,
  776. or null if an internal function should be used instead. */
  777. tree decl;
  778. /* The loop-invariant base value. */
  779. tree base;
  780. /* The original scalar offset, which is a non-loop-invariant SSA_NAME. */
  781. tree offset;
  782. /* Each offset element should be multiplied by this amount before
  783. being added to the base. */
  784. int scale;
  785. /* The definition type for the vectorized offset. */
  786. enum vect_def_type offset_dt;
  787. /* The type of the vectorized offset. */
  788. tree offset_vectype;
  789. /* The type of the scalar elements after loading or before storing. */
  790. tree element_type;
  791. /* The type of the scalar elements being loaded or stored. */
  792. tree memory_type;
  793. };
  794. /* Access Functions. */
  795. #define STMT_VINFO_TYPE(S) (S)->type
  796. #define STMT_VINFO_STMT(S) (S)->stmt
  797. inline loop_vec_info
  798. STMT_VINFO_LOOP_VINFO (stmt_vec_info stmt_vinfo)
  799. {
  800. if (loop_vec_info loop_vinfo = dyn_cast <loop_vec_info> (stmt_vinfo->vinfo))
  801. return loop_vinfo;
  802. return NULL;
  803. }
  804. inline bb_vec_info
  805. STMT_VINFO_BB_VINFO (stmt_vec_info stmt_vinfo)
  806. {
  807. if (bb_vec_info bb_vinfo = dyn_cast <bb_vec_info> (stmt_vinfo->vinfo))
  808. return bb_vinfo;
  809. return NULL;
  810. }
  811. #define STMT_VINFO_RELEVANT(S) (S)->relevant
  812. #define STMT_VINFO_LIVE_P(S) (S)->live
  813. #define STMT_VINFO_VECTYPE(S) (S)->vectype
  814. #define STMT_VINFO_VEC_STMT(S) (S)->vectorized_stmt
  815. #define STMT_VINFO_VECTORIZABLE(S) (S)->vectorizable
  816. #define STMT_VINFO_DATA_REF(S) ((S)->dr_aux.dr + 0)
  817. #define STMT_VINFO_GATHER_SCATTER_P(S) (S)->gather_scatter_p
  818. #define STMT_VINFO_STRIDED_P(S) (S)->strided_p
  819. #define STMT_VINFO_MEMORY_ACCESS_TYPE(S) (S)->memory_access_type
  820. #define STMT_VINFO_SIMD_LANE_ACCESS_P(S) (S)->simd_lane_access_p
  821. #define STMT_VINFO_VEC_REDUCTION_TYPE(S) (S)->v_reduc_type
  822. #define STMT_VINFO_VEC_CONST_COND_REDUC_CODE(S) (S)->const_cond_reduc_code
  823. #define STMT_VINFO_DR_WRT_VEC_LOOP(S) (S)->dr_wrt_vec_loop
  824. #define STMT_VINFO_DR_BASE_ADDRESS(S) (S)->dr_wrt_vec_loop.base_address
  825. #define STMT_VINFO_DR_INIT(S) (S)->dr_wrt_vec_loop.init
  826. #define STMT_VINFO_DR_OFFSET(S) (S)->dr_wrt_vec_loop.offset
  827. #define STMT_VINFO_DR_STEP(S) (S)->dr_wrt_vec_loop.step
  828. #define STMT_VINFO_DR_BASE_ALIGNMENT(S) (S)->dr_wrt_vec_loop.base_alignment
  829. #define STMT_VINFO_DR_BASE_MISALIGNMENT(S) \
  830. (S)->dr_wrt_vec_loop.base_misalignment
  831. #define STMT_VINFO_DR_OFFSET_ALIGNMENT(S) \
  832. (S)->dr_wrt_vec_loop.offset_alignment
  833. #define STMT_VINFO_DR_STEP_ALIGNMENT(S) \
  834. (S)->dr_wrt_vec_loop.step_alignment
  835. #define STMT_VINFO_DR_INFO(S) \
  836. (gcc_checking_assert ((S)->dr_aux.stmt == (S)), &(S)->dr_aux)
  837. #define STMT_VINFO_IN_PATTERN_P(S) (S)->in_pattern_p
  838. #define STMT_VINFO_RELATED_STMT(S) (S)->related_stmt
  839. #define STMT_VINFO_PATTERN_DEF_SEQ(S) (S)->pattern_def_seq
  840. #define STMT_VINFO_SAME_ALIGN_REFS(S) (S)->same_align_refs
  841. #define STMT_VINFO_SIMD_CLONE_INFO(S) (S)->simd_clone_info
  842. #define STMT_VINFO_DEF_TYPE(S) (S)->def_type
  843. #define STMT_VINFO_GROUPED_ACCESS(S) \
  844. ((S)->dr_aux.dr && DR_GROUP_FIRST_ELEMENT(S))
  845. #define STMT_VINFO_LOOP_PHI_EVOLUTION_BASE_UNCHANGED(S) (S)->loop_phi_evolution_base_unchanged
  846. #define STMT_VINFO_LOOP_PHI_EVOLUTION_PART(S) (S)->loop_phi_evolution_part
  847. #define STMT_VINFO_MIN_NEG_DIST(S) (S)->min_neg_dist
  848. #define STMT_VINFO_NUM_SLP_USES(S) (S)->num_slp_uses
  849. #define STMT_VINFO_REDUC_TYPE(S) (S)->reduc_type
  850. #define STMT_VINFO_REDUC_DEF(S) (S)->reduc_def
  851. #define DR_GROUP_FIRST_ELEMENT(S) \
  852. (gcc_checking_assert ((S)->dr_aux.dr), (S)->first_element)
  853. #define DR_GROUP_NEXT_ELEMENT(S) \
  854. (gcc_checking_assert ((S)->dr_aux.dr), (S)->next_element)
  855. #define DR_GROUP_SIZE(S) \
  856. (gcc_checking_assert ((S)->dr_aux.dr), (S)->size)
  857. #define DR_GROUP_STORE_COUNT(S) \
  858. (gcc_checking_assert ((S)->dr_aux.dr), (S)->store_count)
  859. #define DR_GROUP_GAP(S) \
  860. (gcc_checking_assert ((S)->dr_aux.dr), (S)->gap)
  861. #define REDUC_GROUP_FIRST_ELEMENT(S) \
  862. (gcc_checking_assert (!(S)->dr_aux.dr), (S)->first_element)
  863. #define REDUC_GROUP_NEXT_ELEMENT(S) \
  864. (gcc_checking_assert (!(S)->dr_aux.dr), (S)->next_element)
  865. #define REDUC_GROUP_SIZE(S) \
  866. (gcc_checking_assert (!(S)->dr_aux.dr), (S)->size)
  867. #define STMT_VINFO_RELEVANT_P(S) ((S)->relevant != vect_unused_in_scope)
  868. #define HYBRID_SLP_STMT(S) ((S)->slp_type == hybrid)
  869. #define PURE_SLP_STMT(S) ((S)->slp_type == pure_slp)
  870. #define STMT_SLP_TYPE(S) (S)->slp_type
  871. #define VECT_MAX_COST 1000
  872. /* The maximum number of intermediate steps required in multi-step type
  873. conversion. */
  874. #define MAX_INTERM_CVT_STEPS 3
  875. #define MAX_VECTORIZATION_FACTOR INT_MAX
  876. /* Nonzero if TYPE represents a (scalar) boolean type or type
  877. in the middle-end compatible with it (unsigned precision 1 integral
  878. types). Used to determine which types should be vectorized as
  879. VECTOR_BOOLEAN_TYPE_P. */
  880. #define VECT_SCALAR_BOOLEAN_TYPE_P(TYPE) \
  881. (TREE_CODE (TYPE) == BOOLEAN_TYPE \
  882. || ((TREE_CODE (TYPE) == INTEGER_TYPE \
  883. || TREE_CODE (TYPE) == ENUMERAL_TYPE) \
  884. && TYPE_PRECISION (TYPE) == 1 \
  885. && TYPE_UNSIGNED (TYPE)))
  886. static inline bool
  887. nested_in_vect_loop_p (struct loop *loop, stmt_vec_info stmt_info)
  888. {
  889. return (loop->inner
  890. && (loop->inner == (gimple_bb (stmt_info->stmt))->loop_father));
  891. }
  892. /* Return TRUE if a statement represented by STMT_INFO is a part of a
  893. pattern. */
  894. static inline bool
  895. is_pattern_stmt_p (stmt_vec_info stmt_info)
  896. {
  897. return stmt_info->pattern_stmt_p;
  898. }
  899. /* If STMT_INFO is a pattern statement, return the statement that it
  900. replaces, otherwise return STMT_INFO itself. */
  901. inline stmt_vec_info
  902. vect_orig_stmt (stmt_vec_info stmt_info)
  903. {
  904. if (is_pattern_stmt_p (stmt_info))
  905. return STMT_VINFO_RELATED_STMT (stmt_info);
  906. return stmt_info;
  907. }
  908. /* Return the later statement between STMT1_INFO and STMT2_INFO. */
  909. static inline stmt_vec_info
  910. get_later_stmt (stmt_vec_info stmt1_info, stmt_vec_info stmt2_info)
  911. {
  912. if (gimple_uid (vect_orig_stmt (stmt1_info)->stmt)
  913. > gimple_uid (vect_orig_stmt (stmt2_info)->stmt))
  914. return stmt1_info;
  915. else
  916. return stmt2_info;
  917. }
  918. /* If STMT_INFO has been replaced by a pattern statement, return the
  919. replacement statement, otherwise return STMT_INFO itself. */
  920. inline stmt_vec_info
  921. vect_stmt_to_vectorize (stmt_vec_info stmt_info)
  922. {
  923. if (STMT_VINFO_IN_PATTERN_P (stmt_info))
  924. return STMT_VINFO_RELATED_STMT (stmt_info);
  925. return stmt_info;
  926. }
  927. /* Return true if BB is a loop header. */
  928. static inline bool
  929. is_loop_header_bb_p (basic_block bb)
  930. {
  931. if (bb == (bb->loop_father)->header)
  932. return true;
  933. gcc_checking_assert (EDGE_COUNT (bb->preds) == 1);
  934. return false;
  935. }
  936. /* Return pow2 (X). */
  937. static inline int
  938. vect_pow2 (int x)
  939. {
  940. int i, res = 1;
  941. for (i = 0; i < x; i++)
  942. res *= 2;
  943. return res;
  944. }
  945. /* Alias targetm.vectorize.builtin_vectorization_cost. */
  946. static inline int
  947. builtin_vectorization_cost (enum vect_cost_for_stmt type_of_cost,
  948. tree vectype, int misalign)
  949. {
  950. return targetm.vectorize.builtin_vectorization_cost (type_of_cost,
  951. vectype, misalign);
  952. }
  953. /* Get cost by calling cost target builtin. */
  954. static inline
  955. int vect_get_stmt_cost (enum vect_cost_for_stmt type_of_cost)
  956. {
  957. return builtin_vectorization_cost (type_of_cost, NULL, 0);
  958. }
  959. /* Alias targetm.vectorize.init_cost. */
  960. static inline void *
  961. init_cost (struct loop *loop_info)
  962. {
  963. return targetm.vectorize.init_cost (loop_info);
  964. }
  965. extern void dump_stmt_cost (FILE *, void *, int, enum vect_cost_for_stmt,
  966. stmt_vec_info, int, unsigned,
  967. enum vect_cost_model_location);
  968. /* Alias targetm.vectorize.add_stmt_cost. */
  969. static inline unsigned
  970. add_stmt_cost (void *data, int count, enum vect_cost_for_stmt kind,
  971. stmt_vec_info stmt_info, int misalign,
  972. enum vect_cost_model_location where)
  973. {
  974. unsigned cost = targetm.vectorize.add_stmt_cost (data, count, kind,
  975. stmt_info, misalign, where);
  976. if (dump_file && (dump_flags & TDF_DETAILS))
  977. dump_stmt_cost (dump_file, data, count, kind, stmt_info, misalign,
  978. cost, where);
  979. return cost;
  980. }
  981. /* Alias targetm.vectorize.finish_cost. */
  982. static inline void
  983. finish_cost (void *data, unsigned *prologue_cost,
  984. unsigned *body_cost, unsigned *epilogue_cost)
  985. {
  986. targetm.vectorize.finish_cost (data, prologue_cost, body_cost, epilogue_cost);
  987. }
  988. /* Alias targetm.vectorize.destroy_cost_data. */
  989. static inline void
  990. destroy_cost_data (void *data)
  991. {
  992. targetm.vectorize.destroy_cost_data (data);
  993. }
  994. inline void
  995. add_stmt_costs (void *data, stmt_vector_for_cost *cost_vec)
  996. {
  997. stmt_info_for_cost *cost;
  998. unsigned i;
  999. FOR_EACH_VEC_ELT (*cost_vec, i, cost)
  1000. add_stmt_cost (data, cost->count, cost->kind, cost->stmt_info,
  1001. cost->misalign, cost->where);
  1002. }
  1003. /*-----------------------------------------------------------------*/
  1004. /* Info on data references alignment. */
  1005. /*-----------------------------------------------------------------*/
  1006. #define DR_MISALIGNMENT_UNKNOWN (-1)
  1007. #define DR_MISALIGNMENT_UNINITIALIZED (-2)
  1008. inline void
  1009. set_dr_misalignment (dr_vec_info *dr_info, int val)
  1010. {
  1011. dr_info->misalignment = val;
  1012. }
  1013. inline int
  1014. dr_misalignment (dr_vec_info *dr_info)
  1015. {
  1016. int misalign = dr_info->misalignment;
  1017. gcc_assert (misalign != DR_MISALIGNMENT_UNINITIALIZED);
  1018. return misalign;
  1019. }
  1020. /* Reflects actual alignment of first access in the vectorized loop,
  1021. taking into account peeling/versioning if applied. */
  1022. #define DR_MISALIGNMENT(DR) dr_misalignment (DR)
  1023. #define SET_DR_MISALIGNMENT(DR, VAL) set_dr_misalignment (DR, VAL)
  1024. /* Only defined once DR_MISALIGNMENT is defined. */
  1025. #define DR_TARGET_ALIGNMENT(DR) ((DR)->target_alignment)
  1026. /* Return true if data access DR_INFO is aligned to its target alignment
  1027. (which may be less than a full vector). */
  1028. static inline bool
  1029. aligned_access_p (dr_vec_info *dr_info)
  1030. {
  1031. return (DR_MISALIGNMENT (dr_info) == 0);
  1032. }
  1033. /* Return TRUE if the alignment of the data access is known, and FALSE
  1034. otherwise. */
  1035. static inline bool
  1036. known_alignment_for_access_p (dr_vec_info *dr_info)
  1037. {
  1038. return (DR_MISALIGNMENT (dr_info) != DR_MISALIGNMENT_UNKNOWN);
  1039. }
  1040. /* Return the minimum alignment in bytes that the vectorized version
  1041. of DR_INFO is guaranteed to have. */
  1042. static inline unsigned int
  1043. vect_known_alignment_in_bytes (dr_vec_info *dr_info)
  1044. {
  1045. if (DR_MISALIGNMENT (dr_info) == DR_MISALIGNMENT_UNKNOWN)
  1046. return TYPE_ALIGN_UNIT (TREE_TYPE (DR_REF (dr_info->dr)));
  1047. if (DR_MISALIGNMENT (dr_info) == 0)
  1048. return known_alignment (DR_TARGET_ALIGNMENT (dr_info));
  1049. return DR_MISALIGNMENT (dr_info) & -DR_MISALIGNMENT (dr_info);
  1050. }
  1051. /* Return the behavior of DR_INFO with respect to the vectorization context
  1052. (which for outer loop vectorization might not be the behavior recorded
  1053. in DR_INFO itself). */
  1054. static inline innermost_loop_behavior *
  1055. vect_dr_behavior (dr_vec_info *dr_info)
  1056. {
  1057. stmt_vec_info stmt_info = dr_info->stmt;
  1058. loop_vec_info loop_vinfo = STMT_VINFO_LOOP_VINFO (stmt_info);
  1059. if (loop_vinfo == NULL
  1060. || !nested_in_vect_loop_p (LOOP_VINFO_LOOP (loop_vinfo), stmt_info))
  1061. return &DR_INNERMOST (dr_info->dr);
  1062. else
  1063. return &STMT_VINFO_DR_WRT_VEC_LOOP (stmt_info);
  1064. }
  1065. /* Return true if the vect cost model is unlimited. */
  1066. static inline bool
  1067. unlimited_cost_model (loop_p loop)
  1068. {
  1069. if (loop != NULL && loop->force_vectorize
  1070. && flag_simd_cost_model != VECT_COST_MODEL_DEFAULT)
  1071. return flag_simd_cost_model == VECT_COST_MODEL_UNLIMITED;
  1072. return (flag_vect_cost_model == VECT_COST_MODEL_UNLIMITED);
  1073. }
  1074. /* Return true if the loop described by LOOP_VINFO is fully-masked and
  1075. if the first iteration should use a partial mask in order to achieve
  1076. alignment. */
  1077. static inline bool
  1078. vect_use_loop_mask_for_alignment_p (loop_vec_info loop_vinfo)
  1079. {
  1080. return (LOOP_VINFO_FULLY_MASKED_P (loop_vinfo)
  1081. && LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo));
  1082. }
  1083. /* Return the number of vectors of type VECTYPE that are needed to get
  1084. NUNITS elements. NUNITS should be based on the vectorization factor,
  1085. so it is always a known multiple of the number of elements in VECTYPE. */
  1086. static inline unsigned int
  1087. vect_get_num_vectors (poly_uint64 nunits, tree vectype)
  1088. {
  1089. return exact_div (nunits, TYPE_VECTOR_SUBPARTS (vectype)).to_constant ();
  1090. }
  1091. /* Return the number of copies needed for loop vectorization when
  1092. a statement operates on vectors of type VECTYPE. This is the
  1093. vectorization factor divided by the number of elements in
  1094. VECTYPE and is always known at compile time. */
  1095. static inline unsigned int
  1096. vect_get_num_copies (loop_vec_info loop_vinfo, tree vectype)
  1097. {
  1098. return vect_get_num_vectors (LOOP_VINFO_VECT_FACTOR (loop_vinfo), vectype);
  1099. }
  1100. /* Update maximum unit count *MAX_NUNITS so that it accounts for
  1101. NUNITS. *MAX_NUNITS can be 1 if we haven't yet recorded anything. */
  1102. static inline void
  1103. vect_update_max_nunits (poly_uint64 *max_nunits, poly_uint64 nunits)
  1104. {
  1105. /* All unit counts have the form current_vector_size * X for some
  1106. rational X, so two unit sizes must have a common multiple.
  1107. Everything is a multiple of the initial value of 1. */
  1108. *max_nunits = force_common_multiple (*max_nunits, nunits);
  1109. }
  1110. /* Update maximum unit count *MAX_NUNITS so that it accounts for
  1111. the number of units in vector type VECTYPE. *MAX_NUNITS can be 1
  1112. if we haven't yet recorded any vector types. */
  1113. static inline void
  1114. vect_update_max_nunits (poly_uint64 *max_nunits, tree vectype)
  1115. {
  1116. vect_update_max_nunits (max_nunits, TYPE_VECTOR_SUBPARTS (vectype));
  1117. }
  1118. /* Return the vectorization factor that should be used for costing
  1119. purposes while vectorizing the loop described by LOOP_VINFO.
  1120. Pick a reasonable estimate if the vectorization factor isn't
  1121. known at compile time. */
  1122. static inline unsigned int
  1123. vect_vf_for_cost (loop_vec_info loop_vinfo)
  1124. {
  1125. return estimated_poly_value (LOOP_VINFO_VECT_FACTOR (loop_vinfo));
  1126. }
  1127. /* Estimate the number of elements in VEC_TYPE for costing purposes.
  1128. Pick a reasonable estimate if the exact number isn't known at
  1129. compile time. */
  1130. static inline unsigned int
  1131. vect_nunits_for_cost (tree vec_type)
  1132. {
  1133. return estimated_poly_value (TYPE_VECTOR_SUBPARTS (vec_type));
  1134. }
  1135. /* Return the maximum possible vectorization factor for LOOP_VINFO. */
  1136. static inline unsigned HOST_WIDE_INT
  1137. vect_max_vf (loop_vec_info loop_vinfo)
  1138. {
  1139. unsigned HOST_WIDE_INT vf;
  1140. if (LOOP_VINFO_VECT_FACTOR (loop_vinfo).is_constant (&vf))
  1141. return vf;
  1142. return MAX_VECTORIZATION_FACTOR;
  1143. }
  1144. /* Return the size of the value accessed by unvectorized data reference
  1145. DR_INFO. This is only valid once STMT_VINFO_VECTYPE has been calculated
  1146. for the associated gimple statement, since that guarantees that DR_INFO
  1147. accesses either a scalar or a scalar equivalent. ("Scalar equivalent"
  1148. here includes things like V1SI, which can be vectorized in the same way
  1149. as a plain SI.) */
  1150. inline unsigned int
  1151. vect_get_scalar_dr_size (dr_vec_info *dr_info)
  1152. {
  1153. return tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (DR_REF (dr_info->dr))));
  1154. }
  1155. /* Source location + hotness information. */
  1156. extern dump_user_location_t vect_location;
  1157. /* A macro for calling:
  1158. dump_begin_scope (MSG, vect_location);
  1159. via an RAII object, thus printing "=== MSG ===\n" to the dumpfile etc,
  1160. and then calling
  1161. dump_end_scope ();
  1162. once the object goes out of scope, thus capturing the nesting of
  1163. the scopes.
  1164. These scopes affect dump messages within them: dump messages at the
  1165. top level implicitly default to MSG_PRIORITY_USER_FACING, whereas those
  1166. in a nested scope implicitly default to MSG_PRIORITY_INTERNALS. */
  1167. #define DUMP_VECT_SCOPE(MSG) \
  1168. AUTO_DUMP_SCOPE (MSG, vect_location)
  1169. /* A sentinel class for ensuring that the "vect_location" global gets
  1170. reset at the end of a scope.
  1171. The "vect_location" global is used during dumping and contains a
  1172. location_t, which could contain references to a tree block via the
  1173. ad-hoc data. This data is used for tracking inlining information,
  1174. but it's not a GC root; it's simply assumed that such locations never
  1175. get accessed if the blocks are optimized away.
  1176. Hence we need to ensure that such locations are purged at the end
  1177. of any operations using them (e.g. via this class). */
  1178. class auto_purge_vect_location
  1179. {
  1180. public:
  1181. ~auto_purge_vect_location ();
  1182. };
  1183. /*-----------------------------------------------------------------*/
  1184. /* Function prototypes. */
  1185. /*-----------------------------------------------------------------*/
  1186. /* Simple loop peeling and versioning utilities for vectorizer's purposes -
  1187. in tree-vect-loop-manip.c. */
  1188. extern void vect_set_loop_condition (struct loop *, loop_vec_info,
  1189. tree, tree, tree, bool);
  1190. extern bool slpeel_can_duplicate_loop_p (const struct loop *, const_edge);
  1191. struct loop *slpeel_tree_duplicate_loop_to_edge_cfg (struct loop *,
  1192. struct loop *, edge);
  1193. struct loop *vect_loop_versioning (loop_vec_info, unsigned int, bool,
  1194. poly_uint64);
  1195. extern struct loop *vect_do_peeling (loop_vec_info, tree, tree,
  1196. tree *, tree *, tree *, int, bool, bool);
  1197. extern void vect_prepare_for_masked_peels (loop_vec_info);
  1198. extern dump_user_location_t find_loop_location (struct loop *);
  1199. extern bool vect_can_advance_ivs_p (loop_vec_info);
  1200. /* In tree-vect-stmts.c. */
  1201. extern poly_uint64 current_vector_size;
  1202. extern tree get_vectype_for_scalar_type (tree);
  1203. extern tree get_vectype_for_scalar_type_and_size (tree, poly_uint64);
  1204. extern tree get_mask_type_for_scalar_type (tree);
  1205. extern tree get_same_sized_vectype (tree, tree);
  1206. extern bool vect_get_loop_mask_type (loop_vec_info);
  1207. extern bool vect_is_simple_use (tree, vec_info *, enum vect_def_type *,
  1208. stmt_vec_info * = NULL, gimple ** = NULL);
  1209. extern bool vect_is_simple_use (tree, vec_info *, enum vect_def_type *,
  1210. tree *, stmt_vec_info * = NULL,
  1211. gimple ** = NULL);
  1212. extern bool supportable_widening_operation (enum tree_code, stmt_vec_info,
  1213. tree, tree, enum tree_code *,
  1214. enum tree_code *, int *,
  1215. vec<tree> *);
  1216. extern bool supportable_narrowing_operation (enum tree_code, tree, tree,
  1217. enum tree_code *,
  1218. int *, vec<tree> *);
  1219. extern unsigned record_stmt_cost (stmt_vector_for_cost *, int,
  1220. enum vect_cost_for_stmt, stmt_vec_info,
  1221. int, enum vect_cost_model_location);
  1222. extern stmt_vec_info vect_finish_replace_stmt (stmt_vec_info, gimple *);
  1223. extern stmt_vec_info vect_finish_stmt_generation (stmt_vec_info, gimple *,
  1224. gimple_stmt_iterator *);
  1225. extern opt_result vect_mark_stmts_to_be_vectorized (loop_vec_info);
  1226. extern tree vect_get_store_rhs (stmt_vec_info);
  1227. extern tree vect_get_vec_def_for_operand_1 (stmt_vec_info, enum vect_def_type);
  1228. extern tree vect_get_vec_def_for_operand (tree, stmt_vec_info, tree = NULL);
  1229. extern void vect_get_vec_defs (tree, tree, stmt_vec_info, vec<tree> *,
  1230. vec<tree> *, slp_tree);
  1231. extern void vect_get_vec_defs_for_stmt_copy (vec_info *,
  1232. vec<tree> *, vec<tree> *);
  1233. extern tree vect_init_vector (stmt_vec_info, tree, tree,
  1234. gimple_stmt_iterator *);
  1235. extern tree vect_get_vec_def_for_stmt_copy (vec_info *, tree);
  1236. extern bool vect_transform_stmt (stmt_vec_info, gimple_stmt_iterator *,
  1237. slp_tree, slp_instance);
  1238. extern void vect_remove_stores (stmt_vec_info);
  1239. extern opt_result vect_analyze_stmt (stmt_vec_info, bool *, slp_tree,
  1240. slp_instance, stmt_vector_for_cost *);
  1241. extern bool vectorizable_condition (stmt_vec_info, gimple_stmt_iterator *,
  1242. stmt_vec_info *, bool, slp_tree,
  1243. stmt_vector_for_cost *);
  1244. extern bool vectorizable_shift (stmt_vec_info, gimple_stmt_iterator *,
  1245. stmt_vec_info *, slp_tree,
  1246. stmt_vector_for_cost *);
  1247. extern void vect_get_load_cost (stmt_vec_info, int, bool,
  1248. unsigned int *, unsigned int *,
  1249. stmt_vector_for_cost *,
  1250. stmt_vector_for_cost *, bool);
  1251. extern void vect_get_store_cost (stmt_vec_info, int,
  1252. unsigned int *, stmt_vector_for_cost *);
  1253. extern bool vect_supportable_shift (enum tree_code, tree);
  1254. extern tree vect_gen_perm_mask_any (tree, const vec_perm_indices &);
  1255. extern tree vect_gen_perm_mask_checked (tree, const vec_perm_indices &);
  1256. extern void optimize_mask_stores (struct loop*);
  1257. extern gcall *vect_gen_while (tree, tree, tree);
  1258. extern tree vect_gen_while_not (gimple_seq *, tree, tree, tree);
  1259. extern opt_result vect_get_vector_types_for_stmt (stmt_vec_info, tree *,
  1260. tree *);
  1261. extern opt_tree vect_get_mask_type_for_stmt (stmt_vec_info);
  1262. /* In tree-vect-data-refs.c. */
  1263. extern bool vect_can_force_dr_alignment_p (const_tree, poly_uint64);
  1264. extern enum dr_alignment_support vect_supportable_dr_alignment
  1265. (dr_vec_info *, bool);
  1266. extern tree vect_get_smallest_scalar_type (stmt_vec_info, HOST_WIDE_INT *,
  1267. HOST_WIDE_INT *);
  1268. extern opt_result vect_analyze_data_ref_dependences (loop_vec_info, unsigned int *);
  1269. extern bool vect_slp_analyze_instance_dependence (slp_instance);
  1270. extern opt_result vect_enhance_data_refs_alignment (loop_vec_info);
  1271. extern opt_result vect_analyze_data_refs_alignment (loop_vec_info);
  1272. extern opt_result vect_verify_datarefs_alignment (loop_vec_info);
  1273. extern bool vect_slp_analyze_and_verify_instance_alignment (slp_instance);
  1274. extern opt_result vect_analyze_data_ref_accesses (vec_info *);
  1275. extern opt_result vect_prune_runtime_alias_test_list (loop_vec_info);
  1276. extern bool vect_gather_scatter_fn_p (bool, bool, tree, tree, unsigned int,
  1277. signop, int, internal_fn *, tree *);
  1278. extern bool vect_check_gather_scatter (stmt_vec_info, loop_vec_info,
  1279. gather_scatter_info *);
  1280. extern opt_result vect_find_stmt_data_reference (loop_p, gimple *,
  1281. vec<data_reference_p> *);
  1282. extern opt_result vect_analyze_data_refs (vec_info *, poly_uint64 *);
  1283. extern void vect_record_base_alignments (vec_info *);
  1284. extern tree vect_create_data_ref_ptr (stmt_vec_info, tree, struct loop *, tree,
  1285. tree *, gimple_stmt_iterator *,
  1286. gimple **, bool,
  1287. tree = NULL_TREE, tree = NULL_TREE);
  1288. extern tree bump_vector_ptr (tree, gimple *, gimple_stmt_iterator *,
  1289. stmt_vec_info, tree);
  1290. extern void vect_copy_ref_info (tree, tree);
  1291. extern tree vect_create_destination_var (tree, tree);
  1292. extern bool vect_grouped_store_supported (tree, unsigned HOST_WIDE_INT);
  1293. extern bool vect_store_lanes_supported (tree, unsigned HOST_WIDE_INT, bool);
  1294. extern bool vect_grouped_load_supported (tree, bool, unsigned HOST_WIDE_INT);
  1295. extern bool vect_load_lanes_supported (tree, unsigned HOST_WIDE_INT, bool);
  1296. extern void vect_permute_store_chain (vec<tree> ,unsigned int, stmt_vec_info,
  1297. gimple_stmt_iterator *, vec<tree> *);
  1298. extern tree vect_setup_realignment (stmt_vec_info, gimple_stmt_iterator *,
  1299. tree *, enum dr_alignment_support, tree,
  1300. struct loop **);
  1301. extern void vect_transform_grouped_load (stmt_vec_info, vec<tree> , int,
  1302. gimple_stmt_iterator *);
  1303. extern void vect_record_grouped_load_vectors (stmt_vec_info, vec<tree>);
  1304. extern tree vect_get_new_vect_var (tree, enum vect_var_kind, const char *);
  1305. extern tree vect_get_new_ssa_name (tree, enum vect_var_kind,
  1306. const char * = NULL);
  1307. extern tree vect_create_addr_base_for_vector_ref (stmt_vec_info, gimple_seq *,
  1308. tree, tree = NULL_TREE);
  1309. /* In tree-vect-loop.c. */
  1310. /* FORNOW: Used in tree-parloops.c. */
  1311. extern stmt_vec_info vect_force_simple_reduction (loop_vec_info, stmt_vec_info,
  1312. bool *, bool);
  1313. /* Used in gimple-loop-interchange.c. */
  1314. extern bool check_reduction_path (dump_user_location_t, loop_p, gphi *, tree,
  1315. enum tree_code);
  1316. /* Drive for loop analysis stage. */
  1317. extern opt_loop_vec_info vect_analyze_loop (struct loop *,
  1318. loop_vec_info,
  1319. vec_info_shared *);
  1320. extern tree vect_build_loop_niters (loop_vec_info, bool * = NULL);
  1321. extern void vect_gen_vector_loop_niters (loop_vec_info, tree, tree *,
  1322. tree *, bool);
  1323. extern tree vect_halve_mask_nunits (tree);
  1324. extern tree vect_double_mask_nunits (tree);
  1325. extern void vect_record_loop_mask (loop_vec_info, vec_loop_masks *,
  1326. unsigned int, tree);
  1327. extern tree vect_get_loop_mask (gimple_stmt_iterator *, vec_loop_masks *,
  1328. unsigned int, tree, unsigned int);
  1329. /* Drive for loop transformation stage. */
  1330. extern struct loop *vect_transform_loop (loop_vec_info);
  1331. extern opt_loop_vec_info vect_analyze_loop_form (struct loop *,
  1332. vec_info_shared *);
  1333. extern bool vectorizable_live_operation (stmt_vec_info, gimple_stmt_iterator *,
  1334. slp_tree, int, stmt_vec_info *,
  1335. stmt_vector_for_cost *);
  1336. extern bool vectorizable_reduction (stmt_vec_info, gimple_stmt_iterator *,
  1337. stmt_vec_info *, slp_tree, slp_instance,
  1338. stmt_vector_for_cost *);
  1339. extern bool vectorizable_induction (stmt_vec_info, gimple_stmt_iterator *,
  1340. stmt_vec_info *, slp_tree,
  1341. stmt_vector_for_cost *);
  1342. extern tree get_initial_def_for_reduction (stmt_vec_info, tree, tree *);
  1343. extern bool vect_worthwhile_without_simd_p (vec_info *, tree_code);
  1344. extern int vect_get_known_peeling_cost (loop_vec_info, int, int *,
  1345. stmt_vector_for_cost *,
  1346. stmt_vector_for_cost *,
  1347. stmt_vector_for_cost *);
  1348. extern tree cse_and_gimplify_to_preheader (loop_vec_info, tree);
  1349. /* In tree-vect-slp.c. */
  1350. extern void vect_free_slp_instance (slp_instance, bool);
  1351. extern bool vect_transform_slp_perm_load (slp_tree, vec<tree> ,
  1352. gimple_stmt_iterator *, poly_uint64,
  1353. slp_instance, bool, unsigned *);
  1354. extern bool vect_slp_analyze_operations (vec_info *);
  1355. extern void vect_schedule_slp (vec_info *);
  1356. extern opt_result vect_analyze_slp (vec_info *, unsigned);
  1357. extern bool vect_make_slp_decision (loop_vec_info);
  1358. extern void vect_detect_hybrid_slp (loop_vec_info);
  1359. extern void vect_get_slp_defs (vec<tree> , slp_tree, vec<vec<tree> > *);
  1360. extern bool vect_slp_bb (basic_block);
  1361. extern stmt_vec_info vect_find_last_scalar_stmt_in_slp (slp_tree);
  1362. extern bool is_simple_and_all_uses_invariant (stmt_vec_info, loop_vec_info);
  1363. extern bool can_duplicate_and_interleave_p (unsigned int, machine_mode,
  1364. unsigned int * = NULL,
  1365. tree * = NULL, tree * = NULL);
  1366. extern void duplicate_and_interleave (gimple_seq *, tree, vec<tree>,
  1367. unsigned int, vec<tree> &);
  1368. extern int vect_get_place_in_interleaving_chain (stmt_vec_info, stmt_vec_info);
  1369. /* In tree-vect-patterns.c. */
  1370. /* Pattern recognition functions.
  1371. Additional pattern recognition functions can (and will) be added
  1372. in the future. */
  1373. void vect_pattern_recog (vec_info *);
  1374. /* In tree-vectorizer.c. */
  1375. unsigned vectorize_loops (void);
  1376. void vect_free_loop_info_assumptions (struct loop *);
  1377. #endif /* GCC_TREE_VECTORIZER_H */