1 //===- PPCMachineScheduler.cpp - MI Scheduler for PowerPC -------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "PPCMachineScheduler.h"
10 #include "MCTargetDesc/PPCMCTargetDesc.h"
15 DisableAddiLoadHeuristic("disable-ppc-sched-addi-load",
16 cl::desc("Disable scheduling addi instruction before"
17 "load for ppc"), cl::Hidden
);
19 bool PPCPreRASchedStrategy::biasAddiLoadCandidate(SchedCandidate
&Cand
,
20 SchedCandidate
&TryCand
,
21 SchedBoundary
&Zone
) const {
22 if (DisableAddiLoadHeuristic
)
25 auto isADDIInstr
= [&] (const MachineInstr
&Inst
) {
26 return Inst
.getOpcode() == PPC::ADDI
|| Inst
.getOpcode() == PPC::ADDI8
;
29 SchedCandidate
&FirstCand
= Zone
.isTop() ? TryCand
: Cand
;
30 SchedCandidate
&SecondCand
= Zone
.isTop() ? Cand
: TryCand
;
31 if (isADDIInstr(*FirstCand
.SU
->getInstr()) &&
32 SecondCand
.SU
->getInstr()->mayLoad()) {
33 TryCand
.Reason
= Stall
;
36 if (FirstCand
.SU
->getInstr()->mayLoad() &&
37 isADDIInstr(*SecondCand
.SU
->getInstr())) {
38 TryCand
.Reason
= NoCand
;
45 void PPCPreRASchedStrategy::tryCandidate(SchedCandidate
&Cand
,
46 SchedCandidate
&TryCand
,
47 SchedBoundary
*Zone
) const {
48 GenericScheduler::tryCandidate(Cand
, TryCand
, Zone
);
50 if (!Cand
.isValid() || !Zone
)
53 // Add powerpc specific heuristic only when TryCand isn't selected or
54 // selected as node order.
55 if (TryCand
.Reason
!= NodeOrder
&& TryCand
.Reason
!= NoCand
)
58 // There are some benefits to schedule the ADDI before the load to hide the
59 // latency, as RA may create a true dependency between the load and addi.
60 if (biasAddiLoadCandidate(Cand
, TryCand
, *Zone
))
64 void PPCPostRASchedStrategy::enterMBB(MachineBasicBlock
*MBB
) {
65 // Custom PPC PostRA specific behavior here.
66 PostGenericScheduler::enterMBB(MBB
);
69 void PPCPostRASchedStrategy::leaveMBB() {
70 // Custom PPC PostRA specific behavior here.
71 PostGenericScheduler::leaveMBB();
74 void PPCPostRASchedStrategy::initialize(ScheduleDAGMI
*Dag
) {
75 // Custom PPC PostRA specific initialization here.
76 PostGenericScheduler::initialize(Dag
);
79 SUnit
*PPCPostRASchedStrategy::pickNode(bool &IsTopNode
) {
80 // Custom PPC PostRA specific scheduling here.
81 return PostGenericScheduler::pickNode(IsTopNode
);