2012-02-01 23:13:57 +01:00
|
|
|
//===----- ResourcePriorityQueue.h - A DFA-oriented priority queue -------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-02-01 23:13:57 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the ResourcePriorityQueue class, which is a
|
|
|
|
// SchedulingPriorityQueue that schedules using DFA state to
|
|
|
|
// reduce the length of the critical path through the basic block
|
|
|
|
// on VLIW platforms.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 01:45:19 +01:00
|
|
|
#ifndef LLVM_CODEGEN_RESOURCEPRIORITYQUEUE_H
|
|
|
|
#define LLVM_CODEGEN_RESOURCEPRIORITYQUEUE_H
|
2012-02-01 23:13:57 +01:00
|
|
|
|
|
|
|
#include "llvm/CodeGen/DFAPacketizer.h"
|
|
|
|
#include "llvm/CodeGen/ScheduleDAG.h"
|
2012-12-03 18:02:12 +01:00
|
|
|
#include "llvm/CodeGen/SelectionDAGISel.h"
|
2017-11-08 02:01:31 +01:00
|
|
|
#include "llvm/CodeGen/TargetInstrInfo.h"
|
2017-11-17 02:07:10 +01:00
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
2012-02-01 23:13:57 +01:00
|
|
|
#include "llvm/MC/MCInstrItineraries.h"
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class ResourcePriorityQueue;
|
|
|
|
|
|
|
|
/// Sorting functions for the Available queue.
|
2017-09-14 20:33:25 +02:00
|
|
|
struct resource_sort {
|
2012-02-01 23:13:57 +01:00
|
|
|
ResourcePriorityQueue *PQ;
|
|
|
|
explicit resource_sort(ResourcePriorityQueue *pq) : PQ(pq) {}
|
|
|
|
|
2018-07-16 20:51:40 +02:00
|
|
|
bool operator()(const SUnit* LHS, const SUnit* RHS) const;
|
2012-02-01 23:13:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class ResourcePriorityQueue : public SchedulingPriorityQueue {
|
|
|
|
/// SUnits - The SUnits for the current graph.
|
|
|
|
std::vector<SUnit> *SUnits;
|
|
|
|
|
|
|
|
/// NumNodesSolelyBlocking - This vector contains, for every node in the
|
|
|
|
/// Queue, the number of nodes that the node is the sole unscheduled
|
|
|
|
/// predecessor for. This is used as a tie-breaker heuristic for better
|
|
|
|
/// mobility.
|
|
|
|
std::vector<unsigned> NumNodesSolelyBlocking;
|
|
|
|
|
|
|
|
/// Queue - The queue.
|
|
|
|
std::vector<SUnit*> Queue;
|
|
|
|
|
|
|
|
/// RegPressure - Tracking current reg pressure per register class.
|
|
|
|
///
|
|
|
|
std::vector<unsigned> RegPressure;
|
|
|
|
|
|
|
|
/// RegLimit - Tracking the number of allocatable registers per register
|
|
|
|
/// class.
|
|
|
|
std::vector<unsigned> RegLimit;
|
|
|
|
|
|
|
|
resource_sort Picker;
|
|
|
|
const TargetRegisterInfo *TRI;
|
|
|
|
const TargetLowering *TLI;
|
|
|
|
const TargetInstrInfo *TII;
|
|
|
|
const InstrItineraryData* InstrItins;
|
|
|
|
/// ResourcesModel - Represents VLIW state.
|
|
|
|
/// Not limited to VLIW targets per say, but assumes
|
|
|
|
/// definition of DFA by a target.
|
2015-03-03 21:49:08 +01:00
|
|
|
std::unique_ptr<DFAPacketizer> ResourcesModel;
|
2012-02-01 23:13:57 +01:00
|
|
|
|
|
|
|
/// Resource model - packet/bundle model. Purely
|
|
|
|
/// internal at the time.
|
|
|
|
std::vector<SUnit*> Packet;
|
|
|
|
|
|
|
|
/// Heuristics for estimating register pressure.
|
|
|
|
unsigned ParallelLiveRanges;
|
2016-06-21 07:10:24 +02:00
|
|
|
int HorizontalVerticalBalance;
|
2012-02-01 23:13:57 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
ResourcePriorityQueue(SelectionDAGISel *IS);
|
2012-03-08 00:00:49 +01:00
|
|
|
|
2014-03-08 07:31:39 +01:00
|
|
|
bool isBottomUp() const override { return false; }
|
2012-02-01 23:13:57 +01:00
|
|
|
|
2014-03-08 07:31:39 +01:00
|
|
|
void initNodes(std::vector<SUnit> &sunits) override;
|
2012-02-01 23:13:57 +01:00
|
|
|
|
2014-03-08 07:31:39 +01:00
|
|
|
void addNode(const SUnit *SU) override {
|
2012-02-01 23:13:57 +01:00
|
|
|
NumNodesSolelyBlocking.resize(SUnits->size(), 0);
|
|
|
|
}
|
|
|
|
|
2014-03-08 07:31:39 +01:00
|
|
|
void updateNode(const SUnit *SU) override {}
|
2012-02-01 23:13:57 +01:00
|
|
|
|
2014-03-08 07:31:39 +01:00
|
|
|
void releaseState() override {
|
2014-04-15 08:32:26 +02:00
|
|
|
SUnits = nullptr;
|
2012-02-01 23:13:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getLatency(unsigned NodeNum) const {
|
|
|
|
assert(NodeNum < (*SUnits).size());
|
|
|
|
return (*SUnits)[NodeNum].getHeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned getNumSolelyBlockNodes(unsigned NodeNum) const {
|
|
|
|
assert(NodeNum < NumNodesSolelyBlocking.size());
|
|
|
|
return NumNodesSolelyBlocking[NodeNum];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Single cost function reflecting benefit of scheduling SU
|
|
|
|
/// in the current cycle.
|
2016-06-21 07:10:24 +02:00
|
|
|
int SUSchedulingCost (SUnit *SU);
|
2012-02-01 23:13:57 +01:00
|
|
|
|
|
|
|
/// InitNumRegDefsLeft - Determine the # of regs defined by this node.
|
|
|
|
///
|
|
|
|
void initNumRegDefsLeft(SUnit *SU);
|
|
|
|
void updateNumRegDefsLeft(SUnit *SU);
|
2016-06-21 07:10:24 +02:00
|
|
|
int regPressureDelta(SUnit *SU, bool RawPressure = false);
|
|
|
|
int rawRegPressureDelta (SUnit *SU, unsigned RCId);
|
2012-02-01 23:13:57 +01:00
|
|
|
|
2014-03-08 07:31:39 +01:00
|
|
|
bool empty() const override { return Queue.empty(); }
|
2012-02-01 23:13:57 +01:00
|
|
|
|
2014-03-08 07:31:39 +01:00
|
|
|
void push(SUnit *U) override;
|
2012-02-01 23:13:57 +01:00
|
|
|
|
2014-03-08 07:31:39 +01:00
|
|
|
SUnit *pop() override;
|
2012-02-01 23:13:57 +01:00
|
|
|
|
2014-03-08 07:31:39 +01:00
|
|
|
void remove(SUnit *SU) override;
|
2012-02-01 23:13:57 +01:00
|
|
|
|
2012-03-08 00:00:49 +01:00
|
|
|
/// scheduledNode - Main resource tracking point.
|
2018-07-16 20:51:40 +02:00
|
|
|
void scheduledNode(SUnit *SU) override;
|
2012-02-01 23:13:57 +01:00
|
|
|
bool isResourceAvailable(SUnit *SU);
|
|
|
|
void reserveResources(SUnit *SU);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void adjustPriorityOfUnscheduledPreds(SUnit *SU);
|
|
|
|
SUnit *getSingleUnscheduledPred(SUnit *SU);
|
|
|
|
unsigned numberRCValPredInSU (SUnit *SU, unsigned RCId);
|
|
|
|
unsigned numberRCValSuccInSU (SUnit *SU, unsigned RCId);
|
|
|
|
};
|
2015-06-23 11:49:53 +02:00
|
|
|
}
|
2012-02-01 23:13:57 +01:00
|
|
|
|
|
|
|
#endif
|