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
50 // Public query interface.
52 /// Determine whether the specified value comparison with a constant is known
53 /// to be true or false on the specified CFG edge.
54 /// Pred is a CmpInst predicate.
55 Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
56 BasicBlock *FromBB, BasicBlock *ToBB,
57 Instruction *CxtI = nullptr);
59 /// Determine whether the specified value comparison with a constant is known
60 /// to be true or false at the specified instruction
61 /// (from an assume intrinsic). Pred is a CmpInst predicate.
62 Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
65 /// Determine whether the specified value is known to be a
66 /// constant at the end of the specified block. Return null if not.
67 Constant *getConstant(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
69 /// Determine whether the specified value is known to be a
70 /// constant on the specified edge. Return null if not.
71 Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB,
72 Instruction *CxtI = nullptr);
74 /// Inform the analysis cache that we have threaded an edge from
75 /// PredBB to OldSucc to be from PredBB to NewSucc instead.
76 void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
78 /// Inform the analysis cache that we have erased a block.
79 void eraseBlock(BasicBlock *BB);
81 // Implementation boilerplate.
83 void getAnalysisUsage(AnalysisUsage &AU) const override;
84 void releaseMemory() override;
85 bool runOnFunction(Function &F) override;
88 } // end namespace llvm