2002-08-09 20:08:03 +00:00
|
|
|
//===-- SchedPriorities.h - Encapsulate scheduling heuristics --*- C++ -*--===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2003-10-21 15:17:13 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file was developed by the LLVM research group and is distributed under
|
|
|
|
// the University of Illinois Open Source License. See LICENSE.TXT for details.
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2003-10-21 15:17:13 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2001-09-18 12:49:39 +00:00
|
|
|
// Strategy:
|
|
|
|
// Priority ordering rules:
|
|
|
|
// (1) Max delay, which is the order of the heap S.candsAsHeap.
|
|
|
|
// (2) Instruction that frees up a register.
|
|
|
|
// (3) Instruction that has the maximum number of dependent instructions.
|
|
|
|
// Note that rules 2 and 3 are only used if issue conflicts prevent
|
|
|
|
// choosing a higher priority instruction by rule 1.
|
2002-08-09 20:08:03 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2001-08-28 23:06:49 +00:00
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_SCHEDPRIORITIES_H
|
|
|
|
#define LLVM_CODEGEN_SCHEDPRIORITIES_H
|
|
|
|
|
2001-09-14 16:56:32 +00:00
|
|
|
#include "SchedGraph.h"
|
2001-09-07 21:18:16 +00:00
|
|
|
#include "llvm/CodeGen/InstrScheduling.h"
|
2002-12-29 03:13:05 +00:00
|
|
|
#include "llvm/Target/TargetSchedInfo.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/hash_set"
|
2001-09-28 22:56:31 +00:00
|
|
|
#include <list>
|
2002-08-09 20:08:03 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2002-03-23 22:51:58 +00:00
|
|
|
class Function;
|
2001-08-28 23:06:49 +00:00
|
|
|
class MachineInstr;
|
|
|
|
class SchedulingManager;
|
2002-04-27 07:27:19 +00:00
|
|
|
class FunctionLiveVarInfo;
|
2001-08-28 23:06:49 +00:00
|
|
|
|
2002-02-04 05:55:42 +00:00
|
|
|
//---------------------------------------------------------------------------
|
2002-02-04 02:44:20 +00:00
|
|
|
// Debug option levels for instruction scheduling
|
2002-02-04 05:55:42 +00:00
|
|
|
|
2002-02-04 02:44:20 +00:00
|
|
|
enum SchedDebugLevel_t {
|
|
|
|
Sched_NoDebugInfo,
|
2002-03-24 03:45:35 +00:00
|
|
|
Sched_Disable,
|
2005-04-21 23:30:14 +00:00
|
|
|
Sched_PrintMachineCode,
|
2002-02-04 02:44:20 +00:00
|
|
|
Sched_PrintSchedTrace,
|
|
|
|
Sched_PrintSchedGraphs,
|
|
|
|
};
|
|
|
|
|
2002-05-22 17:08:27 +00:00
|
|
|
extern SchedDebugLevel_t SchedDebugLevel;
|
2001-08-28 23:06:49 +00:00
|
|
|
|
2002-02-04 05:55:42 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// Function: instrIsFeasible
|
2005-04-21 23:30:14 +00:00
|
|
|
//
|
2002-02-04 05:55:42 +00:00
|
|
|
// Purpose:
|
|
|
|
// Used by the priority analysis to filter out instructions
|
|
|
|
// that are not feasible to issue in the current cycle.
|
|
|
|
// Should only be used during schedule construction..
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool instrIsFeasible(const SchedulingManager &S, MachineOpCode opCode);
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-08-28 23:06:49 +00:00
|
|
|
struct NodeDelayPair {
|
|
|
|
const SchedGraphNode* node;
|
2005-01-16 04:20:30 +00:00
|
|
|
CycleCount_t delay;
|
|
|
|
NodeDelayPair(const SchedGraphNode* n, CycleCount_t d) : node(n), delay(d) {}
|
2002-01-20 22:54:45 +00:00
|
|
|
inline bool operator<(const NodeDelayPair& np) { return delay < np.delay; }
|
2001-08-28 23:06:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
NDPLessThan(const NodeDelayPair* np1, const NodeDelayPair* np2)
|
|
|
|
{
|
2002-01-20 22:54:45 +00:00
|
|
|
return np1->delay < np2->delay;
|
2001-08-28 23:06:49 +00:00
|
|
|
}
|
|
|
|
|
2003-06-02 22:45:07 +00:00
|
|
|
class NodeHeap : public std::list<NodeDelayPair*> {
|
|
|
|
NodeHeap(const NodeHeap&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const NodeHeap&); // DO NOT IMPLEMENT
|
2001-08-28 23:06:49 +00:00
|
|
|
public:
|
2002-01-20 22:54:45 +00:00
|
|
|
typedef std::list<NodeDelayPair*>::iterator iterator;
|
|
|
|
typedef std::list<NodeDelayPair*>::const_iterator const_iterator;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2001-08-28 23:06:49 +00:00
|
|
|
public:
|
2002-02-04 16:35:45 +00:00
|
|
|
NodeHeap() : _size(0) {}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2002-02-04 16:35:45 +00:00
|
|
|
inline unsigned size() const { return _size; }
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
const SchedGraphNode* getNode (const_iterator i) const { return (*i)->node; }
|
|
|
|
CycleCount_t getDelay(const_iterator i) const { return (*i)->delay;}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
inline void makeHeap() {
|
2001-08-28 23:06:49 +00:00
|
|
|
// make_heap(begin(), end(), NDPLessThan);
|
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
inline iterator findNode(const SchedGraphNode* node) {
|
2001-08-28 23:06:49 +00:00
|
|
|
for (iterator I=begin(); I != end(); ++I)
|
|
|
|
if (getNode(I) == node)
|
2005-07-27 05:53:44 +00:00
|
|
|
return I;
|
2001-08-28 23:06:49 +00:00
|
|
|
return end();
|
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
inline void removeNode (const SchedGraphNode* node) {
|
2001-08-28 23:06:49 +00:00
|
|
|
iterator ndpPtr = findNode(node);
|
|
|
|
if (ndpPtr != end())
|
|
|
|
{
|
2005-07-27 05:53:44 +00:00
|
|
|
delete *ndpPtr;
|
|
|
|
erase(ndpPtr);
|
|
|
|
--_size;
|
2001-08-28 23:06:49 +00:00
|
|
|
}
|
|
|
|
};
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
void insert(const SchedGraphNode* node, CycleCount_t delay) {
|
2001-08-28 23:06:49 +00:00
|
|
|
NodeDelayPair* ndp = new NodeDelayPair(node, delay);
|
|
|
|
if (_size == 0 || front()->delay < delay)
|
|
|
|
push_front(ndp);
|
|
|
|
else
|
|
|
|
{
|
2005-07-27 05:53:44 +00:00
|
|
|
iterator I=begin();
|
|
|
|
for ( ; I != end() && getDelay(I) >= delay; ++I)
|
|
|
|
;
|
|
|
|
std::list<NodeDelayPair*>::insert(I, ndp);
|
2001-08-28 23:06:49 +00:00
|
|
|
}
|
|
|
|
_size++;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
unsigned int _size;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-06-02 22:45:07 +00:00
|
|
|
class SchedPriorities {
|
|
|
|
SchedPriorities(const SchedPriorities&); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const SchedPriorities &); // DO NOT IMPLEMENT
|
2001-08-28 23:06:49 +00:00
|
|
|
public:
|
2002-03-23 22:51:58 +00:00
|
|
|
SchedPriorities(const Function *F, const SchedGraph *G,
|
2002-04-27 07:27:19 +00:00
|
|
|
FunctionLiveVarInfo &LVI);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
|
|
|
|
2001-08-28 23:06:49 +00:00
|
|
|
// This must be called before scheduling begins.
|
2005-07-27 05:53:44 +00:00
|
|
|
void initialize ();
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
CycleCount_t getTime () const { return curTime; }
|
|
|
|
CycleCount_t getEarliestReadyTime () const { return earliestReadyTime; }
|
|
|
|
unsigned getNumReady () const { return candsAsHeap.size(); }
|
|
|
|
bool nodeIsReady (const SchedGraphNode* node) const {
|
2001-08-28 23:06:49 +00:00
|
|
|
return (candsAsSet.find(node) != candsAsSet.end());
|
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
void issuedReadyNodeAt (CycleCount_t curTime,
|
|
|
|
const SchedGraphNode* node);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
void insertReady (const SchedGraphNode* node);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
void updateTime (CycleCount_t /*unused*/);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
const SchedGraphNode* getNextHighest (const SchedulingManager& S,
|
|
|
|
CycleCount_t curTime);
|
|
|
|
// choose next highest priority instr
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2001-08-28 23:06:49 +00:00
|
|
|
private:
|
|
|
|
typedef NodeHeap::iterator candIndex;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2001-08-28 23:06:49 +00:00
|
|
|
private:
|
2005-01-16 04:20:30 +00:00
|
|
|
CycleCount_t curTime;
|
2001-08-28 23:06:49 +00:00
|
|
|
const SchedGraph* graph;
|
2002-04-27 07:27:19 +00:00
|
|
|
FunctionLiveVarInfo &methodLiveVarInfo;
|
2002-07-24 21:21:33 +00:00
|
|
|
hash_map<const MachineInstr*, bool> lastUseMap;
|
2005-01-16 04:20:30 +00:00
|
|
|
std::vector<CycleCount_t> nodeDelayVec;
|
|
|
|
std::vector<CycleCount_t> nodeEarliestUseVec;
|
|
|
|
std::vector<CycleCount_t> earliestReadyTimeForNode;
|
|
|
|
CycleCount_t earliestReadyTime;
|
2005-07-27 05:53:44 +00:00
|
|
|
NodeHeap candsAsHeap; // candidate nodes, ready to go
|
2002-07-24 21:21:33 +00:00
|
|
|
hash_set<const SchedGraphNode*> candsAsSet; //same entries as candsAsHeap,
|
2005-07-27 05:53:44 +00:00
|
|
|
// but as set for fast lookup
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<candIndex> mcands; // holds pointers into cands
|
2005-07-27 05:53:44 +00:00
|
|
|
candIndex nextToTry; // next cand after the last
|
|
|
|
// one tried in this cycle
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
int chooseByRule1 (std::vector<candIndex>& mcands);
|
|
|
|
int chooseByRule2 (std::vector<candIndex>& mcands);
|
|
|
|
int chooseByRule3 (std::vector<candIndex>& mcands);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
void findSetWithMaxDelay (std::vector<candIndex>& mcands,
|
|
|
|
const SchedulingManager& S);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
void computeDelays (const SchedGraph* graph);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
void initializeReadyHeap (const SchedGraph* graph);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-07-27 05:53:44 +00:00
|
|
|
bool instructionHasLastUse (FunctionLiveVarInfo& LVI,
|
|
|
|
const SchedGraphNode* graphNode);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2001-08-28 23:06:49 +00:00
|
|
|
// NOTE: The next two return references to the actual vector entries.
|
2002-07-08 22:59:23 +00:00
|
|
|
// Use the following two if you don't need to modify the value.
|
2005-07-27 05:53:44 +00:00
|
|
|
CycleCount_t& getNodeDelayRef (const SchedGraphNode* node) {
|
2001-08-28 23:06:49 +00:00
|
|
|
assert(node->getNodeId() < nodeDelayVec.size());
|
|
|
|
return nodeDelayVec[node->getNodeId()];
|
|
|
|
}
|
2005-01-16 04:20:30 +00:00
|
|
|
CycleCount_t& getEarliestReadyTimeForNodeRef (const SchedGraphNode* node) {
|
2002-07-08 22:59:23 +00:00
|
|
|
assert(node->getNodeId() < earliestReadyTimeForNode.size());
|
|
|
|
return earliestReadyTimeForNode[node->getNodeId()];
|
|
|
|
}
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-01-16 04:20:30 +00:00
|
|
|
CycleCount_t getNodeDelay (const SchedGraphNode* node) const {
|
2005-04-21 23:30:14 +00:00
|
|
|
return ((SchedPriorities*) this)->getNodeDelayRef(node);
|
2002-07-08 22:59:23 +00:00
|
|
|
}
|
2005-01-16 04:20:30 +00:00
|
|
|
CycleCount_t getEarliestReadyTimeForNode(const SchedGraphNode* node) const {
|
2002-07-08 22:59:23 +00:00
|
|
|
return ((SchedPriorities*) this)->getEarliestReadyTimeForNodeRef(node);
|
2001-08-28 23:06:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-01-16 04:20:30 +00:00
|
|
|
inline void SchedPriorities::updateTime(CycleCount_t c) {
|
2001-08-28 23:06:49 +00:00
|
|
|
curTime = c;
|
|
|
|
nextToTry = candsAsHeap.begin();
|
|
|
|
mcands.clear();
|
|
|
|
}
|
|
|
|
|
2002-11-02 22:07:51 +00:00
|
|
|
std::ostream &operator<<(std::ostream &os, const NodeDelayPair* nd);
|
2001-08-28 23:06:49 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-08-28 23:06:49 +00:00
|
|
|
#endif
|