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 {
32 class TargetLibraryInfo *TLI;
35 LazyValueInfo(const LazyValueInfo&) = delete;
36 void operator=(const LazyValueInfo&) = delete;
39 LazyValueInfo() : FunctionPass(ID), PImpl(nullptr) {
40 initializeLazyValueInfoPass(*PassRegistry::getPassRegistry());
42 ~LazyValueInfo() override { assert(!PImpl && "releaseMemory not called"); }
44 /// This is used to return true/false/dunno results.
46 Unknown = -1, False = 0, True = 1
49 // Public query interface.
51 /// Determine whether the specified value comparison with a constant is known
52 /// to be true or false on the specified CFG edge.
53 /// Pred is a CmpInst predicate.
54 Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
55 BasicBlock *FromBB, BasicBlock *ToBB,
56 Instruction *CxtI = nullptr);
58 /// Determine whether the specified value comparison with a constant is known
59 /// to be true or false at the specified instruction
60 /// (from an assume intrinsic). Pred is a CmpInst predicate.
61 Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
64 /// Determine whether the specified value is known to be a
65 /// constant at the end of the specified block. Return null if not.
66 Constant *getConstant(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
68 /// Determine whether the specified value is known to be a
69 /// constant on the specified edge. Return null if not.
70 Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB,
71 Instruction *CxtI = nullptr);
73 /// Inform the analysis cache that we have threaded an edge from
74 /// PredBB to OldSucc to be from PredBB to NewSucc instead.
75 void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
77 /// Inform the analysis cache that we have erased a block.
78 void eraseBlock(BasicBlock *BB);
80 // Implementation boilerplate.
82 void getAnalysisUsage(AnalysisUsage &AU) const override;
83 void releaseMemory() override;
84 bool runOnFunction(Function &F) override;
87 } // end namespace llvm