Skip to content
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

[CodeGen] Preserved additional analyses in StackSlotColoring pass. #93779

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion llvm/lib/CodeGen/StackSlotColoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/CodeGen/LiveDebugVariables.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably avoid the include by using the PassID

Copy link
Contributor Author

@vg0204 vg0204 Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For that, "char &llvm::passID = pass::ID", need to be added in the respective pass (not presently there in LiveDebugVariables.cpp), followed by exposing it via extern in Passes.h. So, I think this is better option.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But those should be there

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I was going through the Codegen passes, while most of them have it, others don't. What should be the right practice?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They all should (but the PassID will go away in new PM so it's probably not worth fixing all of the missing instances)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, what should be supposed to be my final take on it!

#include "llvm/CodeGen/LiveInterval.h"
#include "llvm/CodeGen/LiveIntervalUnion.h"
#include "llvm/CodeGen/LiveIntervals.h"
Expand Down Expand Up @@ -64,6 +65,7 @@ namespace {
MachineFrameInfo *MFI = nullptr;
const TargetInstrInfo *TII = nullptr;
const MachineBlockFrequencyInfo *MBFI = nullptr;
SlotIndexes *Indexes = nullptr;

// SSIntervals - Spill slot intervals.
std::vector<LiveInterval*> SSIntervals;
Expand Down Expand Up @@ -152,6 +154,14 @@ namespace {
AU.addRequired<MachineBlockFrequencyInfo>();
AU.addPreserved<MachineBlockFrequencyInfo>();
AU.addPreservedID(MachineDominatorsID);

// As in some Target's pipeline, register allocation (RA) might be
// splitted into multiple phases based on register class. So, this pass
vg0204 marked this conversation as resolved.
Show resolved Hide resolved
// may be invoked multiple times requiring it to save these analyses to be
// used by RA later.
AU.addPreserved<LiveIntervals>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to addPreserved<SlotIndexes>? I'm also surprised you don't need to refer to LiveIntervals to maintain them?

Copy link
Contributor Author

@vg0204 vg0204 Jun 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"addPreserved < SlotIndexes > " was already there before. As for LiveIntervals, it would be needed to be preserved for maybe the upcoming regAlloc pass for remaining register classes, else it is being re-computed, which somehow creating problem.

AU.addPreserved<LiveDebugVariables>();

MachineFunctionPass::getAnalysisUsage(AU);
}

Expand Down Expand Up @@ -496,8 +506,10 @@ bool StackSlotColoring::RemoveDeadStores(MachineBasicBlock* MBB) {
++I;
}

for (MachineInstr *MI : toErase)
for (MachineInstr *MI : toErase) {
MI->eraseFromParent();
Indexes->removeMachineInstrFromMaps(*MI);
vg0204 marked this conversation as resolved.
Show resolved Hide resolved
vg0204 marked this conversation as resolved.
Show resolved Hide resolved
}

return changed;
}
Expand All @@ -515,6 +527,7 @@ bool StackSlotColoring::runOnMachineFunction(MachineFunction &MF) {
TII = MF.getSubtarget().getInstrInfo();
LS = &getAnalysis<LiveStacks>();
MBFI = &getAnalysis<MachineBlockFrequencyInfo>();
Indexes = &getAnalysis<SlotIndexes>();

bool Changed = false;

Expand Down
Loading