LLVM 20.0.0git
GCNIterativeScheduler.h
Go to the documentation of this file.
1//===- GCNIterativeScheduler.h - GCN Scheduler ------------------*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file defines the class GCNIterativeScheduler, which uses an iterative
11/// approach to find a best schedule for GCN architecture. It basically makes
12/// use of various lightweight schedules, scores them, chooses best one based on
13/// their scores, and finally implements the chosen one.
14///
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
18#define LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
19
20#include "GCNRegPressure.h"
22
23namespace llvm {
24
25class MachineInstr;
26class SUnit;
27class raw_ostream;
28
31
32public:
38 };
39
41 StrategyKind S);
42
43 void schedule() override;
44
48 unsigned RegionInstrs) override;
49
50 void finalizeSchedule() override;
51
52protected:
54
56 std::vector<MachineInstr *> Schedule;
58 };
59
60 struct Region {
61 // Fields except for BestSchedule are supposed to reflect current IR state
62 // `const` fields are to emphasize they shouldn't change for any schedule.
64 // End is either a boundary instruction or end of basic block
66 const unsigned NumRegionInstrs;
68
69 // best schedule for the region so far (not scheduled yet)
70 std::unique_ptr<TentativeSchedule> BestSchedule;
71 };
72
74 std::vector<Region*> Regions;
75
79
80 class BuildDAG;
82
83 template <typename Range>
85 Range &&Schedule) const;
86
89
91 return getRegionPressure(R.Begin, R.End);
92 }
93
94 void setBestSchedule(Region &R,
95 ScheduleRef Schedule,
96 const GCNRegPressure &MaxRP = GCNRegPressure());
97
98 void scheduleBest(Region &R);
99
100 std::vector<MachineInstr*> detachSchedule(ScheduleRef Schedule) const;
101
102 void sortRegionsByPressure(unsigned TargetOcc);
103
104 template <typename Range>
105 void scheduleRegion(Region &R, Range &&Schedule,
106 const GCNRegPressure &MaxRP = GCNRegPressure());
107
108 unsigned tryMaximizeOccupancy(unsigned TargetOcc =
109 std::numeric_limits<unsigned>::max());
110
111 void scheduleLegacyMaxOccupancy(bool TryMaximizeOccupancy = true);
112 void scheduleMinReg(bool force = false);
113 void scheduleILP(bool TryMaximizeOccupancy = true);
114
115 void printRegions(raw_ostream &OS) const;
117 const Region *R,
118 const GCNRegPressure &RP) const;
120 const GCNRegPressure &Before,
121 const GCNRegPressure &After) const;
122};
123
124} // end namespace llvm
125
126#endif // LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
bool End
Definition: ELF_riscv.cpp:480
This file defines the GCNRegPressure class, which tracks registry pressure by bookkeeping number of S...
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
raw_pwrite_stream & OS
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
SpecificBumpPtrAllocator< Region > Alloc
void printSchedRP(raw_ostream &OS, const GCNRegPressure &Before, const GCNRegPressure &After) const
void enterRegion(MachineBasicBlock *BB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, unsigned RegionInstrs) override
Implement the ScheduleDAGInstrs interface for handling the next scheduling region.
void sortRegionsByPressure(unsigned TargetOcc)
std::vector< Region * > Regions
void scheduleILP(bool TryMaximizeOccupancy=true)
void printSchedResult(raw_ostream &OS, const Region *R, const GCNRegPressure &RP) const
unsigned tryMaximizeOccupancy(unsigned TargetOcc=std::numeric_limits< unsigned >::max())
void printRegions(raw_ostream &OS) const
void setBestSchedule(Region &R, ScheduleRef Schedule, const GCNRegPressure &MaxRP=GCNRegPressure())
void finalizeSchedule() override
Allow targets to perform final scheduling actions at the level of the whole MachineFunction.
void scheduleLegacyMaxOccupancy(bool TryMaximizeOccupancy=true)
void schedule() override
Implement ScheduleDAGInstrs interface for scheduling a sequence of reorderable instructions.
GCNRegPressure getSchedulePressure(const Region &R, Range &&Schedule) const
void scheduleMinReg(bool force=false)
GCNRegPressure getRegionPressure(MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End) const
ArrayRef< const SUnit * > ScheduleRef
void scheduleRegion(Region &R, Range &&Schedule, const GCNRegPressure &MaxRP=GCNRegPressure())
GCNRegPressure getRegionPressure(const Region &R) const
std::vector< MachineInstr * > detachSchedule(ScheduleRef Schedule) const
MachineBasicBlock * BB
The block in which to insert instructions.
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
Definition: Allocator.h:389
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
const MachineBasicBlock::iterator End
std::unique_ptr< TentativeSchedule > BestSchedule
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...