LLVM  13.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 
23 namespace llvm {
24 
25 class MachineInstr;
26 class SUnit;
27 class raw_ostream;
28 
31 
32 public:
33  enum StrategyKind {
38  };
39 
41  StrategyKind S);
42 
43  void schedule() override;
44 
48  unsigned RegionInstrs) override;
49 
50  void finalizeSchedule() override;
51 
52 protected:
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 
88  MachineBasicBlock::iterator End) const;
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 =
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;
116  void printSchedResult(raw_ostream &OS,
117  const Region *R,
118  const GCNRegPressure &RP) const;
119  void printSchedRP(raw_ostream &OS,
120  const GCNRegPressure &Before,
121  const GCNRegPressure &After) const;
122 };
123 
124 } // end namespace llvm
125 
126 #endif // LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
llvm::GCNIterativeScheduler::TentativeSchedule
Definition: GCNIterativeScheduler.h:55
llvm
Definition: AllocatorList.h:23
llvm::GCNRegPressure
Definition: GCNRegPressure.h:30
llvm::GCNIterativeScheduler::tryMaximizeOccupancy
unsigned tryMaximizeOccupancy(unsigned TargetOcc=std::numeric_limits< unsigned >::max())
Definition: GCNIterativeScheduler.cpp:434
llvm::GCNIterativeScheduler::getRegionPressure
GCNRegPressure getRegionPressure(const Region &R) const
Definition: GCNIterativeScheduler.h:90
llvm::GCNIterativeScheduler::SCHEDULE_ILP
@ SCHEDULE_ILP
Definition: GCNIterativeScheduler.h:37
llvm::GCNIterativeScheduler::SCHEDULE_MINREGONLY
@ SCHEDULE_MINREGONLY
Definition: GCNIterativeScheduler.h:34
llvm::GCNIterativeScheduler::SCHEDULE_LEGACYMAXOCCUPANCY
@ SCHEDULE_LEGACYMAXOCCUPANCY
Definition: GCNIterativeScheduler.h:36
llvm::SpecificBumpPtrAllocator
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
Definition: Allocator.h:376
llvm::GCNIterativeScheduler::getRegionPressure
GCNRegPressure getRegionPressure(MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End) const
Definition: GCNIterativeScheduler.cpp:232
llvm::GCNIterativeScheduler::TentativeSchedule::MaxPressure
GCNRegPressure MaxPressure
Definition: GCNIterativeScheduler.h:57
llvm::GCNIterativeScheduler::Region::End
const MachineBasicBlock::iterator End
Definition: GCNIterativeScheduler.h:65
llvm::GCNIterativeScheduler::Regions
std::vector< Region * > Regions
Definition: GCNIterativeScheduler.h:74
llvm::GCNIterativeScheduler::schedule
void schedule() override
Implement ScheduleDAGInstrs interface for scheduling a sequence of reorderable instructions.
Definition: GCNIterativeScheduler.cpp:296
llvm::GCNIterativeScheduler::TentativeSchedule::Schedule
std::vector< MachineInstr * > Schedule
Definition: GCNIterativeScheduler.h:56
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:180
llvm::GCNIterativeScheduler::printRegions
void printRegions(raw_ostream &OS) const
Definition: GCNIterativeScheduler.cpp:93
llvm::GCNIterativeScheduler::finalizeSchedule
void finalizeSchedule() override
Allow targets to perform final scheduling actions at the level of the whole MachineFunction.
Definition: GCNIterativeScheduler.cpp:307
llvm::AArch64::RP
@ RP
Definition: AArch64ISelLowering.h:468
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::GCNIterativeScheduler::printSchedResult
void printSchedResult(raw_ostream &OS, const Region *R, const GCNRegPressure &RP) const
Definition: GCNIterativeScheduler.cpp:105
llvm::GCNIterativeScheduler::getSchedulePressure
GCNRegPressure getSchedulePressure(const Region &R, Range &&Schedule) const
Definition: GCNIterativeScheduler.cpp:264
llvm::GCNIterativeScheduler::Context
MachineSchedContext * Context
Definition: GCNIterativeScheduler.h:76
llvm::GCNIterativeScheduler::OverrideLegacyStrategy
Definition: GCNIterativeScheduler.cpp:158
llvm::GCNIterativeScheduler::UPTracker
GCNUpwardRPTracker UPTracker
Definition: GCNIterativeScheduler.h:78
llvm::GCNIterativeScheduler
Definition: GCNIterativeScheduler.h:29
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:50
llvm::GCNUpwardRPTracker
Definition: GCNRegPressure.h:145
llvm::GCNIterativeScheduler::scheduleRegion
void scheduleRegion(Region &R, Range &&Schedule, const GCNRegPressure &MaxRP=GCNRegPressure())
Definition: GCNIterativeScheduler.cpp:356
force
therefore end up llgh r3 lr r0 br r14 but truncating the load would lh r3 br r14 Functions ret i64 and ought to be implemented ngr r0 br r14 but two address optimizations reverse the order of the AND and force
Definition: README.txt:112
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:95
llvm::GCNIterativeScheduler::scheduleBest
void scheduleBest(Region &R)
Definition: GCNIterativeScheduler.cpp:347
llvm::GCNIterativeScheduler::sortRegionsByPressure
void sortRegionsByPressure(unsigned TargetOcc)
Definition: GCNIterativeScheduler.cpp:418
llvm::GCNIterativeScheduler::Region::BestSchedule
std::unique_ptr< TentativeSchedule > BestSchedule
Definition: GCNIterativeScheduler.h:70
llvm::MachineSchedContext
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
Definition: MachineScheduler.h:120
llvm::GCNIterativeScheduler::SCHEDULE_MINREGFORCED
@ SCHEDULE_MINREGFORCED
Definition: GCNIterativeScheduler.h:35
llvm::GCNIterativeScheduler::Alloc
SpecificBumpPtrAllocator< Region > Alloc
Definition: GCNIterativeScheduler.h:73
llvm::GCNIterativeScheduler::ScheduleRef
ArrayRef< const SUnit * > ScheduleRef
Definition: GCNIterativeScheduler.h:53
llvm::GCNIterativeScheduler::Region
Definition: GCNIterativeScheduler.h:60
llvm::GCNIterativeScheduler::Strategy
const StrategyKind Strategy
Definition: GCNIterativeScheduler.h:77
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::GCNIterativeScheduler::scheduleLegacyMaxOccupancy
void scheduleLegacyMaxOccupancy(bool TryMaximizeOccupancy=true)
Definition: GCNIterativeScheduler.cpp:471
llvm::GCNIterativeScheduler::Region::MaxPressure
GCNRegPressure MaxPressure
Definition: GCNIterativeScheduler.h:67
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::GCNIterativeScheduler::setBestSchedule
void setBestSchedule(Region &R, ScheduleRef Schedule, const GCNRegPressure &MaxRP=GCNRegPressure())
Definition: GCNIterativeScheduler.cpp:340
llvm::ScheduleDAGMILive::ScheduleDAGMILive
ScheduleDAGMILive(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S)
Definition: MachineScheduler.h:428
llvm::GCNIterativeScheduler::Region::Begin
MachineBasicBlock::iterator Begin
Definition: GCNIterativeScheduler.h:63
llvm::GCNIterativeScheduler::StrategyKind
StrategyKind
Definition: GCNIterativeScheduler.h:33
llvm::GCNIterativeScheduler::BuildDAG
Definition: GCNIterativeScheduler.cpp:127
GCNRegPressure.h
llvm::GCNIterativeScheduler::detachSchedule
std::vector< MachineInstr * > detachSchedule(ScheduleRef Schedule) const
Definition: GCNIterativeScheduler.cpp:321
llvm::ScheduleDAGInstrs::BB
MachineBasicBlock * BB
The block in which to insert instructions.
Definition: ScheduleDAGInstrs.h:145
MachineScheduler.h
llvm::GCNIterativeScheduler::enterRegion
void enterRegion(MachineBasicBlock *BB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, unsigned RegionInstrs) override
Implement the ScheduleDAGInstrs interface for handling the next scheduling region.
Definition: GCNIterativeScheduler.cpp:283
llvm::GCNIterativeScheduler::scheduleILP
void scheduleILP(bool TryMaximizeOccupancy=true)
Definition: GCNIterativeScheduler.cpp:559
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
llvm::GCNIterativeScheduler::GCNIterativeScheduler
GCNIterativeScheduler(MachineSchedContext *C, StrategyKind S)
Definition: GCNIterativeScheduler.cpp:222
llvm::ScheduleDAGMILive
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
Definition: MachineScheduler.h:385
llvm::Region
Definition: RegionInfo.h:889
llvm::GCNIterativeScheduler::scheduleMinReg
void scheduleMinReg(bool force=false)
Definition: GCNIterativeScheduler.cpp:526
llvm::MachineInstrBundleIterator< MachineInstr >
llvm::GCNIterativeScheduler::printSchedRP
void printSchedRP(raw_ostream &OS, const GCNRegPressure &Before, const GCNRegPressure &After) const
Definition: GCNIterativeScheduler.cpp:115
llvm::GCNIterativeScheduler::Region::NumRegionInstrs
const unsigned NumRegionInstrs
Definition: GCNIterativeScheduler.h:66