@@ -8806,11 +8806,11 @@ ScalarEvolution::computeBackedgeTakenCount(const Loop *L,
88068806 const SCEV *MayExitMaxBECount = nullptr;
88078807 bool MustExitMaxOrZero = false;
88088808 bool IsOnlyExit = ExitingBlocks.size() == 1;
8809- std::optional<LoopGuards> LoopGuards ;
8810- auto GetLoopGuards = [&LoopGuards , &L, this]() {
8811- if (!LoopGuards )
8812- LoopGuards .emplace(LoopGuards::collect(L, *this));
8813- return *LoopGuards ;
8809+ std::optional<LoopGuards> CachedLoopGuards ;
8810+ auto GetLoopGuards = [&CachedLoopGuards , &L, this]() -> const LoopGuards & {
8811+ if (!CachedLoopGuards )
8812+ CachedLoopGuards .emplace(LoopGuards::collect(L, *this));
8813+ return *CachedLoopGuards ;
88148814 };
88158815
88168816 // Compute the ExitLimit for each loop exit. Use this to populate ExitCounts
@@ -8901,10 +8901,10 @@ ScalarEvolution::computeBackedgeTakenCount(const Loop *L,
89018901 MaxBECount, MaxOrZero);
89028902}
89038903
8904- ScalarEvolution::ExitLimit
8905- ScalarEvolution::computeExitLimit( const Loop *L, BasicBlock *ExitingBlock,
8906- std::function< LoopGuards()> GetLoopGuards,
8907- bool IsOnlyExit, bool AllowPredicates) {
8904+ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimit(
8905+ const Loop *L, BasicBlock *ExitingBlock,
8906+ function_ref<const LoopGuards & ()> GetLoopGuards, bool IsOnlyExit ,
8907+ bool AllowPredicates) {
89088908 assert(L->contains(ExitingBlock) && "Exit count for non-loop block?");
89098909 // If our exiting block does not dominate the latch, then its connection with
89108910 // loop's exit limit may be far from trivial.
@@ -8942,8 +8942,9 @@ ScalarEvolution::computeExitLimit(const Loop *L, BasicBlock *ExitingBlock,
89428942}
89438943
89448944ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromCond(
8945- const Loop *L, Value *ExitCond, std::function<LoopGuards()> GetLoopGuards,
8946- bool ExitIfTrue, bool ControlsOnlyExit, bool AllowPredicates) {
8945+ const Loop *L, Value *ExitCond,
8946+ function_ref<const LoopGuards &()> GetLoopGuards, bool ExitIfTrue,
8947+ bool ControlsOnlyExit, bool AllowPredicates) {
89478948 ScalarEvolution::ExitLimitCacheTy Cache(L, ExitIfTrue, AllowPredicates);
89488949 return computeExitLimitFromCondCached(Cache, L, ExitCond, GetLoopGuards,
89498950 ExitIfTrue, ControlsOnlyExit,
@@ -8984,7 +8985,7 @@ void ScalarEvolution::ExitLimitCache::insert(const Loop *L, Value *ExitCond,
89848985
89858986ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromCondCached(
89868987 ExitLimitCacheTy &Cache, const Loop *L, Value *ExitCond,
8987- std::function< LoopGuards()> GetLoopGuards, bool ExitIfTrue,
8988+ function_ref<const LoopGuards & ()> GetLoopGuards, bool ExitIfTrue,
89888989 bool ControlsOnlyExit, bool AllowPredicates) {
89898990
89908991 if (auto MaybeEL = Cache.find(L, ExitCond, ExitIfTrue, ControlsOnlyExit,
@@ -9000,7 +9001,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromCondCached(
90009001
90019002ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromCondImpl(
90029003 ExitLimitCacheTy &Cache, const Loop *L, Value *ExitCond,
9003- std::function< LoopGuards()> GetLoopGuards, bool ExitIfTrue,
9004+ function_ref<const LoopGuards & ()> GetLoopGuards, bool ExitIfTrue,
90049005 bool ControlsOnlyExit, bool AllowPredicates) {
90059006 // Handle BinOp conditions (And, Or).
90069007 if (auto LimitFromBinOp = computeExitLimitFromCondFromBinOp(
@@ -9066,7 +9067,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromCondImpl(
90669067std::optional<ScalarEvolution::ExitLimit>
90679068ScalarEvolution::computeExitLimitFromCondFromBinOp(
90689069 ExitLimitCacheTy &Cache, const Loop *L, Value *ExitCond,
9069- std::function< LoopGuards()> GetLoopGuards, bool ExitIfTrue,
9070+ function_ref<const LoopGuards & ()> GetLoopGuards, bool ExitIfTrue,
90709071 bool ControlsOnlyExit, bool AllowPredicates) {
90719072 // Check if the controlling expression for this loop is an And or Or.
90729073 Value *Op0, *Op1;
@@ -9147,7 +9148,7 @@ ScalarEvolution::computeExitLimitFromCondFromBinOp(
91479148
91489149ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromICmp(
91499150 const Loop *L, ICmpInst *ExitCond,
9150- std::function< LoopGuards()> GetLoopGuards, bool ExitIfTrue,
9151+ function_ref<const LoopGuards & ()> GetLoopGuards, bool ExitIfTrue,
91519152 bool ControlsOnlyExit, bool AllowPredicates) {
91529153 // If the condition was exit on true, convert the condition to exit on false
91539154 ICmpInst::Predicate Pred;
@@ -9176,7 +9177,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromICmp(
91769177}
91779178ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromICmp(
91789179 const Loop *L, ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS,
9179- std::function< LoopGuards()> GetLoopGuards, bool ControlsOnlyExit,
9180+ function_ref<const LoopGuards & ()> GetLoopGuards, bool ControlsOnlyExit,
91809181 bool AllowPredicates) {
91819182
91829183 // Try to evaluate any dependencies out of the loop.
@@ -9350,7 +9351,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromICmp(
93509351ScalarEvolution::ExitLimit
93519352ScalarEvolution::computeExitLimitFromSingleExitSwitch(
93529353 const Loop *L, SwitchInst *Switch, BasicBlock *ExitingBlock,
9353- std::function< LoopGuards()> GetLoopGuards, bool ControlsOnlyExit) {
9354+ function_ref<const LoopGuards & ()> GetLoopGuards, bool ControlsOnlyExit) {
93549355 assert(!L->contains(ExitingBlock) && "Not an exiting block!");
93559356
93569357 // Give up if the exit is the default dest of a switch.
@@ -10504,7 +10505,7 @@ SolveQuadraticAddRecRange(const SCEVAddRecExpr *AddRec,
1050410505
1050510506ScalarEvolution::ExitLimit
1050610507ScalarEvolution::howFarToZero(const SCEV *V, const Loop *L,
10507- std::function< LoopGuards()> GetLoopGuards,
10508+ function_ref<const LoopGuards & ()> GetLoopGuards,
1050810509 bool ControlsOnlyExit, bool AllowPredicates) {
1050910510
1051010511 // This is only used for loops with a "x != y" exit test. The exit condition
0 commit comments