2016-08-30 03:42:52 +08:00
|
|
|
//===-- GCNSchedStrategy.h - GCN Scheduler Strategy -*- C++ -*-------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// \file
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H
|
|
|
|
#define LLVM_LIB_TARGET_AMDGPU_GCNSCHEDSTRATEGY_H
|
|
|
|
|
2017-05-16 23:43:52 +08:00
|
|
|
#include "GCNRegPressure.h"
|
2016-08-30 03:42:52 +08:00
|
|
|
#include "llvm/CodeGen/MachineScheduler.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2017-03-01 03:20:33 +08:00
|
|
|
class SIMachineFunctionInfo;
|
2016-08-30 03:42:52 +08:00
|
|
|
class SIRegisterInfo;
|
2017-03-01 03:20:33 +08:00
|
|
|
class SISubtarget;
|
2016-08-30 03:42:52 +08:00
|
|
|
|
|
|
|
/// This is a minimal scheduler strategy. The main difference between this
|
|
|
|
/// and the GenericScheduler is that GCNSchedStrategy uses different
|
|
|
|
/// heuristics to determine excess/critical pressure sets. Its goal is to
|
|
|
|
/// maximize kernel occupancy (i.e. maximum number of waves per simd).
|
|
|
|
class GCNMaxOccupancySchedStrategy : public GenericScheduler {
|
2017-02-16 01:19:50 +08:00
|
|
|
friend class GCNScheduleDAGMILive;
|
2016-08-30 03:42:52 +08:00
|
|
|
|
|
|
|
SUnit *pickNodeBidirectional(bool &IsTopNode);
|
|
|
|
|
|
|
|
void pickNodeFromQueue(SchedBoundary &Zone, const CandPolicy &ZonePolicy,
|
|
|
|
const RegPressureTracker &RPTracker,
|
|
|
|
SchedCandidate &Cand);
|
|
|
|
|
|
|
|
void initCandidate(SchedCandidate &Cand, SUnit *SU,
|
|
|
|
bool AtTop, const RegPressureTracker &RPTracker,
|
|
|
|
const SIRegisterInfo *SRI,
|
2017-02-16 01:19:50 +08:00
|
|
|
unsigned SGPRPressure, unsigned VGPRPressure);
|
2016-08-30 03:42:52 +08:00
|
|
|
|
2017-02-16 01:19:50 +08:00
|
|
|
unsigned SGPRExcessLimit;
|
|
|
|
unsigned VGPRExcessLimit;
|
|
|
|
unsigned SGPRCriticalLimit;
|
|
|
|
unsigned VGPRCriticalLimit;
|
2016-08-30 03:42:52 +08:00
|
|
|
|
2017-03-01 03:20:33 +08:00
|
|
|
unsigned TargetOccupancy;
|
|
|
|
|
|
|
|
MachineFunction *MF;
|
|
|
|
|
2016-08-30 03:42:52 +08:00
|
|
|
public:
|
|
|
|
GCNMaxOccupancySchedStrategy(const MachineSchedContext *C);
|
|
|
|
|
|
|
|
SUnit *pickNode(bool &IsTopNode) override;
|
2017-02-16 01:19:50 +08:00
|
|
|
|
|
|
|
void initialize(ScheduleDAGMI *DAG) override;
|
2017-03-21 21:15:46 +08:00
|
|
|
|
|
|
|
void setTargetOccupancy(unsigned Occ) { TargetOccupancy = Occ; }
|
2017-02-16 01:19:50 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
class GCNScheduleDAGMILive : public ScheduleDAGMILive {
|
2017-03-01 01:22:39 +08:00
|
|
|
|
2017-03-01 03:20:33 +08:00
|
|
|
const SISubtarget &ST;
|
|
|
|
|
2018-05-31 13:36:04 +08:00
|
|
|
SIMachineFunctionInfo &MFI;
|
2017-03-01 03:20:33 +08:00
|
|
|
|
2017-07-13 14:48:39 +08:00
|
|
|
// Occupancy target at the beginning of function scheduling cycle.
|
2017-03-01 03:20:33 +08:00
|
|
|
unsigned StartingOccupancy;
|
|
|
|
|
|
|
|
// Minimal real occupancy recorder for the function.
|
|
|
|
unsigned MinOccupancy;
|
|
|
|
|
|
|
|
// Scheduling stage number.
|
|
|
|
unsigned Stage;
|
|
|
|
|
2017-05-17 00:11:26 +08:00
|
|
|
// Current region index.
|
|
|
|
size_t RegionIdx;
|
|
|
|
|
2017-03-01 03:20:33 +08:00
|
|
|
// Vecor of regions recorder for later rescheduling
|
2017-03-29 05:48:54 +08:00
|
|
|
SmallVector<std::pair<MachineBasicBlock::iterator,
|
|
|
|
MachineBasicBlock::iterator>, 32> Regions;
|
2017-03-01 03:20:33 +08:00
|
|
|
|
2017-05-17 00:11:26 +08:00
|
|
|
// Region live-in cache.
|
|
|
|
SmallVector<GCNRPTracker::LiveRegSet, 32> LiveIns;
|
|
|
|
|
|
|
|
// Region pressure cache.
|
|
|
|
SmallVector<GCNRegPressure, 32> Pressure;
|
2017-03-01 01:22:39 +08:00
|
|
|
|
2017-05-17 00:11:26 +08:00
|
|
|
// Temporary basic block live-in cache.
|
|
|
|
DenseMap<const MachineBasicBlock*, GCNRPTracker::LiveRegSet> MBBLiveIns;
|
2017-03-01 01:22:39 +08:00
|
|
|
|
2017-05-16 23:43:52 +08:00
|
|
|
// Return current region pressure.
|
|
|
|
GCNRegPressure getRealRegPressure() const;
|
2017-03-01 01:22:39 +08:00
|
|
|
|
2017-05-17 00:11:26 +08:00
|
|
|
// Compute and cache live-ins and pressure for all regions in block.
|
|
|
|
void computeBlockPressure(const MachineBasicBlock *MBB);
|
|
|
|
|
|
|
|
|
2017-02-16 01:19:50 +08:00
|
|
|
public:
|
|
|
|
GCNScheduleDAGMILive(MachineSchedContext *C,
|
2017-03-01 03:20:33 +08:00
|
|
|
std::unique_ptr<MachineSchedStrategy> S);
|
|
|
|
|
2017-02-16 01:19:50 +08:00
|
|
|
void schedule() override;
|
2017-03-01 01:22:39 +08:00
|
|
|
|
|
|
|
void finalizeSchedule() override;
|
2016-08-30 03:42:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End namespace llvm
|
|
|
|
|
|
|
|
#endif // GCNSCHEDSTRATEGY_H
|