X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FLoopVR.cpp;h=6854e950ef8f083de2c2e6b775a65f771ae105a3;hb=d9ef1a860e01321cacbd57b6f7c154f399c813d4;hp=3a7ec7b988633fe9ca4fd0736bdefcb0985fc287;hpb=46bdfb0e6bb9de86b19562fc52fddefd7014cf73;p=oota-llvm.git diff --git a/lib/Analysis/LoopVR.cpp b/lib/Analysis/LoopVR.cpp index 3a7ec7b9886..6854e950ef8 100644 --- a/lib/Analysis/LoopVR.cpp +++ b/lib/Analysis/LoopVR.cpp @@ -15,6 +15,8 @@ #include "llvm/Analysis/LoopVR.h" #include "llvm/Constants.h" #include "llvm/Instructions.h" +#include "llvm/LLVMContext.h" +#include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/ScalarEvolutionExpressions.h" #include "llvm/Assembly/Writer.h" #include "llvm/Support/CFG.h" @@ -23,11 +25,11 @@ using namespace llvm; char LoopVR::ID = 0; -static RegisterPass X("loopvr", "Loop Value Ranges", true, true); +static RegisterPass X("loopvr", "Loop Value Ranges", false, true); /// getRange - determine the range for a particular SCEV within a given Loop -ConstantRange LoopVR::getRange(SCEVHandle S, Loop *L, ScalarEvolution &SE) { - SCEVHandle T = SE.getBackedgeTakenCount(L); +ConstantRange LoopVR::getRange(const SCEV *S, Loop *L, ScalarEvolution &SE) { + const SCEV *T = SE.getBackedgeTakenCount(L); if (isa(T)) return ConstantRange(cast(S->getType())->getBitWidth(), true); @@ -36,16 +38,16 @@ ConstantRange LoopVR::getRange(SCEVHandle S, Loop *L, ScalarEvolution &SE) { } /// getRange - determine the range for a particular SCEV with a given trip count -ConstantRange LoopVR::getRange(SCEVHandle S, SCEVHandle T, ScalarEvolution &SE){ +ConstantRange LoopVR::getRange(const SCEV *S, const SCEV *T, ScalarEvolution &SE){ - if (SCEVConstant *C = dyn_cast(S)) + if (const SCEVConstant *C = dyn_cast(S)) return ConstantRange(C->getValue()->getValue()); ConstantRange FullSet(cast(S->getType())->getBitWidth(), true); // {x,+,y,+,...z}. We detect overflow by checking the size of the set after // summing the upper and lower. - if (SCEVAddExpr *Add = dyn_cast(S)) { + if (const SCEVAddExpr *Add = dyn_cast(S)) { ConstantRange X = getRange(Add->getOperand(0), T, SE); if (X.isFullSet()) return FullSet; for (unsigned i = 1, e = Add->getNumOperands(); i != e; ++i) { @@ -67,12 +69,12 @@ ConstantRange LoopVR::getRange(SCEVHandle S, SCEVHandle T, ScalarEvolution &SE){ // {x,*,y,*,...,z}. In order to detect overflow, we use k*bitwidth where // k is the number of terms being multiplied. - if (SCEVMulExpr *Mul = dyn_cast(S)) { + if (const SCEVMulExpr *Mul = dyn_cast(S)) { ConstantRange X = getRange(Mul->getOperand(0), T, SE); if (X.isFullSet()) return FullSet; - const IntegerType *Ty = IntegerType::get(X.getBitWidth()); - const IntegerType *ExTy = IntegerType::get(X.getBitWidth() * + const IntegerType *Ty = Context->getIntegerType(X.getBitWidth()); + const IntegerType *ExTy = Context->getIntegerType(X.getBitWidth() * Mul->getNumOperands()); ConstantRange XExt = X.zeroExtend(ExTy->getBitWidth()); @@ -91,7 +93,7 @@ ConstantRange LoopVR::getRange(SCEVHandle S, SCEVHandle T, ScalarEvolution &SE){ // smax(X_smax, Y_smax, ..., Z_smax)) // It doesn't matter if one of the SCEVs has FullSet because we're taking // a maximum of the minimums across all of them. - if (SCEVSMaxExpr *SMax = dyn_cast(S)) { + if (const SCEVSMaxExpr *SMax = dyn_cast(S)) { ConstantRange X = getRange(SMax->getOperand(0), T, SE); if (X.isFullSet()) return FullSet; @@ -109,7 +111,7 @@ ConstantRange LoopVR::getRange(SCEVHandle S, SCEVHandle T, ScalarEvolution &SE){ // umax(X_umax, Y_umax, ..., Z_umax)) // It doesn't matter if one of the SCEVs has FullSet because we're taking // a maximum of the minimums across all of them. - if (SCEVUMaxExpr *UMax = dyn_cast(S)) { + if (const SCEVUMaxExpr *UMax = dyn_cast(S)) { ConstantRange X = getRange(UMax->getOperand(0), T, SE); if (X.isFullSet()) return FullSet; @@ -124,7 +126,7 @@ ConstantRange LoopVR::getRange(SCEVHandle S, SCEVHandle T, ScalarEvolution &SE){ } // L udiv R. Luckily, there's only ever 2 sides to a udiv. - if (SCEVUDivExpr *UDiv = dyn_cast(S)) { + if (const SCEVUDivExpr *UDiv = dyn_cast(S)) { ConstantRange L = getRange(UDiv->getLHS(), T, SE); ConstantRange R = getRange(UDiv->getRHS(), T, SE); if (L.isFullSet() && R.isFullSet()) return FullSet; @@ -158,34 +160,34 @@ ConstantRange LoopVR::getRange(SCEVHandle S, SCEVHandle T, ScalarEvolution &SE){ // ConstantRange already implements the cast operators. - if (SCEVZeroExtendExpr *ZExt = dyn_cast(S)) { + if (const SCEVZeroExtendExpr *ZExt = dyn_cast(S)) { T = SE.getTruncateOrZeroExtend(T, ZExt->getOperand()->getType()); ConstantRange X = getRange(ZExt->getOperand(), T, SE); return X.zeroExtend(cast(ZExt->getType())->getBitWidth()); } - if (SCEVSignExtendExpr *SExt = dyn_cast(S)) { + if (const SCEVSignExtendExpr *SExt = dyn_cast(S)) { T = SE.getTruncateOrZeroExtend(T, SExt->getOperand()->getType()); ConstantRange X = getRange(SExt->getOperand(), T, SE); return X.signExtend(cast(SExt->getType())->getBitWidth()); } - if (SCEVTruncateExpr *Trunc = dyn_cast(S)) { + if (const SCEVTruncateExpr *Trunc = dyn_cast(S)) { T = SE.getTruncateOrZeroExtend(T, Trunc->getOperand()->getType()); ConstantRange X = getRange(Trunc->getOperand(), T, SE); if (X.isFullSet()) return FullSet; return X.truncate(cast(Trunc->getType())->getBitWidth()); } - if (SCEVAddRecExpr *AddRec = dyn_cast(S)) { - SCEVConstant *Trip = dyn_cast(T); + if (const SCEVAddRecExpr *AddRec = dyn_cast(S)) { + const SCEVConstant *Trip = dyn_cast(T); if (!Trip) return FullSet; if (AddRec->isAffine()) { - SCEVHandle StartHandle = AddRec->getStart(); - SCEVHandle StepHandle = AddRec->getOperand(1); + const SCEV *StartHandle = AddRec->getStart(); + const SCEV *StepHandle = AddRec->getOperand(1); - SCEVConstant *Step = dyn_cast(StepHandle); + const SCEVConstant *Step = dyn_cast(StepHandle); if (!Step) return FullSet; uint32_t ExWidth = 2 * Trip->getValue()->getBitWidth(); @@ -194,10 +196,10 @@ ConstantRange LoopVR::getRange(SCEVHandle S, SCEVHandle T, ScalarEvolution &SE){ if ((TripExt * StepExt).ugt(APInt::getLowBitsSet(ExWidth, ExWidth >> 1))) return FullSet; - SCEVHandle EndHandle = SE.getAddExpr(StartHandle, + const SCEV *EndHandle = SE.getAddExpr(StartHandle, SE.getMulExpr(T, StepHandle)); - SCEVConstant *Start = dyn_cast(StartHandle); - SCEVConstant *End = dyn_cast(EndHandle); + const SCEVConstant *Start = dyn_cast(StartHandle); + const SCEVConstant *End = dyn_cast(EndHandle); if (!Start || !End) return FullSet; const APInt &StartInt = Start->getValue()->getValue(); @@ -219,6 +221,12 @@ ConstantRange LoopVR::getRange(SCEVHandle S, SCEVHandle T, ScalarEvolution &SE){ return FullSet; } +void LoopVR::getAnalysisUsage(AnalysisUsage &AU) const { + AU.addRequiredTransitive(); + AU.addRequiredTransitive(); + AU.setPreservesAll(); +} + bool LoopVR::runOnFunction(Function &F) { Map.clear(); return false; } void LoopVR::print(std::ostream &os, const Module *) const { @@ -254,7 +262,7 @@ ConstantRange LoopVR::compute(Value *V) { ScalarEvolution &SE = getAnalysis(); - SCEVHandle S = SE.getSCEV(I); + const SCEV *S = SE.getSCEV(I); if (isa(S) || isa(S)) return ConstantRange(cast(V->getType())->getBitWidth(), false);