@@ -125,6 +125,11 @@ static cl::opt<unsigned> PrintBeforePassNumber(
125
125
cl::desc(" Print IR before the pass with this number as "
126
126
" reported by print-pass-numbers" ));
127
127
128
+ static cl::opt<unsigned >
129
+ PrintAfterPassNumber (" print-after-pass-number" , cl::init(0 ), cl::Hidden,
130
+ cl::desc(" Print IR after the pass with this number as "
131
+ " reported by print-pass-numbers" ));
132
+
128
133
static cl::opt<std::string> IRDumpDirectory (
129
134
" ir-dump-directory" ,
130
135
cl::desc (" If specified, IR printed using the "
@@ -854,7 +859,9 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
854
859
855
860
std::string DumpIRFilename;
856
861
if (!IRDumpDirectory.empty () &&
857
- (shouldPrintBeforePass (PassID) || shouldPrintAfterPass (PassID)))
862
+ (shouldPrintBeforePass (PassID) || shouldPrintAfterPass (PassID) ||
863
+ shouldPrintBeforeCurrentPassNumber () ||
864
+ shouldPrintAfterCurrentPassNumber ()))
858
865
DumpIRFilename = fetchDumpFilename (PassID, IR);
859
866
860
867
// Saving Module for AfterPassInvalidated operations.
@@ -873,12 +880,15 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
873
880
dbgs () << " Running pass " << CurrentPassNumber << " " << PassID
874
881
<< " on " << getIRName (IR) << " \n " ;
875
882
876
- if (!shouldPrintBeforePass (PassID))
883
+ if (shouldPrintAfterCurrentPassNumber ())
884
+ pushPassRunDescriptor (PassID, IR, DumpIRFilename);
885
+
886
+ if (!shouldPrintBeforePass (PassID) && !shouldPrintBeforeCurrentPassNumber ())
877
887
return ;
878
888
879
889
auto WriteIRToStream = [&](raw_ostream &Stream) {
880
890
Stream << " ; *** IR Dump Before " ;
881
- if (shouldPrintBeforePassNumber ())
891
+ if (shouldPrintBeforeSomePassNumber ())
882
892
Stream << CurrentPassNumber << " -" ;
883
893
Stream << PassID << " on " << getIRName (IR) << " ***\n " ;
884
894
unwrapAndPrint (Stream, IR);
@@ -898,18 +908,21 @@ void PrintIRInstrumentation::printAfterPass(StringRef PassID, Any IR) {
898
908
if (isIgnored (PassID))
899
909
return ;
900
910
901
- if (!shouldPrintAfterPass (PassID))
911
+ if (!shouldPrintAfterPass (PassID) && ! shouldPrintAfterCurrentPassNumber () )
902
912
return ;
903
913
904
914
auto [M, DumpIRFilename, IRName, StoredPassID] = popPassRunDescriptor (PassID);
905
915
assert (StoredPassID == PassID && " mismatched PassID" );
906
916
907
- if (!shouldPrintIR (IR) || !shouldPrintAfterPass (PassID))
917
+ if (!shouldPrintIR (IR) ||
918
+ (!shouldPrintAfterPass (PassID) && !shouldPrintAfterCurrentPassNumber ()))
908
919
return ;
909
920
910
921
auto WriteIRToStream = [&](raw_ostream &Stream, const StringRef IRName) {
911
- Stream << " ; *** IR Dump " << StringRef (formatv (" After {0}" , PassID))
912
- << " on " << IRName << " ***\n " ;
922
+ Stream << " ; *** IR Dump After " ;
923
+ if (shouldPrintAfterSomePassNumber ())
924
+ Stream << CurrentPassNumber << " -" ;
925
+ Stream << StringRef (formatv (" {0}" , PassID)) << " on " << IRName << " ***\n " ;
913
926
unwrapAndPrint (Stream, IR);
914
927
};
915
928
@@ -931,14 +944,15 @@ void PrintIRInstrumentation::printAfterPassInvalidated(StringRef PassID) {
931
944
if (isIgnored (PassID))
932
945
return ;
933
946
934
- if (!shouldPrintAfterPass (PassID))
947
+ if (!shouldPrintAfterPass (PassID) && ! shouldPrintAfterCurrentPassNumber () )
935
948
return ;
936
949
937
950
auto [M, DumpIRFilename, IRName, StoredPassID] = popPassRunDescriptor (PassID);
938
951
assert (StoredPassID == PassID && " mismatched PassID" );
939
952
// Additional filtering (e.g. -filter-print-func) can lead to module
940
953
// printing being skipped.
941
- if (!M || !shouldPrintAfterPass (PassID))
954
+ if (!M ||
955
+ (!shouldPrintAfterPass (PassID) && !shouldPrintAfterCurrentPassNumber ()))
942
956
return ;
943
957
944
958
auto WriteIRToStream = [&](raw_ostream &Stream, const Module *M,
@@ -968,10 +982,6 @@ bool PrintIRInstrumentation::shouldPrintBeforePass(StringRef PassID) {
968
982
if (shouldPrintBeforeAll ())
969
983
return true ;
970
984
971
- if (shouldPrintBeforePassNumber () &&
972
- CurrentPassNumber == PrintBeforePassNumber)
973
- return true ;
974
-
975
985
StringRef PassName = PIC->getPassNameForClassName (PassID);
976
986
return is_contained (printBeforePasses (), PassName);
977
987
}
@@ -984,26 +994,42 @@ bool PrintIRInstrumentation::shouldPrintAfterPass(StringRef PassID) {
984
994
return is_contained (printAfterPasses (), PassName);
985
995
}
986
996
997
+ bool PrintIRInstrumentation::shouldPrintBeforeCurrentPassNumber () {
998
+ return shouldPrintBeforeSomePassNumber () &&
999
+ (CurrentPassNumber == PrintBeforePassNumber);
1000
+ }
1001
+
1002
+ bool PrintIRInstrumentation::shouldPrintAfterCurrentPassNumber () {
1003
+ return shouldPrintAfterSomePassNumber () &&
1004
+ (CurrentPassNumber == PrintAfterPassNumber);
1005
+ }
1006
+
987
1007
bool PrintIRInstrumentation::shouldPrintPassNumbers () {
988
1008
return PrintPassNumbers;
989
1009
}
990
1010
991
- bool PrintIRInstrumentation::shouldPrintBeforePassNumber () {
1011
+ bool PrintIRInstrumentation::shouldPrintBeforeSomePassNumber () {
992
1012
return PrintBeforePassNumber > 0 ;
993
1013
}
994
1014
1015
+ bool PrintIRInstrumentation::shouldPrintAfterSomePassNumber () {
1016
+ return PrintAfterPassNumber > 0 ;
1017
+ }
1018
+
995
1019
void PrintIRInstrumentation::registerCallbacks (
996
1020
PassInstrumentationCallbacks &PIC) {
997
1021
this ->PIC = &PIC;
998
1022
999
1023
// BeforePass callback is not just for printing, it also saves a Module
1000
- // for later use in AfterPassInvalidated.
1001
- if (shouldPrintPassNumbers () || shouldPrintBeforePassNumber () ||
1002
- shouldPrintBeforeSomePass () || shouldPrintAfterSomePass ())
1024
+ // for later use in AfterPassInvalidated and keeps tracks of the
1025
+ // CurrentPassNumber.
1026
+ if (shouldPrintPassNumbers () || shouldPrintBeforeSomePassNumber () ||
1027
+ shouldPrintAfterSomePassNumber () || shouldPrintBeforeSomePass () ||
1028
+ shouldPrintAfterSomePass ())
1003
1029
PIC.registerBeforeNonSkippedPassCallback (
1004
1030
[this ](StringRef P, Any IR) { this ->printBeforePass (P, IR); });
1005
1031
1006
- if (shouldPrintAfterSomePass ()) {
1032
+ if (shouldPrintAfterSomePass () || shouldPrintAfterSomePassNumber () ) {
1007
1033
PIC.registerAfterPassCallback (
1008
1034
[this ](StringRef P, Any IR, const PreservedAnalyses &) {
1009
1035
this ->printAfterPass (P, IR);
0 commit comments