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 AssumptionTracker;
26 class TargetLibraryInfo;
29 /// LazyValueInfo - This pass computes, caches, and vends lazy value constraint
31 class LazyValueInfo : public FunctionPass {
32 AssumptionTracker *AT;
34 class TargetLibraryInfo *TLI;
37 LazyValueInfo(const LazyValueInfo&) LLVM_DELETED_FUNCTION;
38 void operator=(const LazyValueInfo&) LLVM_DELETED_FUNCTION;
41 LazyValueInfo() : FunctionPass(ID), PImpl(nullptr) {
42 initializeLazyValueInfoPass(*PassRegistry::getPassRegistry());
44 ~LazyValueInfo() { assert(!PImpl && "releaseMemory not called"); }
46 /// Tristate - This is used to return true/false/dunno results.
48 Unknown = -1, False = 0, True = 1
52 // Public query interface.
54 /// getPredicateOnEdge - Determine whether the specified value comparison
55 /// with a constant is known to be true or false on the specified CFG edge.
56 /// Pred is a CmpInst predicate.
57 Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
58 BasicBlock *FromBB, BasicBlock *ToBB,
59 Instruction *CxtI = nullptr);
61 /// getPredicateAt - Determine whether the specified value comparison
62 /// with a constant is known to be true or false at the specified instruction
63 /// (from an assume intrinsic). Pred is a CmpInst predicate.
64 Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
67 /// getConstant - Determine whether the specified value is known to be a
68 /// constant at the end of the specified block. Return null if not.
69 Constant *getConstant(Value *V, BasicBlock *BB, Instruction *CxtI = nullptr);
71 /// getConstantOnEdge - Determine whether the specified value is known to be a
72 /// constant on the specified edge. Return null if not.
73 Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB,
74 Instruction *CxtI = nullptr);
76 /// threadEdge - Inform the analysis cache that we have threaded an edge from
77 /// PredBB to OldSucc to be from PredBB to NewSucc instead.
78 void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
80 /// eraseBlock - Inform the analysis cache that we have erased a block.
81 void eraseBlock(BasicBlock *BB);
83 // Implementation boilerplate.
85 void getAnalysisUsage(AnalysisUsage &AU) const override;
86 void releaseMemory() override;
87 bool runOnFunction(Function &F) override;
90 } // end namespace llvm