Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:17

0001 //===- llvm/Analysis/ScalarEvolutionNormalization.h - See below -*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines utilities for working with "normalized" ScalarEvolution
0010 // expressions.
0011 //
0012 // The following example illustrates post-increment uses and how normalized
0013 // expressions help.
0014 //
0015 //   for (i=0; i!=n; ++i) {
0016 //     ...
0017 //   }
0018 //   use(i);
0019 //
0020 // While the expression for most uses of i inside the loop is {0,+,1}<%L>, the
0021 // expression for the use of i outside the loop is {1,+,1}<%L>, since i is
0022 // incremented at the end of the loop body. This is inconveient, since it
0023 // suggests that we need two different induction variables, one that starts
0024 // at 0 and one that starts at 1. We'd prefer to be able to think of these as
0025 // the same induction variable, with uses inside the loop using the
0026 // "pre-incremented" value, and uses after the loop using the
0027 // "post-incremented" value.
0028 //
0029 // Expressions for post-incremented uses are represented as an expression
0030 // paired with a set of loops for which the expression is in "post-increment"
0031 // mode (there may be multiple loops).
0032 //
0033 //===----------------------------------------------------------------------===//
0034 
0035 #ifndef LLVM_ANALYSIS_SCALAREVOLUTIONNORMALIZATION_H
0036 #define LLVM_ANALYSIS_SCALAREVOLUTIONNORMALIZATION_H
0037 
0038 #include "llvm/ADT/STLFunctionalExtras.h"
0039 #include "llvm/ADT/SmallPtrSet.h"
0040 
0041 namespace llvm {
0042 
0043 class Loop;
0044 class ScalarEvolution;
0045 class SCEV;
0046 class SCEVAddRecExpr;
0047 
0048 typedef SmallPtrSet<const Loop *, 2> PostIncLoopSet;
0049 
0050 typedef function_ref<bool(const SCEVAddRecExpr *)> NormalizePredTy;
0051 
0052 /// Normalize \p S to be post-increment for all loops present in \p
0053 /// Loops. Returns nullptr if the result is not invertible and \p
0054 /// CheckInvertible is true.
0055 const SCEV *normalizeForPostIncUse(const SCEV *S, const PostIncLoopSet &Loops,
0056                                    ScalarEvolution &SE,
0057                                    bool CheckInvertible = true);
0058 
0059 /// Normalize \p S for all add recurrence sub-expressions for which \p
0060 /// Pred returns true.
0061 const SCEV *normalizeForPostIncUseIf(const SCEV *S, NormalizePredTy Pred,
0062                                      ScalarEvolution &SE);
0063 
0064 /// Denormalize \p S to be post-increment for all loops present in \p
0065 /// Loops.
0066 const SCEV *denormalizeForPostIncUse(const SCEV *S, const PostIncLoopSet &Loops,
0067                                      ScalarEvolution &SE);
0068 } // namespace llvm
0069 
0070 #endif