-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Instrumentation] Support MachineFunction in ChangeReporter #80946
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
llvm/test/Other/ChangePrinters/DotCfg/print-changed-dot-cfg.mir
Outdated
Show resolved
Hide resolved
Out << "*** MIR Dump At Start ***\n"; | ||
for (const Function &F : M) | ||
if (auto *MF = MMI.getMachineFunction(F)) | ||
MF->print(Out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, not all machine functions are available at this time, when running default codegen pipeline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good point. I'm not sure if we should print something to tell the user that the machine function doesn't exist.
it is weird to print MIR Dump At Start
and then not print anything if we don't have any MFs yet. perhaps we just don't print anything here if we don't have any MFs
Out << "*** MIR Dump At Start ***\n"; | ||
for (const Function &F : M) | ||
if (auto *MF = MMI.getMachineFunction(F)) | ||
MF->print(Out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good point. I'm not sure if we should print something to tell the user that the machine function doesn't exist.
it is weird to print MIR Dump At Start
and then not print anything if we don't have any MFs yet. perhaps we just don't print anything here if we don't have any MFs
@@ -90,7 +90,9 @@ Error MachineFunctionPassManager::run(Module &M, | |||
for (unsigned I = Begin, E = Idx; I != E; ++I) { | |||
auto *P = Passes[I].get(); | |||
|
|||
if (!PI.runBeforePass<MachineFunction>(*P, MF)) | |||
// Keep BeforeStack empty in ChangeReporter | |||
if (P->name() != FreeMachineFunctionPass::name() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should invoke runAfterPassInvalidated
below if we see that we're running FreeMachineFunctionPass
, rather than not running instrumentation on it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have something that does this in my rewrite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can keep this for now, but #81068 will overwrite this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lg with or without the "no MIR functions to print" comment resolved
@@ -90,7 +90,9 @@ Error MachineFunctionPassManager::run(Module &M, | |||
for (unsigned I = Begin, E = Idx; I != E; ++I) { | |||
auto *P = Passes[I].get(); | |||
|
|||
if (!PI.runBeforePass<MachineFunction>(*P, MF)) | |||
// Keep BeforeStack empty in ChangeReporter | |||
if (P->name() != FreeMachineFunctionPass::name() && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can keep this for now, but #81068 will overwrite this
for simplicity, I think we should just not print the initial MIR since it's unclear exactly what the right thing to do is |
should we just completely drop |
CFG instruments may benefit from this in verbose mode, but remove it is also ok. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm after comments addressed
@@ -448,6 +477,11 @@ template <typename T> void TextChangeReporter<T>::handleInitialIR(Any IR) { | |||
M->print(Out, nullptr); | |||
} | |||
|
|||
template <typename T> | |||
void TextChangeReporter<T>::handleInitialMIR(const MachineFunction *IR) { | |||
// For simplicity, don't print the initial MIR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the reason that it's likely that the MIR doesn't initially exist
@@ -362,6 +384,13 @@ void ChangeReporter<T>::saveIRBeforePass(Any IR, StringRef PassID, | |||
handleInitialIR(IR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we be calling this on MIR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found previous implementation has some problem, will try to combine handleInitialIR and handleInitialMIR.
btw we should probably start looking into how to get the hard passes ported, like SelectionDAG or the AsmPrinters |
a547f69
to
32fcaa3
Compare
28f6547
to
a8d5576
Compare
InitialIR = false; | ||
if (VerboseMode) | ||
handleInitialIR(IR); | ||
if (const auto *MF = unwrapIR<MachineFunction>(IR); !MF || !MF->empty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the intention here to make the output of instruction selection the "initial IR"?
I feel like being explicit about the fact that instruction selection is actually modifying the MachineFunction is reasonable, so the initial IR being empty isn't too bad. but I'm open to this as well
@@ -409,6 +435,10 @@ template <typename T> | |||
void ChangeReporter<T>::handleInvalidatedPass(StringRef PassID) { | |||
assert(!BeforeStack.empty() && "Unexpected empty stack encountered."); | |||
|
|||
// Prepare to process the next MIR. | |||
if (PassID == FreeMachineFunctionPass::name()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you explain why this is necessary?
I think in general I'm not understanding the intent with "InitialIR" in regards to MIR. Previously we'd always start with the entire module as the initial IR right? Why are we handling MachineFunctions differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard to determine when the initial MIR for a function is created. If the input is general LLVM IR and the pipeline is not interrupted by a module pass then new machine function will not be created until FreeMachineFunction
, which is the initial MIR for the next function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InitialIR
is used to determine when to call handleInitialIR
, which is typically used to print to the user "Initial IR: ...". I don't think we need that for MIR, except in the case where we start with MIR (mostly just tests). We can just let before/after pass handle MIR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let before/after pass handle MIR now, but still print all available MIRs when print-module-scope
is on.
0442446
to
b4726bd
Compare
Ping? Now empty machine functions are no longer treated specially. |
b4726bd
to
6db1fd7
Compare
6db1fd7
to
73937a2
Compare
No description provided.