00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef LLVM_ANALYSIS_POINTERTRACKING_H
00028 #define LLVM_ANALYSIS_POINTERTRACKING_H
00029
00030 #include "llvm/ADT/SmallSet.h"
00031 #include "llvm/Analysis/Dominators.h"
00032 #include "llvm/Instructions.h"
00033 #include "llvm/Pass.h"
00034 #include "llvm/Support/PredIteratorCache.h"
00035
00036 namespace llvm {
00037 class DominatorTree;
00038 class ScalarEvolution;
00039 class SCEV;
00040 class Loop;
00041 class LoopInfo;
00042 class TargetData;
00043
00044
00045
00046 enum SolverResult {
00047 AlwaysFalse,
00048 AlwaysTrue,
00049 Unknown
00050 };
00051
00052 class PointerTracking : public FunctionPass {
00053 public:
00054 typedef ICmpInst::Predicate Predicate;
00055 static char ID;
00056 PointerTracking();
00057
00058 virtual bool doInitialization(Module &M);
00059
00060
00061
00062
00063
00064
00065 const SCEV *getAllocationElementCount(Value *P) const;
00066
00067
00068
00069 const SCEV *getAllocationSizeInBytes(Value *V) const;
00070
00071
00072
00073
00074
00075
00076 void getPointerOffset(Value *Pointer, Value *&Base, const SCEV *& BaseSize,
00077 const SCEV *&Offset) const;
00078
00079
00080
00081
00082 enum SolverResult compareSCEV(const SCEV *A, Predicate Pred, const SCEV *B,
00083 const Loop *L);
00084
00085
00086
00087
00088
00089 bool conditionSufficient(const SCEV *LHS, Predicate Pred1, const SCEV *RHS,
00090 const SCEV *A, Predicate Pred2, const SCEV *B,
00091 const Loop *L);
00092
00093
00094
00095 enum SolverResult checkLimits(const SCEV *Offset, const SCEV *Limit,
00096 BasicBlock *BB);
00097
00098 virtual bool runOnFunction(Function &F);
00099 virtual void getAnalysisUsage(AnalysisUsage &AU) const;
00100 void print(raw_ostream &OS, const Module* = 0) const;
00101 private:
00102 Function *FF;
00103 TargetData *TD;
00104 ScalarEvolution *SE;
00105 LoopInfo *LI;
00106 DominatorTree *DT;
00107
00108 Function *callocFunc;
00109 Function *reallocFunc;
00110 PredIteratorCache predCache;
00111
00112 SmallPtrSet<const SCEV*, 1> analyzing;
00113
00114 enum SolverResult isLoopGuardedBy(const Loop *L, Predicate Pred,
00115 const SCEV *A, const SCEV *B) const;
00116 static bool isMonotonic(const SCEV *S);
00117 bool scevPositive(const SCEV *A, const Loop *L, bool strict=true) const;
00118 bool conditionSufficient(Value *Cond, bool negated,
00119 const SCEV *A, Predicate Pred, const SCEV *B);
00120 Value *getConditionToReach(BasicBlock *A,
00121 DomTreeNodeBase<BasicBlock> *B,
00122 bool &negated);
00123 Value *getConditionToReach(BasicBlock *A,
00124 BasicBlock *B,
00125 bool &negated);
00126 const SCEV *computeAllocationCount(Value *P, const Type *&Ty) const;
00127 const SCEV *computeAllocationCountForType(Value *P, const Type *Ty) const;
00128 };
00129 }
00130 #endif
00131