@@ -767,27 +767,35 @@ bool OptNoneInstrumentation::shouldRun(StringRef PassID, Any IR) {
767
767
return ShouldRun;
768
768
}
769
769
770
- void OptBisectInstrumentation::registerCallbacks (
770
+ bool OptPassGateInstrumentation::shouldRun (StringRef PassName, Any IR) {
771
+ if (isIgnored (PassName))
772
+ return true ;
773
+
774
+ bool ShouldRun =
775
+ Context.getOptPassGate ().shouldRunPass (PassName, getIRName (IR));
776
+ if (!ShouldRun && !this ->HasWrittenIR && !OptBisectPrintIRPath.empty ()) {
777
+ // FIXME: print IR if limit is higher than number of opt-bisect
778
+ // invocations
779
+ this ->HasWrittenIR = true ;
780
+ const Module *M = unwrapModule (IR, /* Force=*/ true );
781
+ assert ((M && &M->getContext () == &Context) && " Missing/Mismatching Module" );
782
+ std::error_code EC;
783
+ raw_fd_ostream OS (OptBisectPrintIRPath, EC);
784
+ if (EC)
785
+ report_fatal_error (errorCodeToError (EC));
786
+ M->print (OS, nullptr );
787
+ }
788
+ return ShouldRun;
789
+ }
790
+
791
+ void OptPassGateInstrumentation::registerCallbacks (
771
792
PassInstrumentationCallbacks &PIC) {
772
- if (!getOptBisector ().isEnabled ())
793
+ OptPassGate &PassGate = Context.getOptPassGate ();
794
+ if (!PassGate.isEnabled ())
773
795
return ;
774
- PIC.registerShouldRunOptionalPassCallback ([this ](StringRef PassID, Any IR) {
775
- if (isIgnored (PassID))
776
- return true ;
777
- bool ShouldRun = getOptBisector ().checkPass (PassID, getIRName (IR));
778
- if (!ShouldRun && !this ->HasWrittenIR && !OptBisectPrintIRPath.empty ()) {
779
- // FIXME: print IR if limit is higher than number of opt-bisect
780
- // invocations
781
- this ->HasWrittenIR = true ;
782
- const Module *M = unwrapModule (IR, /* Force=*/ true );
783
- assert (M && " expected Module" );
784
- std::error_code EC;
785
- raw_fd_ostream OS (OptBisectPrintIRPath, EC);
786
- if (EC)
787
- report_fatal_error (errorCodeToError (EC));
788
- M->print (OS, nullptr );
789
- }
790
- return ShouldRun;
796
+
797
+ PIC.registerShouldRunOptionalPassCallback ([this ](StringRef PassName, Any IR) {
798
+ return this ->shouldRun (PassName, IR);
791
799
});
792
800
}
793
801
@@ -2037,8 +2045,11 @@ void DotCfgChangeReporter::registerCallbacks(
2037
2045
}
2038
2046
2039
2047
StandardInstrumentations::StandardInstrumentations (
2040
- bool DebugLogging, bool VerifyEach, PrintPassOptions PrintPassOpts)
2041
- : PrintPass(DebugLogging, PrintPassOpts), OptNone(DebugLogging),
2048
+ LLVMContext &Context, bool DebugLogging, bool VerifyEach,
2049
+ PrintPassOptions PrintPassOpts)
2050
+ : PrintPass(DebugLogging, PrintPassOpts),
2051
+ OptNone (DebugLogging),
2052
+ OptPassGate(Context),
2042
2053
PrintChangedIR(PrintChanged == ChangePrinter::Verbose),
2043
2054
PrintChangedDiff(PrintChanged == ChangePrinter::DiffVerbose ||
2044
2055
PrintChanged == ChangePrinter::ColourDiffVerbose,
@@ -2099,7 +2110,7 @@ void StandardInstrumentations::registerCallbacks(
2099
2110
PrintPass.registerCallbacks (PIC);
2100
2111
TimePasses.registerCallbacks (PIC);
2101
2112
OptNone.registerCallbacks (PIC);
2102
- OptBisect .registerCallbacks (PIC);
2113
+ OptPassGate .registerCallbacks (PIC);
2103
2114
if (FAM)
2104
2115
PreservedCFGChecker.registerCallbacks (PIC, *FAM);
2105
2116
PrintChangedIR.registerCallbacks (PIC);
0 commit comments