2003-09-30 18:37:50 +00:00
|
|
|
//===- Target/TargetSchedInfo.h - Target Instruction Sched Info -*- C++ -*-===//
|
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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
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 {
|
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
typedef long long cycles_t;
|
2002-02-04 05:55:10 +00:00
|
|
|
static const cycles_t HUGE_LATENCY = ~((long long) 1 << (sizeof(cycles_t)-2));
|
|
|
|
static const cycles_t INVALID_LATENCY = -HUGE_LATENCY;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
// class MachineResource
|
|
|
|
// class CPUResource
|
|
|
|
//
|
|
|
|
// 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
|
2001-09-18 12:38:31 +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
|
|
|
|
// struct InstrRUsageDelta
|
|
|
|
// struct InstrIssueDelta
|
|
|
|
// struct InstrRUsage
|
|
|
|
//
|
|
|
|
// Purpose:
|
|
|
|
// The first three are structures used to specify machine resource
|
|
|
|
// usages for each instruction in a machine description file:
|
|
|
|
// InstrClassRUsage : resource usages common to all instrs. in a class
|
|
|
|
// InstrRUsageDelta : add/delete resource usage for individual instrs.
|
|
|
|
// InstrIssueDelta : add/delete instr. issue info for individual instrs
|
|
|
|
//
|
|
|
|
// 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;
|
|
|
|
int totCycles;
|
|
|
|
|
|
|
|
// Issue restrictions common to instructions in this class
|
2002-02-04 05:55:10 +00:00
|
|
|
unsigned maxNumIssue;
|
|
|
|
bool isSingleIssue;
|
|
|
|
bool breaksGroup;
|
|
|
|
cycles_t numBubbles;
|
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];
|
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;
|
|
|
|
int numCycles;
|
|
|
|
} V[MAX_NUM_CYCLES];
|
2001-09-18 12:38:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct InstrRUsageDelta {
|
|
|
|
MachineOpCode opCode;
|
|
|
|
resourceId_t resourceId;
|
2002-02-04 05:55:10 +00:00
|
|
|
unsigned startCycle;
|
2001-09-18 12:38:31 +00:00
|
|
|
int numCycles;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Specify instruction issue restrictions for individual instructions
|
|
|
|
// that differ from the common rules for the class.
|
|
|
|
//
|
|
|
|
struct InstrIssueDelta {
|
|
|
|
MachineOpCode opCode;
|
|
|
|
bool isSingleIssue;
|
|
|
|
bool breaksGroup;
|
|
|
|
cycles_t numBubbles;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct InstrRUsage {
|
|
|
|
bool sameAsClass;
|
|
|
|
|
|
|
|
// Issue restrictions for this instruction
|
|
|
|
bool isSingleIssue;
|
|
|
|
bool breaksGroup;
|
|
|
|
cycles_t numBubbles;
|
|
|
|
|
|
|
|
// Feasible slots to use for this instruction.
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<bool> feasibleSlots;
|
2001-09-18 12:38:31 +00:00
|
|
|
|
|
|
|
// Resource usages for this instruction, with one resource vector per cycle.
|
|
|
|
cycles_t numCycles;
|
2002-01-20 22:54:45 +00:00
|
|
|
std::vector<std::vector<resourceId_t> > resourcesByCycle;
|
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
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
void addUsageDelta (const InstrRUsageDelta& delta);
|
|
|
|
void setMaxSlots (int maxNumSlots) {
|
|
|
|
feasibleSlots.resize(maxNumSlots);
|
|
|
|
}
|
2001-09-18 12:38:31 +00:00
|
|
|
|
2002-12-29 03:13:05 +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
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
2002-12-29 03:13:05 +00:00
|
|
|
/// TargetSchedInfo - Common interface to machine information for
|
|
|
|
/// instruction scheduling
|
|
|
|
///
|
|
|
|
struct TargetSchedInfo {
|
2001-11-08 05:22:43 +00:00
|
|
|
const TargetMachine& target;
|
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
unsigned maxNumIssueTotal;
|
2001-09-18 12:38:31 +00:00
|
|
|
int longestIssueConflict;
|
|
|
|
|
|
|
|
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:
|
2002-12-29 03:13:05 +00:00
|
|
|
/*ctor*/ TargetSchedInfo (const TargetMachine& tgt,
|
2001-11-08 05:22:43 +00:00
|
|
|
int _numSchedClasses,
|
2001-09-18 12:38:31 +00:00
|
|
|
const InstrClassRUsage* _classRUsages,
|
|
|
|
const InstrRUsageDelta* _usageDeltas,
|
|
|
|
const InstrIssueDelta* _issueDeltas,
|
2002-02-04 05:55:10 +00:00
|
|
|
unsigned _numUsageDeltas,
|
|
|
|
unsigned _numIssueDeltas);
|
2002-12-29 03:13:05 +00:00
|
|
|
/*dtor*/ virtual ~TargetSchedInfo() {}
|
2001-09-18 12:38:31 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int getNumSchedClasses() const {
|
|
|
|
return numSchedClasses;
|
|
|
|
}
|
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
inline unsigned getMaxNumIssueTotal() const {
|
2001-09-18 12:38:31 +00:00
|
|
|
return maxNumIssueTotal;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline InstrSchedClass getSchedClass (MachineOpCode opCode) const {
|
|
|
|
return getInstrInfo().getSchedClass(opCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool instrCanUseSlot (MachineOpCode opCode,
|
|
|
|
unsigned s) const {
|
|
|
|
assert(s < getInstrRUsage(opCode).feasibleSlots.size() && "Invalid slot!");
|
|
|
|
return getInstrRUsage(opCode).feasibleSlots[s];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int getLongestIssueConflict () const {
|
|
|
|
return longestIssueConflict;
|
|
|
|
}
|
2002-10-13 00:37:46 +00:00
|
|
|
|
2001-09-18 12:38:31 +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>&
|
2001-09-18 12:38:31 +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
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
inline bool isSingleIssue (MachineOpCode opCode) const {
|
|
|
|
return getInstrRUsage(opCode).isSingleIssue;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool breaksIssueGroup (MachineOpCode opCode) const {
|
|
|
|
return getInstrRUsage(opCode).breaksGroup;
|
|
|
|
}
|
|
|
|
|
2002-02-04 05:55:10 +00:00
|
|
|
inline unsigned numBubblesAfter (MachineOpCode opCode) const {
|
2001-09-18 12:38:31 +00:00
|
|
|
return getInstrRUsage(opCode).numBubbles;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
protected:
|
|
|
|
virtual void initializeResources ();
|
|
|
|
|
|
|
|
private:
|
2002-01-20 22:54:45 +00:00
|
|
|
void computeInstrResources(const std::vector<InstrRUsage>& instrRUForClasses);
|
|
|
|
void computeIssueGaps(const std::vector<InstrRUsage>& instrRUForClasses);
|
2001-09-18 12:38:31 +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;
|
|
|
|
}
|
|
|
|
|
2003-04-07 00:00:36 +00:00
|
|
|
public:
|
2003-04-07 00:25:09 +00:00
|
|
|
std::vector<std::pair<int,int> > resourceNumVector;
|
2003-04-07 00:00:36 +00:00
|
|
|
|
2001-09-18 12:38:31 +00:00
|
|
|
protected:
|
2002-10-28 04:53:18 +00:00
|
|
|
unsigned numSchedClasses;
|
2003-01-14 22:00:31 +00:00
|
|
|
const TargetInstrInfo* mii;
|
2002-01-20 22:54:45 +00:00
|
|
|
const InstrClassRUsage* classRUsages; // raw array by sclass
|
|
|
|
const InstrRUsageDelta* usageDeltas; // raw array [1:numUsageDeltas]
|
|
|
|
const InstrIssueDelta* issueDeltas; // raw array [1:numIssueDeltas]
|
2002-02-04 05:55:10 +00:00
|
|
|
unsigned numUsageDeltas;
|
|
|
|
unsigned numIssueDeltas;
|
2001-09-18 12:38:31 +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> >
|
|
|
|
conflictLists; // indexed by [opcode]
|
2003-04-07 00:00:36 +00:00
|
|
|
|
|
|
|
|
2004-05-08 16:13:26 +00:00
|
|
|
friend class ModuloSchedulingPass;
|
2004-08-01 18:57:38 +00:00
|
|
|
friend class MSSchedule;
|
2003-04-07 00:00:36 +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
|