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<ReturnInst>(TI) && !RefRegion.getExit() && TI->getNumOperands() == 0)
+ if (isa<ReturnInst>(TI) && !CurRegion.getExit() && TI->getNumOperands() == 0)
return true;
BranchInst *Br = dyn_cast<BranchInst>(TI);
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<ReportNonAffBranch>(Context, /*Assert=*/true, &BB, LHS,
RHS, ICmp);
}
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);
const Instruction *Insn = Pair.first;
const SCEV *AF = Pair.second;
- if (!isAffineExpr(&Context.CurRegion, AF, *SE, BaseValue)) {
+ if (!isAffineExpr(&CurRegion, AF, *SE, BaseValue)) {
invalid<ReportNonAffineAccess>(Context, /*Assert=*/true, AF, Insn,
BaseValue);
if (!KeepGoing)
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;
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;
}
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);
// 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.
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<ReportNonAffineAccess>(Context, /*Assert=*/true,
AccessFunction, &Inst, BaseValue);
}
// sure the base pointer is not an instruction defined inside the scop.
for (const auto &Ptr : AS) {
Instruction *Inst = dyn_cast<Instruction>(Ptr.getValue());
- if (Inst && Context.CurRegion.contains(Inst)) {
+ if (Inst && CurRegion.contains(Inst)) {
CanBuildRunTimeCheck = false;
break;
}
}
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;
}
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<PHINode>(*I))
return invalid<ReportPHIinExit>(Context, /*Assert=*/true, I);
}
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";
return false;
}
- if (!R.getEnteringBlock()) {
- BasicBlock *entry = R.getEntry();
+ if (!CurRegion.getEnteringBlock()) {
+ BasicBlock *entry = CurRegion.getEntry();
Loop *L = LI->getLoopFor(entry);
if (L) {
++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<ReportIndEdge>(Context, /*Assert=*/true, *PI);
}
}
// 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<ReportEntry>(Context, /*Assert=*/true, R.getEntry());
+ if (CurRegion.getEntry() ==
+ &(CurRegion.getEntry()->getParent()->getEntryBlock()))
+ return invalid<ReportEntry>(Context, /*Assert=*/true, CurRegion.getEntry());
if (!isValidExit(Context))
return false;