@@ -118,10 +118,10 @@ static cl::opt<bool> PrintPassNumbers(
118
118
" print-pass-numbers" , cl::init(false ), cl::Hidden,
119
119
cl::desc(" Print pass names and their ordinals" ));
120
120
121
- static cl::opt<unsigned >
122
- PrintAtPassNumber ( " print-at -pass-number" , cl::init(0 ), cl::Hidden,
123
- cl::desc(" Print IR at pass with this number as "
124
- " reported by print-passes-names " ));
121
+ static cl::opt<unsigned > PrintBeforePassNumber (
122
+ " print-before -pass-number" , cl::init(0 ), cl::Hidden,
123
+ cl::desc(" Print IR before the pass with this number as "
124
+ " reported by print-pass-numbers " ));
125
125
126
126
static cl::opt<std::string> IRDumpDirectory (
127
127
" ir-dump-directory" ,
@@ -806,8 +806,7 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
806
806
// Note: here we rely on a fact that we do not change modules while
807
807
// traversing the pipeline, so the latest captured module is good
808
808
// for all print operations that has not happen yet.
809
- if (shouldPrintPassNumbers () || shouldPrintAtPassNumber () ||
810
- shouldPrintAfterPass (PassID))
809
+ if (shouldPrintAfterPass (PassID))
811
810
pushPassRunDescriptor (PassID, IR, DumpIRFilename);
812
811
813
812
if (!shouldPrintIR (IR))
@@ -823,8 +822,10 @@ void PrintIRInstrumentation::printBeforePass(StringRef PassID, Any IR) {
823
822
return ;
824
823
825
824
auto WriteIRToStream = [&](raw_ostream &Stream) {
826
- Stream << " ; *** IR Dump Before " << PassID << " on " << getIRName (IR)
827
- << " ***\n " ;
825
+ Stream << " ; *** IR Dump Before " ;
826
+ if (shouldPrintBeforePassNumber ())
827
+ Stream << CurrentPassNumber << " -" ;
828
+ Stream << PassID << " on " << getIRName (IR) << " ***\n " ;
828
829
unwrapAndPrint (Stream, IR);
829
830
};
830
831
@@ -842,8 +843,7 @@ void PrintIRInstrumentation::printAfterPass(StringRef PassID, Any IR) {
842
843
if (isIgnored (PassID))
843
844
return ;
844
845
845
- if (!shouldPrintAfterPass (PassID) && !shouldPrintPassNumbers () &&
846
- !shouldPrintAtPassNumber ())
846
+ if (!shouldPrintAfterPass (PassID))
847
847
return ;
848
848
849
849
auto [M, DumpIRFilename, IRName, StoredPassID] = popPassRunDescriptor (PassID);
@@ -853,10 +853,7 @@ void PrintIRInstrumentation::printAfterPass(StringRef PassID, Any IR) {
853
853
return ;
854
854
855
855
auto WriteIRToStream = [&](raw_ostream &Stream, const StringRef IRName) {
856
- Stream << " ; *** IR Dump "
857
- << (shouldPrintAtPassNumber ()
858
- ? StringRef (formatv (" At {0}-{1}" , CurrentPassNumber, PassID))
859
- : StringRef (formatv (" After {0}" , PassID)))
856
+ Stream << " ; *** IR Dump " << StringRef (formatv (" After {0}" , PassID))
860
857
<< " on " << IRName << " ***\n " ;
861
858
unwrapAndPrint (Stream, IR);
862
859
};
@@ -879,8 +876,7 @@ void PrintIRInstrumentation::printAfterPassInvalidated(StringRef PassID) {
879
876
if (isIgnored (PassID))
880
877
return ;
881
878
882
- if (!shouldPrintAfterPass (PassID) && !shouldPrintPassNumbers () &&
883
- !shouldPrintAtPassNumber ())
879
+ if (!shouldPrintAfterPass (PassID))
884
880
return ;
885
881
886
882
auto [M, DumpIRFilename, IRName, StoredPassID] = popPassRunDescriptor (PassID);
@@ -893,12 +889,8 @@ void PrintIRInstrumentation::printAfterPassInvalidated(StringRef PassID) {
893
889
auto WriteIRToStream = [&](raw_ostream &Stream, const Module *M,
894
890
const StringRef IRName) {
895
891
SmallString<20 > Banner;
896
- if (shouldPrintAtPassNumber ())
897
- Banner = formatv (" ; *** IR Dump At {0}-{1} on {2} (invalidated) ***" ,
898
- CurrentPassNumber, PassID, IRName);
899
- else
900
- Banner = formatv (" ; *** IR Dump After {0} on {1} (invalidated) ***" ,
901
- PassID, IRName);
892
+ Banner = formatv (" ; *** IR Dump After {0} on {1} (invalidated) ***" , PassID,
893
+ IRName);
902
894
Stream << Banner << " \n " ;
903
895
printIR (Stream, M);
904
896
};
@@ -921,6 +913,10 @@ bool PrintIRInstrumentation::shouldPrintBeforePass(StringRef PassID) {
921
913
if (shouldPrintBeforeAll ())
922
914
return true ;
923
915
916
+ if (shouldPrintBeforePassNumber () &&
917
+ CurrentPassNumber == PrintBeforePassNumber)
918
+ return true ;
919
+
924
920
StringRef PassName = PIC->getPassNameForClassName (PassID);
925
921
return is_contained (printBeforePasses (), PassName);
926
922
}
@@ -929,9 +925,6 @@ bool PrintIRInstrumentation::shouldPrintAfterPass(StringRef PassID) {
929
925
if (shouldPrintAfterAll ())
930
926
return true ;
931
927
932
- if (shouldPrintAtPassNumber () && CurrentPassNumber == PrintAtPassNumber)
933
- return true ;
934
-
935
928
StringRef PassName = PIC->getPassNameForClassName (PassID);
936
929
return is_contained (printAfterPasses (), PassName);
937
930
}
@@ -940,8 +933,8 @@ bool PrintIRInstrumentation::shouldPrintPassNumbers() {
940
933
return PrintPassNumbers;
941
934
}
942
935
943
- bool PrintIRInstrumentation::shouldPrintAtPassNumber () {
944
- return PrintAtPassNumber > 0 ;
936
+ bool PrintIRInstrumentation::shouldPrintBeforePassNumber () {
937
+ return PrintBeforePassNumber > 0 ;
945
938
}
946
939
947
940
void PrintIRInstrumentation::registerCallbacks (
@@ -950,13 +943,12 @@ void PrintIRInstrumentation::registerCallbacks(
950
943
951
944
// BeforePass callback is not just for printing, it also saves a Module
952
945
// for later use in AfterPassInvalidated.
953
- if (shouldPrintPassNumbers () || shouldPrintAtPassNumber () ||
946
+ if (shouldPrintPassNumbers () || shouldPrintBeforePassNumber () ||
954
947
shouldPrintBeforeSomePass () || shouldPrintAfterSomePass ())
955
948
PIC.registerBeforeNonSkippedPassCallback (
956
949
[this ](StringRef P, Any IR) { this ->printBeforePass (P, IR); });
957
950
958
- if (shouldPrintPassNumbers () || shouldPrintAtPassNumber () ||
959
- shouldPrintAfterSomePass ()) {
951
+ if (shouldPrintAfterSomePass ()) {
960
952
PIC.registerAfterPassCallback (
961
953
[this ](StringRef P, Any IR, const PreservedAnalyses &) {
962
954
this ->printAfterPass (P, IR);
0 commit comments