ScalarEvolutionNormalization.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/Analysis/ScalarEvolutionNormalization.h - See below -*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines utilities for working with "normalized" ScalarEvolution
  15. // expressions.
  16. //
  17. // The following example illustrates post-increment uses and how normalized
  18. // expressions help.
  19. //
  20. // for (i=0; i!=n; ++i) {
  21. // ...
  22. // }
  23. // use(i);
  24. //
  25. // While the expression for most uses of i inside the loop is {0,+,1}<%L>, the
  26. // expression for the use of i outside the loop is {1,+,1}<%L>, since i is
  27. // incremented at the end of the loop body. This is inconveient, since it
  28. // suggests that we need two different induction variables, one that starts
  29. // at 0 and one that starts at 1. We'd prefer to be able to think of these as
  30. // the same induction variable, with uses inside the loop using the
  31. // "pre-incremented" value, and uses after the loop using the
  32. // "post-incremented" value.
  33. //
  34. // Expressions for post-incremented uses are represented as an expression
  35. // paired with a set of loops for which the expression is in "post-increment"
  36. // mode (there may be multiple loops).
  37. //
  38. //===----------------------------------------------------------------------===//
  39. #ifndef LLVM_ANALYSIS_SCALAREVOLUTIONNORMALIZATION_H
  40. #define LLVM_ANALYSIS_SCALAREVOLUTIONNORMALIZATION_H
  41. #include "llvm/ADT/STLExtras.h"
  42. #include "llvm/ADT/SmallPtrSet.h"
  43. namespace llvm {
  44. class Loop;
  45. class ScalarEvolution;
  46. class SCEV;
  47. class SCEVAddRecExpr;
  48. typedef SmallPtrSet<const Loop *, 2> PostIncLoopSet;
  49. typedef function_ref<bool(const SCEVAddRecExpr *)> NormalizePredTy;
  50. /// Normalize \p S to be post-increment for all loops present in \p
  51. /// Loops.
  52. const SCEV *normalizeForPostIncUse(const SCEV *S, const PostIncLoopSet &Loops,
  53. ScalarEvolution &SE);
  54. /// Normalize \p S for all add recurrence sub-expressions for which \p
  55. /// Pred returns true.
  56. const SCEV *normalizeForPostIncUseIf(const SCEV *S, NormalizePredTy Pred,
  57. ScalarEvolution &SE);
  58. /// Denormalize \p S to be post-increment for all loops present in \p
  59. /// Loops.
  60. const SCEV *denormalizeForPostIncUse(const SCEV *S, const PostIncLoopSet &Loops,
  61. ScalarEvolution &SE);
  62. } // namespace llvm
  63. #endif
  64. #ifdef __GNUC__
  65. #pragma GCC diagnostic pop
  66. #endif