VPlanTransforms.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #ifndef LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H
  13. #define LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H
  14. #include "VPlan.h"
  15. #include "llvm/ADT/STLFunctionalExtras.h"
  16. namespace llvm {
  17. class InductionDescriptor;
  18. class Instruction;
  19. class PHINode;
  20. class ScalarEvolution;
  21. class Loop;
  22. class PredicatedScalarEvolution;
  23. class TargetLibraryInfo;
  24. struct VPlanTransforms {
  25. /// Replaces the VPInstructions in \p Plan with corresponding
  26. /// widen recipes.
  27. static void
  28. VPInstructionsToVPRecipes(Loop *OrigLoop, VPlanPtr &Plan,
  29. function_ref<const InductionDescriptor *(PHINode *)>
  30. GetIntOrFpInductionDescriptor,
  31. SmallPtrSetImpl<Instruction *> &DeadInstructions,
  32. ScalarEvolution &SE, const TargetLibraryInfo &TLI);
  33. static bool sinkScalarOperands(VPlan &Plan);
  34. /// Merge replicate regions in their successor region, if a replicate region
  35. /// is connected to a successor replicate region with the same predicate by a
  36. /// single, empty VPBasicBlock.
  37. static bool mergeReplicateRegionsIntoSuccessors(VPlan &Plan);
  38. /// Remove redundant VPBasicBlocks by merging them into their predecessor if
  39. /// the predecessor has a single successor.
  40. static bool mergeBlocksIntoPredecessors(VPlan &Plan);
  41. /// Remove redundant casts of inductions.
  42. ///
  43. /// Such redundant casts are casts of induction variables that can be ignored,
  44. /// because we already proved that the casted phi is equal to the uncasted phi
  45. /// in the vectorized loop. There is no need to vectorize the cast - the same
  46. /// value can be used for both the phi and casts in the vector loop.
  47. static void removeRedundantInductionCasts(VPlan &Plan);
  48. /// Try to replace VPWidenCanonicalIVRecipes with a widened canonical IV
  49. /// recipe, if it exists.
  50. static void removeRedundantCanonicalIVs(VPlan &Plan);
  51. static void removeDeadRecipes(VPlan &Plan);
  52. /// If any user of a VPWidenIntOrFpInductionRecipe needs scalar values,
  53. /// provide them by building scalar steps off of the canonical scalar IV and
  54. /// update the original IV's users. This is an optional optimization to reduce
  55. /// the needs of vector extracts.
  56. static void optimizeInductions(VPlan &Plan, ScalarEvolution &SE);
  57. /// Remove redundant EpxandSCEVRecipes in \p Plan's entry block by replacing
  58. /// them with already existing recipes expanding the same SCEV expression.
  59. static void removeRedundantExpandSCEVRecipes(VPlan &Plan);
  60. /// Optimize \p Plan based on \p BestVF and \p BestUF. This may restrict the
  61. /// resulting plan to \p BestVF and \p BestUF.
  62. static void optimizeForVFAndUF(VPlan &Plan, ElementCount BestVF,
  63. unsigned BestUF,
  64. PredicatedScalarEvolution &PSE);
  65. };
  66. } // namespace llvm
  67. #endif // LLVM_TRANSFORMS_VECTORIZE_VPLANTRANSFORMS_H