Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:44

0001 //===-- llvm/Transforms/Utils/SimplifyIndVar.h - Indvar Utils ---*- 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 in interface for induction variable simplification. It does
0010 // not define any actual pass or policy, but provides a single function to
0011 // simplify a loop's induction variables based on ScalarEvolution.
0012 //
0013 //===----------------------------------------------------------------------===//
0014 
0015 #ifndef LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
0016 #define LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H
0017 
0018 #include <utility>
0019 
0020 namespace llvm {
0021 
0022 class Type;
0023 class WeakTrackingVH;
0024 template <typename T> class SmallVectorImpl;
0025 class CastInst;
0026 class DominatorTree;
0027 class Loop;
0028 class LoopInfo;
0029 class PHINode;
0030 class ScalarEvolution;
0031 class SCEVExpander;
0032 class TargetTransformInfo;
0033 
0034 /// Interface for visiting interesting IV users that are recognized but not
0035 /// simplified by this utility.
0036 class IVVisitor {
0037 protected:
0038   const DominatorTree *DT = nullptr;
0039 
0040   virtual void anchor();
0041 
0042 public:
0043   IVVisitor() = default;
0044   virtual ~IVVisitor() = default;
0045 
0046   const DominatorTree *getDomTree() const { return DT; }
0047   virtual void visitCast(CastInst *Cast) = 0;
0048 };
0049 
0050 /// simplifyUsersOfIV - Simplify instructions that use this induction variable
0051 /// by using ScalarEvolution to analyze the IV's recurrence. Returns a pair
0052 /// where the first entry indicates that the function makes changes and the
0053 /// second entry indicates that it introduced new opportunities for loop
0054 /// unswitching.
0055 std::pair<bool, bool> simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE,
0056                                         DominatorTree *DT, LoopInfo *LI,
0057                                         const TargetTransformInfo *TTI,
0058                                         SmallVectorImpl<WeakTrackingVH> &Dead,
0059                                         SCEVExpander &Rewriter,
0060                                         IVVisitor *V = nullptr);
0061 
0062 /// SimplifyLoopIVs - Simplify users of induction variables within this
0063 /// loop. This does not actually change or add IVs.
0064 bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, DominatorTree *DT,
0065                      LoopInfo *LI, const TargetTransformInfo *TTI,
0066                      SmallVectorImpl<WeakTrackingVH> &Dead);
0067 
0068 /// Collect information about induction variables that are used by sign/zero
0069 /// extend operations. This information is recorded by CollectExtend and provides
0070 /// the input to WidenIV.
0071 struct WideIVInfo {
0072   PHINode *NarrowIV = nullptr;
0073 
0074   // Widest integer type created [sz]ext
0075   Type *WidestNativeType = nullptr;
0076 
0077   // Was a sext user seen before a zext?
0078   bool IsSigned = false;
0079 };
0080 
0081 /// Widen Induction Variables - Extend the width of an IV to cover its
0082 /// widest uses.
0083 PHINode *createWideIV(const WideIVInfo &WI,
0084     LoopInfo *LI, ScalarEvolution *SE, SCEVExpander &Rewriter,
0085     DominatorTree *DT, SmallVectorImpl<WeakTrackingVH> &DeadInsts,
0086     unsigned &NumElimExt, unsigned &NumWidened,
0087     bool HasGuards, bool UsePostIncrementRanges);
0088 
0089 } // end namespace llvm
0090 
0091 #endif // LLVM_TRANSFORMS_UTILS_SIMPLIFYINDVAR_H