LLVM  6.0.0svn
Namespaces | Macros | Functions | Variables
LazyValueInfo.cpp File Reference
#include "llvm/Analysis/LazyValueInfo.h"
#include "llvm/ADT/DenseSet.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/ValueTracking.h"
#include "llvm/Analysis/ValueLattice.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/Support/Debug.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/raw_ostream.h"
#include <map>
#include <stack>
Include dependency graph for LazyValueInfo.cpp:

Go to the source code of this file.

Namespaces

 llvm
 Compute iterated dominance frontiers using a linear time algorithm.
 

Macros

#define DEBUG_TYPE   "lazy-value-info"
 

Functions

 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 bool InstructionDereferencesPointer (Instruction *I, Value *Ptr)
 
static bool isObjectDereferencedInBlock (Value *Val, BasicBlock *BB)
 Return true if the allocation associated with Val is ever dereferenced within the given basic block. More...
 
static ValueLatticeElement getValueFromCondition (Value *Val, Value *Cond, bool isTrueDest=true)
 
static ValueLatticeElement getValueFromICmpCondition (Value *Val, ICmpInst *ICI, bool isTrueDest)
 
static ValueLatticeElement getValueFromCondition (Value *Val, Value *Cond, bool isTrueDest, DenseMap< Value *, ValueLatticeElement > &Visited)
 
static ValueLatticeElement getValueFromConditionImpl (Value *Val, Value *Cond, bool isTrueDest, DenseMap< Value *, ValueLatticeElement > &Visited)
 
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 bool getEdgeValueLocal (Value *Val, BasicBlock *BBFrom, BasicBlock *BBTo, ValueLatticeElement &Result)
 Compute the value of Val on the edge BBFrom -> BBTo. More...
 
static LazyValueInfoImpl & getImpl (void *&PImpl, AssumptionCache *AC, const DataLayout *DL, DominatorTree *DT=nullptr)
 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
 

Variables

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

◆ DEBUG_TYPE

#define DEBUG_TYPE   "lazy-value-info"

Definition at line 44 of file LazyValueInfo.cpp.

Function Documentation

◆ constantFoldUser()

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

◆ getEdgeValueLocal()

static bool getEdgeValueLocal ( Value Val,
BasicBlock BBFrom,
BasicBlock BBTo,
ValueLatticeElement Result 
)
static

◆ getFromRangeMetadata()

static ValueLatticeElement getFromRangeMetadata ( Instruction BBI)
static

◆ getImpl()

static LazyValueInfoImpl& getImpl ( void *&  PImpl,
AssumptionCache AC,
const DataLayout DL,
DominatorTree DT = nullptr 
)
static

◆ getPredicateResult()

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

◆ getValueFromCondition() [1/2]

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

◆ getValueFromCondition() [2/2]

static ValueLatticeElement getValueFromCondition ( Value Val,
Value Cond,
bool  isTrueDest,
DenseMap< Value *, ValueLatticeElement > &  Visited 
)
static

◆ getValueFromConditionImpl()

static ValueLatticeElement getValueFromConditionImpl ( Value Val,
Value Cond,
bool  isTrueDest,
DenseMap< Value *, ValueLatticeElement > &  Visited 
)
static

◆ getValueFromICmpCondition()

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

◆ hasSingleValue()

static bool hasSingleValue ( const ValueLatticeElement Val)
static

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 67 of file LazyValueInfo.cpp.

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

Referenced by getEdgeValueLocal(), and intersect().

◆ INITIALIZE_PASS_BEGIN() [1/2]

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

◆ INITIALIZE_PASS_BEGIN() [2/2]

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

◆ InstructionDereferencesPointer()

static bool InstructionDereferencesPointer ( Instruction I,
Value Ptr 
)
static

◆ intersect()

static ValueLatticeElement intersect ( const ValueLatticeElement A,
const ValueLatticeElement B 
)
static

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 92 of file LazyValueInfo.cpp.

References assert(), llvm::BasicBlock::back(), llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::clear(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::clear(), clear(), llvm::dbgs(), DEBUG, E, llvm::SmallPtrSetImplBase::empty(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::end(), llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::end(), llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::erase(), llvm::SmallPtrSetImpl< PtrType >::erase(), F(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::find_as(), llvm::ValueLatticeElement::get(), llvm::ValueLatticeElement::getConstantRange(), llvm::ValueLatticeElement::getOverdefined(), llvm::ValueLatticeElement::getRange(), hasSingleValue(), I, llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, ValueInfoT, detail::DenseSetPair< ValueT > >, ValueInfoT >::insert(), llvm::ConstantRange::intersectWith(), llvm::ValueLatticeElement::isConstantRange(), llvm::ValueLatticeElement::isOverdefined(), llvm::ValueLatticeElement::isUndefined(), P, llvm::Function::print(), llvm::SmallVectorTemplateBase< T, isPodLike< T >::value >::push_back(), llvm::PBQP::RegAlloc::solve(), llvm::succ_begin(), llvm::succ_end(), and llvm::AArch64CC::VC.

Referenced by llvm::MDNode::classof(), llvm::rdf::Liveness::computeLiveIns(), getEdgeValueLocal(), getValueFromConditionImpl(), llvm::rdf::RegisterAggr::intersect(), llvm::rdf::RegisterAggr::isCoverOf(), and isObjectDereferencedInBlock().

◆ isKnownNonConstant()

static bool isKnownNonConstant ( Value V)
static

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 1508 of file LazyValueInfo.cpp.

References llvm::Value::stripPointerCasts().

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

◆ isObjectDereferencedInBlock()

static bool isObjectDereferencedInBlock ( Value Val,
BasicBlock BB 
)
static

Return true if the allocation associated with Val is ever dereferenced within the given basic block.

This establishes the fact Val is not null, but does not imply that the memory at Val is dereferenceable. (Val may point off the end of the dereferenceable part of the object.)

Definition at line 664 of file LazyValueInfo.cpp.

References llvm::MCID::Add, assert(), B, llvm::ConstantRange::binaryOp(), llvm::ConstantRange::castOp(), llvm::dbgs(), DEBUG, llvm::dyn_cast(), E, llvm::SelectPatternResult::Flavor, llvm::ConstantInt::get(), llvm::ConstantPointerNull::get(), llvm::SelectInst::getCondition(), llvm::ValueLatticeElement::getConstantRange(), llvm::Module::getDataLayout(), llvm::Function::getEntryBlock(), llvm::SelectInst::getFalseValue(), llvm::Module::getFunction(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::Type::getIntegerBitWidth(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Instruction::getModule(), llvm::BasicBlock::getModule(), llvm::Intrinsic::getName(), llvm::Value::getName(), llvm::ValueLatticeElement::getNot(), llvm::PHINode::getNumIncomingValues(), llvm::BinaryOperator::getOpcode(), llvm::CastInst::getOpcode(), llvm::User::getOperand(), llvm::ValueLatticeElement::getOverdefined(), llvm::Instruction::getParent(), llvm::BasicBlock::getParent(), llvm::ValueLatticeElement::getRange(), llvm::ilist_iterator< OptionsT, IsReverse, IsConst >::getReverse(), llvm::SelectInst::getTrueValue(), llvm::ConstantInt::getType(), llvm::Value::getType(), llvm::GetUnderlyingObject(), llvm::ConstantInt::getValue(), getValueFromCondition(), I, llvm::CmpInst::ICMP_EQ, llvm::CmpInst::ICMP_NE, InstructionDereferencesPointer(), intersect(), llvm::ValueLatticeElement::isConstantRange(), llvm::isKnownNonZero(), llvm::SelectPatternResult::isMinOrMax(), llvm::ValueLatticeElement::isOverdefined(), llvm::Type::isPointerTy(), llvm::Type::isSized(), llvm::isValidAssumeForContext(), llvm_unreachable, llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_ConstantInt(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::make_range(), llvm::PatternMatch::match(), llvm::matchSelectPattern(), llvm::ValueLatticeElement::mergeIn(), llvm::pred_begin(), llvm::pred_end(), llvm::BasicBlock::rend(), SI, llvm::ConstantRange::smax(), llvm::ConstantRange::smin(), llvm::SPF_SMAX, llvm::SPF_SMIN, llvm::SPF_UMAX, llvm::SPF_UMIN, llvm::ConstantRange::umax(), and llvm::ConstantRange::umin().

◆ isOperationFoldable()

static bool isOperationFoldable ( User Usr)
static

Definition at line 1163 of file LazyValueInfo.cpp.

Referenced by constantFoldUser(), and getEdgeValueLocal().

◆ usesOperand()

static bool usesOperand ( User Usr,
Value Op 
)
static

Definition at line 1155 of file LazyValueInfo.cpp.

References llvm::find(), llvm::User::op_end(), and llvm::User::operands().

Referenced by getEdgeValueLocal().

Variable Documentation

◆ Analysis

lazy value Lazy Value Information Analysis

Definition at line 55 of file LazyValueInfo.cpp.

◆ false

print lazy value Lazy Value Info Printer false

Definition at line 55 of file LazyValueInfo.cpp.

◆ info

print lazy value info

◆ MaxProcessedPerValue

const unsigned MaxProcessedPerValue = 500
static

Definition at line 48 of file LazyValueInfo.cpp.

◆ Pass

print lazy value Lazy Value Info Printer Pass