LLVM  6.0.0svn
GCNIterativeScheduler.h
Go to the documentation of this file.
1 //===- GCNIterativeScheduler.h - GCN Scheduler ------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
11 #define LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
12 
13 #include "GCNRegPressure.h"
14 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/Support/Allocator.h"
18 #include <limits>
19 #include <memory>
20 #include <vector>
21 
22 namespace llvm {
23 
24 class MachineInstr;
25 class SUnit;
26 class raw_ostream;
27 
30 
31 public:
32  enum StrategyKind {
36  };
37 
39  StrategyKind S);
40 
41  void schedule() override;
42 
46  unsigned RegionInstrs) override;
47 
48  void finalizeSchedule() override;
49 
50 protected:
52 
54  std::vector<MachineInstr *> Schedule;
56  };
57 
58  struct Region {
59  // Fields except for BestSchedule are supposed to reflect current IR state
60  // `const` fields are to emphasize they shouldn't change for any schedule.
62  // End is either a boundary instruction or end of basic block
64  const unsigned NumRegionInstrs;
66 
67  // best schedule for the region so far (not scheduled yet)
68  std::unique_ptr<TentativeSchedule> BestSchedule;
69  };
70 
72  std::vector<Region*> Regions;
73 
77 
78  class BuildDAG;
80 
81  template <typename Range>
83  Range &&Schedule) const;
84 
87 
89  return getRegionPressure(R.Begin, R.End);
90  }
91 
92  void setBestSchedule(Region &R,
94  const GCNRegPressure &MaxRP = GCNRegPressure());
95 
96  void scheduleBest(Region &R);
97 
98  std::vector<MachineInstr*> detachSchedule(ScheduleRef Schedule) const;
99 
100  void sortRegionsByPressure(unsigned TargetOcc);
101 
102  template <typename Range>
103  void scheduleRegion(Region &R, Range &&Schedule,
104  const GCNRegPressure &MaxRP = GCNRegPressure());
105 
106  unsigned tryMaximizeOccupancy(unsigned TargetOcc =
108 
109  void scheduleLegacyMaxOccupancy(bool TryMaximizeOccupancy = true);
110  void scheduleMinReg(bool force = false);
111 
112  void printRegions(raw_ostream &OS) const;
113  void printSchedResult(raw_ostream &OS,
114  const Region *R,
115  const GCNRegPressure &RP) const;
116  void printSchedRP(raw_ostream &OS,
117  const GCNRegPressure &Before,
118  const GCNRegPressure &After) const;
119 };
120 
121 } // end namespace llvm
122 
123 #endif // LLVM_LIB_TARGET_AMDGPU_GCNITERATIVESCHEDULER_H
unsigned tryMaximizeOccupancy(unsigned TargetOcc=std::numeric_limits< unsigned >::max())
uint64_t CallInst * C
void enterRegion(MachineBasicBlock *BB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End, unsigned RegionInstrs) override
Implement the ScheduleDAGInstrs interface for handling the next scheduling region.
GCNRegPressure getRegionPressure(MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End) const
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
void sortRegionsByPressure(unsigned TargetOcc)
SpecificBumpPtrAllocator< Region > Alloc
std::vector< Region * > Regions
std::vector< MachineInstr * > detachSchedule(ScheduleRef Schedule) const
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
ScheduleDAGMILive is an implementation of ScheduleDAGInstrs that schedules machine instructions while...
void printRegions(raw_ostream &OS) const
void finalizeSchedule() override
Allow targets to perform final scheduling actions at the level of the whole MachineFunction.
void scheduleLegacyMaxOccupancy(bool TryMaximizeOccupancy=true)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
void printSchedRP(raw_ostream &OS, const GCNRegPressure &Before, const GCNRegPressure &After) const
void setBestSchedule(Region &R, ScheduleRef Schedule, const GCNRegPressure &MaxRP=GCNRegPressure())
static const unsigned End
GCNRegPressure getSchedulePressure(const Region &R, Range &&Schedule) const
void schedule() override
Implement ScheduleDAGInstrs interface for scheduling a sequence of reorderable instructions.
A BumpPtrAllocator that allows only elements of a specific type to be allocated.
Definition: Allocator.h:385
const MachineBasicBlock::iterator End
ScheduleDAGMILive(MachineSchedContext *C, std::unique_ptr< MachineSchedStrategy > S)
void printSchedResult(raw_ostream &OS, const Region *R, const GCNRegPressure &RP) const
GCNIterativeScheduler(MachineSchedContext *C, StrategyKind S)
MachineSchedContext provides enough context from the MachineScheduler pass for the target to instanti...
void scheduleRegion(Region &R, Range &&Schedule, const GCNRegPressure &MaxRP=GCNRegPressure())
void scheduleMinReg(bool force=false)
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
MachineBasicBlock * BB
The block in which to insert instructions.
GCNRegPressure getRegionPressure(const Region &R) const
std::unique_ptr< TentativeSchedule > BestSchedule