From fb79a96d4274c291e97370862d0b9a1918d84474 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Mon, 23 Feb 2015 14:18:28 +0000 Subject: [PATCH] [NFC] Unify the use of Context.CurRegion llvm-svn: 230222 --- polly/lib/Analysis/ScopDetection.cpp | 57 ++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/polly/lib/Analysis/ScopDetection.cpp b/polly/lib/Analysis/ScopDetection.cpp index 2f5ea9d..5e4d972 100644 --- a/polly/lib/Analysis/ScopDetection.cpp +++ b/polly/lib/Analysis/ScopDetection.cpp @@ -278,11 +278,12 @@ std::string ScopDetection::regionIsInvalidBecause(const Region *R) const { bool ScopDetection::isValidCFG(BasicBlock &BB, DetectionContext &Context) const { - Region &RefRegion = Context.CurRegion; + Region &CurRegion = Context.CurRegion; + TerminatorInst *TI = BB.getTerminator(); // Return instructions are only valid if the region is the top level region. - if (isa(TI) && !RefRegion.getExit() && TI->getNumOperands() == 0) + if (isa(TI) && !CurRegion.getExit() && TI->getNumOperands() == 0) return true; BranchInst *Br = dyn_cast(TI); @@ -324,8 +325,8 @@ bool ScopDetection::isValidCFG(BasicBlock &BB, const SCEV *LHS = SE->getSCEVAtScope(ICmp->getOperand(0), L); const SCEV *RHS = SE->getSCEVAtScope(ICmp->getOperand(1), L); - if (!isAffineExpr(&Context.CurRegion, LHS, *SE) || - !isAffineExpr(&Context.CurRegion, RHS, *SE)) + if (!isAffineExpr(&CurRegion, LHS, *SE) || + !isAffineExpr(&CurRegion, RHS, *SE)) return invalid(Context, /*Assert=*/true, &BB, LHS, RHS, ICmp); } @@ -426,6 +427,8 @@ bool ScopDetection::isInvariant(const Value &Val, const Region &Reg) const { MapInsnToMemAcc InsnToMemAcc; bool ScopDetection::hasAffineMemoryAccesses(DetectionContext &Context) const { + Region &CurRegion = Context.CurRegion; + for (const SCEVUnknown *BasePointer : Context.NonAffineAccesses) { Value *BaseValue = BasePointer->getValue(); ArrayShape *Shape = new ArrayShape(BasePointer); @@ -454,7 +457,7 @@ bool ScopDetection::hasAffineMemoryAccesses(DetectionContext &Context) const { const Instruction *Insn = Pair.first; const SCEV *AF = Pair.second; - if (!isAffineExpr(&Context.CurRegion, AF, *SE, BaseValue)) { + if (!isAffineExpr(&CurRegion, AF, *SE, BaseValue)) { invalid(Context, /*Assert=*/true, AF, Insn, BaseValue); if (!KeepGoing) @@ -481,7 +484,7 @@ bool ScopDetection::hasAffineMemoryAccesses(DetectionContext &Context) const { TempMemoryAccesses.insert({Insn, Acc}); if (!AF) { - if (isAffineExpr(&Context.CurRegion, Pair.second, *SE, BaseValue)) + if (isAffineExpr(&CurRegion, Pair.second, *SE, BaseValue)) Acc->DelinearizedSubscripts.push_back(Pair.second); else IsNonAffine = true; @@ -491,7 +494,7 @@ bool ScopDetection::hasAffineMemoryAccesses(DetectionContext &Context) const { if (Acc->DelinearizedSubscripts.size() == 0) IsNonAffine = true; for (const SCEV *S : Acc->DelinearizedSubscripts) - if (!isAffineExpr(&Context.CurRegion, S, *SE, BaseValue)) + if (!isAffineExpr(&CurRegion, S, *SE, BaseValue)) IsNonAffine = true; } @@ -514,6 +517,8 @@ bool ScopDetection::hasAffineMemoryAccesses(DetectionContext &Context) const { bool ScopDetection::isValidMemoryAccess(Instruction &Inst, DetectionContext &Context) const { + Region &CurRegion = Context.CurRegion; + Value *Ptr = getPointerOperand(Inst); Loop *L = LI->getLoopFor(Inst.getParent()); const SCEV *AccessFunction = SE->getSCEVAtScope(Ptr, L); @@ -532,7 +537,7 @@ bool ScopDetection::isValidMemoryAccess(Instruction &Inst, // Check that the base address of the access is invariant in the current // region. - if (!isInvariant(*BaseValue, Context.CurRegion)) + if (!isInvariant(*BaseValue, CurRegion)) // Verification of this property is difficult as the independent blocks // pass may introduce aliasing that we did not have when running the // scop detection. @@ -553,10 +558,10 @@ bool ScopDetection::isValidMemoryAccess(Instruction &Inst, if (PollyDelinearize) { Context.Accesses[BasePointer].push_back({&Inst, AccessFunction}); - if (!isAffineExpr(&Context.CurRegion, AccessFunction, *SE, BaseValue)) + if (!isAffineExpr(&CurRegion, AccessFunction, *SE, BaseValue)) Context.NonAffineAccesses.insert(BasePointer); } else if (!AllowNonAffine) { - if (!isAffineExpr(&Context.CurRegion, AccessFunction, *SE, BaseValue)) + if (!isAffineExpr(&CurRegion, AccessFunction, *SE, BaseValue)) return invalid(Context, /*Assert=*/true, AccessFunction, &Inst, BaseValue); } @@ -592,7 +597,7 @@ bool ScopDetection::isValidMemoryAccess(Instruction &Inst, // sure the base pointer is not an instruction defined inside the scop. for (const auto &Ptr : AS) { Instruction *Inst = dyn_cast(Ptr.getValue()); - if (Inst && Context.CurRegion.contains(Inst)) { + if (Inst && CurRegion.contains(Inst)) { CanBuildRunTimeCheck = false; break; } @@ -787,19 +792,19 @@ void ScopDetection::findScops(Region &R) { } bool ScopDetection::allBlocksValid(DetectionContext &Context) const { - Region &R = Context.CurRegion; + Region &CurRegion = Context.CurRegion; - for (const BasicBlock *BB : R.blocks()) { + for (const BasicBlock *BB : CurRegion.blocks()) { Loop *L = LI->getLoopFor(BB); if (L && L->getHeader() == BB && (!isValidLoop(L, Context) && !KeepGoing)) return false; } - for (BasicBlock *BB : R.blocks()) + for (BasicBlock *BB : CurRegion.blocks()) if (!isValidCFG(*BB, Context) && !KeepGoing) return false; - for (BasicBlock *BB : R.blocks()) + for (BasicBlock *BB : CurRegion.blocks()) for (BasicBlock::iterator I = BB->begin(), E = --BB->end(); I != E; ++I) if (!isValidInstruction(*I, Context) && !KeepGoing) return false; @@ -811,10 +816,9 @@ bool ScopDetection::allBlocksValid(DetectionContext &Context) const { } bool ScopDetection::isValidExit(DetectionContext &Context) const { - Region &R = Context.CurRegion; // PHI nodes are not allowed in the exit basic block. - if (BasicBlock *Exit = R.getExit()) { + if (BasicBlock *Exit = Context.CurRegion.getExit()) { BasicBlock::iterator I = Exit->begin(); if (I != Exit->end() && isa(*I)) return invalid(Context, /*Assert=*/true, I); @@ -824,16 +828,16 @@ bool ScopDetection::isValidExit(DetectionContext &Context) const { } bool ScopDetection::isValidRegion(DetectionContext &Context) const { - Region &R = Context.CurRegion; + Region &CurRegion = Context.CurRegion; - DEBUG(dbgs() << "Checking region: " << R.getNameStr() << "\n\t"); + DEBUG(dbgs() << "Checking region: " << CurRegion.getNameStr() << "\n\t"); - if (R.isTopLevelRegion()) { + if (CurRegion.isTopLevelRegion()) { DEBUG(dbgs() << "Top level region is invalid\n"); return false; } - if (!R.getEntry()->getName().count(OnlyRegion)) { + if (!CurRegion.getEntry()->getName().count(OnlyRegion)) { DEBUG({ dbgs() << "Region entry does not match -polly-region-only"; dbgs() << "\n"; @@ -841,8 +845,8 @@ bool ScopDetection::isValidRegion(DetectionContext &Context) const { return false; } - if (!R.getEnteringBlock()) { - BasicBlock *entry = R.getEntry(); + if (!CurRegion.getEnteringBlock()) { + BasicBlock *entry = CurRegion.getEntry(); Loop *L = LI->getLoopFor(entry); if (L) { @@ -853,7 +857,7 @@ bool ScopDetection::isValidRegion(DetectionContext &Context) const { ++PI) { // Region entering edges come from the same loop but outside the region // are not allowed. - if (L->contains(*PI) && !R.contains(*PI)) + if (L->contains(*PI) && !CurRegion.contains(*PI)) return invalid(Context, /*Assert=*/true, *PI); } } @@ -861,8 +865,9 @@ bool ScopDetection::isValidRegion(DetectionContext &Context) const { // SCoP cannot contain the entry block of the function, because we need // to insert alloca instruction there when translate scalar to array. - if (R.getEntry() == &(R.getEntry()->getParent()->getEntryBlock())) - return invalid(Context, /*Assert=*/true, R.getEntry()); + if (CurRegion.getEntry() == + &(CurRegion.getEntry()->getParent()->getEntryBlock())) + return invalid(Context, /*Assert=*/true, CurRegion.getEntry()); if (!isValidExit(Context)) return false; -- 2.7.4