#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"
static RegisterPass<LoopVR> 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<SCEVCouldNotCompute>(T))
return ConstantRange(cast<IntegerType>(S->getType())->getBitWidth(), true);
}
/// 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 (const SCEVConstant *C = dyn_cast<SCEVConstant>(S))
return ConstantRange(C->getValue()->getValue());
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());
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);
const SCEVConstant *Step = dyn_cast<SCEVConstant>(StepHandle);
if (!Step) return FullSet;
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));
const SCEVConstant *Start = dyn_cast<SCEVConstant>(StartHandle);
const SCEVConstant *End = dyn_cast<SCEVConstant>(EndHandle);
return FullSet;
}
+void LoopVR::getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.addRequiredTransitive<LoopInfo>();
+ AU.addRequiredTransitive<ScalarEvolution>();
+ AU.setPreservesAll();
+}
+
bool LoopVR::runOnFunction(Function &F) { Map.clear(); return false; }
void LoopVR::print(std::ostream &os, const Module *) const {
ScalarEvolution &SE = getAnalysis<ScalarEvolution>();
- SCEVHandle S = SE.getSCEV(I);
+ const SCEV *S = SE.getSCEV(I);
if (isa<SCEVUnknown>(S) || isa<SCEVCouldNotCompute>(S))
return ConstantRange(cast<IntegerType>(V->getType())->getBitWidth(), false);