1199481Srdivacky//===- LazyValueInfo.h - Value constraint analysis --------------*- C++ -*-===//
2199481Srdivacky//
3199481Srdivacky//                     The LLVM Compiler Infrastructure
4199481Srdivacky//
5199481Srdivacky// This file is distributed under the University of Illinois Open Source
6199481Srdivacky// License. See LICENSE.TXT for details.
7199481Srdivacky//
8199481Srdivacky//===----------------------------------------------------------------------===//
9199481Srdivacky//
10199481Srdivacky// This file defines the interface for lazy computation of value constraint
11199481Srdivacky// information.
12199481Srdivacky//
13199481Srdivacky//===----------------------------------------------------------------------===//
14199481Srdivacky
15212904Sdim#ifndef LLVM_ANALYSIS_LAZYVALUEINFO_H
16212904Sdim#define LLVM_ANALYSIS_LAZYVALUEINFO_H
17199481Srdivacky
18199481Srdivacky#include "llvm/Pass.h"
19199481Srdivacky
20199481Srdivackynamespace llvm {
21199481Srdivacky  class Constant;
22243830Sdim  class DataLayout;
23234353Sdim  class TargetLibraryInfo;
24199481Srdivacky  class Value;
25199481Srdivacky
26199481Srdivacky/// LazyValueInfo - This pass computes, caches, and vends lazy value constraint
27199481Srdivacky/// information.
28199481Srdivackyclass LazyValueInfo : public FunctionPass {
29243830Sdim  class DataLayout *TD;
30234353Sdim  class TargetLibraryInfo *TLI;
31199481Srdivacky  void *PImpl;
32243830Sdim  LazyValueInfo(const LazyValueInfo&) LLVM_DELETED_FUNCTION;
33243830Sdim  void operator=(const LazyValueInfo&) LLVM_DELETED_FUNCTION;
34199481Srdivackypublic:
35199481Srdivacky  static char ID;
36218893Sdim  LazyValueInfo() : FunctionPass(ID), PImpl(0) {
37218893Sdim    initializeLazyValueInfoPass(*PassRegistry::getPassRegistry());
38218893Sdim  }
39199481Srdivacky  ~LazyValueInfo() { assert(PImpl == 0 && "releaseMemory not called"); }
40199481Srdivacky
41199481Srdivacky  /// Tristate - This is used to return true/false/dunno results.
42199481Srdivacky  enum Tristate {
43199481Srdivacky    Unknown = -1, False = 0, True = 1
44199481Srdivacky  };
45199481Srdivacky
46199481Srdivacky
47199481Srdivacky  // Public query interface.
48199481Srdivacky
49199481Srdivacky  /// getPredicateOnEdge - Determine whether the specified value comparison
50199481Srdivacky  /// with a constant is known to be true or false on the specified CFG edge.
51199481Srdivacky  /// Pred is a CmpInst predicate.
52199481Srdivacky  Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
53199481Srdivacky                              BasicBlock *FromBB, BasicBlock *ToBB);
54199481Srdivacky
55199481Srdivacky
56199481Srdivacky  /// getConstant - Determine whether the specified value is known to be a
57199481Srdivacky  /// constant at the end of the specified block.  Return null if not.
58199481Srdivacky  Constant *getConstant(Value *V, BasicBlock *BB);
59199481Srdivacky
60199481Srdivacky  /// getConstantOnEdge - Determine whether the specified value is known to be a
61199481Srdivacky  /// constant on the specified edge.  Return null if not.
62199481Srdivacky  Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB);
63199481Srdivacky
64212904Sdim  /// threadEdge - Inform the analysis cache that we have threaded an edge from
65212904Sdim  /// PredBB to OldSucc to be from PredBB to NewSucc instead.
66212904Sdim  void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc);
67199481Srdivacky
68212904Sdim  /// eraseBlock - Inform the analysis cache that we have erased a block.
69212904Sdim  void eraseBlock(BasicBlock *BB);
70212904Sdim
71199481Srdivacky  // Implementation boilerplate.
72199481Srdivacky
73234353Sdim  virtual void getAnalysisUsage(AnalysisUsage &AU) const;
74199481Srdivacky  virtual void releaseMemory();
75199481Srdivacky  virtual bool runOnFunction(Function &F);
76199481Srdivacky};
77199481Srdivacky
78199481Srdivacky}  // end namespace llvm
79199481Srdivacky
80199481Srdivacky#endif
81199481Srdivacky
82