19
19
#include " llvm/Analysis/CallGraphSCCPass.h"
20
20
#include " llvm/Analysis/LazyCallGraph.h"
21
21
#include " llvm/Analysis/LoopInfo.h"
22
+ #include " llvm/CodeGen/FreeMachineFunction.h"
23
+ #include " llvm/CodeGen/MIRPrinter.h"
22
24
#include " llvm/CodeGen/MachineFunction.h"
23
25
#include " llvm/CodeGen/MachineModuleInfo.h"
24
26
#include " llvm/IR/Constants.h"
@@ -379,15 +381,10 @@ void ChangeReporter<T>::saveIRBeforePass(Any IR, StringRef PassID,
379
381
StringRef PassName) {
380
382
// Is this the initial IR?
381
383
if (InitialIR) {
382
- InitialIR = false ;
383
- if (VerboseMode)
384
- handleInitialIR (IR);
385
- }
386
-
387
- if (const auto *MF = unwrapIR<MachineFunction>(IR)) {
388
- if (VerboseMode && !HandledMIR.contains (MF->getName ()) && !MF->empty ()) {
389
- handleInitialMIR (MF);
390
- HandledMIR.insert (MF->getName ());
384
+ if (const auto *MF = unwrapIR<MachineFunction>(IR); !MF || !MF->empty ()) {
385
+ InitialIR = false ;
386
+ if (VerboseMode)
387
+ handleInitialIR (IR);
391
388
}
392
389
}
393
390
@@ -438,6 +435,10 @@ template <typename T>
438
435
void ChangeReporter<T>::handleInvalidatedPass(StringRef PassID) {
439
436
assert (!BeforeStack.empty () && " Unexpected empty stack encountered." );
440
437
438
+ // Prepare to process the next MIR.
439
+ if (PassID == FreeMachineFunctionPass::name ())
440
+ InitialIR = true ;
441
+
441
442
// Always flag it as invalidated as we cannot determine when
442
443
// a pass for a filtered function is invalidated since we do not
443
444
// get the IR in the call. Also, the output is just alternate
@@ -469,6 +470,13 @@ TextChangeReporter<T>::TextChangeReporter(bool Verbose)
469
470
: ChangeReporter<T>(Verbose), Out(dbgs()) {}
470
471
471
472
template <typename T> void TextChangeReporter<T>::handleInitialIR(Any IR) {
473
+ // MIR is special, not all MIRs are available at the beginning.
474
+ if (const auto *MF = unwrapIR<MachineFunction>(IR)) {
475
+ Out << " *** MIR Dump At Start ***\n " ;
476
+ MF->print (Out);
477
+ return ;
478
+ }
479
+
472
480
// Always print the module.
473
481
// Unwrap and print directly to avoid filtering problems in general routines.
474
482
auto *M = unwrapModule (IR, /* Force=*/ true );
@@ -477,11 +485,6 @@ template <typename T> void TextChangeReporter<T>::handleInitialIR(Any IR) {
477
485
M->print (Out, nullptr );
478
486
}
479
487
480
- template <typename T>
481
- void TextChangeReporter<T>::handleInitialMIR(const MachineFunction *IR) {
482
- // For simplicity, don't print the initial MIR.
483
- }
484
-
485
488
template <typename T>
486
489
void TextChangeReporter<T>::omitAfter(StringRef PassID, std::string &Name) {
487
490
Out << formatv (" *** IR Dump After {0} on {1} omitted because no change ***\n " ,
@@ -580,12 +583,6 @@ void IRChangedTester::handleInitialIR(Any IR) {
580
583
handleIR (S, " Initial IR" );
581
584
}
582
585
583
- void IRChangedTester::handleInitialMIR (const MachineFunction *IR) {
584
- std::string S;
585
- generateIRRepresentation (IR, " Initial MIR" , S);
586
- handleIR (S, " Initial MIR" );
587
- }
588
-
589
586
void IRChangedTester::omitAfter (StringRef PassID, std::string &Name) {}
590
587
void IRChangedTester::handleInvalidated (StringRef PassID) {}
591
588
void IRChangedTester::handleFiltered (StringRef PassID, std::string &Name) {}
@@ -2257,7 +2254,7 @@ std::string DotCfgChangeReporter::genHTML(StringRef Text, StringRef DotFile,
2257
2254
2258
2255
void DotCfgChangeReporter::handleInitialIR (Any IR) {
2259
2256
assert (HTML && " Expected outstream to be set" );
2260
- *HTML << " <button type=\" button\" class=\" collapsible\" >0 . "
2257
+ *HTML << " <button type=\" button\" class=\" collapsible\" >" << N << " . "
2261
2258
<< " Initial IR (by function)</button>\n "
2262
2259
<< " <div class=\" content\" >\n "
2263
2260
<< " <p>\n " ;
@@ -2279,30 +2276,6 @@ void DotCfgChangeReporter::handleInitialIR(Any IR) {
2279
2276
++N;
2280
2277
}
2281
2278
2282
- void DotCfgChangeReporter::handleInitialMIR (const MachineFunction *IR) {
2283
- assert (HTML && " Expected outstream to be set" );
2284
- *HTML << " <button type=\" button\" class=\" collapsible\" >" << N << " . "
2285
- << " Initial MIR (by machine function)</button>\n "
2286
- << " <div class=\" content\" >\n "
2287
- << " <p>\n " ;
2288
- // Create representation of IR
2289
- IRDataT<DCData> Data;
2290
- IRComparer<DCData>::analyzeIR (llvm::Any (IR), Data);
2291
- // Now compare it against itself, which will have everything the
2292
- // same and will generate the files.
2293
- IRComparer<DCData>(Data, Data)
2294
- .compare (getModuleForComparison (IR),
2295
- [&](bool InModule, unsigned Minor,
2296
- const FuncDataT<DCData> &Before,
2297
- const FuncDataT<DCData> &After) -> void {
2298
- handleFunctionCompare (" " , " " , " Initial MIR" , " " , InModule,
2299
- Minor, Before, After);
2300
- });
2301
- *HTML << " </p>\n "
2302
- << " </div><br/>\n " ;
2303
- ++N;
2304
- }
2305
-
2306
2279
void DotCfgChangeReporter::generateIRRepresentation (Any IR, StringRef PassID,
2307
2280
IRDataT<DCData> &Data) {
2308
2281
IRComparer<DCData>::analyzeIR (IR, Data);
0 commit comments