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/STLExtras.h"
18 #include "llvm/Transforms/Vectorize/LoopVectorizationLegality.h"
19 
20 namespace llvm {
21 
22 class InductionDescriptor;
23 class Instruction;
24 class PHINode;
25 class ScalarEvolution;
26 class Loop;
27 
28 struct VPlanTransforms {
29   /// Replaces the VPInstructions in \p Plan with corresponding
30   /// widen recipes.
31   static void
32   VPInstructionsToVPRecipes(Loop *OrigLoop, VPlanPtr &Plan,
33                             function_ref<const InductionDescriptor *(PHINode *)>
34                                 GetIntOrFpInductionDescriptor,
35                             SmallPtrSetImpl<Instruction *> &DeadInstructions,
36                             ScalarEvolution &SE);
37 
38   static bool sinkScalarOperands(VPlan &Plan);
39 
40   static bool mergeReplicateRegions(VPlan &Plan);
41 
42   /// Remove redundant casts of inductions.
43   ///
44   /// Such redundant casts are casts of induction variables that can be ignored,
45   /// because we already proved that the casted phi is equal to the uncasted phi
46   /// in the vectorized loop. There is no need to vectorize the cast - the same
47   /// value can be used for both the phi and casts in the vector loop.
48   static void removeRedundantInductionCasts(VPlan &Plan);
49 
50   /// Try to replace VPWidenCanonicalIVRecipes with a widened canonical IV
51   /// recipe, if it exists.
52   static void removeRedundantCanonicalIVs(VPlan &Plan);
53 
54   /// Try to remove dead recipes. At the moment, only dead header recipes are
55   /// removed.
56   static void removeDeadRecipes(VPlan &Plan, Loop &OrigLoop);
57 
58   //  If all users of a vector IV need scalar values, provide them by building
59   //  scalar steps off of the canonical scalar IV, and remove the vector IV.
60   static void optimizeInductions(VPlan &Plan, ScalarEvolution &SE);
61 };
62 
63 } // namespace llvm
64 
65 #endif // LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H
66