Mercurial > hg > CbC > CbC_llvm
comparison lib/Analysis/DependenceAnalysis.cpp @ 83:60c9769439b8 LLVM3.7
LLVM 3.7
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 18 Feb 2015 14:55:36 +0900 |
parents | 54457678186b |
children | afa8332a0e37 |
comparison
equal
deleted
inserted
replaced
78:af83660cff7b | 83:60c9769439b8 |
---|---|
112 //===----------------------------------------------------------------------===// | 112 //===----------------------------------------------------------------------===// |
113 // basics | 113 // basics |
114 | 114 |
115 INITIALIZE_PASS_BEGIN(DependenceAnalysis, "da", | 115 INITIALIZE_PASS_BEGIN(DependenceAnalysis, "da", |
116 "Dependence Analysis", true, true) | 116 "Dependence Analysis", true, true) |
117 INITIALIZE_PASS_DEPENDENCY(LoopInfo) | 117 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass) |
118 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution) | 118 INITIALIZE_PASS_DEPENDENCY(ScalarEvolution) |
119 INITIALIZE_AG_DEPENDENCY(AliasAnalysis) | 119 INITIALIZE_AG_DEPENDENCY(AliasAnalysis) |
120 INITIALIZE_PASS_END(DependenceAnalysis, "da", | 120 INITIALIZE_PASS_END(DependenceAnalysis, "da", |
121 "Dependence Analysis", true, true) | 121 "Dependence Analysis", true, true) |
122 | 122 |
130 | 130 |
131 bool DependenceAnalysis::runOnFunction(Function &F) { | 131 bool DependenceAnalysis::runOnFunction(Function &F) { |
132 this->F = &F; | 132 this->F = &F; |
133 AA = &getAnalysis<AliasAnalysis>(); | 133 AA = &getAnalysis<AliasAnalysis>(); |
134 SE = &getAnalysis<ScalarEvolution>(); | 134 SE = &getAnalysis<ScalarEvolution>(); |
135 LI = &getAnalysis<LoopInfo>(); | 135 LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo(); |
136 return false; | 136 return false; |
137 } | 137 } |
138 | 138 |
139 | 139 |
140 void DependenceAnalysis::releaseMemory() { | 140 void DependenceAnalysis::releaseMemory() { |
143 | 143 |
144 void DependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { | 144 void DependenceAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { |
145 AU.setPreservesAll(); | 145 AU.setPreservesAll(); |
146 AU.addRequiredTransitive<AliasAnalysis>(); | 146 AU.addRequiredTransitive<AliasAnalysis>(); |
147 AU.addRequiredTransitive<ScalarEvolution>(); | 147 AU.addRequiredTransitive<ScalarEvolution>(); |
148 AU.addRequiredTransitive<LoopInfo>(); | 148 AU.addRequiredTransitive<LoopInfoWrapperPass>(); |
149 } | 149 } |
150 | 150 |
151 | 151 |
152 // Used to test the dependence analyzer. | 152 // Used to test the dependence analyzer. |
153 // Looks through the function, noting loads and stores. | 153 // Looks through the function, noting loads and stores. |
779 Loops.set(Level); | 779 Loops.set(Level); |
780 LoopNest = LoopNest->getParentLoop(); | 780 LoopNest = LoopNest->getParentLoop(); |
781 } | 781 } |
782 } | 782 } |
783 | 783 |
784 void DependenceAnalysis::unifySubscriptType(Subscript *Pair) { | |
785 const SCEV *Src = Pair->Src; | |
786 const SCEV *Dst = Pair->Dst; | |
787 IntegerType *SrcTy = dyn_cast<IntegerType>(Src->getType()); | |
788 IntegerType *DstTy = dyn_cast<IntegerType>(Dst->getType()); | |
789 if (SrcTy == nullptr || DstTy == nullptr) { | |
790 assert(SrcTy == DstTy && "This function only unify integer types and " | |
791 "expect Src and Dst share the same type " | |
792 "otherwise."); | |
793 return; | |
794 } | |
795 if (SrcTy->getBitWidth() > DstTy->getBitWidth()) { | |
796 // Sign-extend Dst to typeof(Src) if typeof(Src) is wider than typeof(Dst). | |
797 Pair->Dst = SE->getSignExtendExpr(Dst, SrcTy); | |
798 } else if (SrcTy->getBitWidth() < DstTy->getBitWidth()) { | |
799 // Sign-extend Src to typeof(Dst) if typeof(Dst) is wider than typeof(Src). | |
800 Pair->Src = SE->getSignExtendExpr(Src, DstTy); | |
801 } | |
802 } | |
784 | 803 |
785 // removeMatchingExtensions - Examines a subscript pair. | 804 // removeMatchingExtensions - Examines a subscript pair. |
786 // If the source and destination are identically sign (or zero) | 805 // If the source and destination are identically sign (or zero) |
787 // extended, it strips off the extension in an effect to simplify | 806 // extended, it strips off the extension in an effect to simplify |
788 // the actual analysis. | 807 // the actual analysis. |
791 const SCEV *Dst = Pair->Dst; | 810 const SCEV *Dst = Pair->Dst; |
792 if ((isa<SCEVZeroExtendExpr>(Src) && isa<SCEVZeroExtendExpr>(Dst)) || | 811 if ((isa<SCEVZeroExtendExpr>(Src) && isa<SCEVZeroExtendExpr>(Dst)) || |
793 (isa<SCEVSignExtendExpr>(Src) && isa<SCEVSignExtendExpr>(Dst))) { | 812 (isa<SCEVSignExtendExpr>(Src) && isa<SCEVSignExtendExpr>(Dst))) { |
794 const SCEVCastExpr *SrcCast = cast<SCEVCastExpr>(Src); | 813 const SCEVCastExpr *SrcCast = cast<SCEVCastExpr>(Src); |
795 const SCEVCastExpr *DstCast = cast<SCEVCastExpr>(Dst); | 814 const SCEVCastExpr *DstCast = cast<SCEVCastExpr>(Dst); |
796 if (SrcCast->getType() == DstCast->getType()) { | 815 const SCEV *SrcCastOp = SrcCast->getOperand(); |
797 Pair->Src = SrcCast->getOperand(); | 816 const SCEV *DstCastOp = DstCast->getOperand(); |
798 Pair->Dst = DstCast->getOperand(); | 817 if (SrcCastOp->getType() == DstCastOp->getType()) { |
818 Pair->Src = SrcCastOp; | |
819 Pair->Dst = DstCastOp; | |
799 } | 820 } |
800 } | 821 } |
801 } | 822 } |
802 | 823 |
803 | 824 |
2954 Sum, | 2975 Sum, |
2955 AddRec->getLoop(), | 2976 AddRec->getLoop(), |
2956 AddRec->getNoWrapFlags()); | 2977 AddRec->getNoWrapFlags()); |
2957 } | 2978 } |
2958 if (SE->isLoopInvariant(AddRec, TargetLoop)) | 2979 if (SE->isLoopInvariant(AddRec, TargetLoop)) |
2959 return SE->getAddRecExpr(AddRec, | 2980 return SE->getAddRecExpr(AddRec, Value, TargetLoop, SCEV::FlagAnyWrap); |
2960 Value, | 2981 return SE->getAddRecExpr( |
2961 TargetLoop, | 2982 addToCoefficient(AddRec->getStart(), TargetLoop, Value), |
2962 SCEV::FlagAnyWrap); | 2983 AddRec->getStepRecurrence(*SE), AddRec->getLoop(), |
2963 return SE->getAddRecExpr(addToCoefficient(AddRec->getStart(), | 2984 AddRec->getNoWrapFlags()); |
2964 TargetLoop, Value), | |
2965 AddRec->getStepRecurrence(*SE), | |
2966 AddRec->getLoop(), | |
2967 AddRec->getNoWrapFlags()); | |
2968 } | 2985 } |
2969 | 2986 |
2970 | 2987 |
2971 // Review the constraints, looking for opportunities | 2988 // Review the constraints, looking for opportunities |
2972 // to simplify a subscript pair (Src and Dst). | 2989 // to simplify a subscript pair (Src and Dst). |
3180 /// this function flattens the nested recurrences into separate recurrences | 3197 /// this function flattens the nested recurrences into separate recurrences |
3181 /// for each loop level. | 3198 /// for each loop level. |
3182 bool DependenceAnalysis::tryDelinearize(const SCEV *SrcSCEV, | 3199 bool DependenceAnalysis::tryDelinearize(const SCEV *SrcSCEV, |
3183 const SCEV *DstSCEV, | 3200 const SCEV *DstSCEV, |
3184 SmallVectorImpl<Subscript> &Pair, | 3201 SmallVectorImpl<Subscript> &Pair, |
3185 const SCEV *ElementSize) const { | 3202 const SCEV *ElementSize) { |
3186 const SCEVUnknown *SrcBase = | 3203 const SCEVUnknown *SrcBase = |
3187 dyn_cast<SCEVUnknown>(SE->getPointerBase(SrcSCEV)); | 3204 dyn_cast<SCEVUnknown>(SE->getPointerBase(SrcSCEV)); |
3188 const SCEVUnknown *DstBase = | 3205 const SCEVUnknown *DstBase = |
3189 dyn_cast<SCEVUnknown>(SE->getPointerBase(DstSCEV)); | 3206 dyn_cast<SCEVUnknown>(SE->getPointerBase(DstSCEV)); |
3190 | 3207 |
3235 // has found, and then initialize the pairs following the delinearization. | 3252 // has found, and then initialize the pairs following the delinearization. |
3236 Pair.resize(size); | 3253 Pair.resize(size); |
3237 for (int i = 0; i < size; ++i) { | 3254 for (int i = 0; i < size; ++i) { |
3238 Pair[i].Src = SrcSubscripts[i]; | 3255 Pair[i].Src = SrcSubscripts[i]; |
3239 Pair[i].Dst = DstSubscripts[i]; | 3256 Pair[i].Dst = DstSubscripts[i]; |
3257 unifySubscriptType(&Pair[i]); | |
3240 | 3258 |
3241 // FIXME: we should record the bounds SrcSizes[i] and DstSizes[i] that the | 3259 // FIXME: we should record the bounds SrcSizes[i] and DstSizes[i] that the |
3242 // delinearization has found, and add these constraints to the dependence | 3260 // delinearization has found, and add these constraints to the dependence |
3243 // check to avoid memory accesses overflow from one dimension into another. | 3261 // check to avoid memory accesses overflow from one dimension into another. |
3244 // This is related to the problem of determining the existence of data | 3262 // This is related to the problem of determining the existence of data |
3343 DstIdx = DstGEP->idx_begin(); | 3361 DstIdx = DstGEP->idx_begin(); |
3344 SrcIdx != SrcEnd; | 3362 SrcIdx != SrcEnd; |
3345 ++SrcIdx, ++DstIdx, ++P) { | 3363 ++SrcIdx, ++DstIdx, ++P) { |
3346 Pair[P].Src = SE->getSCEV(*SrcIdx); | 3364 Pair[P].Src = SE->getSCEV(*SrcIdx); |
3347 Pair[P].Dst = SE->getSCEV(*DstIdx); | 3365 Pair[P].Dst = SE->getSCEV(*DstIdx); |
3366 unifySubscriptType(&Pair[P]); | |
3348 } | 3367 } |
3349 } | 3368 } |
3350 else { | 3369 else { |
3351 DEBUG(dbgs() << " ignoring GEPs\n"); | 3370 DEBUG(dbgs() << " ignoring GEPs\n"); |
3352 const SCEV *SrcSCEV = SE->getSCEV(SrcPtr); | 3371 const SCEV *SrcSCEV = SE->getSCEV(SrcPtr); |