1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===- LazyValueInfo.h - Value constraint analysis --------------*- C++ -*-===// 2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The LLVM Compiler Infrastructure 4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source 6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details. 7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file defines the interface for lazy computation of value constraint 11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// information. 12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 1519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#ifndef LLVM_ANALYSIS_LAZYVALUEINFO_H 1619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#define LLVM_ANALYSIS_LAZYVALUEINFO_H 17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Pass.h" 19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm { 21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class Constant; 22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class TargetData; 23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class Value; 24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// LazyValueInfo - This pass computes, caches, and vends lazy value constraint 26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// information. 27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanclass LazyValueInfo : public FunctionPass { 28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class TargetData *TD; 29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void *PImpl; 30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman LazyValueInfo(const LazyValueInfo&); // DO NOT IMPLEMENT. 31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void operator=(const LazyValueInfo&); // DO NOT IMPLEMENT. 32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic: 33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman static char ID; 3419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman LazyValueInfo() : FunctionPass(ID), PImpl(0) { 3519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman initializeLazyValueInfoPass(*PassRegistry::getPassRegistry()); 3619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman ~LazyValueInfo() { assert(PImpl == 0 && "releaseMemory not called"); } 38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// Tristate - This is used to return true/false/dunno results. 40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman enum Tristate { 41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Unknown = -1, False = 0, True = 1 42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Public query interface. 46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getPredicateOnEdge - Determine whether the specified value comparison 48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// with a constant is known to be true or false on the specified CFG edge. 49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// Pred is a CmpInst predicate. 50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C, 51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman BasicBlock *FromBB, BasicBlock *ToBB); 52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getConstant - Determine whether the specified value is known to be a 55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// constant at the end of the specified block. Return null if not. 56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Constant *getConstant(Value *V, BasicBlock *BB); 57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getConstantOnEdge - Determine whether the specified value is known to be a 59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// constant on the specified edge. Return null if not. 60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Constant *getConstantOnEdge(Value *V, BasicBlock *FromBB, BasicBlock *ToBB); 61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// threadEdge - Inform the analysis cache that we have threaded an edge from 63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// PredBB to OldSucc to be from PredBB to NewSucc instead. 64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void threadEdge(BasicBlock *PredBB, BasicBlock *OldSucc, BasicBlock *NewSucc); 65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 6619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// eraseBlock - Inform the analysis cache that we have erased a block. 6719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman void eraseBlock(BasicBlock *BB); 68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // Implementation boilerplate. 70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman virtual void getAnalysisUsage(AnalysisUsage &AU) const { 72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman AU.setPreservesAll(); 73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman virtual void releaseMemory(); 75894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman virtual bool runOnFunction(Function &F); 76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}; 77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} // end namespace llvm 79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif 81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 82