52#include "llvm/ADT/SmallPtrSet.h"
53#include "llvm/ADT/Statistic.h"
54#include "llvm/Analysis/AliasAnalysis.h"
55#include "llvm/Analysis/Delinearization.h"
56#include "llvm/Analysis/Loads.h"
57#include "llvm/Analysis/LoopInfo.h"
58#include "llvm/Analysis/OptimizationRemarkEmitter.h"
59#include "llvm/Analysis/RegionInfo.h"
60#include "llvm/Analysis/ScalarEvolution.h"
61#include "llvm/Analysis/ScalarEvolutionExpressions.h"
62#include "llvm/IR/BasicBlock.h"
63#include "llvm/IR/DebugLoc.h"
64#include "llvm/IR/DerivedTypes.h"
65#include "llvm/IR/DiagnosticInfo.h"
66#include "llvm/IR/DiagnosticPrinter.h"
67#include "llvm/IR/Dominators.h"
68#include "llvm/IR/Function.h"
69#include "llvm/IR/InstrTypes.h"
70#include "llvm/IR/Instruction.h"
71#include "llvm/IR/Instructions.h"
72#include "llvm/IR/IntrinsicInst.h"
73#include "llvm/IR/Metadata.h"
74#include "llvm/IR/Module.h"
75#include "llvm/IR/Value.h"
76#include "llvm/Support/Debug.h"
77#include "llvm/Support/Regex.h"
78#include "llvm/Support/raw_ostream.h"
91#define DEBUG_TYPE "polly-detect"
98 "polly-detect-profitability-min-per-loop-insts",
99 cl::desc(
"The minimal number of per-loop instructions before a single loop "
100 "region is considered profitable"),
101 cl::Hidden, cl::ValueRequired, cl::init(100000000), cl::cat(
PollyCategory));
106 "polly-process-unprofitable",
108 "Process scops that are unlikely to benefit from Polly optimizations."),
116 "polly-detect-for-vectorization",
117 cl::desc(
"Bypass some Polly profitability checks for vectorization"),
128 "polly-optimize-for-vectorization",
129 cl::desc(
"Make the profitability heuristic consider vectorization "
136 cl::desc(
"Only run on functions that match a regex. "
137 "Multiple regexes can be comma separated. "
138 "Scop detection will run on all functions that match "
139 "ANY of the regexes provided."),
144 cl::desc(
"Ignore functions that match a regex. "
145 "Multiple regexes can be comma separated. "
146 "Scop detection will ignore all functions that match "
147 "ANY of the regexes provided."),
152static cl::opt<bool, true>
154 cl::desc(
"Allow the detection of full functions"),
160 cl::desc(
"Only run on certain regions (The provided identifier must "
161 "appear in the name of the region's entry block"),
162 cl::value_desc(
"identifier"), cl::ValueRequired, cl::init(
""),
167 cl::desc(
"Ignore possible aliasing of the array bases"),
173 "polly-allow-unsigned-operations",
174 cl::desc(
"Allow unsigned operations such as comparisons or zero-extends."),
181 "polly-use-runtime-alias-checks",
182 cl::desc(
"Use runtime alias checks to resolve possible aliasing."),
188 cl::desc(
"Print information about the activities of Polly"),
192 "polly-allow-differing-element-types",
193 cl::desc(
"Allow different element types for array accesses"), cl::Hidden,
198 cl::desc(
"Allow non affine access functions in arrays"),
203 cl::desc(
"Allow functions with known modref behavior"),
207 "polly-allow-nonaffine-branches",
208 cl::desc(
"Allow non affine conditions for branches"), cl::Hidden,
213 cl::desc(
"Allow non affine conditions for loops"),
216static cl::opt<bool, true>
218 cl::desc(
"Track failure strings in detecting scop regions"),
222static cl::opt<bool>
KeepGoing(
"polly-detect-keep-going",
223 cl::desc(
"Do not fail on the first error."),
226static cl::opt<bool, true>
228 cl::desc(
"Delinearize array access functions"),
234 cl::desc(
"Verify the detected SCoPs after each transformation"),
239static cl::opt<bool, true>
241 cl::desc(
"Hoist invariant loads."),
246 "polly-allow-error-blocks",
247 cl::desc(
"Allow to speculate on the execution of 'error blocks'."),
262STATISTIC(NumScopsDepthZero,
"Number of scops with maximal loop depth 0");
263STATISTIC(NumScopsDepthOne,
"Number of scops with maximal loop depth 1");
264STATISTIC(NumScopsDepthTwo,
"Number of scops with maximal loop depth 2");
265STATISTIC(NumScopsDepthThree,
"Number of scops with maximal loop depth 3");
266STATISTIC(NumScopsDepthFour,
"Number of scops with maximal loop depth 4");
267STATISTIC(NumScopsDepthFive,
"Number of scops with maximal loop depth 5");
269 "Number of scops with maximal loop depth 6 and larger");
270STATISTIC(NumProfScopRegions,
"Number of scops (profitable scops only)");
272 "Number of loops in scops (profitable scops only)");
275 "Number of scops with maximal loop depth 0 (profitable scops only)");
277 "Number of scops with maximal loop depth 1 (profitable scops only)");
279 "Number of scops with maximal loop depth 2 (profitable scops only)");
281 "Number of scops with maximal loop depth 3 (profitable scops only)");
283 "Number of scops with maximal loop depth 4 (profitable scops only)");
285 "Number of scops with maximal loop depth 5 (profitable scops only)");
287 "Number of scops with maximal loop depth 6 and larger "
288 "(profitable scops only)");
289STATISTIC(MaxNumLoopsInScop,
"Maximal number of loops in scops");
291 "Maximal number of loops in scops (profitable scops only)");
294 bool OnlyProfitable);
298class DiagnosticScopFound final :
public DiagnosticInfo {
300 static int PluginDiagnosticKind;
303 std::string FileName;
304 unsigned EntryLine, ExitLine;
307 DiagnosticScopFound(Function &F, std::string FileName,
unsigned EntryLine,
309 : DiagnosticInfo(PluginDiagnosticKind, DS_Note), F(F), FileName(FileName),
310 EntryLine(EntryLine), ExitLine(ExitLine) {}
312 void print(DiagnosticPrinter &DP)
const override;
314 static bool classof(
const DiagnosticInfo *DI) {
315 return DI->getKind() == PluginDiagnosticKind;
320int DiagnosticScopFound::PluginDiagnosticKind =
321 getNextAvailablePluginDiagnosticKind();
323void DiagnosticScopFound::print(DiagnosticPrinter &DP)
const {
324 DP <<
"Polly detected an optimizable loop region (scop) in function '" << F
327 if (FileName.empty()) {
328 DP <<
"Scop location is unknown. Compile with debug info "
329 "(-g) to get more precise information. ";
333 DP << FileName <<
":" << EntryLine <<
": Start of scop\n";
334 DP << FileName <<
":" << ExitLine <<
": End of scop";
341 const cl::list<std::string> &RegexList) {
342 for (
auto RegexStr : RegexList) {
347 report_fatal_error(Twine(
"invalid regex given as input to polly: ") + Err,
360 LoopInfo &
LI, RegionInfo &
RI, AAResults &
AA,
361 OptimizationRemarkEmitter &
ORE)
370 Region *TopRegion =
RI.getTopLevelRegion();
414 "Cached more results than valid regions");
417template <
class RR,
typename... Args>
419 Args &&...Arguments)
const {
422 std::shared_ptr<RR>
RejectReason = std::make_shared<RR>(Arguments...);
432 assert(!Assert &&
"Verification of detected scop failed");
450 Entry = std::make_unique<DetectionContext>(
const_cast<Region &
>(R),
AA,
466 if (!Log || !Log->hasErrors())
470 return RR->getMessage();
482 for (BasicBlock *BB : AR->blocks()) {
483 Loop *L =
LI.getLoopFor(BB);
494 const DataLayout &DL = CurRegion.getEntry()->getModule()->getDataLayout();
499 for (LoadInst *Load : RequiredILS) {
511 if (isSafeToLoadUnconditionally(Load->getPointerOperand(),
512 Load->getType(), Load->getAlign(), DL))
515 if (NonAffineRegion->contains(Load) &&
516 Load->getParent() != NonAffineRegion->getEntry())
528 SetVector<Value *> Values;
533 SmallPtrSet<Value *, 8> PtrVals;
534 for (
auto *V : Values) {
535 if (
auto *P2I = dyn_cast<PtrToIntInst>(V))
536 V = P2I->getOperand(0);
538 if (!V->getType()->isPointerTy())
541 const SCEV *PtrSCEV =
SE.getSCEVAtScope(V, Scope);
542 if (isa<SCEVConstant>(PtrSCEV))
545 auto *BasePtr = dyn_cast<SCEVUnknown>(
SE.getPointerBase(PtrSCEV));
549 Value *BasePtrVal = BasePtr->getValue();
550 if (PtrVals.insert(BasePtrVal).second) {
551 for (
auto *PtrVal : PtrVals)
552 if (PtrVal != BasePtrVal && !
AA.isNoAlias(PtrVal, BasePtrVal))
573 Value *Condition,
bool IsLoopBranch,
575 Loop *L =
LI.getLoopFor(&BB);
576 const SCEV *ConditionSCEV =
SE.getSCEVAtScope(Condition, L);
578 if (IsLoopBranch && L->isLoopLatch(&BB))
585 if (
isAffine(ConditionSCEV, L, Context))
593 ConditionSCEV, ConditionSCEV, SI);
597 Value *Condition,
bool IsLoopBranch,
600 if (isa<ConstantInt>(Condition))
603 if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(Condition)) {
604 auto Opcode = BinOp->getOpcode();
605 if (Opcode == Instruction::And || Opcode == Instruction::Or) {
606 Value *Op0 = BinOp->getOperand(0);
607 Value *Op1 = BinOp->getOperand(1);
613 if (
auto PHI = dyn_cast<PHINode>(Condition)) {
614 auto *Unique = dyn_cast_or_null<ConstantInt>(
616 if (Unique && (Unique->isZero() || Unique->isOne()))
620 if (
auto Load = dyn_cast<LoadInst>(Condition))
621 if (!IsLoopBranch && Context.
CurRegion.contains(Load)) {
627 if (!isa<ICmpInst>(Condition)) {
634 ICmpInst *ICmp = cast<ICmpInst>(Condition);
637 if (isa<UndefValue>(ICmp->getOperand(0)) ||
638 isa<UndefValue>(ICmp->getOperand(1)))
641 Loop *L =
LI.getLoopFor(&BB);
642 const SCEV *LHS =
SE.getSCEVAtScope(ICmp->getOperand(0), L);
643 const SCEV *RHS =
SE.getSCEVAtScope(ICmp->getOperand(1), L);
677 bool AllowUnreachable,
681 Instruction *TI = BB.getTerminator();
683 if (AllowUnreachable && isa<UnreachableInst>(TI))
687 if (isa<ReturnInst>(TI) && CurRegion.isTopLevelRegion())
690 if (isa<UncondBrInst>(TI))
693 if (
auto *BI = dyn_cast<CondBrInst>(TI)) {
694 Value *Condition = BI->getCondition();
695 if (isa<UndefValue>(Condition))
697 return isValidBranch(BB, BI, Condition, IsLoopBranch, Context);
700 if (
auto *SI = dyn_cast<SwitchInst>(TI)) {
701 Value *Condition = SI->getCondition();
702 if (isa<UndefValue>(Condition))
704 return isValidSwitch(BB, SI, Condition, IsLoopBranch, Context);
712 if (CI.doesNotReturn())
715 if (CI.doesNotAccessMemory())
718 if (
auto *II = dyn_cast<IntrinsicInst>(&CI))
722 Function *CalledFunction = CI.getCalledFunction();
725 if (CalledFunction ==
nullptr)
729 POLLY_DEBUG(dbgs() <<
"Allow call to debug function: "
730 << CalledFunction->getName() <<
'\n');
735 MemoryEffects ME =
AA.getMemoryEffects(CalledFunction);
736 if (ME.onlyAccessesArgPointees()) {
737 for (
const auto &Arg : CI.args()) {
738 if (!Arg->getType()->isPointerTy())
743 const SCEV *ArgSCEV =
744 SE.getSCEVAtScope(Arg,
LI.getLoopFor(CI.getParent()));
745 if (ArgSCEV->isZero())
748 auto *BP = dyn_cast<SCEVUnknown>(
SE.getPointerBase(ArgSCEV));
759 Context.
AST.addUnknown(&CI);
763 if (ME.onlyReadsMemory()) {
769 Context.
AST.addUnknown(&CI);
784 Loop *L =
LI.getLoopFor(II.getParent());
788 const SCEVUnknown *BP;
790 switch (II.getIntrinsicID()) {
792 case Intrinsic::memmove:
793 case Intrinsic::memcpy:
794 AF =
SE.getSCEVAtScope(cast<MemTransferInst>(II).getSource(), L);
796 BP = dyn_cast<SCEVUnknown>(
SE.getPointerBase(AF));
802 case Intrinsic::memset:
803 AF =
SE.getSCEVAtScope(cast<MemIntrinsic>(II).getDest(), L);
805 BP = dyn_cast<SCEVUnknown>(
SE.getPointerBase(AF));
812 if (!
isAffine(
SE.getSCEVAtScope(cast<MemIntrinsic>(II).getLength(), L), L,
827 if (isa<Argument>(Val) || isa<Constant>(Val))
830 Instruction *I = dyn_cast<Instruction>(&Val);
834 if (!Reg.contains(I))
840 if (
auto LI = dyn_cast<LoadInst>(I)) {
841 Ctx.RequiredILS.insert(
LI);
862class SCEVRemoveMax final :
public SCEVRewriteVisitor<SCEVRemoveMax> {
864 SCEVRemoveMax(ScalarEvolution &SE, std::vector<const SCEV *> *Terms)
865 : SCEVRewriteVisitor(SE), Terms(Terms) {}
867 static const SCEV *rewrite(
const SCEV *Scev, ScalarEvolution &SE,
868 std::vector<const SCEV *> *Terms =
nullptr) {
869 SCEVRemoveMax Rewriter(SE, Terms);
870 return Rewriter.visit(Scev);
873 const SCEV *visitSMaxExpr(
const SCEVSMaxExpr *Expr) {
874 if ((Expr->getNumOperands() == 2) && Expr->getOperand(0)->isZero()) {
875 auto Res = visit(Expr->getOperand(1));
877 (*Terms).push_back(
Res);
885 std::vector<const SCEV *> *Terms;
889SmallVector<const SCEV *, 4>
891 const SCEVUnknown *BasePointer)
const {
892 SmallVector<const SCEV *, 4> Terms;
893 for (
const auto &
Pair : Context.
Accesses[BasePointer]) {
894 std::vector<const SCEV *> MaxTerms;
895 SCEVRemoveMax::rewrite(
Pair.second,
SE, &MaxTerms);
896 if (!MaxTerms.empty()) {
897 for (
const SCEV *Max : MaxTerms)
899 SE.getTruncateOrSignExtend(Max,
Pair.second->getType()));
910 if (
auto *AF = dyn_cast<SCEVAddExpr>(
Pair.second)) {
911 for (
auto Op : AF->operands()) {
912 if (
auto *AF2 = dyn_cast<SCEVAddRecExpr>(Op))
913 collectParametricTerms(
SE, AF2, Terms);
914 if (
auto *AF2 = dyn_cast<SCEVMulExpr>(Op)) {
915 SmallVector<SCEVUse, 0> Operands;
917 for (
const SCEV *MulOp : AF2->operands()) {
918 if (
auto *Const = dyn_cast<SCEVConstant>(MulOp))
919 Operands.push_back(Const);
920 if (
auto *Unknown = dyn_cast<SCEVUnknown>(MulOp)) {
921 if (
auto *Inst = dyn_cast<Instruction>(Unknown->getValue())) {
923 Operands.push_back(MulOp);
926 Operands.push_back(MulOp);
931 Terms.push_back(
SE.getMulExpr(Operands));
936 collectParametricTerms(
SE,
Pair.second, Terms);
942 SmallVectorImpl<const SCEV *> &Sizes,
943 const SCEVUnknown *BasePointer,
951 if (Sizes.size() == 0)
954 Value *BaseValue = BasePointer->getValue();
956 for (
const SCEV *DelinearizedSize : Sizes) {
959 if (!
isAffine(DelinearizedSize,
nullptr, Context)) {
963 if (
auto *Unknown = dyn_cast<SCEVUnknown>(DelinearizedSize)) {
964 auto *V = dyn_cast<Value>(Unknown->getValue());
965 if (
auto *Load = dyn_cast<LoadInst>(V)) {
975 Context,
true, DelinearizedSize,
976 Context.
Accesses[BasePointer].front().first, BaseValue);
984 for (
const auto &
Pair : Context.
Accesses[BasePointer]) {
985 const Instruction *Insn =
Pair.first;
986 const SCEV *AF =
Pair.second;
988 if (!
isAffine(AF, Scope, Context)) {
1008 std::shared_ptr<ArrayShape> Shape)
const {
1009 Value *BaseValue = BasePointer->getValue();
1010 bool BasePtrHasNonAffine =
false;
1012 for (
const auto &
Pair : Context.
Accesses[BasePointer]) {
1013 const Instruction *Insn =
Pair.first;
1014 auto *AF =
Pair.second;
1015 AF = SCEVRemoveMax::rewrite(AF,
SE);
1016 bool IsNonAffine =
false;
1017 TempMemoryAccesses.insert(std::make_pair(Insn,
MemAcc(Insn, Shape)));
1018 MemAcc *Acc = &TempMemoryAccesses.find(Insn)->second;
1019 auto *Scope =
LI.getLoopFor(Insn->getParent());
1027 if (Shape->DelinearizedSizes.size() == 0) {
1031 Shape->DelinearizedSizes);
1042 BasePtrHasNonAffine =
true;
1052 if (!BasePtrHasNonAffine)
1053 Context.
InsnToMemAcc.insert(TempMemoryAccesses.begin(),
1054 TempMemoryAccesses.end());
1060 const SCEVUnknown *BasePointer,
1061 Loop *Scope)
const {
1062 auto Shape = std::shared_ptr<ArrayShape>(
new ArrayShape(BasePointer));
1066 findArrayDimensions(
SE, Terms, Shape->DelinearizedSizes,
1083 auto *BasePointer =
Pair.first;
1084 auto *Scope =
Pair.second;
1095 const SCEVUnknown *BP,
1101 auto *BV = BP->getValue();
1102 if (isa<UndefValue>(BV))
1106 if (IntToPtrInst *Inst = dyn_cast<IntToPtrInst>(BV))
1114 AF =
SE.getMinusSCEV(AF, BP);
1117 if (!isa<MemIntrinsic>(Inst)) {
1118 Size =
SE.getElementSize(Inst);
1121 SE.getEffectiveSCEVType(PointerType::getUnqual(
SE.getContext()));
1122 Size =
SE.getConstant(SizeTy, 8);
1135 bool IsVariantInNonAffineLoop =
false;
1136 SetVector<const Loop *> Loops;
1138 for (
const Loop *L : Loops)
1140 IsVariantInNonAffineLoop =
true;
1142 auto *Scope =
LI.getLoopFor(Inst->getParent());
1143 bool IsAffine = !IsVariantInNonAffineLoop &&
isAffine(AF, Scope, Context);
1145 if (isa<MemIntrinsic>(Inst) && !IsAffine) {
1149 Context.
Accesses[BP].push_back({Inst, AF});
1153 std::make_pair(BP,
LI.getLoopFor(Inst->getParent())));
1164 AAMDNodes AATags = Inst->getAAMetadata();
1165 AliasSet &AS = Context.
AST.getAliasSetFor(
1166 MemoryLocation::getBeforeOrAfter(BP->getValue(), AATags));
1168 if (!AS.isMustAlias()) {
1170 bool CanBuildRunTimeCheck =
true;
1177 auto ASPointers = AS.getPointers();
1185 const unsigned int VariantSize = VariantLS.size(),
1186 InvariantSize = InvariantLS.size();
1188 for (
const Value *Ptr : ASPointers) {
1189 Instruction *Inst = dyn_cast<Instruction>(
const_cast<Value *
>(Ptr));
1190 if (Inst && Context.
CurRegion.contains(Inst)) {
1191 auto *Load = dyn_cast<LoadInst>(Inst);
1192 if (Load && InvariantLS.count(Load))
1196 if (VariantLS.count(Load))
1197 VariantLS.remove(Load);
1199 InvariantLS.insert(Load);
1201 CanBuildRunTimeCheck =
false;
1202 VariantLS.insert(Load);
1207 if (InvariantSize == InvariantLS.size() &&
1208 VariantSize == VariantLS.size())
1212 if (CanBuildRunTimeCheck)
1224 Loop *L =
LI.getLoopFor(Inst->getParent());
1225 const SCEV *AccessFunction =
SE.getSCEVAtScope(Ptr, L);
1226 const SCEVUnknown *BasePointer;
1228 BasePointer = dyn_cast<SCEVUnknown>(
SE.getPointerBase(AccessFunction));
1230 return isValidAccess(Inst, AccessFunction, BasePointer, Context);
1238 if (isa<ScalableVectorType>(Ty))
1246 for (
auto &Op : Inst.operands()) {
1247 auto *OpInst = dyn_cast<Instruction>(&Op);
1256 auto *
PHI = dyn_cast<PHINode>(OpInst);
1258 for (Instruction *UI :
PHI->users()) {
1259 if (!UI->isTerminator())
1268 if (isa<LandingPadInst>(&Inst) || isa<ResumeInst>(&Inst))
1275 if (CallInst *CI = dyn_cast<CallInst>(&Inst)) {
1282 if (!Inst.mayReadOrWriteMemory()) {
1283 if (!isa<AllocaInst>(Inst))
1291 Context.
hasStores |= isa<StoreInst>(MemInst);
1292 Context.
hasLoads |= isa<LoadInst>(MemInst);
1293 if (!MemInst.isSimple())
1310 SmallVector<BasicBlock *, 4> ExitingBlocks;
1311 L->getExitingBlocks(ExitingBlocks);
1312 return !ExitingBlocks.empty();
1327 SmallVector<BasicBlock *, 4> LoopControlBlocks;
1328 L->getExitingBlocks(LoopControlBlocks);
1329 L->getLoopLatches(LoopControlBlocks);
1330 for (BasicBlock *ControlBB : LoopControlBlocks) {
1331 if (!
isValidCFG(*ControlBB,
true,
false, Context)) {
1379 SmallVector<BasicBlock *, 4> ExitBlocks;
1380 L->getExitBlocks(ExitBlocks);
1381 BasicBlock *TheExitBlock = ExitBlocks[0];
1382 for (BasicBlock *ExitBB : ExitBlocks) {
1383 if (TheExitBlock != ExitBB)
1391 Region *R =
RI.getRegionFor(L->getHeader());
1392 while (R != &Context.
CurRegion && !R->contains(L))
1399 const SCEV *LoopCount =
SE.getBackedgeTakenCount(L);
1407 unsigned MinProfitableTrips) {
1408 const SCEV *TripCount =
SE.getBackedgeTakenCount(L);
1411 int MaxLoopDepth = 1;
1412 if (MinProfitableTrips > 0)
1413 if (
auto *TripCountC = dyn_cast<SCEVConstant>(TripCount))
1414 if (TripCountC->getType()->getScalarSizeInBits() <= 64)
1415 if (TripCountC->getValue()->getZExtValue() <= MinProfitableTrips)
1418 for (
auto &SubLoop : *L) {
1421 MaxLoopDepth = std::max(MaxLoopDepth, Stats.
MaxDepth + 1);
1424 return {NumLoops, MaxLoopDepth};
1429 LoopInfo &
LI,
unsigned MinProfitableTrips) {
1431 int MaxLoopDepth = 0;
1433 auto L =
LI.getLoopFor(R->getEntry());
1437 if (L && R->contains(L)) {
1438 L = R->outermostLoopInRegion(L);
1439 L = L->getParentLoop();
1443 L ? L->getSubLoops() : std::vector<Loop *>(
LI.begin(),
LI.end());
1445 for (
auto &SubLoop : SubLoops)
1446 if (R->contains(SubLoop)) {
1450 MaxLoopDepth = std::max(MaxLoopDepth, Stats.
MaxDepth);
1453 return {LoopNum, MaxLoopDepth};
1457 const DominatorTree &DT) {
1458 if (isa<UnreachableInst>(BB.getTerminator()))
1461 if (LI.isLoopHeader(&BB))
1466 if (!R.contains(&BB))
1471 bool DominatesAllPredecessors =
true;
1472 if (R.isTopLevelRegion()) {
1473 for (BasicBlock &I : *R.getEntry()->getParent()) {
1474 if (isa<ReturnInst>(I.getTerminator()) && !DT.dominates(&BB, &I)) {
1475 DominatesAllPredecessors =
false;
1480 for (
auto Pred : predecessors(R.getExit())) {
1481 if (R.contains(Pred) && !DT.dominates(&BB, Pred)) {
1482 DominatesAllPredecessors =
false;
1488 if (DominatesAllPredecessors)
1491 for (Instruction &Inst : BB)
1492 if (CallInst *CI = dyn_cast<CallInst>(&Inst)) {
1500 if (isa<MemSetInst>(CI) || isa<MemTransferInst>(CI))
1503 if (!CI->doesNotAccessMemory())
1505 if (CI->doesNotReturn())
1518 return It.first->getSecond();
1521 It.first->second = Result;
1527 std::unique_ptr<Region> LastValidRegion;
1528 auto ExpandedRegion = std::unique_ptr<Region>(R.getExpandedRegion());
1530 POLLY_DEBUG(dbgs() <<
"\tExpanding " << R.getNameStr() <<
"\n");
1532 while (ExpandedRegion) {
1535 Entry = std::make_unique<DetectionContext>(*ExpandedRegion,
AA,
1539 POLLY_DEBUG(dbgs() <<
"\t\tTrying " << ExpandedRegion->getNameStr()
1555 if (LastValidRegion) {
1559 LastValidRegion = std::move(ExpandedRegion);
1563 std::unique_ptr<Region>(LastValidRegion->getExpandedRegion());
1570 std::unique_ptr<Region>(ExpandedRegion->getExpandedRegion());
1575 if (LastValidRegion)
1576 dbgs() <<
"\tto " << LastValidRegion->getNameStr() <<
"\n";
1578 dbgs() <<
"\tExpanding " << R.getNameStr() <<
" failed\n";
1581 return LastValidRegion.release();
1585 for (
const BasicBlock *BB : R.blocks())
1586 if (R.contains(LI.getLoopFor(BB)))
1593 for (
auto &SubRegion : R) {
1606 std::unique_ptr<DetectionContext> &
Entry =
1608 Entry = std::make_unique<DetectionContext>(R,
AA,
false);
1611 bool DidBailout =
true;
1620 "With -polly-detect-keep-going, it is sufficient that if "
1621 "isValidRegion short-circuited, that SCoP is invalid");
1624 "isValidRegion must short-circuit iff the ScoP is invalid");
1634 for (
auto &SubRegion : R)
1643 std::vector<Region *> ToExpand;
1645 for (
auto &SubRegion : R)
1646 ToExpand.push_back(SubRegion.get());
1648 for (Region *CurrentRegion : ToExpand) {
1664 R.addSubRegion(ExpandedR,
true);
1674 for (
const BasicBlock *BB : CurRegion.blocks()) {
1675 Loop *L =
LI.getLoopFor(BB);
1676 if (L && L->getHeader() == BB) {
1677 if (CurRegion.contains(L)) {
1684 SmallVector<BasicBlock *, 1> Latches;
1685 L->getLoopLatches(Latches);
1686 for (BasicBlock *Latch : Latches)
1687 if (CurRegion.contains(Latch))
1694 for (BasicBlock *BB : CurRegion.blocks()) {
1706 for (BasicBlock::iterator I = BB->begin(), E = --BB->end(); I != E; ++I)
1721 int NumLoops)
const {
1727 for (
auto *BB : Context.
CurRegion.blocks())
1728 if (Context.
CurRegion.contains(
LI.getLoopFor(BB)))
1729 InstCount += BB->size();
1731 InstCount = InstCount / NumLoops;
1738 for (
auto *BB : Context.
CurRegion.blocks()) {
1739 auto *L =
LI.getLoopFor(BB);
1746 unsigned StmtsWithStoresInLoops = 0;
1747 for (
auto *LBB : L->blocks()) {
1748 bool MemStore =
false;
1749 for (
auto &I : *LBB)
1750 MemStore |= isa<StoreInst>(&I);
1751 StmtsWithStoresInLoops += MemStore;
1753 return (StmtsWithStoresInLoops > 1);
1779 int NumAffineLoops = NumLoops - Context.
BoxedLoopsSet.size();
1783 if (NumAffineLoops >= 2)
1805 POLLY_DEBUG(dbgs() <<
"Checking region: " << CurRegion.getNameStr()
1809 POLLY_DEBUG(dbgs() <<
"Top level region is invalid\n");
1815 if (CurRegion.getExit() &&
1816 isa<UnreachableInst>(CurRegion.getExit()->getTerminator())) {
1819 CurRegion.getExit(), DbgLoc);
1823 !CurRegion.getEntry()->getName().count(
OnlyRegion)) {
1825 dbgs() <<
"Region entry does not match -polly-only-region";
1832 for (BasicBlock *Pred : predecessors(CurRegion.getEntry())) {
1833 Instruction *PredTerm = Pred->getTerminator();
1834 if (isa<IndirectBrInst>(PredTerm) || isa<CallBrInst>(PredTerm))
1836 Context,
true, PredTerm, PredTerm->getDebugLoc());
1842 CurRegion.getEntry() ==
1843 &(CurRegion.getEntry()->getParent()->getEntryBlock()))
1856 &CurRegion, DbgLoc);
1871 for (
const Region *R : *
this) {
1872 unsigned LineEntry, LineExit;
1873 std::string FileName;
1876 DiagnosticScopFound Diagnostic(F, FileName, LineEntry, LineExit);
1877 F.getContext().diagnose(Diagnostic);
1895 enum Color { WHITE, GREY, BLACK };
1897 BasicBlock *REntry = R.getEntry();
1898 BasicBlock *RExit = R.getExit();
1900 DenseMap<const BasicBlock *, Color> BBColorMap;
1902 std::stack<std::pair<BasicBlock *, unsigned>> DFSStack;
1904 unsigned AdjacentBlockIndex = 0;
1905 BasicBlock *CurrBB, *SuccBB;
1909 for (
auto *BB : R.blocks())
1910 BBColorMap[BB] = WHITE;
1913 BBColorMap[CurrBB] = GREY;
1914 DFSStack.push(std::make_pair(CurrBB, 0));
1916 while (!DFSStack.empty()) {
1918 CurrBB = DFSStack.top().first;
1919 AdjacentBlockIndex = DFSStack.top().second;
1923 const Instruction *TInst = CurrBB->getTerminator();
1924 unsigned NSucc = TInst->getNumSuccessors();
1925 for (
unsigned I = AdjacentBlockIndex; I < NSucc;
1926 ++I, ++AdjacentBlockIndex) {
1927 SuccBB = TInst->getSuccessor(I);
1930 if (SuccBB == RExit || SuccBB == CurrBB)
1934 if (BBColorMap[SuccBB] == WHITE) {
1936 DFSStack.push(std::make_pair(CurrBB, I + 1));
1938 DFSStack.push(std::make_pair(SuccBB, 0));
1940 BBColorMap[SuccBB] = GREY;
1942 }
else if (BBColorMap[SuccBB] == GREY) {
1946 if (!
DT.dominates(SuccBB, CurrBB)) {
1948 DbgLoc = TInst->getDebugLoc();
1956 if (AdjacentBlockIndex == NSucc)
1957 BBColorMap[CurrBB] = BLACK;
1964 bool OnlyProfitable) {
1965 if (!OnlyProfitable) {
1968 std::max(MaxNumLoopsInScop.getValue(), (uint64_t)Stats.
NumLoops);
1970 NumScopsDepthZero++;
1976 NumScopsDepthThree++;
1978 NumScopsDepthFour++;
1980 NumScopsDepthFive++;
1982 NumScopsDepthLarger++;
1984 NumLoopsInProfScop += Stats.
NumLoops;
1985 MaxNumLoopsInProfScop =
1986 std::max(MaxNumLoopsInProfScop.getValue(), (uint64_t)Stats.
NumLoops);
1988 NumProfScopsDepthZero++;
1990 NumProfScopsDepthOne++;
1992 NumProfScopsDepthTwo++;
1994 NumProfScopsDepthThree++;
1996 NumProfScopsDepthFour++;
1998 NumProfScopsDepthFive++;
2000 NumProfScopsDepthLarger++;
2009 return DCMIt->second.get();
2014 return DC ? &DC->
Log :
nullptr;
2041 auto &LI = FAM.getResult<LoopAnalysis>(F);
2042 auto &RI = FAM.getResult<RegionInfoAnalysis>(F);
2043 auto &AA = FAM.getResult<AAManager>(F);
2044 auto &SE = FAM.getResult<ScalarEvolutionAnalysis>(F);
2045 auto &DT = FAM.getResult<DominatorTreeAnalysis>(F);
2046 auto &ORE = FAM.getResult<OptimizationRemarkEmitterAnalysis>(F);
2054 FunctionAnalysisManager &FAM) {
2055 OS <<
"Detected Scops in Function " << F.getName() <<
"\n";
2057 for (
const Region *R : SD.ValidRegions)
2058 OS <<
"Valid Region for Scop: " << R->getNameStr() <<
'\n';
2061 return PreservedAnalyses::all();
static cl::opt< bool > Verify("polly-codegen-verify", cl::desc("Verify the function generated by Polly"), cl::Hidden, cl::cat(PollyCategory))
llvm::cl::OptionCategory PollyCategory
static const unsigned MIN_LOOP_TRIP_COUNT
The minimal trip count under which loops are considered unprofitable.
static cl::opt< bool, true > XPollyProcessUnprofitable("polly-process-unprofitable", cl::desc("Process scops that are unlikely to benefit from Polly optimizations."), cl::location(PollyProcessUnprofitable), cl::cat(PollyCategory))
static cl::opt< bool > AllowDifferentTypes("polly-allow-differing-element-types", cl::desc("Allow different element types for array accesses"), cl::Hidden, cl::init(true), cl::cat(PollyCategory))
static cl::opt< bool > AllowNonAffine("polly-allow-nonaffine", cl::desc("Allow non affine access functions in arrays"), cl::Hidden, cl::cat(PollyCategory))
STATISTIC(NumScopRegions, "Number of scops")
static cl::opt< bool, true > XPollyOptimizeForVectorization("polly-optimize-for-vectorization", cl::desc("Make the profitability heuristic consider vectorization " "opportunities"), cl::location(PollyOptimizeForVectorization), cl::init(false), cl::cat(PollyCategory))
static cl::list< std::string > OnlyFunctions("polly-only-func", cl::desc("Only run on functions that match a regex. " "Multiple regexes can be comma separated. " "Scop detection will run on all functions that match " "ANY of the regexes provided."), cl::CommaSeparated, cl::cat(PollyCategory))
static cl::opt< bool > VerifyScops("polly-detect-verify", cl::desc("Verify the detected SCoPs after each transformation"), cl::Hidden, cl::cat(PollyCategory))
static bool hasExitingBlocks(Loop *L)
Check whether L has exiting blocks.
static cl::opt< std::string > OnlyRegion("polly-only-region", cl::desc("Only run on certain regions (The provided identifier must " "appear in the name of the region's entry block"), cl::value_desc("identifier"), cl::ValueRequired, cl::init(""), cl::cat(PollyCategory))
static bool regionWithoutLoops(Region &R, LoopInfo &LI)
static cl::opt< bool > KeepGoing("polly-detect-keep-going", cl::desc("Do not fail on the first error."), cl::Hidden, cl::cat(PollyCategory))
static cl::opt< int > ProfitabilityMinPerLoopInstructions("polly-detect-profitability-min-per-loop-insts", cl::desc("The minimal number of per-loop instructions before a single loop " "region is considered profitable"), cl::Hidden, cl::ValueRequired, cl::init(100000000), cl::cat(PollyCategory))
static cl::opt< bool, true > TrackFailures("polly-detect-track-failures", cl::desc("Track failure strings in detecting scop regions"), cl::location(PollyTrackFailures), cl::Hidden, cl::init(true), cl::cat(PollyCategory))
static bool doesStringMatchAnyRegex(StringRef Str, const cl::list< std::string > &RegexList)
Check if a string matches any regex in a list of regexes.
static cl::opt< bool > PollyAllowErrorBlocks("polly-allow-error-blocks", cl::desc("Allow to speculate on the execution of 'error blocks'."), cl::Hidden, cl::init(true), cl::cat(PollyCategory))
static cl::list< std::string > IgnoredFunctions("polly-ignore-func", cl::desc("Ignore functions that match a regex. " "Multiple regexes can be comma separated. " "Scop detection will ignore all functions that match " "ANY of the regexes provided."), cl::CommaSeparated, cl::cat(PollyCategory))
static cl::opt< bool > ReportLevel("polly-report", cl::desc("Print information about the activities of Polly"), cl::cat(PollyCategory))
static bool isErrorBlockImpl(BasicBlock &BB, const Region &R, LoopInfo &LI, const DominatorTree &DT)
static cl::opt< bool, true > XPollyDetectForVectorization("polly-detect-for-vectorization", cl::desc("Bypass some Polly profitability checks for vectorization"), cl::location(PollyDetectForVectorization), cl::init(false), cl::cat(PollyCategory))
static cl::opt< bool, true > PollyDelinearizeX("polly-delinearize", cl::desc("Delinearize array access functions"), cl::location(PollyDelinearize), cl::Hidden, cl::init(true), cl::cat(PollyCategory))
static cl::opt< bool, true > XPollyAllowUnsignedOperations("polly-allow-unsigned-operations", cl::desc("Allow unsigned operations such as comparisons or zero-extends."), cl::location(PollyAllowUnsignedOperations), cl::Hidden, cl::init(true), cl::cat(PollyCategory))
static void updateLoopCountStatistic(ScopDetection::LoopStats Stats, bool OnlyProfitable)
static cl::opt< bool > AllowNonAffineSubRegions("polly-allow-nonaffine-branches", cl::desc("Allow non affine conditions for branches"), cl::Hidden, cl::init(true), cl::cat(PollyCategory))
static cl::opt< bool, true > XAllowFullFunction("polly-detect-full-functions", cl::desc("Allow the detection of full functions"), cl::location(polly::PollyAllowFullFunction), cl::init(false), cl::cat(PollyCategory))
static cl::opt< bool, true > XPollyInvariantLoadHoisting("polly-invariant-load-hoisting", cl::desc("Hoist invariant loads."), cl::location(PollyInvariantLoadHoisting), cl::Hidden, cl::cat(PollyCategory))
static cl::opt< bool > AllowNonAffineSubLoops("polly-allow-nonaffine-loops", cl::desc("Allow non affine conditions for loops"), cl::Hidden, cl::cat(PollyCategory))
static cl::opt< bool, true > XPollyUseRuntimeAliasChecks("polly-use-runtime-alias-checks", cl::desc("Use runtime alias checks to resolve possible aliasing."), cl::location(PollyUseRuntimeAliasChecks), cl::Hidden, cl::init(true), cl::cat(PollyCategory))
static cl::opt< bool > IgnoreAliasing("polly-ignore-aliasing", cl::desc("Ignore possible aliasing of the array bases"), cl::Hidden, cl::cat(PollyCategory))
static cl::opt< bool > AllowModrefCall("polly-allow-modref-calls", cl::desc("Allow functions with known modref behavior"), cl::Hidden, cl::cat(PollyCategory))
Utility proxy to wrap the common members of LoadInst and StoreInst.
static MemAccInst dyn_cast(llvm::Value &V)
llvm::Value * getPointerOperand() const
Stores all errors that occurred during the detection.
void report(RejectReasonPtr Reject)
bool hasErrors() const
Returns true, if we store at least one error.
Base class of all reject reasons found during Scop detection.
virtual std::string getMessage() const =0
Generate a reasonable diagnostic message describing this error.
Pass to detect the maximal static control parts (Scops) of a function.
static void markFunctionAsInvalid(Function *F)
Mark the function as invalid so we will not extract any scop from the function.
bool addOverApproximatedRegion(Region *AR, DetectionContext &Context) const
Add the region AR as over approximated sub-region in Context.
bool isValidAccess(Instruction *Inst, const SCEV *AF, const SCEVUnknown *BP, DetectionContext &Context) const
Check if the memory access caused by Inst is valid.
bool onlyValidRequiredInvariantLoads(InvariantLoadsSetTy &RequiredILS, DetectionContext &Context) const
Check if the given loads could be invariant and can be hoisted.
bool isInvariant(Value &Val, const Region &Reg, DetectionContext &Ctx) const
Check if a value is invariant in the region Reg.
bool isReducibleRegion(Region &R, DebugLoc &DbgLoc) const
Check if a region is reducible or not.
bool computeAccessFunctions(DetectionContext &Context, const SCEVUnknown *BasePointer, std::shared_ptr< ArrayShape > Shape) const
Derive access functions for a given base pointer.
DetectionContext * getDetectionContext(const Region *R) const
Return the detection context for R, nullptr if R was invalid.
void removeCachedResultsRecursively(const Region &R)
Remove cached results for the children of R recursively.
bool hasSufficientCompute(DetectionContext &Context, int NumAffineLoops) const
Check if a region has sufficient compute instructions.
bool isProfitableRegion(DetectionContext &Context) const
Check if a region is profitable to optimize.
void emitMissedRemarks(const Function &F)
Emit rejection remarks for all rejected regions.
bool isValidLoop(Loop *L, DetectionContext &Context)
Is a loop valid with respect to a given region.
static ScopDetection::LoopStats countBeneficialLoops(Region *R, ScalarEvolution &SE, LoopInfo &LI, unsigned MinProfitableTrips)
Count the number of loops and the maximal loop depth in R.
const RejectLog * lookupRejectionLog(const Region *R) const
Return the set of rejection causes for R.
bool involvesMultiplePtrs(const SCEV *S0, const SCEV *S1, Loop *Scope) const
Check if S0 and S1 do contain multiple possibly aliasing pointers.
bool isValidSwitch(BasicBlock &BB, SwitchInst *SI, Value *Condition, bool IsLoopBranch, DetectionContext &Context) const
Check if the switch SI with condition Condition is valid.
bool isValidRegion(DetectionContext &Context)
Check if a region is a Scop.
Region * expandRegion(Region &R)
Try to expand the region R.
const DominatorTree & DT
Analyses used.
bool hasBaseAffineAccesses(DetectionContext &Context, const SCEVUnknown *BasePointer, Loop *Scope) const
Check if all accesses to a given BasePointer are affine.
OptimizationRemarkEmitter & ORE
OptimizationRemarkEmitter object used to emit diagnostic remarks.
bool hasAffineMemoryAccesses(DetectionContext &Context) const
Delinearize all non affine memory accesses and return false when there exists a non affine memory acc...
bool isValidMemoryAccess(MemAccInst Inst, DetectionContext &Context) const
Check if a memory access can be part of a Scop.
bool isValidCFG(BasicBlock &BB, bool IsLoopBranch, bool AllowUnreachable, DetectionContext &Context)
Check if the control flow in a basic block is valid.
void printLocations(Function &F)
Print the locations of all detected scops.
bool hasValidArraySizes(DetectionContext &Context, SmallVectorImpl< const SCEV * > &Sizes, const SCEVUnknown *BasePointer, Loop *Scope) const
Check if the dimension size of a delinearized array is valid.
DenseMap< std::tuple< const BasicBlock *, const Region * >, bool > ErrorBlockCache
Cache for the isErrorBlock function.
void removeCachedResults(const Region &R)
Remove cached results for R.
ScopDetection(const DominatorTree &DT, ScalarEvolution &SE, LoopInfo &LI, RegionInfo &RI, AAResults &AA, OptimizationRemarkEmitter &ORE)
bool hasPossiblyDistributableLoop(DetectionContext &Context) const
Check if the unique affine loop might be amendable to distribution.
bool isValidBranch(BasicBlock &BB, CondBrInst *BI, Value *Condition, bool IsLoopBranch, DetectionContext &Context)
Check if the branch BI with condition Condition is valid.
void verifyAnalysis()
Verify if all valid Regions in this Function are still valid after some transformations.
SmallVector< const SCEV *, 4 > getDelinearizationTerms(DetectionContext &Context, const SCEVUnknown *BasePointer) const
Find for a given base pointer terms that hint towards dimension sizes of a multi-dimensional array.
bool isValidInstruction(Instruction &Inst, DetectionContext &Context)
Check if an instruction can be part of a Scop.
bool isAffine(const SCEV *S, Loop *Scope, DetectionContext &Context) const
Check if the SCEV S is affine in the current Context.
DetectionContextMapTy DetectionContextMap
bool allBlocksValid(DetectionContext &Context)
Check if all basic block in the region are valid.
void findScops(Region &R)
Find the Scops in this region tree.
bool isValidIntrinsicInst(IntrinsicInst &II, DetectionContext &Context) const
Check if an intrinsic call can be part of a Scop.
std::string regionIsInvalidBecause(const Region *R) const
Get a message why a region is invalid.
bool isMaxRegionInScop(const Region &R, bool Verify=true)
Is the region is the maximum region of a Scop?
bool isValidCallInst(CallInst &CI, DetectionContext &Context) const
Check if a call instruction can be part of a Scop.
void verifyRegion(const Region &R)
Verify if R is still a valid part of Scop after some transformations.
static bool isValidFunction(Function &F)
Check if the function F is marked as invalid.
bool isErrorBlock(llvm::BasicBlock &BB, const llvm::Region &R)
Check if the block is a error block.
bool invalid(DetectionContext &Context, bool Assert, Args &&...Arguments) const
Track diagnostics for invalid scops.
bool canUseISLTripCount(Loop *L, DetectionContext &Context)
Can ISL compute the trip count of a loop.
bool isCompatibleType(Instruction *Inst, llvm::Type *Ty, DetectionContext &Context)
Filter out types that we do not support.
static ScopDetection::LoopStats countBeneficialSubLoops(Loop *L, ScalarEvolution &SE, unsigned MinProfitableTrips)
Count the number of loops and the maximal loop depth in L.
void findValues(const llvm::SCEV *Expr, llvm::ScalarEvolution &SE, llvm::SetVector< llvm::Value * > &Values)
Find the values referenced by SCEVUnknowns in a given SCEV expression.
void findLoops(const llvm::SCEV *Expr, llvm::SetVector< const llvm::Loop * > &Loops)
Find the loops referenced from a SCEV expression.
std::shared_ptr< RejectReason > RejectReasonPtr
StringRef PollySkipFnAttr
A function attribute which will cause Polly to skip the function.
bool PollyAllowFullFunction
llvm::SetVector< llvm::AssertingVH< llvm::LoadInst > > InvariantLoadsSetTy
Type for a set of invariant loads.
bool isAffineExpr(const llvm::Region *R, llvm::Loop *Scope, const llvm::SCEV *Expression, llvm::ScalarEvolution &SE, InvariantLoadsSetTy *ILS=nullptr)
bool PollyDetectForVectorization
Bypass some of Polly's profitability checks that might harm loops from getting annotated with vectori...
@ Value
MemoryKind::Value: Models an llvm::Value.
@ PHI
MemoryKind::PHI: Models PHI nodes within the SCoP.
void emitRejectionRemarks(const BBPair &P, const RejectLog &Log, OptimizationRemarkEmitter &ORE)
Emit optimization remarks about the rejected regions to the user.
void getDebugLocation(const llvm::Region *R, unsigned &LineBegin, unsigned &LineEnd, std::string &FileName)
Get the location of a region from the debug info.
std::map< const Instruction *, MemAcc > MapInsnToMemAcc
const llvm::SCEV * tryForwardThroughPHI(const llvm::SCEV *Expr, llvm::Region &R, llvm::ScalarEvolution &SE, ScopDetection *SD)
Try to look through PHI nodes, where some incoming edges come from error blocks.
bool isDebugCall(llvm::Instruction *Inst)
Is the given instruction a call to a debug function?
BBPair getBBPairForRegion(const Region *R)
Return the region delimiters (entry & exit block) of R.
bool PollyProcessUnprofitable
bool PollyOptimizeForVectorization
Bypass some of Polly's profitability checks and add vectorize.enable metadata to vectorizable loops a...
bool isHoistableLoad(llvm::LoadInst *LInst, llvm::Region &R, llvm::LoopInfo &LI, llvm::ScalarEvolution &SE, const llvm::DominatorTree &DT, const InvariantLoadsSetTy &KnownInvariantLoads)
Check if LInst can be hoisted in R.
bool PollyUseRuntimeAliasChecks
bool hasScalarDepsInsideRegion(const llvm::SCEV *Expr, const llvm::Region *R, llvm::Loop *Scope, bool AllowLoops, const InvariantLoadsSetTy &ILS)
Returns true when the SCEV contains references to instructions within the region.
bool PollyAllowUnsignedOperations
llvm::Value * getUniqueNonErrorValue(llvm::PHINode *PHI, llvm::Region *R, ScopDetection *SD)
Return a unique non-error block incoming value for PHI if available.
bool PollyInvariantLoadHoisting
bool isIgnoredIntrinsic(const llvm::Value *V)
Return true iff V is an intrinsic that we ignore during code generation.
std::pair< llvm::BasicBlock *, llvm::BasicBlock * > BBPair
Type to hold region delimiters (entry & exit block).
SmallVector< const SCEV *, 4 > DelinearizedSubscripts
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
Result run(Function &F, FunctionAnalysisManager &FAM)
Context variables for SCoP detection.
BaseToAFs Accesses
Map a base pointer to all access functions accessing it.
InvariantLoadsSetTy RequiredILS
Loads that need to be invariant during execution.
bool hasLoads
The region has at least one load instruction.
bool IsInvalid
If this flag is set, the SCoP must eventually be rejected, even with KeepGoing.
bool HasUnknownAccess
Flag to indicate the region has at least one unknown access.
BoxedLoopsSetTy BoxedLoopsSet
The set of loops contained in non-affine regions.
MapInsnToMemAcc InsnToMemAcc
Map to memory access description for the corresponding LLVM instructions.
RejectLog Log
Container to remember rejection reasons for this region.
RegionSet NonAffineSubRegionSet
The set of non-affine subregions in the region we analyze.
llvm::SetVector< std::pair< const SCEVUnknown *, Loop * > > NonAffineAccesses
The set of base pointers with non-affine accesses.
bool hasStores
The region has at least one store instruction.
Helper data structure to collect statistics about loop counts.