@@ -347,10 +347,11 @@ updateSSA(SILModule &M, SILLoop *Loop,
347
347
}
348
348
349
349
// / Try to fully unroll the loop if we can determine the trip count and the trip
350
- // / count lis below a threshold.
350
+ // / count is below a threshold.
351
351
static bool tryToUnrollLoop (SILLoop *Loop) {
352
352
assert (Loop->getSubLoops ().empty () && " Expecting innermost loops" );
353
353
354
+ LLVM_DEBUG (llvm::dbgs () << " Trying to unroll loop : \n " << *Loop);
354
355
auto *Preheader = Loop->getLoopPreheader ();
355
356
if (!Preheader)
356
357
return false ;
@@ -364,11 +365,15 @@ static bool tryToUnrollLoop(SILLoop *Loop) {
364
365
365
366
Optional<uint64_t > MaxTripCount =
366
367
getMaxLoopTripCount (Loop, Preheader, Header, Latch);
367
- if (!MaxTripCount)
368
+ if (!MaxTripCount) {
369
+ LLVM_DEBUG (llvm::dbgs () << " Not unrolling, did not find trip count\n " );
368
370
return false ;
371
+ }
369
372
370
- if (!canAndShouldUnrollLoop (Loop, MaxTripCount.getValue ()))
373
+ if (!canAndShouldUnrollLoop (Loop, MaxTripCount.getValue ())) {
374
+ LLVM_DEBUG (llvm::dbgs () << " Not unrolling, exceeds cost threshold\n " );
371
375
return false ;
376
+ }
372
377
373
378
// TODO: We need to split edges from non-condbr exits for the SSA updater. For
374
379
// now just don't handle loops containing such exits.
@@ -443,7 +448,6 @@ class LoopUnrolling : public SILFunctionTransform {
443
448
444
449
void run () override {
445
450
bool Changed = false ;
446
-
447
451
auto *Fun = getFunction ();
448
452
SILLoopInfo *LoopInfo = PM->getAnalysis <SILLoopAnalysis>()->get (Fun);
449
453
@@ -462,6 +466,12 @@ class LoopUnrolling : public SILFunctionTransform {
462
466
}
463
467
}
464
468
469
+ if (InnermostLoops.empty ())
470
+ return ;
471
+
472
+ LLVM_DEBUG (llvm::dbgs () << " Loop Unroll running on function : "
473
+ << Fun->getName () << " \n " );
474
+
465
475
// Try to unroll innermost loops.
466
476
for (auto *Loop : InnermostLoops)
467
477
Changed |= tryToUnrollLoop (Loop);
0 commit comments