//===- llvm/Analysis/ScalarEvolutionExpressions.h - SCEV Exprs --*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file defines the classes used to represent and build scalar expressions. // //===----------------------------------------------------------------------===// #ifndef LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H #define LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/ScalarEvolution.h" #include "llvm/IR/Constants.h" #include "llvm/IR/ValueHandle.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" #include <cassert> #include <cstddef> namespace llvm { class APInt; class Constant; class ConstantInt; class ConstantRange; class Loop; class Type; class Value; enum SCEVTypes : unsigned short { … }; /// This class represents a constant integer value. class SCEVConstant : public SCEV { … }; /// This class represents the value of vscale, as used when defining the length /// of a scalable vector or returned by the llvm.vscale() intrinsic. class SCEVVScale : public SCEV { … }; inline unsigned short computeExpressionSize(ArrayRef<const SCEV *> Args) { … } /// This is the base class for unary cast operator classes. class SCEVCastExpr : public SCEV { … }; /// This class represents a cast from a pointer to a pointer-sized integer /// value. class SCEVPtrToIntExpr : public SCEVCastExpr { … }; /// This is the base class for unary integral cast operator classes. class SCEVIntegralCastExpr : public SCEVCastExpr { … }; /// This class represents a truncation of an integer value to a /// smaller integer value. class SCEVTruncateExpr : public SCEVIntegralCastExpr { … }; /// This class represents a zero extension of a small integer value /// to a larger integer value. class SCEVZeroExtendExpr : public SCEVIntegralCastExpr { … }; /// This class represents a sign extension of a small integer value /// to a larger integer value. class SCEVSignExtendExpr : public SCEVIntegralCastExpr { … }; /// This node is a base class providing common functionality for /// n'ary operators. class SCEVNAryExpr : public SCEV { … }; /// This node is the base class for n'ary commutative operators. class SCEVCommutativeExpr : public SCEVNAryExpr { … }; /// This node represents an addition of some number of SCEVs. class SCEVAddExpr : public SCEVCommutativeExpr { … }; /// This node represents multiplication of some number of SCEVs. class SCEVMulExpr : public SCEVCommutativeExpr { … }; /// This class represents a binary unsigned division operation. class SCEVUDivExpr : public SCEV { … }; /// This node represents a polynomial recurrence on the trip count /// of the specified loop. This is the primary focus of the /// ScalarEvolution framework; all the other SCEV subclasses are /// mostly just supporting infrastructure to allow SCEVAddRecExpr /// expressions to be created and analyzed. /// /// All operands of an AddRec are required to be loop invariant. /// class SCEVAddRecExpr : public SCEVNAryExpr { … }; /// This node is the base class min/max selections. class SCEVMinMaxExpr : public SCEVCommutativeExpr { … }; /// This class represents a signed maximum selection. class SCEVSMaxExpr : public SCEVMinMaxExpr { … }; /// This class represents an unsigned maximum selection. class SCEVUMaxExpr : public SCEVMinMaxExpr { … }; /// This class represents a signed minimum selection. class SCEVSMinExpr : public SCEVMinMaxExpr { … }; /// This class represents an unsigned minimum selection. class SCEVUMinExpr : public SCEVMinMaxExpr { … }; /// This node is the base class for sequential/in-order min/max selections. /// Note that their fundamental difference from SCEVMinMaxExpr's is that they /// are early-returning upon reaching saturation point. /// I.e. given `0 umin_seq poison`, the result will be `0`, /// while the result of `0 umin poison` is `poison`. class SCEVSequentialMinMaxExpr : public SCEVNAryExpr { … }; /// This class represents a sequential/in-order unsigned minimum selection. class SCEVSequentialUMinExpr : public SCEVSequentialMinMaxExpr { … }; /// This means that we are dealing with an entirely unknown SCEV /// value, and only represent it as its LLVM Value. This is the /// "bottom" value for the analysis. class SCEVUnknown final : public SCEV, private CallbackVH { … }; /// This class defines a simple visitor class that may be used for /// various SCEV analysis purposes. template <typename SC, typename RetVal = void> struct SCEVVisitor { … }; /// Visit all nodes in the expression tree using worklist traversal. /// /// Visitor implements: /// // return true to follow this node. /// bool follow(const SCEV *S); /// // return true to terminate the search. /// bool isDone(); template <typename SV> class SCEVTraversal { … }; /// Use SCEVTraversal to visit all nodes in the given expression tree. template <typename SV> void visitAll(const SCEV *Root, SV &Visitor) { … } /// Return true if any node in \p Root satisfies the predicate \p Pred. template <typename PredTy> bool SCEVExprContains(const SCEV *Root, PredTy Pred) { … } /// This visitor recursively visits a SCEV expression and re-writes it. /// The result from each visit is cached, so it will return the same /// SCEV for the same input. template <typename SC> class SCEVRewriteVisitor : public SCEVVisitor<SC, const SCEV *> { … }; ValueToValueMap; ValueToSCEVMapTy; /// The SCEVParameterRewriter takes a scalar evolution expression and updates /// the SCEVUnknown components following the Map (Value -> SCEV). class SCEVParameterRewriter : public SCEVRewriteVisitor<SCEVParameterRewriter> { … }; LoopToScevMapT; /// The SCEVLoopAddRecRewriter takes a scalar evolution expression and applies /// the Map (Loop -> SCEV) to all AddRecExprs. class SCEVLoopAddRecRewriter : public SCEVRewriteVisitor<SCEVLoopAddRecRewriter> { … }; } // end namespace llvm #endif // LLVM_ANALYSIS_SCALAREVOLUTIONEXPRESSIONS_H