1e60b36cfSFlorian Hahn //===- VPlanTransforms.h - Utility VPlan to VPlan transforms --------------===// 2e60b36cfSFlorian Hahn // 3e60b36cfSFlorian Hahn // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4e60b36cfSFlorian Hahn // See https://llvm.org/LICENSE.txt for license information. 5e60b36cfSFlorian Hahn // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6e60b36cfSFlorian Hahn // 7e60b36cfSFlorian Hahn //===----------------------------------------------------------------------===// 8e60b36cfSFlorian Hahn /// 9e60b36cfSFlorian Hahn /// \file 10e60b36cfSFlorian Hahn /// This file provides utility VPlan to VPlan transformations. 11e60b36cfSFlorian Hahn //===----------------------------------------------------------------------===// 12e60b36cfSFlorian Hahn 13e60b36cfSFlorian Hahn #ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H 14e60b36cfSFlorian Hahn #define LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H 15e60b36cfSFlorian Hahn 16e60b36cfSFlorian Hahn #include "VPlan.h" 171b89c832Sserge-sans-paille #include "llvm/ADT/STLFunctionalExtras.h" 18e60b36cfSFlorian Hahn 19e60b36cfSFlorian Hahn namespace llvm { 20e60b36cfSFlorian Hahn 21978883d2SFlorian Hahn class InductionDescriptor; 2249999d43SFlorian Hahn class Instruction; 23978883d2SFlorian Hahn class PHINode; 2449999d43SFlorian Hahn class ScalarEvolution; 25da740492SFlorian Hahn class Loop; 2649999d43SFlorian Hahn 27ae1e353aSFlorian Hahn struct VPlanTransforms { 28e60b36cfSFlorian Hahn /// Replaces the VPInstructions in \p Plan with corresponding 29e60b36cfSFlorian Hahn /// widen recipes. 30978883d2SFlorian Hahn static void 31978883d2SFlorian Hahn VPInstructionsToVPRecipes(Loop *OrigLoop, VPlanPtr &Plan, 32978883d2SFlorian Hahn function_ref<const InductionDescriptor *(PHINode *)> 33978883d2SFlorian Hahn GetIntOrFpInductionDescriptor, 34978883d2SFlorian Hahn SmallPtrSetImpl<Instruction *> &DeadInstructions, 35978883d2SFlorian Hahn ScalarEvolution &SE); 3665d3dd7cSFlorian Hahn 3765d3dd7cSFlorian Hahn static bool sinkScalarOperands(VPlan &Plan); 3880aa7e14SFlorian Hahn 3980aa7e14SFlorian Hahn static bool mergeReplicateRegions(VPlan &Plan); 40505ad03cSFlorian Hahn 41505ad03cSFlorian Hahn /// Remove redundant casts of inductions. 42505ad03cSFlorian Hahn /// 43505ad03cSFlorian Hahn /// Such redundant casts are casts of induction variables that can be ignored, 44505ad03cSFlorian Hahn /// because we already proved that the casted phi is equal to the uncasted phi 45505ad03cSFlorian Hahn /// in the vectorized loop. There is no need to vectorize the cast - the same 46505ad03cSFlorian Hahn /// value can be used for both the phi and casts in the vector loop. 47505ad03cSFlorian Hahn static void removeRedundantInductionCasts(VPlan &Plan); 485f2854f1SFlorian Hahn 495f2854f1SFlorian Hahn /// Try to replace VPWidenCanonicalIVRecipes with a widened canonical IV 505f2854f1SFlorian Hahn /// recipe, if it exists. 515f2854f1SFlorian Hahn static void removeRedundantCanonicalIVs(VPlan &Plan); 52da740492SFlorian Hahn 53*763f2bdbSFlorian Hahn static void removeDeadRecipes(VPlan &Plan); 54b3e8ace1SFlorian Hahn 5595f76bffSFlorian Hahn /// If any user of a VPWidenIntOrFpInductionRecipe needs scalar values, 5695f76bffSFlorian Hahn /// provide them by building scalar steps off of the canonical scalar IV and 5795f76bffSFlorian Hahn /// update the original IV's users. This is an optional optimization to reduce 5895f76bffSFlorian Hahn /// the needs of vector extracts. 59b3e8ace1SFlorian Hahn static void optimizeInductions(VPlan &Plan, ScalarEvolution &SE); 60a65f2730SFlorian Hahn 61a65f2730SFlorian Hahn /// Remove redundant EpxandSCEVRecipes in \p Plan's entry block by replacing 62a65f2730SFlorian Hahn /// them with already existing recipes expanding the same SCEV expression. 63a65f2730SFlorian Hahn static void removeRedundantExpandSCEVRecipes(VPlan &Plan); 64e60b36cfSFlorian Hahn }; 65e60b36cfSFlorian Hahn 66e60b36cfSFlorian Hahn } // namespace llvm 67e60b36cfSFlorian Hahn 68e60b36cfSFlorian Hahn #endif // LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H 69