STATISTIC(MaxNumLoopsInProfScop,
"Maximal number of loops in scops (profitable scops only)");
+static void updateLoopCountStatistic(ScopDetection::LoopStats Stats,
+ bool OnlyProfitable);
+
class DiagnosticScopFound : public DiagnosticInfo {
private:
static int PluginDiagnosticKind;
//===----------------------------------------------------------------------===//
// ScopDetection.
-ScopDetection::ScopDetection() : FunctionPass(ID) {
- // Disable runtime alias checks if we ignore aliasing all together.
- if (IgnoreAliasing)
- PollyUseRuntimeAliasChecks = false;
+ScopDetection::ScopDetection(Function &F, const DominatorTree &DT,
+ ScalarEvolution &SE, LoopInfo &LI, RegionInfo &RI,
+ AliasAnalysis &AA)
+ : DT(DT), SE(SE), LI(LI), RI(RI), AA(AA) {
+
+ if (!PollyProcessUnprofitable && LI.empty())
+ return;
+
+ Region *TopRegion = RI.getTopLevelRegion();
+
+ if (OnlyFunction != "" && !F.getName().count(OnlyFunction))
+ return;
+
+ if (!isValidFunction(F))
+ return;
+
+ findScops(*TopRegion);
+
+ NumScopRegions += ValidRegions.size();
+
+ // Prune non-profitable regions.
+ for (auto &DIt : DetectionContextMap) {
+ auto &DC = DIt.getSecond();
+ if (DC.Log.hasErrors())
+ continue;
+ if (!ValidRegions.count(&DC.CurRegion))
+ continue;
+ LoopStats Stats = countBeneficialLoops(&DC.CurRegion, SE, LI, 0);
+ updateLoopCountStatistic(Stats, false /* OnlyProfitable */);
+ if (isProfitableRegion(DC)) {
+ updateLoopCountStatistic(Stats, true /* OnlyProfitable */);
+ continue;
+ }
+
+ ValidRegions.remove(&DC.CurRegion);
+ }
+
+ NumProfScopRegions += ValidRegions.size();
+ NumLoopsOverall += countBeneficialLoops(TopRegion, SE, LI, 0).NumLoops;
+
+ // Only makes sense when we tracked errors.
+ if (PollyTrackFailures)
+ emitMissedRemarks(F);
+
+ if (ReportLevel)
+ printLocations(F);
+
+ assert(ValidRegions.size() <= DetectionContextMap.size() &&
+ "Cached more results than valid regions");
}
template <class RR, typename... Args>
DetectionContextMap.erase(getBBPairForRegion(&R));
const auto &It = DetectionContextMap.insert(std::make_pair(
getBBPairForRegion(&R),
- DetectionContext(const_cast<Region &>(R), *AA, false /*verifying*/)));
+ DetectionContext(const_cast<Region &>(R), AA, false /*verifying*/)));
DetectionContext &Context = It.first->second;
return isValidRegion(Context);
}
// are accesses that depend on the iteration count.
for (BasicBlock *BB : AR->blocks()) {
- Loop *L = LI->getLoopFor(BB);
+ Loop *L = LI.getLoopFor(BB);
if (AR->contains(L))
Context.BoxedLoopsSet.insert(L);
}
if (Context.RequiredILS.count(Load))
continue;
- if (!isHoistableLoad(Load, CurRegion, *LI, *SE, *DT))
+ if (!isHoistableLoad(Load, CurRegion, LI, SE, DT))
return false;
for (auto NonAffineRegion : Context.NonAffineSubRegionSet) {
bool ScopDetection::involvesMultiplePtrs(const SCEV *S0, const SCEV *S1,
Loop *Scope) const {
SetVector<Value *> Values;
- findValues(S0, *SE, Values);
+ findValues(S0, SE, Values);
if (S1)
- findValues(S1, *SE, Values);
+ findValues(S1, SE, Values);
SmallPtrSet<Value *, 8> PtrVals;
for (auto *V : Values) {
if (!V->getType()->isPointerTy())
continue;
- auto *PtrSCEV = SE->getSCEVAtScope(V, Scope);
+ auto *PtrSCEV = SE.getSCEVAtScope(V, Scope);
if (isa<SCEVConstant>(PtrSCEV))
continue;
- auto *BasePtr = dyn_cast<SCEVUnknown>(SE->getPointerBase(PtrSCEV));
+ auto *BasePtr = dyn_cast<SCEVUnknown>(SE.getPointerBase(PtrSCEV));
if (!BasePtr)
return true;
auto *BasePtrVal = BasePtr->getValue();
if (PtrVals.insert(BasePtrVal).second) {
for (auto *PtrVal : PtrVals)
- if (PtrVal != BasePtrVal && !AA->isNoAlias(PtrVal, BasePtrVal))
+ if (PtrVal != BasePtrVal && !AA.isNoAlias(PtrVal, BasePtrVal))
return true;
}
}
DetectionContext &Context) const {
InvariantLoadsSetTy AccessILS;
- if (!isAffineExpr(&Context.CurRegion, Scope, S, *SE, &AccessILS))
+ if (!isAffineExpr(&Context.CurRegion, Scope, S, SE, &AccessILS))
return false;
if (!onlyValidRequiredInvariantLoads(AccessILS, Context))
bool ScopDetection::isValidSwitch(BasicBlock &BB, SwitchInst *SI,
Value *Condition, bool IsLoopBranch,
DetectionContext &Context) const {
- Loop *L = LI->getLoopFor(&BB);
- const SCEV *ConditionSCEV = SE->getSCEVAtScope(Condition, L);
+ Loop *L = LI.getLoopFor(&BB);
+ const SCEV *ConditionSCEV = SE.getSCEVAtScope(Condition, L);
if (IsLoopBranch && L->isLoopLatch(&BB))
return false;
return true;
if (AllowNonAffineSubRegions &&
- addOverApproximatedRegion(RI->getRegionFor(&BB), Context))
+ addOverApproximatedRegion(RI.getRegionFor(&BB), Context))
return true;
return invalid<ReportNonAffBranch>(Context, /*Assert=*/true, &BB,
// Non constant conditions of branches need to be ICmpInst.
if (!isa<ICmpInst>(Condition)) {
if (!IsLoopBranch && AllowNonAffineSubRegions &&
- addOverApproximatedRegion(RI->getRegionFor(&BB), Context))
+ addOverApproximatedRegion(RI.getRegionFor(&BB), Context))
return true;
return invalid<ReportInvalidCond>(Context, /*Assert=*/true, BI, &BB);
}
isa<UndefValue>(ICmp->getOperand(1)))
return invalid<ReportUndefOperand>(Context, /*Assert=*/true, &BB, ICmp);
- Loop *L = LI->getLoopFor(&BB);
- const SCEV *LHS = SE->getSCEVAtScope(ICmp->getOperand(0), L);
- const SCEV *RHS = SE->getSCEVAtScope(ICmp->getOperand(1), L);
+ Loop *L = LI.getLoopFor(&BB);
+ const SCEV *LHS = SE.getSCEVAtScope(ICmp->getOperand(0), L);
+ const SCEV *RHS = SE.getSCEVAtScope(ICmp->getOperand(1), L);
// If unsigned operations are not allowed try to approximate the region.
if (ICmp->isUnsigned() && !PollyAllowUnsignedOperations)
return !IsLoopBranch && AllowNonAffineSubRegions &&
- addOverApproximatedRegion(RI->getRegionFor(&BB), Context);
+ addOverApproximatedRegion(RI.getRegionFor(&BB), Context);
// Check for invalid usage of different pointers in one expression.
if (ICmp->isEquality() && involvesMultiplePtrs(LHS, nullptr, L) &&
return true;
if (!IsLoopBranch && AllowNonAffineSubRegions &&
- addOverApproximatedRegion(RI->getRegionFor(&BB), Context))
+ addOverApproximatedRegion(RI.getRegionFor(&BB), Context))
return true;
if (IsLoopBranch)
return false;
if (AllowModrefCall) {
- switch (AA->getModRefBehavior(CalledFunction)) {
+ switch (AA.getModRefBehavior(CalledFunction)) {
case FMRB_UnknownModRefBehavior:
return false;
case FMRB_DoesNotAccessMemory:
// Bail if a pointer argument has a base address not known to
// ScalarEvolution. Note that a zero pointer is acceptable.
- auto *ArgSCEV = SE->getSCEVAtScope(Arg, LI->getLoopFor(CI.getParent()));
+ auto *ArgSCEV = SE.getSCEVAtScope(Arg, LI.getLoopFor(CI.getParent()));
if (ArgSCEV->isZero())
continue;
- auto *BP = dyn_cast<SCEVUnknown>(SE->getPointerBase(ArgSCEV));
+ auto *BP = dyn_cast<SCEVUnknown>(SE.getPointerBase(ArgSCEV));
if (!BP)
return false;
return true;
// The closest loop surrounding the call instruction.
- Loop *L = LI->getLoopFor(II.getParent());
+ Loop *L = LI.getLoopFor(II.getParent());
// The access function and base pointer for memory intrinsics.
const SCEV *AF;
// Memory intrinsics that can be represented are supported.
case llvm::Intrinsic::memmove:
case llvm::Intrinsic::memcpy:
- AF = SE->getSCEVAtScope(cast<MemTransferInst>(II).getSource(), L);
+ AF = SE.getSCEVAtScope(cast<MemTransferInst>(II).getSource(), L);
if (!AF->isZero()) {
- BP = dyn_cast<SCEVUnknown>(SE->getPointerBase(AF));
+ BP = dyn_cast<SCEVUnknown>(SE.getPointerBase(AF));
// Bail if the source pointer is not valid.
if (!isValidAccess(&II, AF, BP, Context))
return false;
}
// Fall through
case llvm::Intrinsic::memset:
- AF = SE->getSCEVAtScope(cast<MemIntrinsic>(II).getDest(), L);
+ AF = SE.getSCEVAtScope(cast<MemIntrinsic>(II).getDest(), L);
if (!AF->isZero()) {
- BP = dyn_cast<SCEVUnknown>(SE->getPointerBase(AF));
+ BP = dyn_cast<SCEVUnknown>(SE.getPointerBase(AF));
// Bail if the destination pointer is not valid.
if (!isValidAccess(&II, AF, BP, Context))
return false;
}
// Bail if the length is not affine.
- if (!isAffine(SE->getSCEVAtScope(cast<MemIntrinsic>(II).getLength(), L), L,
+ if (!isAffine(SE.getSCEVAtScope(cast<MemIntrinsic>(II).getLength(), L), L,
Context))
return false;
SmallVector<const SCEV *, 4> Terms;
for (const auto &Pair : Context.Accesses[BasePointer]) {
std::vector<const SCEV *> MaxTerms;
- SCEVRemoveMax::rewrite(Pair.second, *SE, &MaxTerms);
+ SCEVRemoveMax::rewrite(Pair.second, SE, &MaxTerms);
if (MaxTerms.size() > 0) {
Terms.insert(Terms.begin(), MaxTerms.begin(), MaxTerms.end());
continue;
if (auto *AF = dyn_cast<SCEVAddExpr>(Pair.second)) {
for (auto Op : AF->operands()) {
if (auto *AF2 = dyn_cast<SCEVAddRecExpr>(Op))
- SE->collectParametricTerms(AF2, Terms);
+ SE.collectParametricTerms(AF2, Terms);
if (auto *AF2 = dyn_cast<SCEVMulExpr>(Op)) {
SmallVector<const SCEV *, 0> Operands;
}
}
if (Operands.size())
- Terms.push_back(SE->getMulExpr(Operands));
+ Terms.push_back(SE.getMulExpr(Operands));
}
}
}
if (Terms.empty())
- SE->collectParametricTerms(Pair.second, Terms);
+ SE.collectParametricTerms(Pair.second, Terms);
}
return Terms;
}
auto *V = dyn_cast<Value>(Unknown->getValue());
if (auto *Load = dyn_cast<LoadInst>(V)) {
if (Context.CurRegion.contains(Load) &&
- isHoistableLoad(Load, CurRegion, *LI, *SE, *DT))
+ isHoistableLoad(Load, CurRegion, LI, SE, DT))
Context.RequiredILS.insert(Load);
continue;
}
for (const auto &Pair : Context.Accesses[BasePointer]) {
const Instruction *Insn = Pair.first;
auto *AF = Pair.second;
- AF = SCEVRemoveMax::rewrite(AF, *SE);
+ AF = SCEVRemoveMax::rewrite(AF, SE);
bool IsNonAffine = false;
TempMemoryAccesses.insert(std::make_pair(Insn, MemAcc(Insn, Shape)));
MemAcc *Acc = &TempMemoryAccesses.find(Insn)->second;
- auto *Scope = LI->getLoopFor(Insn->getParent());
+ auto *Scope = LI.getLoopFor(Insn->getParent());
if (!AF) {
if (isAffine(Pair.second, Scope, Context))
else
IsNonAffine = true;
} else {
- SE->computeAccessFunctions(AF, Acc->DelinearizedSubscripts,
- Shape->DelinearizedSizes);
+ SE.computeAccessFunctions(AF, Acc->DelinearizedSubscripts,
+ Shape->DelinearizedSizes);
if (Acc->DelinearizedSubscripts.size() == 0)
IsNonAffine = true;
for (const SCEV *S : Acc->DelinearizedSubscripts)
auto Terms = getDelinearizationTerms(Context, BasePointer);
- SE->findArrayDimensions(Terms, Shape->DelinearizedSizes,
- Context.ElementSize[BasePointer]);
+ SE.findArrayDimensions(Terms, Shape->DelinearizedSizes,
+ Context.ElementSize[BasePointer]);
if (!hasValidArraySizes(Context, Shape->DelinearizedSizes, BasePointer,
Scope))
if (!isInvariant(*BV, Context.CurRegion, Context))
return invalid<ReportVariantBasePtr>(Context, /*Assert=*/true, BV, Inst);
- AF = SE->getMinusSCEV(AF, BP);
+ AF = SE.getMinusSCEV(AF, BP);
const SCEV *Size;
if (!isa<MemIntrinsic>(Inst)) {
- Size = SE->getElementSize(Inst);
+ Size = SE.getElementSize(Inst);
} else {
auto *SizeTy =
- SE->getEffectiveSCEVType(PointerType::getInt8PtrTy(SE->getContext()));
- Size = SE->getConstant(SizeTy, 8);
+ SE.getEffectiveSCEVType(PointerType::getInt8PtrTy(SE.getContext()));
+ Size = SE.getConstant(SizeTy, 8);
}
if (Context.ElementSize[BP]) {
return invalid<ReportDifferentArrayElementSize>(Context, /*Assert=*/true,
Inst, BV);
- Context.ElementSize[BP] = SE->getSMinExpr(Size, Context.ElementSize[BP]);
+ Context.ElementSize[BP] = SE.getSMinExpr(Size, Context.ElementSize[BP]);
} else {
Context.ElementSize[BP] = Size;
}
if (Context.BoxedLoopsSet.count(L))
IsVariantInNonAffineLoop = true;
- auto *Scope = LI->getLoopFor(Inst->getParent());
+ auto *Scope = LI.getLoopFor(Inst->getParent());
bool IsAffine = !IsVariantInNonAffineLoop && isAffine(AF, Scope, Context);
// Do not try to delinearize memory intrinsics and force them to be affine.
if (isa<MemIntrinsic>(Inst) && !IsAffine) {
if (!IsAffine)
Context.NonAffineAccesses.insert(
- std::make_pair(BP, LI->getLoopFor(Inst->getParent())));
+ std::make_pair(BP, LI.getLoopFor(Inst->getParent())));
} else if (!AllowNonAffine && !IsAffine) {
return invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, AF, Inst,
BV);
Instruction *Inst = dyn_cast<Instruction>(Ptr.getValue());
if (Inst && Context.CurRegion.contains(Inst)) {
auto *Load = dyn_cast<LoadInst>(Inst);
- if (Load && isHoistableLoad(Load, Context.CurRegion, *LI, *SE, *DT)) {
+ if (Load && isHoistableLoad(Load, Context.CurRegion, LI, SE, DT)) {
Context.RequiredILS.insert(Load);
continue;
}
bool ScopDetection::isValidMemoryAccess(MemAccInst Inst,
DetectionContext &Context) const {
Value *Ptr = Inst.getPointerOperand();
- Loop *L = LI->getLoopFor(Inst->getParent());
- const SCEV *AccessFunction = SE->getSCEVAtScope(Ptr, L);
+ Loop *L = LI.getLoopFor(Inst->getParent());
+ const SCEV *AccessFunction = SE.getSCEVAtScope(Ptr, L);
const SCEVUnknown *BasePointer;
- BasePointer = dyn_cast<SCEVUnknown>(SE->getPointerBase(AccessFunction));
+ BasePointer = dyn_cast<SCEVUnknown>(SE.getPointerBase(AccessFunction));
return isValidAccess(Inst, AccessFunction, BasePointer, Context);
}
if (!OpInst)
continue;
- if (isErrorBlock(*OpInst->getParent(), Context.CurRegion, *LI, *DT))
+ if (isErrorBlock(*OpInst->getParent(), Context.CurRegion, LI, DT))
return false;
}
return true;
if (AllowNonAffineSubLoops && AllowNonAffineSubRegions) {
- Region *R = RI->getRegionFor(L->getHeader());
+ Region *R = RI.getRegionFor(L->getHeader());
while (R != &Context.CurRegion && !R->contains(L))
R = R->getParent();
return true;
}
- const SCEV *LoopCount = SE->getBackedgeTakenCount(L);
+ const SCEV *LoopCount = SE.getBackedgeTakenCount(L);
return invalid<ReportLoopBound>(Context, /*Assert=*/true, L, LoopCount);
}
while (ExpandedRegion) {
const auto &It = DetectionContextMap.insert(std::make_pair(
getBBPairForRegion(ExpandedRegion.get()),
- DetectionContext(*ExpandedRegion, *AA, false /*verifying*/)));
+ DetectionContext(*ExpandedRegion, AA, false /*verifying*/)));
DetectionContext &Context = It.first->second;
DEBUG(dbgs() << "\t\tTrying " << ExpandedRegion->getNameStr() << "\n");
// Only expand when we did not collect errors.
return LastValidRegion.release();
}
-static bool regionWithoutLoops(Region &R, LoopInfo *LI) {
+static bool regionWithoutLoops(Region &R, LoopInfo &LI) {
for (const BasicBlock *BB : R.blocks())
- if (R.contains(LI->getLoopFor(BB)))
+ if (R.contains(LI.getLoopFor(BB)))
return false;
return true;
void ScopDetection::findScops(Region &R) {
const auto &It = DetectionContextMap.insert(std::make_pair(
- getBBPairForRegion(&R), DetectionContext(R, *AA, false /*verifying*/)));
+ getBBPairForRegion(&R), DetectionContext(R, AA, false /*verifying*/)));
DetectionContext &Context = It.first->second;
bool RegionIsValid = false;
Region &CurRegion = Context.CurRegion;
for (const BasicBlock *BB : CurRegion.blocks()) {
- Loop *L = LI->getLoopFor(BB);
+ Loop *L = LI.getLoopFor(BB);
if (L && L->getHeader() == BB && CurRegion.contains(L) &&
(!isValidLoop(L, Context) && !KeepGoing))
return false;
}
for (BasicBlock *BB : CurRegion.blocks()) {
- bool IsErrorBlock = isErrorBlock(*BB, CurRegion, *LI, *DT);
+ bool IsErrorBlock = isErrorBlock(*BB, CurRegion, LI, DT);
// Also check exception blocks (and possibly register them as non-affine
// regions). Even though exception blocks are not modeled, we use them
return false;
for (auto *BB : Context.CurRegion.blocks())
- if (Context.CurRegion.contains(LI->getLoopFor(BB)))
+ if (Context.CurRegion.contains(LI.getLoopFor(BB)))
InstCount += BB->size();
InstCount = InstCount / NumLoops;
bool ScopDetection::hasPossiblyDistributableLoop(
DetectionContext &Context) const {
for (auto *BB : Context.CurRegion.blocks()) {
- auto *L = LI->getLoopFor(BB);
+ auto *L = LI.getLoopFor(BB);
if (!Context.CurRegion.contains(L))
continue;
if (Context.BoxedLoopsSet.count(L))
return invalid<ReportUnprofitable>(Context, /*Assert=*/true, &CurRegion);
int NumLoops =
- countBeneficialLoops(&CurRegion, *SE, *LI, MIN_LOOP_TRIP_COUNT).NumLoops;
+ countBeneficialLoops(&CurRegion, SE, LI, MIN_LOOP_TRIP_COUNT).NumLoops;
int NumAffineLoops = NumLoops - Context.BoxedLoopsSet.size();
// Scops with at least two loops may allow either loop fusion or tiling and
// GREY indicates a loop in the control flow.
// If the destination dominates the source, it is a natural loop
// else, an irreducible control flow in the region is detected.
- if (!DT->dominates(SuccBB, CurrBB)) {
+ if (!DT.dominates(SuccBB, CurrBB)) {
// Get debug info of instruction which causes irregular control flow.
DbgLoc = TInst->getDebugLoc();
return false;
return true;
}
-void updateLoopCountStatistic(ScopDetection::LoopStats Stats,
- bool OnlyProfitable) {
+static void updateLoopCountStatistic(ScopDetection::LoopStats Stats,
+ bool OnlyProfitable) {
if (!OnlyProfitable) {
NumLoopsInScop += Stats.NumLoops;
MaxNumLoopsInScop =
}
}
-bool ScopDetection::runOnFunction(llvm::Function &F) {
- LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
- RI = &getAnalysis<RegionInfoPass>().getRegionInfo();
- if (!PollyProcessUnprofitable && LI->empty())
- return false;
-
- AA = &getAnalysis<AAResultsWrapperPass>().getAAResults();
- SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
- DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
- Region *TopRegion = RI->getTopLevelRegion();
-
- releaseMemory();
-
- if (OnlyFunction != "" && !F.getName().count(OnlyFunction))
- return false;
-
- if (!isValidFunction(F))
- return false;
-
- findScops(*TopRegion);
-
- NumScopRegions += ValidRegions.size();
-
- // Prune non-profitable regions.
- for (auto &DIt : DetectionContextMap) {
- auto &DC = DIt.getSecond();
- if (DC.Log.hasErrors())
- continue;
- if (!ValidRegions.count(&DC.CurRegion))
- continue;
- LoopStats Stats = countBeneficialLoops(&DC.CurRegion, *SE, *LI, 0);
- updateLoopCountStatistic(Stats, false /* OnlyProfitable */);
- if (isProfitableRegion(DC)) {
- updateLoopCountStatistic(Stats, true /* OnlyProfitable */);
- continue;
- }
-
- ValidRegions.remove(&DC.CurRegion);
- }
-
- NumProfScopRegions += ValidRegions.size();
- NumLoopsOverall += countBeneficialLoops(TopRegion, *SE, *LI, 0).NumLoops;
-
- // Only makes sense when we tracked errors.
- if (PollyTrackFailures)
- emitMissedRemarks(F);
-
- if (ReportLevel)
- printLocations(F);
-
- assert(ValidRegions.size() <= DetectionContextMap.size() &&
- "Cached more results than valid regions");
- return false;
-}
-
ScopDetection::DetectionContext *
ScopDetection::getDetectionContext(const Region *R) const {
auto DCMIt = DetectionContextMap.find(getBBPairForRegion(R));
void polly::ScopDetection::verifyRegion(const Region &R) const {
assert(isMaxRegionInScop(R) && "Expect R is a valid region.");
- DetectionContext Context(const_cast<Region &>(R), *AA, true /*verifying*/);
+ DetectionContext Context(const_cast<Region &>(R), AA, true /*verifying*/);
isValidRegion(Context);
}
verifyRegion(*R);
}
-void ScopDetection::getAnalysisUsage(AnalysisUsage &AU) const {
+bool ScopDetectionWrapperPass::runOnFunction(llvm::Function &F) {
+ auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
+ auto &RI = getAnalysis<RegionInfoPass>().getRegionInfo();
+ auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults();
+ auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE();
+ auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+ Result.reset(new ScopDetection(F, DT, SE, LI, RI, AA));
+ return false;
+}
+
+void ScopDetectionWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<LoopInfoWrapperPass>();
AU.addRequiredTransitive<ScalarEvolutionWrapperPass>();
AU.addRequired<DominatorTreeWrapperPass>();
AU.setPreservesAll();
}
-void ScopDetection::print(raw_ostream &OS, const Module *) const {
- for (const Region *R : ValidRegions)
+void ScopDetectionWrapperPass::print(raw_ostream &OS, const Module *) const {
+ for (const Region *R : Result->ValidRegions)
OS << "Valid Region for Scop: " << R->getNameStr() << '\n';
OS << "\n";
}
-void ScopDetection::releaseMemory() {
- ValidRegions.clear();
- DetectionContextMap.clear();
+ScopDetectionWrapperPass::ScopDetectionWrapperPass() : FunctionPass(ID) {
+ // Disable runtime alias checks if we ignore aliasing all together.
+ if (IgnoreAliasing)
+ PollyUseRuntimeAliasChecks = false;
+}
+
+void ScopDetectionWrapperPass::releaseMemory() { Result.reset(); }
+
+char ScopDetectionWrapperPass::ID;
+
+AnalysisKey ScopAnalysis::Key;
- // Do not clear the invalid function set.
+ScopDetection ScopAnalysis::run(Function &F, FunctionAnalysisManager &FAM) {
+ auto &LI = FAM.getResult<LoopAnalysis>(F);
+ auto &RI = FAM.getResult<RegionInfoAnalysis>(F);
+ auto &AA = FAM.getResult<AAManager>(F);
+ auto &SE = FAM.getResult<ScalarEvolutionAnalysis>(F);
+ auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
+ return {F, DT, SE, LI, RI, AA};
}
-char ScopDetection::ID = 0;
+PreservedAnalyses ScopAnalysisPrinterPass::run(Function &F,
+ FunctionAnalysisManager &FAM) {
+ auto &SD = FAM.getResult<ScopAnalysis>(F);
+ for (const Region *R : SD.ValidRegions)
+ Stream << "Valid Region for Scop: " << R->getNameStr() << '\n';
-Pass *polly::createScopDetectionPass() { return new ScopDetection(); }
+ Stream << "\n";
+ return PreservedAnalyses::all();
+}
+
+Pass *polly::createScopDetectionWrapperPassPass() {
+ return new ScopDetectionWrapperPass();
+}
-INITIALIZE_PASS_BEGIN(ScopDetection, "polly-detect",
+INITIALIZE_PASS_BEGIN(ScopDetectionWrapperPass, "polly-detect",
"Polly - Detect static control parts (SCoPs)", false,
false);
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass);
INITIALIZE_PASS_DEPENDENCY(RegionInfoPass);
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass);
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass);
-INITIALIZE_PASS_END(ScopDetection, "polly-detect",
+INITIALIZE_PASS_END(ScopDetectionWrapperPass, "polly-detect",
"Polly - Detect static control parts (SCoPs)", false, false)