Skip to content

Commit eaff28c

Browse files
authored
[MachineScheduler] Turn SU->isScheduled check into an assert in pickNode() (#160145)
It is unnecessary and confusing to have a do/while loop that checks SU->isScheduled as this should never be true. ScheduleDAGMI::updateQueues() is always called after pickNode() and it sets isScheduled on the SU. Turn this into an assertion instead.
1 parent 14f5504 commit eaff28c

File tree

1 file changed

+59
-61
lines changed

1 file changed

+59
-61
lines changed

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 59 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4157,33 +4157,32 @@ SUnit *GenericScheduler::pickNode(bool &IsTopNode) {
41574157
return nullptr;
41584158
}
41594159
SUnit *SU;
4160-
do {
4161-
if (RegionPolicy.OnlyTopDown) {
4162-
SU = Top.pickOnlyChoice();
4163-
if (!SU) {
4164-
CandPolicy NoPolicy;
4165-
TopCand.reset(NoPolicy);
4166-
pickNodeFromQueue(Top, NoPolicy, DAG->getTopRPTracker(), TopCand);
4167-
assert(TopCand.Reason != NoCand && "failed to find a candidate");
4168-
tracePick(TopCand);
4169-
SU = TopCand.SU;
4170-
}
4171-
IsTopNode = true;
4172-
} else if (RegionPolicy.OnlyBottomUp) {
4173-
SU = Bot.pickOnlyChoice();
4174-
if (!SU) {
4175-
CandPolicy NoPolicy;
4176-
BotCand.reset(NoPolicy);
4177-
pickNodeFromQueue(Bot, NoPolicy, DAG->getBotRPTracker(), BotCand);
4178-
assert(BotCand.Reason != NoCand && "failed to find a candidate");
4179-
tracePick(BotCand);
4180-
SU = BotCand.SU;
4181-
}
4182-
IsTopNode = false;
4183-
} else {
4184-
SU = pickNodeBidirectional(IsTopNode);
4160+
if (RegionPolicy.OnlyTopDown) {
4161+
SU = Top.pickOnlyChoice();
4162+
if (!SU) {
4163+
CandPolicy NoPolicy;
4164+
TopCand.reset(NoPolicy);
4165+
pickNodeFromQueue(Top, NoPolicy, DAG->getTopRPTracker(), TopCand);
4166+
assert(TopCand.Reason != NoCand && "failed to find a candidate");
4167+
tracePick(TopCand);
4168+
SU = TopCand.SU;
41854169
}
4186-
} while (SU->isScheduled);
4170+
IsTopNode = true;
4171+
} else if (RegionPolicy.OnlyBottomUp) {
4172+
SU = Bot.pickOnlyChoice();
4173+
if (!SU) {
4174+
CandPolicy NoPolicy;
4175+
BotCand.reset(NoPolicy);
4176+
pickNodeFromQueue(Bot, NoPolicy, DAG->getBotRPTracker(), BotCand);
4177+
assert(BotCand.Reason != NoCand && "failed to find a candidate");
4178+
tracePick(BotCand);
4179+
SU = BotCand.SU;
4180+
}
4181+
IsTopNode = false;
4182+
} else {
4183+
SU = pickNodeBidirectional(IsTopNode);
4184+
}
4185+
assert(!SU->isScheduled && "SUnit scheduled twice.");
41874186

41884187
// If IsTopNode, then SU is in Top.Available and must be removed. Otherwise,
41894188
// if isTopReady(), then SU is in either Top.Available or Top.Pending.
@@ -4524,43 +4523,42 @@ SUnit *PostGenericScheduler::pickNode(bool &IsTopNode) {
45244523
return nullptr;
45254524
}
45264525
SUnit *SU;
4527-
do {
4528-
if (RegionPolicy.OnlyBottomUp) {
4529-
SU = Bot.pickOnlyChoice();
4530-
if (SU) {
4531-
tracePick(Only1, /*IsTopNode=*/true, /*IsPostRA=*/true);
4532-
} else {
4533-
CandPolicy NoPolicy;
4534-
BotCand.reset(NoPolicy);
4535-
// Set the bottom-up policy based on the state of the current bottom
4536-
// zone and the instructions outside the zone, including the top zone.
4537-
setPolicy(BotCand.Policy, /*IsPostRA=*/true, Bot, nullptr);
4538-
pickNodeFromQueue(Bot, BotCand);
4539-
assert(BotCand.Reason != NoCand && "failed to find a candidate");
4540-
tracePick(BotCand, /*IsPostRA=*/true);
4541-
SU = BotCand.SU;
4542-
}
4543-
IsTopNode = false;
4544-
} else if (RegionPolicy.OnlyTopDown) {
4545-
SU = Top.pickOnlyChoice();
4546-
if (SU) {
4547-
tracePick(Only1, /*IsTopNode=*/true, /*IsPostRA=*/true);
4548-
} else {
4549-
CandPolicy NoPolicy;
4550-
TopCand.reset(NoPolicy);
4551-
// Set the top-down policy based on the state of the current top zone
4552-
// and the instructions outside the zone, including the bottom zone.
4553-
setPolicy(TopCand.Policy, /*IsPostRA=*/true, Top, nullptr);
4554-
pickNodeFromQueue(Top, TopCand);
4555-
assert(TopCand.Reason != NoCand && "failed to find a candidate");
4556-
tracePick(TopCand, /*IsPostRA=*/true);
4557-
SU = TopCand.SU;
4558-
}
4559-
IsTopNode = true;
4526+
if (RegionPolicy.OnlyBottomUp) {
4527+
SU = Bot.pickOnlyChoice();
4528+
if (SU) {
4529+
tracePick(Only1, /*IsTopNode=*/true, /*IsPostRA=*/true);
45604530
} else {
4561-
SU = pickNodeBidirectional(IsTopNode);
4531+
CandPolicy NoPolicy;
4532+
BotCand.reset(NoPolicy);
4533+
// Set the bottom-up policy based on the state of the current bottom
4534+
// zone and the instructions outside the zone, including the top zone.
4535+
setPolicy(BotCand.Policy, /*IsPostRA=*/true, Bot, nullptr);
4536+
pickNodeFromQueue(Bot, BotCand);
4537+
assert(BotCand.Reason != NoCand && "failed to find a candidate");
4538+
tracePick(BotCand, /*IsPostRA=*/true);
4539+
SU = BotCand.SU;
45624540
}
4563-
} while (SU->isScheduled);
4541+
IsTopNode = false;
4542+
} else if (RegionPolicy.OnlyTopDown) {
4543+
SU = Top.pickOnlyChoice();
4544+
if (SU) {
4545+
tracePick(Only1, /*IsTopNode=*/true, /*IsPostRA=*/true);
4546+
} else {
4547+
CandPolicy NoPolicy;
4548+
TopCand.reset(NoPolicy);
4549+
// Set the top-down policy based on the state of the current top zone
4550+
// and the instructions outside the zone, including the bottom zone.
4551+
setPolicy(TopCand.Policy, /*IsPostRA=*/true, Top, nullptr);
4552+
pickNodeFromQueue(Top, TopCand);
4553+
assert(TopCand.Reason != NoCand && "failed to find a candidate");
4554+
tracePick(TopCand, /*IsPostRA=*/true);
4555+
SU = TopCand.SU;
4556+
}
4557+
IsTopNode = true;
4558+
} else {
4559+
SU = pickNodeBidirectional(IsTopNode);
4560+
}
4561+
assert(!SU->isScheduled && "SUnit scheduled twice.");
45644562

45654563
if (SU->isTopReady())
45664564
Top.removeReady(SU);

0 commit comments

Comments
 (0)