LLVM  13.0.0git
Namespaces | Macros | Functions | Variables
LazyValueInfo.cpp File Reference
#include "llvm/Analysis/LazyValueInfo.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/ConstantFolding.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/ValueLattice.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/AssemblyAnnotationWriter.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/raw_ostream.h"
#include <map>
Include dependency graph for LazyValueInfo.cpp:

Go to the source code of this file.


 ---------------------— PointerInfo ------------------------------------—


#define DEBUG_TYPE   "lazy-value-info"


 INITIALIZE_PASS_BEGIN (LazyValueInfoWrapperPass, "lazy-value-info", "Lazy Value Information Analysis", false, true) INITIALIZE_PASS_END(LazyValueInfoWrapperPass
FunctionPassllvm::createLazyValueInfoPass ()
 createLazyValueInfoPass - This creates an instance of the LazyValueInfo pass. More...
static bool hasSingleValue (const ValueLatticeElement &Val)
 Returns true if this lattice value represents at most one possible value. More...
static ValueLatticeElement intersect (const ValueLatticeElement &A, const ValueLatticeElement &B)
 Combine two sets of facts about the same value into a single set of facts. More...
static ValueLatticeElement getFromRangeMetadata (Instruction *BBI)
static void AddNonNullPointer (Value *Ptr, NonNullPointerSet &PtrSet)
static void AddNonNullPointersByInstruction (Instruction *I, NonNullPointerSet &PtrSet)
static ValueLatticeElement getValueFromCondition (Value *Val, Value *Cond, bool isTrueDest=true)
static bool matchICmpOperand (APInt &Offset, Value *LHS, Value *Val, ICmpInst::Predicate Pred)
static ValueLatticeElement getValueFromSimpleICmpCondition (CmpInst::Predicate Pred, Value *RHS, const APInt &Offset)
 Get value range for a "(Val + Offset) Pred RHS" condition. More...
static ValueLatticeElement getValueFromICmpCondition (Value *Val, ICmpInst *ICI, bool isTrueDest)
static ValueLatticeElement getValueFromOverflowCondition (Value *Val, WithOverflowInst *WO, bool IsTrueDest)
static Optional< ValueLatticeElementgetValueFromConditionImpl (Value *Val, Value *Cond, bool isTrueDest, bool isRevisit, SmallDenseMap< Value *, ValueLatticeElement > &Visited, SmallVectorImpl< Value * > &Worklist)
static bool usesOperand (User *Usr, Value *Op)
static bool isOperationFoldable (User *Usr)
static ValueLatticeElement constantFoldUser (User *Usr, Value *Op, const APInt &OpConstVal, const DataLayout &DL)
static Optional< ValueLatticeElementgetEdgeValueLocal (Value *Val, BasicBlock *BBFrom, BasicBlock *BBTo)
 Compute the value of Val on the edge BBFrom -> BBTo. More...
static LazyValueInfoImpl & getImpl (void *&PImpl, AssumptionCache *AC, const Module *M)
 This lazily constructs the LazyValueInfoImpl. More...
static bool isKnownNonConstant (Value *V)
 Returns true if we can statically tell that this value will never be a "useful" constant. More...
static LazyValueInfo::Tristate getPredicateResult (unsigned Pred, Constant *C, const ValueLatticeElement &Val, const DataLayout &DL, TargetLibraryInfo *TLI)
 INITIALIZE_PASS_BEGIN (LazyValueInfoPrinter, "print-lazy-value-info", "Lazy Value Info Printer Pass", false, false) INITIALIZE_PASS_END(LazyValueInfoPrinter


static const unsigned MaxProcessedPerValue = 500
lazy value info
lazy value Lazy Value Information Analysis
lazy value Lazy Value Information false
print lazy value Lazy Value Info Printer Pass

Macro Definition Documentation


#define DEBUG_TYPE   "lazy-value-info"

Definition at line 45 of file LazyValueInfo.cpp.

Function Documentation

◆ AddNonNullPointer()

static void AddNonNullPointer ( Value Ptr,
NonNullPointerSet &  PtrSet 

◆ AddNonNullPointersByInstruction()

static void AddNonNullPointersByInstruction ( Instruction I,
NonNullPointerSet &  PtrSet 

Definition at line 637 of file LazyValueInfo.cpp.

References AddNonNullPointer(), I, llvm::ConstantInt::isZero(), MI, and S.

◆ constantFoldUser()

static ValueLatticeElement constantFoldUser ( User Usr,
Value Op,
const APInt OpConstVal,
const DataLayout DL 

◆ getEdgeValueLocal()

static Optional<ValueLatticeElement> getEdgeValueLocal ( Value Val,
BasicBlock BBFrom,
BasicBlock BBTo 

◆ getFromRangeMetadata()

static ValueLatticeElement getFromRangeMetadata ( Instruction BBI)

◆ getImpl()

static LazyValueInfoImpl& getImpl ( void *&  PImpl,
AssumptionCache AC,
const Module M 

◆ getPredicateResult()

static LazyValueInfo::Tristate getPredicateResult ( unsigned  Pred,
Constant C,
const ValueLatticeElement Val,
const DataLayout DL,
TargetLibraryInfo TLI 

◆ getValueFromCondition()

ValueLatticeElement getValueFromCondition ( Value Val,
Value Cond,
bool  isTrueDest = true 

◆ getValueFromConditionImpl()

static Optional<ValueLatticeElement> getValueFromConditionImpl ( Value Val,
Value Cond,
bool  isTrueDest,
bool  isRevisit,
SmallDenseMap< Value *, ValueLatticeElement > &  Visited,
SmallVectorImpl< Value * > &  Worklist 

◆ getValueFromICmpCondition()

static ValueLatticeElement getValueFromICmpCondition ( Value Val,
ICmpInst ICI,
bool  isTrueDest 

◆ getValueFromOverflowCondition()

static ValueLatticeElement getValueFromOverflowCondition ( Value Val,
WithOverflowInst WO,
bool  IsTrueDest 

◆ getValueFromSimpleICmpCondition()

static ValueLatticeElement getValueFromSimpleICmpCondition ( CmpInst::Predicate  Pred,
Value RHS,
const APInt Offset 

◆ hasSingleValue()

static bool hasSingleValue ( const ValueLatticeElement Val)

Returns true if this lattice value represents at most one possible value.

This is as precise as any lattice value can get while still representing reachable code.

Definition at line 71 of file LazyValueInfo.cpp.

References llvm::ValueLatticeElement::getConstantRange(), llvm::ValueLatticeElement::isConstant(), llvm::ValueLatticeElement::isConstantRange(), and llvm::ConstantRange::isSingleElement().

Referenced by intersect().


INITIALIZE_PASS_BEGIN ( LazyValueInfoPrinter  ,
"print-lazy-value-info ,
"Lazy Value Info Printer Pass ,
false  ,


INITIALIZE_PASS_BEGIN ( LazyValueInfoWrapperPass  ,
"lazy-value-info ,
"Lazy Value Information Analysis ,
false  ,

◆ intersect()

static ValueLatticeElement intersect ( const ValueLatticeElement A,
const ValueLatticeElement B 

Combine two sets of facts about the same value into a single set of facts.

Note that this method is not suitable for merging facts along different paths in a CFG; that's what the mergeIn function is for. This is for merging facts gathered about the same value at the same location through two independent means. Notes:

  • This method does not promise to return the most precise possible lattice value implied by A and B. It is allowed to return any lattice element which is at least as strong as either A or B (unless our facts conflict, see below).
  • Due to unreachable code, the intersection of two lattice values could be contradictory. If this happens, we return some valid lattice value so as not confuse the rest of LVI. Ideally, we'd always return Undefined, but we do not make this guarantee. TODO: This would be a useful enhancement.

Definition at line 96 of file LazyValueInfo.cpp.

References B, llvm::ValueLatticeElement::getRange(), hasSingleValue(), and move.

Referenced by getValueFromConditionImpl().

◆ isKnownNonConstant()

static bool isKnownNonConstant ( Value V)

Returns true if we can statically tell that this value will never be a "useful" constant.

In practice, this means we've got something like an alloca or a malloc call for which a comparison against a constant can only be guarding dead code. Note that we are potentially giving up some precision in dead code (a constant result) in favour of avoiding a expensive search for a easily answered common query.

Definition at line 1575 of file LazyValueInfo.cpp.

References llvm::Value::stripPointerCasts().

Referenced by llvm::LazyValueInfo::getConstant().

◆ isOperationFoldable()

static bool isOperationFoldable ( User Usr)

Definition at line 1246 of file LazyValueInfo.cpp.

Referenced by constantFoldUser(), and getEdgeValueLocal().

◆ matchICmpOperand()

static bool matchICmpOperand ( APInt Offset,
Value LHS,
Value Val,
ICmpInst::Predicate  Pred 

◆ usesOperand()

static bool usesOperand ( User Usr,
Value Op 

Definition at line 1238 of file LazyValueInfo.cpp.

References llvm::is_contained(), and llvm::User::operands().

Referenced by getEdgeValueLocal().

Variable Documentation

◆ Analysis

lazy value Lazy Value Information Analysis

Definition at line 60 of file LazyValueInfo.cpp.

◆ false

print lazy value Lazy Value Info Printer false

Definition at line 60 of file LazyValueInfo.cpp.

◆ info

print lazy value info

◆ MaxProcessedPerValue

const unsigned MaxProcessedPerValue = 500

Definition at line 49 of file LazyValueInfo.cpp.

◆ Pass

print lazy value Lazy Value Info Printer Pass