diff options
Diffstat (limited to 'include/llvm/Analysis/ValueTracking.h')
-rw-r--r-- | include/llvm/Analysis/ValueTracking.h | 73 |
1 files changed, 67 insertions, 6 deletions
diff --git a/include/llvm/Analysis/ValueTracking.h b/include/llvm/Analysis/ValueTracking.h index 1c51523b1573..e6a219a8045b 100644 --- a/include/llvm/Analysis/ValueTracking.h +++ b/include/llvm/Analysis/ValueTracking.h @@ -101,6 +101,12 @@ class Value; const Instruction *CxtI = nullptr, const DominatorTree *DT = nullptr); + /// Return true if the two given values are negation. + /// Currently can recoginze Value pair: + /// 1: <X, Y> if X = sub (0, Y) or Y = sub (0, X) + /// 2: <X, Y> if X = sub (A, B) and Y = sub (B, A) + bool isKnownNegation(const Value *X, const Value *Y, bool NeedNSW = false); + /// Returns true if the give value is known to be non-negative. bool isKnownNonNegative(const Value *V, const DataLayout &DL, unsigned Depth = 0, @@ -276,6 +282,22 @@ class Value; /// pointer, return 'len+1'. If we can't, return 0. uint64_t GetStringLength(const Value *V, unsigned CharSize = 8); + /// This function returns call pointer argument that is considered the same by + /// aliasing rules. You CAN'T use it to replace one value with another. + const Value *getArgumentAliasingToReturnedPointer(ImmutableCallSite CS); + inline Value *getArgumentAliasingToReturnedPointer(CallSite CS) { + return const_cast<Value *>( + getArgumentAliasingToReturnedPointer(ImmutableCallSite(CS))); + } + + // {launder,strip}.invariant.group returns pointer that aliases its argument, + // and it only captures pointer by returning it. + // These intrinsics are not marked as nocapture, because returning is + // considered as capture. The arguments are not marked as returned neither, + // because it would make it useless. + bool isIntrinsicReturningPointerAliasingArgumentWithoutCapturing( + ImmutableCallSite CS); + /// This method strips off any GEP address adjustments and pointer casts from /// the specified value, returning the original object being addressed. Note /// that the returned value has pointer type if the specified value does. If @@ -288,7 +310,7 @@ class Value; return GetUnderlyingObject(const_cast<Value *>(V), DL, MaxLookup); } - /// \brief This method is similar to GetUnderlyingObject except that it can + /// This method is similar to GetUnderlyingObject except that it can /// look through phi and select instructions and return multiple objects. /// /// If LoopInfo is passed, loop phis are further analyzed. If a pointer @@ -384,6 +406,11 @@ class Value; AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT); + OverflowResult computeOverflowForSignedMul(const Value *LHS, const Value *RHS, + const DataLayout &DL, + AssumptionCache *AC, + const Instruction *CxtI, + const DominatorTree *DT); OverflowResult computeOverflowForUnsignedAdd(const Value *LHS, const Value *RHS, const DataLayout &DL, @@ -401,6 +428,16 @@ class Value; AssumptionCache *AC = nullptr, const Instruction *CxtI = nullptr, const DominatorTree *DT = nullptr); + OverflowResult computeOverflowForUnsignedSub(const Value *LHS, const Value *RHS, + const DataLayout &DL, + AssumptionCache *AC, + const Instruction *CxtI, + const DominatorTree *DT); + OverflowResult computeOverflowForSignedSub(const Value *LHS, const Value *RHS, + const DataLayout &DL, + AssumptionCache *AC, + const Instruction *CxtI, + const DominatorTree *DT); /// Returns true if the arithmetic part of the \p II 's result is /// used only along the paths control dependent on the computation @@ -423,6 +460,13 @@ class Value; /// though division by zero might cause undefined behavior. bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I); + /// Returns true if this block does not contain a potential implicit exit. + /// This is equivelent to saying that all instructions within the basic block + /// are guaranteed to transfer execution to their successor within the basic + /// block. This has the same assumptions w.r.t. undefined behavior as the + /// instruction variant of this function. + bool isGuaranteedToTransferExecutionToSuccessor(const BasicBlock *BB); + /// Return true if this function can prove that the instruction I /// is executed for every iteration of the loop L. /// @@ -454,7 +498,7 @@ class Value; /// the parent of I. bool programUndefinedIfFullPoison(const Instruction *PoisonI); - /// \brief Specific patterns of select instructions we can match. + /// Specific patterns of select instructions we can match. enum SelectPatternFlavor { SPF_UNKNOWN = 0, SPF_SMIN, /// Signed minimum @@ -467,7 +511,7 @@ class Value; SPF_NABS /// Negated absolute value }; - /// \brief Behavior when a floating point min/max is given one NaN and one + /// Behavior when a floating point min/max is given one NaN and one /// non-NaN as input. enum SelectPatternNaNBehavior { SPNB_NA = 0, /// NaN behavior not applicable. @@ -486,15 +530,18 @@ class Value; /// fcmp; select, does the fcmp have to be /// ordered? - /// \brief Return true if \p SPF is a min or a max pattern. + /// Return true if \p SPF is a min or a max pattern. static bool isMinOrMax(SelectPatternFlavor SPF) { - return !(SPF == SPF_UNKNOWN || SPF == SPF_ABS || SPF == SPF_NABS); + return SPF != SPF_UNKNOWN && SPF != SPF_ABS && SPF != SPF_NABS; } }; /// Pattern match integer [SU]MIN, [SU]MAX and ABS idioms, returning the kind /// and providing the out parameter results if we successfully match. /// + /// For ABS/NABS, LHS will be set to the input to the abs idiom. RHS will be + /// the negation instruction from the idiom. + /// /// If CastOp is not nullptr, also match MIN/MAX idioms where the type does /// not match that of the original select. If this is the case, the cast /// operation (one of Trunc,SExt,Zext) that must be done to transform the @@ -508,7 +555,8 @@ class Value; /// -> LHS = %a, RHS = i32 4, *CastOp = Instruction::SExt /// SelectPatternResult matchSelectPattern(Value *V, Value *&LHS, Value *&RHS, - Instruction::CastOps *CastOp = nullptr); + Instruction::CastOps *CastOp = nullptr, + unsigned Depth = 0); inline SelectPatternResult matchSelectPattern(const Value *V, const Value *&LHS, const Value *&RHS, Instruction::CastOps *CastOp = nullptr) { @@ -520,6 +568,19 @@ class Value; return Result; } + /// Return the canonical comparison predicate for the specified + /// minimum/maximum flavor. + CmpInst::Predicate getMinMaxPred(SelectPatternFlavor SPF, + bool Ordered = false); + + /// Return the inverse minimum/maximum flavor of the specified flavor. + /// For example, signed minimum is the inverse of signed maximum. + SelectPatternFlavor getInverseMinMaxFlavor(SelectPatternFlavor SPF); + + /// Return the canonical inverse comparison predicate for the specified + /// minimum/maximum flavor. + CmpInst::Predicate getInverseMinMaxPred(SelectPatternFlavor SPF); + /// Return true if RHS is known to be implied true by LHS. Return false if /// RHS is known to be implied false by LHS. Otherwise, return None if no /// implication can be made. |