1 //===- LazyValueInfo.h - Value constraint analysis --------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interface for lazy computation of value constraint
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ANALYSIS_LAZYVALUEINFO_H
16 #define LLVM_ANALYSIS_LAZYVALUEINFO_H
18 #include "llvm/Pass.h"
21 class AssumptionCache;
26 class TargetLibraryInfo;
29 /// This pass computes, caches, and vends lazy value constraint information.
30 class LazyValueInfo : public FunctionPass {
33 class TargetLibraryInfo *TLI;
36 LazyValueInfo(const LazyValueInfo&) LLVM_DELETED_FUNCTION;
37 void operator=(const LazyValueInfo&) LLVM_DELETED_FUNCTION;
40 LazyValueInfo() : FunctionPass(ID), PImpl(nullptr) {
41 initializeLazyValueInfoPass(*PassRegistry::getPassRegistry());
43 ~LazyValueInfo() { assert(!PImpl && "releaseMemory not called"); }
45 /// This is used to return true/false/dunno results.
47 Unknown = -1, False = 0, True = 1
51 // Public query interface.
53 /// Determine whether the specified value comparison with a constant is known
54 /// to be true or false on the specified CFG edge.
55 /// Pred is a CmpInst predicate.
56 Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
57 BasicBlock *FromBB, BasicBlock *ToBB,
58 Instruction *CxtI = nullptr);
60 /// Determine whether the specified value comparison with a constant is known
61 /// to be true or false at the specified instruction
62 /// (from an assume intrinsic). Pred is a CmpInst predicate.
63 Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
66 /// Determine whether the specified value is known to be a
67 /// constant at the end of the specified block. Return null if not.
68 Constant *getConstant(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
70 /// Determine whether the specified value is known to be a
71 /// constant on the specified edge. Return null if not.
72 Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB,
73 Instruction *CxtI = nullptr);
75 /// Inform the analysis cache that we have threaded an edge from
76 /// PredBB to OldSucc to be from PredBB to NewSucc instead.
77 void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
79 /// Inform the analysis cache that we have erased a block.
80 void eraseBlock(BasicBlock *BB);
82 // Implementation boilerplate.
84 void getAnalysisUsage(AnalysisUsage &AU) const override;
85 void releaseMemory() override;
86 bool runOnFunction(Function &F) override;
89 } // end namespace llvm