Skip to content

Commit 5f9a41f

Browse files
committed
Rebase. Updates per latest review.
1 parent 6c5d72c commit 5f9a41f

9 files changed

+290
-279
lines changed

llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,26 +2162,20 @@ bool SystemZInstrInfo::isLoadAndTestAsCmp(const MachineInstr &MI) const {
21622162
return (MI.getOpcode() == SystemZ::LTEBR ||
21632163
MI.getOpcode() == SystemZ::LTDBR ||
21642164
MI.getOpcode() == SystemZ::LTXBR) &&
2165-
MI.getOperand(0).isDead();
2165+
MI.getOperand(0).isDead();
21662166
}
21672167

21682168
bool SystemZInstrInfo::isCompareZero(const MachineInstr &Compare) const {
21692169
if (isLoadAndTestAsCmp(Compare))
21702170
return true;
21712171
return Compare.isCompare() && Compare.getNumExplicitOperands() == 2 &&
2172-
Compare.getOperand(1).isImm() && Compare.getOperand(1).getImm() == 0;
2172+
Compare.getOperand(1).isImm() && Compare.getOperand(1).getImm() == 0;
21732173
}
21742174

2175-
unsigned SystemZInstrInfo::
2176-
getCompareSourceReg(const MachineInstr &Compare) const {
2177-
unsigned reg = 0;
2178-
if (Compare.isCompare())
2179-
reg = Compare.getOperand(0).getReg();
2180-
else if (isLoadAndTestAsCmp(Compare))
2181-
reg = Compare.getOperand(1).getReg();
2182-
assert(reg);
2183-
2184-
return reg;
2175+
Register
2176+
SystemZInstrInfo::getCompareSourceReg(const MachineInstr &Compare) const {
2177+
assert(isCompareZero(Compare) && "Expected a compare with 0.");
2178+
return Compare.getOperand(isLoadAndTestAsCmp(Compare) ? 1 : 0).getReg();
21852179
}
21862180

21872181
bool SystemZInstrInfo::

llvm/lib/Target/SystemZ/SystemZInstrInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ class SystemZInstrInfo : public SystemZGenInstrInfo {
365365

366366
// Return the source register of Compare, which is the unknown value
367367
// being tested.
368-
unsigned getCompareSourceReg(const MachineInstr &Compare) const;
368+
Register getCompareSourceReg(const MachineInstr &Compare) const;
369369

370370
// Try to find all CC users of the compare instruction (MBBI) and update
371371
// all of them to maintain equivalent behavior after swapping the compare

llvm/lib/Target/SystemZ/SystemZMachineScheduler.cpp

Lines changed: 46 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,29 @@ void SystemZPreRASchedStrategy::initializePrioRegClasses(
5757
}
5858
}
5959

60-
void SystemZPreRASchedStrategy::VRegSet::dump(std::string Msg) {
61-
dbgs() << Msg.c_str();
60+
void SystemZPreRASchedStrategy::VRegSet::insert(Register Reg) {
61+
assert(Reg.isVirtual());
62+
Regs.insert(Reg);
63+
}
64+
65+
void SystemZPreRASchedStrategy::VRegSet::erase(Register Reg) {
66+
assert(Reg.isVirtual());
67+
Regs.erase(Reg);
68+
}
69+
70+
bool SystemZPreRASchedStrategy::VRegSet::count(Register Reg) const {
71+
assert(Reg.isVirtual());
72+
return Regs.count(Reg);
73+
}
74+
75+
void SystemZPreRASchedStrategy::VRegSet::dump() const {
6276
bool First = true;
63-
for (auto R : *this) {
77+
for (auto R : Regs) {
6478
if (!First)
6579
dbgs() << ", ";
6680
else
6781
First = false;
68-
dbgs() << "%" << R.virtRegIndex();
82+
dbgs() << printReg(R);
6983
}
7084
dbgs() << "\n";
7185
}
@@ -109,8 +123,8 @@ void SystemZPreRASchedStrategy::initializeStoresGroup() {
109123
return;
110124
if (IsStore)
111125
StoresGroup.insert(SU);
112-
}
113-
else if (IsStore && !StoresGroup.empty() && SU->getDepth() == CurrMaxDepth) {
126+
} else if (IsStore && !StoresGroup.empty() &&
127+
SU->getDepth() == CurrMaxDepth) {
114128
// The group members should all have the same opcode.
115129
if ((*StoresGroup.begin())->getInstr()->getOpcode() != MI->getOpcode()) {
116130
StoresGroup.clear();
@@ -142,9 +156,8 @@ static int biasPhysRegExtra(const SUnit *SU) {
142156
return 0;
143157
}
144158

145-
int SystemZPreRASchedStrategy::
146-
computeSULivenessScore(SchedCandidate &C, ScheduleDAGMILive *DAG,
147-
SchedBoundary *Zone) const {
159+
int SystemZPreRASchedStrategy::computeSULivenessScore(
160+
SchedCandidate &C, ScheduleDAGMILive *DAG, SchedBoundary *Zone) const {
148161
// Not all data deps are modelled around the SUnit - some data edges near
149162
// boundaries are missing: Look directly at the MI operands instead.
150163
const SUnit *SU = C.SU;
@@ -246,22 +259,24 @@ bool SystemZPreRASchedStrategy::tryCandidate(SchedCandidate &Cand,
246259
return TryCand.Reason != NoCand;
247260

248261
// Don't extend the scheduled latency.
249-
if (ShouldReduceLatency && TryCand.SU->getHeight() != Cand.SU->getHeight() &&
262+
if (ShouldReduceLatency &&
263+
TryCand.SU->getHeight() != Cand.SU->getHeight() &&
250264
(std::max(TryCand.SU->getHeight(), Cand.SU->getHeight()) >
251265
Zone->getScheduledLatency())) {
252-
unsigned HigherSUDepth = TryCand.SU->getHeight() < Cand.SU->getHeight() ?
253-
Cand.SU->getDepth() : TryCand.SU->getDepth();
266+
unsigned HigherSUDepth = TryCand.SU->getHeight() < Cand.SU->getHeight()
267+
? Cand.SU->getDepth()
268+
: TryCand.SU->getDepth();
254269
if (HigherSUDepth != getRemLat(Zone) &&
255-
tryLess(TryCand.SU->getHeight(), Cand.SU->getHeight(),
256-
TryCand, Cand, GenericSchedulerBase::BotHeightReduce)) {
270+
tryLess(TryCand.SU->getHeight(), Cand.SU->getHeight(), TryCand, Cand,
271+
GenericSchedulerBase::BotHeightReduce)) {
257272
return TryCand.Reason != NoCand;
258273
}
259274
}
260275
}
261276

262277
// Weak edges are for clustering and other constraints.
263-
if (tryLess(TryCand.SU->WeakSuccsLeft, Cand.SU->WeakSuccsLeft,
264-
TryCand, Cand, Weak))
278+
if (tryLess(TryCand.SU->WeakSuccsLeft, Cand.SU->WeakSuccsLeft, TryCand, Cand,
279+
Weak))
265280
return TryCand.Reason != NoCand;
266281

267282
// Fall through to original instruction order.
@@ -361,17 +376,22 @@ void SystemZPreRASchedStrategy::initialize(ScheduleDAGMI *dag) {
361376
LLVM_DEBUG(if (ShouldReduceLatency) dbgs() << "Latency scheduling enabled.\n";
362377
else dbgs() << "Latency scheduling disabled.\n";);
363378

364-
// Find the registers that are live at the bottom, before scheduling.
379+
// Find the registers used in the region that are live out.
365380
LiveRegs.clear();
366-
for (unsigned I = 0, E = DAG->MRI.getNumVirtRegs(); I != E; ++I) {
367-
Register VirtReg = Register::index2VirtReg(I);
368-
const LiveInterval &LI = DAG->getLIS()->getInterval(VirtReg);
369-
LiveQueryResult LRQ = LI.Query(
370-
DAG->getLIS()->getInstructionIndex(*DAG->SUnits.back().getInstr()));
371-
if (LRQ.valueOut())
372-
LiveRegs.insert(VirtReg);
381+
std::set<Register> Visited;
382+
for (unsigned Idx = 0, End = DAG->SUnits.size(); Idx != End; ++Idx) {
383+
const MachineInstr *MI = DAG->SUnits[Idx].getInstr();
384+
for (auto &MO : MI->explicit_operands())
385+
if (MO.isReg() && MO.getReg().isVirtual() &&
386+
Visited.insert(MO.getReg()).second) {
387+
const LiveInterval &LI = DAG->getLIS()->getInterval(MO.getReg());
388+
LiveQueryResult LRQ = LI.Query(
389+
DAG->getLIS()->getInstructionIndex(*DAG->SUnits.back().getInstr()));
390+
if (LRQ.valueOut())
391+
LiveRegs.insert(MO.getReg());
392+
}
373393
}
374-
LLVM_DEBUG(LiveRegs.dump("Live out at bottom: "););
394+
LLVM_DEBUG(dbgs() << "Live out at bottom: "; LiveRegs.dump(););
375395

376396
// If MI uses the register it defines, record it one time here.
377397
IsRedefining = std::vector<bool>(DAG->SUnits.size(), false);
@@ -395,7 +415,7 @@ void SystemZPreRASchedStrategy::schedNode(SUnit *SU, bool IsTopNode) {
395415
if (TinyRegion)
396416
return;
397417

398-
LLVM_DEBUG(LiveRegs.dump("Live regs was: "););
418+
LLVM_DEBUG(dbgs() << "Live regs was: "; LiveRegs.dump(););
399419

400420
if (!FirstStoreInGroupScheduled && StoresGroup.count(SU))
401421
FirstStoreInGroupScheduled = true;

llvm/lib/Target/SystemZ/SystemZMachineScheduler.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,19 @@ class SystemZPreRASchedStrategy : public GenericScheduler {
5050
// Num instructions left to schedule.
5151
unsigned NumLeft;
5252

53-
// Tru if latency scheduling is enabled.
53+
// True if latency scheduling is enabled.
5454
bool ShouldReduceLatency;
5555

5656
// Keep track of currently live registers.
57-
struct VRegSet : std::set<Register> {
58-
void dump(std::string Msg);
59-
size_type count(Register Reg) const {
60-
assert(Reg.isVirtual());
61-
return std::set<Register>::count(Reg);
62-
}
57+
class VRegSet {
58+
std::set<Register> Regs;
59+
60+
public:
61+
void clear() { Regs.clear(); }
62+
void insert(Register Reg);
63+
void erase(Register Reg);
64+
bool count(Register Reg) const;
65+
void dump() const;
6366
} LiveRegs;
6467

6568
// True if MI is also using the register it defines.
@@ -70,7 +73,7 @@ class SystemZPreRASchedStrategy : public GenericScheduler {
7073
unsigned getRemLat(SchedBoundary *Zone) const;
7174

7275
// A large group of stores at the bottom is spread upwards.
73-
std::set<const SUnit*> StoresGroup;
76+
std::set<const SUnit *> StoresGroup;
7477
bool FirstStoreInGroupScheduled;
7578
void initializeStoresGroup();
7679

@@ -86,7 +89,8 @@ class SystemZPreRASchedStrategy : public GenericScheduler {
8689
SchedBoundary *Zone) const override;
8790

8891
public:
89-
SystemZPreRASchedStrategy(const MachineSchedContext *C) : GenericScheduler(C) {
92+
SystemZPreRASchedStrategy(const MachineSchedContext *C)
93+
: GenericScheduler(C) {
9094
initializePrioRegClasses(C->MF->getRegInfo().getTargetRegisterInfo());
9195
}
9296

llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,15 @@ SystemZTargetMachine::getSubtargetImpl(const Function &F) const {
212212
}
213213

214214
ScheduleDAGInstrs *
215-
SystemZTargetMachine::createMachineScheduler(MachineSchedContext *C) const {
215+
SystemZTargetMachine::createMachineScheduler(MachineSchedContext *C) const {
216216
// Use GenericScheduler if requested on CL or for Z10, which has no sched
217217
// model.
218218
if (GenericSched ||
219219
!C->MF->getSubtarget().getSchedModel().hasInstrSchedModel())
220220
return nullptr;
221221

222222
ScheduleDAGMILive *DAG =
223-
new ScheduleDAGMILive(C, std::make_unique<SystemZPreRASchedStrategy>(C));
223+
new ScheduleDAGMILive(C, std::make_unique<SystemZPreRASchedStrategy>(C));
224224
DAG->addMutation(createCopyConstrainDAGMutation(DAG->TII, DAG->TRI));
225225
return DAG;
226226
}

0 commit comments

Comments
 (0)