@@ -96,6 +96,10 @@ llvm::cl::opt<std::string> SILBreakOnPass(
96
96
" sil-break-on-pass" , llvm::cl::init(" " ),
97
97
llvm::cl::desc(" Break before running a particular function pass" ));
98
98
99
+ llvm::cl::opt<std::string>
100
+ SILBreakBeforePassCount (" sil-break-before-pass-count" , llvm::cl::init(" " ),
101
+ llvm::cl::desc(" Break before running pass number" ));
102
+
99
103
llvm::cl::list<std::string>
100
104
SILPrintFunction (" sil-print-function" , llvm::cl::CommaSeparated,
101
105
llvm::cl::desc (" Only print out the sil for this function" ));
@@ -403,7 +407,7 @@ SILPassManager::SILPassManager(SILModule *M, bool isMandatory,
403
407
#include " swift/SILOptimizer/Analysis/Analysis.def"
404
408
405
409
if (!SILNumOptPassesToRun.empty ()) {
406
- parsePassCount (SILNumOptPassesToRun);
410
+ parsePassesToRunCount (SILNumOptPassesToRun);
407
411
} else if (!SILPassCountConfigFile.empty ()) {
408
412
StringRef moduleName = M->getSwiftModule ()->getName ().str ();
409
413
std::fstream fs (SILPassCountConfigFile);
@@ -417,13 +421,17 @@ SILPassManager::SILPassManager(SILModule *M, bool isMandatory,
417
421
StringRef modName = pair.first ;
418
422
StringRef countsStr = pair.second ;
419
423
if (modName == moduleName) {
420
- parsePassCount (countsStr);
424
+ parsePassesToRunCount (countsStr);
421
425
break ;
422
426
}
423
427
}
424
428
fs.close ();
425
429
}
426
430
431
+ if (!SILBreakBeforePassCount.empty ()) {
432
+ parseBreakBeforePassCount (SILBreakBeforePassCount);
433
+ }
434
+
427
435
for (SILAnalysis *A : Analyses) {
428
436
A->initialize (this );
429
437
}
@@ -434,7 +442,7 @@ SILPassManager::SILPassManager(SILModule *M, bool isMandatory,
434
442
M->registerDeserializationNotificationHandler (std::move (handler));
435
443
}
436
444
437
- void SILPassManager::parsePassCount (StringRef countsStr) {
445
+ void SILPassManager::parsePassesToRunCount (StringRef countsStr) {
438
446
bool validFormat = true ;
439
447
if (countsStr.consumeInteger (10 , maxNumPassesToRun))
440
448
validFormat = false ;
@@ -449,6 +457,17 @@ void SILPassManager::parsePassCount(StringRef countsStr) {
449
457
}
450
458
}
451
459
460
+ void SILPassManager::parseBreakBeforePassCount (StringRef countsStr) {
461
+ bool validFormat = true ;
462
+ if (countsStr.consumeInteger (10 , breakBeforePassCount))
463
+ validFormat = false ;
464
+ if (!validFormat || !countsStr.empty ()) {
465
+ llvm::errs ()
466
+ << " error: wrong format of -sil-break-before-pass-count option\n " ;
467
+ exit (1 );
468
+ }
469
+ }
470
+
452
471
bool SILPassManager::continueTransforming () {
453
472
if (isMandatory)
454
473
return true ;
@@ -486,19 +505,24 @@ bool SILPassManager::analysesUnlocked() {
486
505
// Test the function and pass names we're given against the debug
487
506
// options that force us to break prior to a given pass and/or on a
488
507
// given function.
489
- static bool breakBeforeRunning (StringRef fnName, SILFunctionTransform *SFT) {
490
- if (SILBreakOnFun.empty () && SILBreakOnPass.empty ())
508
+ bool SILPassManager::breakBeforeRunning (StringRef fnName,
509
+ SILFunctionTransform *SFT) {
510
+ if (SILBreakOnFun.empty () && SILBreakOnPass.empty () &&
511
+ SILBreakBeforePassCount.empty ())
491
512
return false ;
492
513
493
- if (SILBreakOnFun .empty ()
494
- && (SFT->getID () == SILBreakOnPass || SFT->getTag () == SILBreakOnPass))
514
+ if (!SILBreakOnPass .empty () &&
515
+ (SFT->getID () == SILBreakOnPass || SFT->getTag () == SILBreakOnPass))
495
516
return true ;
496
517
497
- if (SILBreakOnPass .empty () && fnName == SILBreakOnFun)
518
+ if (!SILBreakOnFun .empty () && fnName == SILBreakOnFun)
498
519
return true ;
499
520
500
- return fnName == SILBreakOnFun
501
- && (SFT->getID () == SILBreakOnPass || SFT->getTag () == SILBreakOnPass);
521
+ if (!SILBreakBeforePassCount.empty () &&
522
+ breakBeforePassCount == NumPassesRun) {
523
+ return true ;
524
+ }
525
+ return false ;
502
526
}
503
527
504
528
void SILPassManager::dumpPassInfo (const char *Title, SILTransform *Tr,
0 commit comments