2003-09-30 18:37:50 +00:00
|
|
|
//===- Target/TargetSchedInfo.h - Target Instruction Sched Info -*- C++ -*-===//
|
2005-04-21 20:59:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +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 20:59:05 +00:00
|
|
|
//
|
2003-10-20 20:19:47 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-09-18 12:38:31 +00:00
|
|
|
//
|
|
|
|
// This file describes the target machine to the instruction scheduler.
|
|
|
|
//
|
2004-07-27 04:00:54 +00:00
|
|
|
// NOTE: This file is currently sparc V9 specific.
|
|
|
|
//
|
2001-09-18 12:38:31 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2002-12-29 03:13:05 +00:00
|
|
|
#ifndef LLVM_TARGET_TARGETSCHEDINFO_H
|
|
|
|
#define LLVM_TARGET_TARGETSCHEDINFO_H
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2003-01-14 22:00:31 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
2004-09-01 22:55:40 +00:00
|
|
|
#include "llvm/ADT/hash_map"
|
2002-10-28 23:54:23 +00:00
|
|
|
#include <string>
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2005-04-21 20:59:05 +00:00
|
|
|
typedef long long CycleCount_t;
|
2005-01-16 01:31:31 +00:00
|
|
|
static const CycleCount_t HUGE_LATENCY = ~((long long) 1 << (sizeof(CycleCount_t)-2));
|
2005-04-21 20:59:05 +00:00
|
|
|
static const CycleCount_t INVALID_LATENCY = -HUGE_LATENCY;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2005-04-21 20:59:05 +00:00
|
|
|
// class MachineResource
|
2001-09-18 12:38:31 +00:00
|
|
|
// class CPUResource
|
2005-04-21 20:59:05 +00:00
|
|
|
//
|
2001-09-18 12:38:31 +00:00
|
|
|
// Purpose:
|
|
|
|
// Representation of a single machine resource used in specifying
|
|
|
|
// resource usages of machine instructions for scheduling.
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
typedef unsigned resourceId_t;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2004-04-30 20:40:38 +00:00
|
|
|
struct CPUResource {
|
2002-01-20 22:54:45 +00:00
|
|
|
const std::string rname;
|
2001-09-18 12:38:31 +00:00
|
|
|
resourceId_t rid;
|
2004-04-30 20:40:38 +00:00
|
|
|
int maxNumUsers; // MAXINT if no restriction
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2004-04-30 20:46:40 +00:00
|
|
|
CPUResource(const std::string& resourceName, int maxUsers);
|
2004-05-08 16:13:26 +00:00
|
|
|
static CPUResource* getCPUResource(resourceId_t id);
|
2001-09-18 12:38:31 +00:00
|
|
|
private:
|
|
|
|
static resourceId_t nextId;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// struct InstrClassRUsage
|
2005-04-21 20:59:05 +00:00
|
|
|
// struct InstrRUsageDelta
|
|
|
|
// struct InstrIssueDelta
|
|
|
|
// struct InstrRUsage
|
|
|
|
//
|
2001-09-18 12:38:31 +00:00
|
|
|
// Purpose:
|
2005-04-21 20:59:05 +00:00
|
|
|
// The first three are structures used to specify machine resource
|
2001-09-18 12:38:31 +00:00
|
|
|
// usages for each instruction in a machine description file:
|
|
|
|
// InstrClassRUsage : resource usages common to all instrs. in a class
|
2005-04-21 20:59:05 +00:00
|
|
|
// InstrRUsageDelta : add/delete resource usage for individual instrs.
|
|
|
|
// InstrIssueDelta : add/delete instr. issue info for individual instrs
|
|
|
|
//
|
2001-09-18 12:38:31 +00:00
|
|
|
// The last one (InstrRUsage) is the internal representation of
|
|
|
|
// instruction resource usage constructed from the above three.
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
const int MAX_NUM_SLOTS = 32;
|
|
|
|
const int MAX_NUM_CYCLES = 32;
|
|
|
|
|
|
|
|
struct InstrClassRUsage {
|
|
|
|
InstrSchedClass schedClass;
|
2005-04-22 03:46:24 +00:00
|
|
|
int totCycles;
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
// Issue restrictions common to instructions in this class
|
2002-02-04 05:55:10 +00:00
|
|
|
unsigned maxNumIssue;
|
2005-04-22 03:46:24 +00:00
|
|
|
bool isSingleIssue;
|
|
|
|
bool breaksGroup;
|
|
|
|
CycleCount_t numBubbles;
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
// Feasible slots to use for instructions in this class.
|
|
|
|
// The size of vector S[] is `numSlots'.
|
2002-02-04 05:55:10 +00:00
|
|
|
unsigned numSlots;
|
|
|
|
unsigned feasibleSlots[MAX_NUM_SLOTS];
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
// Resource usages common to instructions in this class.
|
|
|
|
// The size of vector V[] is `numRUEntries'.
|
2002-02-04 05:55:10 +00:00
|
|
|
unsigned numRUEntries;
|
2001-09-18 12:38:31 +00:00
|
|
|
struct {
|
|
|
|
resourceId_t resourceId;
|
2002-02-04 05:55:10 +00:00
|
|
|
unsigned startCycle;
|
2005-04-22 03:46:24 +00:00
|
|
|
int numCycles;
|
2002-02-04 05:55:10 +00:00
|
|
|
} V[MAX_NUM_CYCLES];
|
2001-09-18 12:38:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct InstrRUsageDelta {
|
|
|
|
MachineOpCode opCode;
|
2005-04-22 03:46:24 +00:00
|
|
|
resourceId_t resourceId;
|
2002-02-04 05:55:10 +00:00
|
|
|
unsigned startCycle;
|
2005-04-22 03:46:24 +00:00
|
|
|
int numCycles;
|
2001-09-18 12:38:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Specify instruction issue restrictions for individual instructions
|
|
|
|
// that differ from the common rules for the class.
|
2005-04-21 20:59:05 +00:00
|
|
|
//
|
2001-09-18 12:38:31 +00:00
|
|
|
struct InstrIssueDelta {
|
2005-04-22 03:46:24 +00:00
|
|
|
MachineOpCode opCode;
|
|
|
|
bool isSingleIssue;
|
|
|
|
bool breaksGroup;
|
|
|
|
CycleCount_t numBubbles;
|
2001-09-18 12:38:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct InstrRUsage {
|
2005-04-22 03:46:24 +00:00
|
|
|
bool sameAsClass;
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
// Issue restrictions for this instruction
|
2005-04-22 03:46:24 +00:00
|
|
|
bool isSingleIssue;
|
|
|
|
bool breaksGroup;
|
|
|
|
CycleCount_t numBubbles;
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
// Feasible slots to use for this instruction.
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<bool> feasibleSlots;
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
// Resource usages for this instruction, with one resource vector per cycle.
|
2005-04-22 03:46:24 +00:00
|
|
|
CycleCount_t numCycles;
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<std::vector<resourceId_t> > resourcesByCycle;
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
private:
|
|
|
|
// Conveniences for initializing this structure
|
2002-02-04 05:55:10 +00:00
|
|
|
void setTo(const InstrClassRUsage& classRU);
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
void addIssueDelta(const InstrIssueDelta& delta) {
|
|
|
|
sameAsClass = false;
|
|
|
|
isSingleIssue = delta.isSingleIssue;
|
|
|
|
breaksGroup = delta.breaksGroup;
|
|
|
|
numBubbles = delta.numBubbles;
|
|
|
|
}
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2005-04-22 03:46:24 +00:00
|
|
|
void addUsageDelta(const InstrRUsageDelta& delta);
|
|
|
|
void setMaxSlots(int maxNumSlots) {
|
2002-02-04 05:55:10 +00:00
|
|
|
feasibleSlots.resize(maxNumSlots);
|
|
|
|
}
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2005-04-22 03:46:24 +00:00
|
|
|
friend class TargetSchedInfo; // give access to these functions
|
2002-02-04 05:55:10 +00:00
|
|
|
};
|
2001-09-18 12:38:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2005-04-21 20:59:05 +00:00
|
|
|
/// TargetSchedInfo - Common interface to machine information for
|
2002-12-29 03:13:05 +00:00
|
|
|
/// instruction scheduling
|
|
|
|
///
|
2004-10-27 16:14:51 +00:00
|
|
|
class TargetSchedInfo {
|
|
|
|
public:
|
2001-11-08 05:22:43 +00:00
|
|
|
const TargetMachine& target;
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
unsigned maxNumIssueTotal;
|
2005-04-22 03:46:24 +00:00
|
|
|
int longestIssueConflict;
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
protected:
|
|
|
|
inline const InstrRUsage& getInstrRUsage(MachineOpCode opCode) const {
|
|
|
|
assert(opCode >= 0 && opCode < (int) instrRUsages.size());
|
|
|
|
return instrRUsages[opCode];
|
|
|
|
}
|
2002-10-28 04:53:18 +00:00
|
|
|
const InstrClassRUsage& getClassRUsage(const InstrSchedClass& sc) const {
|
|
|
|
assert(sc < numSchedClasses);
|
2001-09-18 12:38:31 +00:00
|
|
|
return classRUsages[sc];
|
|
|
|
}
|
2002-10-28 23:54:23 +00:00
|
|
|
|
|
|
|
private:
|
2002-12-29 03:13:05 +00:00
|
|
|
TargetSchedInfo(const TargetSchedInfo &); // DO NOT IMPLEMENT
|
|
|
|
void operator=(const TargetSchedInfo &); // DO NOT IMPLEMENT
|
2001-09-18 12:38:31 +00:00
|
|
|
public:
|
2005-04-22 03:46:24 +00:00
|
|
|
TargetSchedInfo(const TargetMachine& tgt,
|
|
|
|
int _numSchedClasses,
|
|
|
|
const InstrClassRUsage* _classRUsages,
|
|
|
|
const InstrRUsageDelta* _usageDeltas,
|
|
|
|
const InstrIssueDelta* _issueDeltas,
|
|
|
|
unsigned _numUsageDeltas,
|
|
|
|
unsigned _numIssueDeltas);
|
|
|
|
virtual ~TargetSchedInfo() {}
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2003-01-14 22:00:31 +00:00
|
|
|
inline const TargetInstrInfo& getInstrInfo() const {
|
2001-09-18 12:38:31 +00:00
|
|
|
return *mii;
|
|
|
|
}
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2005-04-22 03:46:24 +00:00
|
|
|
inline int getNumSchedClasses() const {
|
2001-09-18 12:38:31 +00:00
|
|
|
return numSchedClasses;
|
2005-04-21 20:59:05 +00:00
|
|
|
}
|
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
inline unsigned getMaxNumIssueTotal() const {
|
2001-09-18 12:38:31 +00:00
|
|
|
return maxNumIssueTotal;
|
|
|
|
}
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
inline unsigned getMaxIssueForClass(const InstrSchedClass& sc) const {
|
2002-10-28 04:53:18 +00:00
|
|
|
assert(sc < numSchedClasses);
|
2001-09-18 12:38:31 +00:00
|
|
|
return classRUsages[sc].maxNumIssue;
|
|
|
|
}
|
|
|
|
|
2005-04-22 03:46:24 +00:00
|
|
|
inline InstrSchedClass getSchedClass(MachineOpCode opCode) const {
|
2001-09-18 12:38:31 +00:00
|
|
|
return getInstrInfo().getSchedClass(opCode);
|
2005-04-21 20:59:05 +00:00
|
|
|
}
|
|
|
|
|
2005-04-22 03:46:24 +00:00
|
|
|
inline bool instrCanUseSlot(MachineOpCode opCode,
|
|
|
|
unsigned s) const {
|
2001-09-18 12:38:31 +00:00
|
|
|
assert(s < getInstrRUsage(opCode).feasibleSlots.size() && "Invalid slot!");
|
|
|
|
return getInstrRUsage(opCode).feasibleSlots[s];
|
|
|
|
}
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2005-04-22 03:46:24 +00:00
|
|
|
inline int getLongestIssueConflict() const {
|
2001-09-18 12:38:31 +00:00
|
|
|
return longestIssueConflict;
|
|
|
|
}
|
2002-10-13 00:37:46 +00:00
|
|
|
|
2005-04-22 03:46:24 +00:00
|
|
|
inline int getMinIssueGap(MachineOpCode fromOp,
|
|
|
|
MachineOpCode toOp) const {
|
2002-10-13 00:37:46 +00:00
|
|
|
assert(fromOp < (int) issueGaps.size());
|
|
|
|
const std::vector<int>& toGaps = issueGaps[fromOp];
|
|
|
|
return (toOp < (int) toGaps.size())? toGaps[toOp] : 0;
|
2001-09-18 12:38:31 +00:00
|
|
|
}
|
2002-10-13 00:37:46 +00:00
|
|
|
|
|
|
|
inline const std::vector<MachineOpCode>&
|
2005-04-22 03:46:24 +00:00
|
|
|
getConflictList(MachineOpCode opCode) const {
|
2002-10-13 00:37:46 +00:00
|
|
|
assert(opCode < (int) conflictLists.size());
|
|
|
|
return conflictLists[opCode];
|
2001-09-18 12:38:31 +00:00
|
|
|
}
|
2002-10-13 00:37:46 +00:00
|
|
|
|
2005-04-22 03:46:24 +00:00
|
|
|
inline bool isSingleIssue(MachineOpCode opCode) const {
|
2001-09-18 12:38:31 +00:00
|
|
|
return getInstrRUsage(opCode).isSingleIssue;
|
|
|
|
}
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2005-04-22 03:46:24 +00:00
|
|
|
inline bool breaksIssueGroup(MachineOpCode opCode) const {
|
2001-09-18 12:38:31 +00:00
|
|
|
return getInstrRUsage(opCode).breaksGroup;
|
|
|
|
}
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2005-04-22 03:46:24 +00:00
|
|
|
inline unsigned numBubblesAfter(MachineOpCode opCode) const {
|
2001-09-18 12:38:31 +00:00
|
|
|
return getInstrRUsage(opCode).numBubbles;
|
|
|
|
}
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2003-04-07 00:00:36 +00:00
|
|
|
inline unsigned getCPUResourceNum(int rd)const{
|
|
|
|
for(unsigned i=0;i<resourceNumVector.size();i++){
|
|
|
|
if(resourceNumVector[i].first == rd) return resourceNumVector[i].second;
|
|
|
|
}
|
|
|
|
assert( 0&&"resource not found");
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2003-04-07 00:00:36 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
protected:
|
2005-04-22 03:46:24 +00:00
|
|
|
virtual void initializeResources();
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
private:
|
2002-01-20 22:54:45 +00:00
|
|
|
void computeInstrResources(const std::vector<InstrRUsage>& instrRUForClasses);
|
|
|
|
void computeIssueGaps(const std::vector<InstrRUsage>& instrRUForClasses);
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2002-10-13 00:37:46 +00:00
|
|
|
void setGap(int gap, MachineOpCode fromOp, MachineOpCode toOp) {
|
|
|
|
std::vector<int>& toGaps = issueGaps[fromOp];
|
|
|
|
if (toOp >= (int) toGaps.size())
|
|
|
|
toGaps.resize(toOp+1);
|
|
|
|
toGaps[toOp] = gap;
|
|
|
|
}
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2003-04-07 00:00:36 +00:00
|
|
|
public:
|
2003-04-07 00:25:09 +00:00
|
|
|
std::vector<std::pair<int,int> > resourceNumVector;
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
protected:
|
2005-04-22 03:46:24 +00:00
|
|
|
unsigned numSchedClasses;
|
2003-01-14 22:00:31 +00:00
|
|
|
const TargetInstrInfo* mii;
|
2005-04-22 03:46:24 +00:00
|
|
|
const InstrClassRUsage* classRUsages; // raw array by sclass
|
|
|
|
const InstrRUsageDelta* usageDeltas; // raw array [1:numUsageDeltas]
|
|
|
|
const InstrIssueDelta* issueDeltas; // raw array [1:numIssueDeltas]
|
|
|
|
unsigned numUsageDeltas;
|
|
|
|
unsigned numIssueDeltas;
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2002-10-13 00:37:46 +00:00
|
|
|
std::vector<InstrRUsage> instrRUsages; // indexed by opcode
|
|
|
|
std::vector<std::vector<int> > issueGaps; // indexed by [opcode1][opcode2]
|
|
|
|
std::vector<std::vector<MachineOpCode> >
|
2005-04-22 03:46:24 +00:00
|
|
|
conflictLists; // indexed by [opcode]
|
2003-04-07 00:00:36 +00:00
|
|
|
|
|
|
|
|
2004-05-08 16:13:26 +00:00
|
|
|
friend class ModuloSchedulingPass;
|
2005-06-17 03:59:51 +00:00
|
|
|
friend class ModuloSchedulingSBPass;
|
2004-08-01 18:57:38 +00:00
|
|
|
friend class MSSchedule;
|
2005-06-17 03:59:51 +00:00
|
|
|
friend class MSScheduleSB;
|
|
|
|
friend class MSchedGraphSB;
|
2005-04-21 20:59:05 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
};
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
#endif
|