Skip to content

Commit a8d5576

Browse files
committed
Drop handleInitalMIR
1 parent b84f5af commit a8d5576

File tree

3 files changed

+19
-56
lines changed

3 files changed

+19
-56
lines changed

llvm/include/llvm/Passes/StandardInstrumentations.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,6 @@ template <typename IRUnitT> class ChangeReporter {
212212

213213
// Called on the first IR processed.
214214
virtual void handleInitialIR(Any IR) = 0;
215-
// Called on the first MIR processed.
216-
virtual void handleInitialMIR(const MachineFunction *IR) = 0;
217215
// Called before and after a pass to get the representation of the IR.
218216
virtual void generateIRRepresentation(Any IR, StringRef PassID,
219217
IRUnitT &Output) = 0;
@@ -234,8 +232,6 @@ template <typename IRUnitT> class ChangeReporter {
234232
std::vector<IRUnitT> BeforeStack;
235233
// Is this the first IR seen?
236234
bool InitialIR = true;
237-
// Is this the first MIR seen?
238-
StringSet<> HandledMIR;
239235

240236
// Run in verbose mode, printing everything?
241237
const bool VerboseMode;
@@ -250,8 +246,6 @@ class TextChangeReporter : public ChangeReporter<IRUnitT> {
250246

251247
// Print a module dump of the first IR that is changed.
252248
void handleInitialIR(Any IR) override;
253-
// Print a module dump of the first MIR that is changed.
254-
void handleInitialMIR(const MachineFunction *IR) override;
255249
// Report that the IR was omitted because it did not change.
256250
void omitAfter(StringRef PassID, std::string &Name) override;
257251
// Report that the pass was invalidated.
@@ -298,8 +292,6 @@ class IRChangedTester : public IRChangedPrinter {
298292

299293
// Check initial IR
300294
void handleInitialIR(Any IR) override;
301-
// Check initial MIR
302-
void handleInitialMIR(const MachineFunction *IR) override;
303295
// Do nothing.
304296
void omitAfter(StringRef PassID, std::string &Name) override;
305297
// Do nothing.
@@ -533,8 +525,6 @@ class DotCfgChangeReporter : public ChangeReporter<IRDataT<DCData>> {
533525

534526
// Called on the first IR processed.
535527
void handleInitialIR(Any IR) override;
536-
// Called on the first MIR processed.
537-
void handleInitialMIR(const MachineFunction *IR) override;
538528
// Called before and after a pass to get the representation of the IR.
539529
void generateIRRepresentation(Any IR, StringRef PassID,
540530
IRDataT<DCData> &Output) override;

llvm/lib/Passes/StandardInstrumentations.cpp

Lines changed: 18 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "llvm/Analysis/CallGraphSCCPass.h"
2020
#include "llvm/Analysis/LazyCallGraph.h"
2121
#include "llvm/Analysis/LoopInfo.h"
22+
#include "llvm/CodeGen/FreeMachineFunction.h"
23+
#include "llvm/CodeGen/MIRPrinter.h"
2224
#include "llvm/CodeGen/MachineFunction.h"
2325
#include "llvm/CodeGen/MachineModuleInfo.h"
2426
#include "llvm/IR/Constants.h"
@@ -379,15 +381,10 @@ void ChangeReporter<T>::saveIRBeforePass(Any IR, StringRef PassID,
379381
StringRef PassName) {
380382
// Is this the initial IR?
381383
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);
391388
}
392389
}
393390

@@ -438,6 +435,10 @@ template <typename T>
438435
void ChangeReporter<T>::handleInvalidatedPass(StringRef PassID) {
439436
assert(!BeforeStack.empty() && "Unexpected empty stack encountered.");
440437

438+
// Prepare to process the next MIR.
439+
if (PassID == FreeMachineFunctionPass::name())
440+
InitialIR = true;
441+
441442
// Always flag it as invalidated as we cannot determine when
442443
// a pass for a filtered function is invalidated since we do not
443444
// get the IR in the call. Also, the output is just alternate
@@ -469,6 +470,13 @@ TextChangeReporter<T>::TextChangeReporter(bool Verbose)
469470
: ChangeReporter<T>(Verbose), Out(dbgs()) {}
470471

471472
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+
472480
// Always print the module.
473481
// Unwrap and print directly to avoid filtering problems in general routines.
474482
auto *M = unwrapModule(IR, /*Force=*/true);
@@ -477,11 +485,6 @@ template <typename T> void TextChangeReporter<T>::handleInitialIR(Any IR) {
477485
M->print(Out, nullptr);
478486
}
479487

480-
template <typename T>
481-
void TextChangeReporter<T>::handleInitialMIR(const MachineFunction *IR) {
482-
// For simplicity, don't print the initial MIR.
483-
}
484-
485488
template <typename T>
486489
void TextChangeReporter<T>::omitAfter(StringRef PassID, std::string &Name) {
487490
Out << formatv("*** IR Dump After {0} on {1} omitted because no change ***\n",
@@ -580,12 +583,6 @@ void IRChangedTester::handleInitialIR(Any IR) {
580583
handleIR(S, "Initial IR");
581584
}
582585

583-
void IRChangedTester::handleInitialMIR(const MachineFunction *IR) {
584-
std::string S;
585-
generateIRRepresentation(IR, "Initial MIR", S);
586-
handleIR(S, "Initial MIR");
587-
}
588-
589586
void IRChangedTester::omitAfter(StringRef PassID, std::string &Name) {}
590587
void IRChangedTester::handleInvalidated(StringRef PassID) {}
591588
void IRChangedTester::handleFiltered(StringRef PassID, std::string &Name) {}
@@ -2257,7 +2254,7 @@ std::string DotCfgChangeReporter::genHTML(StringRef Text, StringRef DotFile,
22572254

22582255
void DotCfgChangeReporter::handleInitialIR(Any IR) {
22592256
assert(HTML && "Expected outstream to be set");
2260-
*HTML << "<button type=\"button\" class=\"collapsible\">0. "
2257+
*HTML << "<button type=\"button\" class=\"collapsible\">" << N << ". "
22612258
<< "Initial IR (by function)</button>\n"
22622259
<< "<div class=\"content\">\n"
22632260
<< " <p>\n";
@@ -2279,30 +2276,6 @@ void DotCfgChangeReporter::handleInitialIR(Any IR) {
22792276
++N;
22802277
}
22812278

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-
23062279
void DotCfgChangeReporter::generateIRRepresentation(Any IR, StringRef PassID,
23072280
IRDataT<DCData> &Data) {
23082281
IRComparer<DCData>::analyzeIR(IR, Data);

llvm/test/Other/ChangePrinters/DotCfg/print-changed-dot-cfg.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Simple functionality check.
33
# RUN: rm -rf %t && mkdir -p %t
44
# RUN: llc -filetype=null -print-changed=dot-cfg -passes=no-op-machine-function -dot-cfg-dir=%t %s
5-
# RUN: ls %t/*.pdf %t/passes.html | count 5
5+
# RUN: ls %t/*.pdf %t/passes.html | count 3
66

77
---
88
name: g

0 commit comments

Comments
 (0)