Skip to content

Commit 28f6547

Browse files
committed
Drop handleInitalMIR
1 parent b84f5af commit 28f6547

File tree

3 files changed

+22
-57
lines changed

3 files changed

+22
-57
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: 21 additions & 46 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"
@@ -378,16 +380,13 @@ template <typename T>
378380
void ChangeReporter<T>::saveIRBeforePass(Any IR, StringRef PassID,
379381
StringRef PassName) {
380382
// Is this the initial IR?
381-
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());
383+
// TODO: When Module to MachineFunction adaptor is available
384+
// set InitialIR to true when PassID is the adaptor.
385+
if (InitialIR && PassID != PrintMIRPreparePass::name()) {
386+
if (const auto *MF = unwrapIR<MachineFunction>(IR); !MF || !MF->empty()) {
387+
InitialIR = false;
388+
if (VerboseMode)
389+
handleInitialIR(IR);
391390
}
392391
}
393392

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

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

471474
template <typename T> void TextChangeReporter<T>::handleInitialIR(Any IR) {
475+
// MIR is special, not all MIRs are available at the beginning.
476+
if (const auto *MF = unwrapIR<MachineFunction>(IR)) {
477+
Out << "*** MIR Dump At Start ***\n";
478+
MF->print(Out);
479+
return;
480+
}
481+
472482
// Always print the module.
473483
// Unwrap and print directly to avoid filtering problems in general routines.
474484
auto *M = unwrapModule(IR, /*Force=*/true);
@@ -477,11 +487,6 @@ template <typename T> void TextChangeReporter<T>::handleInitialIR(Any IR) {
477487
M->print(Out, nullptr);
478488
}
479489

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

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

22582257
void DotCfgChangeReporter::handleInitialIR(Any IR) {
22592258
assert(HTML && "Expected outstream to be set");
2260-
*HTML << "<button type=\"button\" class=\"collapsible\">0. "
2259+
*HTML << "<button type=\"button\" class=\"collapsible\">" << N << ". "
22612260
<< "Initial IR (by function)</button>\n"
22622261
<< "<div class=\"content\">\n"
22632262
<< " <p>\n";
@@ -2279,30 +2278,6 @@ void DotCfgChangeReporter::handleInitialIR(Any IR) {
22792278
++N;
22802279
}
22812280

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-
23062281
void DotCfgChangeReporter::generateIRRepresentation(Any IR, StringRef PassID,
23072282
IRDataT<DCData> &Data) {
23082283
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)