Skip to content
Merged
Changes from all commits
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
18 changes: 13 additions & 5 deletions llvm/lib/CodeGen/LiveRangeShrink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,25 @@ static MachineInstr *FindDominatedInstruction(MachineInstr &New,
return Old;
}

/// Returns whether this instruction is considered a code motion barrier by this
/// pass. We can be less conservative than hasUnmodeledSideEffects() when
/// deciding whether an instruction is a barrier because it is known that pseudo
/// probes are safe to move in this pass specifically (see commit 1cb47a063e2b).
static bool isCodeMotionBarrier(MachineInstr &MI) {
return MI.hasUnmodeledSideEffects() && !MI.isPseudoProbe();
}
Comment on lines +102 to +104
Copy link
Contributor

Choose a reason for hiding this comment

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

Document this? What is the exact problematic condition? We have several different barrier concepts already spread in MachineInstr and TargetInstrInfo, can we use one of those

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment that describes the situation to the best of my understanding. I don't think the existing ones can be used because the condition is specific to what this pass is doing.


/// Builds Instruction to its dominating order number map \p M by traversing
/// from instruction \p Start.
static void BuildInstOrderMap(MachineBasicBlock::iterator Start,
InstOrderMap &M) {
M.clear();
unsigned i = 0;
for (MachineInstr &I : make_range(Start, Start->getParent()->end()))
for (MachineInstr &I : make_range(Start, Start->getParent()->end())) {
if (isCodeMotionBarrier(I))
break;
M[&I] = i++;
}
}

bool LiveRangeShrink::runOnMachineFunction(MachineFunction &MF) {
Expand Down Expand Up @@ -142,8 +153,6 @@ bool LiveRangeShrink::runOnMachineFunction(MachineFunction &MF) {
while (Next != MBB.end()) {
MachineInstr &MI = *Next;
Next = MBB.SkipPHIsLabelsAndDebug(++Next);
if (MI.mayStore())
SawStore = true;

unsigned CurrentOrder = IOM[&MI];
unsigned Barrier = 0;
Expand All @@ -166,8 +175,7 @@ bool LiveRangeShrink::runOnMachineFunction(MachineFunction &MF) {
// If MI has side effects, it should become a barrier for code motion.
// IOM is rebuild from the next instruction to prevent later
// instructions from being moved before this MI.
if (MI.hasUnmodeledSideEffects() && !MI.isPseudoProbe() &&
Next != MBB.end()) {
if (isCodeMotionBarrier(MI) && Next != MBB.end()) {
BuildInstOrderMap(Next, IOM);
SawStore = false;
}
Expand Down
Loading