1 //===- VPlanTransforms.h - Utility VPlan to VPlan transforms --------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file provides utility VPlan to VPlan transformations.
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H
14 #define LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H
15 
16 #include "VPlan.h"
17 #include "llvm/ADT/STLFunctionalExtras.h"
18 
19 namespace llvm {
20 
21 class InductionDescriptor;
22 class Instruction;
23 class PHINode;
24 class ScalarEvolution;
25 class Loop;
26 class PredicatedScalarEvolution;
27 class TargetLibraryInfo;
28 
29 struct VPlanTransforms {
30   /// Replaces the VPInstructions in \p Plan with corresponding
31   /// widen recipes.
32   static void
33   VPInstructionsToVPRecipes(Loop *OrigLoop, VPlanPtr &Plan,
34                             function_ref<const InductionDescriptor *(PHINode *)>
35                                 GetIntOrFpInductionDescriptor,
36                             SmallPtrSetImpl<Instruction *> &DeadInstructions,
37                             ScalarEvolution &SE, const TargetLibraryInfo &TLI);
38 
39   static bool sinkScalarOperands(VPlan &Plan);
40 
41   /// Merge replicate regions in their successor region, if a replicate region
42   /// is connected to a successor replicate region with the same predicate by a
43   /// single, empty VPBasicBlock.
44   static bool mergeReplicateRegionsIntoSuccessors(VPlan &Plan);
45 
46   /// Remove redundant VPBasicBlocks by merging them into their predecessor if
47   /// the predecessor has a single successor.
48   static bool mergeBlocksIntoPredecessors(VPlan &Plan);
49 
50   /// Remove redundant casts of inductions.
51   ///
52   /// Such redundant casts are casts of induction variables that can be ignored,
53   /// because we already proved that the casted phi is equal to the uncasted phi
54   /// in the vectorized loop. There is no need to vectorize the cast - the same
55   /// value can be used for both the phi and casts in the vector loop.
56   static void removeRedundantInductionCasts(VPlan &Plan);
57 
58   /// Try to replace VPWidenCanonicalIVRecipes with a widened canonical IV
59   /// recipe, if it exists.
60   static void removeRedundantCanonicalIVs(VPlan &Plan);
61 
62   static void removeDeadRecipes(VPlan &Plan);
63 
64   /// If any user of a VPWidenIntOrFpInductionRecipe needs scalar values,
65   /// provide them by building scalar steps off of the canonical scalar IV and
66   /// update the original IV's users. This is an optional optimization to reduce
67   /// the needs of vector extracts.
68   static void optimizeInductions(VPlan &Plan, ScalarEvolution &SE);
69 
70   /// Remove redundant EpxandSCEVRecipes in \p Plan's entry block by replacing
71   /// them with already existing recipes expanding the same SCEV expression.
72   static void removeRedundantExpandSCEVRecipes(VPlan &Plan);
73 
74   /// Optimize \p Plan based on \p BestVF and \p BestUF. This may restrict the
75   /// resulting plan to \p BestVF and \p BestUF.
76   static void optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF,
77                                  unsigned BestUF,
78                                  PredicatedScalarEvolution &PSE);
79 };
80 
81 } // namespace llvm
82 
83 #endif // LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H
84