2003-04-09 21:51:34 +00:00
|
|
|
// ModuloScheduling.h -------------------------------------------*- C++ -*-===//
|
2003-03-27 17:57:44 +00:00
|
|
|
//
|
2003-04-09 21:51:34 +00:00
|
|
|
// This header defines the the classes ModuloScheduling and
|
|
|
|
// ModuloSchedulingSet's structure
|
2003-03-27 17:57:44 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef LLVM_CODEGEN_MODULOSCHEDULING_H
|
|
|
|
#define LLVM_CODEGEN_MODULOSCHEDULING_H
|
|
|
|
|
|
|
|
#include "ModuloSchedGraph.h"
|
|
|
|
#include <iostream>
|
2003-04-06 23:56:19 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2003-04-09 21:51:34 +00:00
|
|
|
class ModuloScheduling: NonCopyable {
|
|
|
|
private:
|
2003-03-27 17:57:44 +00:00
|
|
|
|
|
|
|
typedef std::vector<ModuloSchedGraphNode*> NodeVec;
|
2003-04-09 21:51:34 +00:00
|
|
|
typedef std::vector<std::vector<unsigned> > Resources;
|
|
|
|
|
|
|
|
// The graph to feed in
|
|
|
|
ModuloSchedGraph &graph;
|
|
|
|
const TargetMachine ⌖
|
|
|
|
|
|
|
|
// The BasicBlock to be scheduled
|
|
|
|
BasicBlock *bb;
|
|
|
|
|
|
|
|
// Iteration Interval
|
|
|
|
// FIXME: II may be a better name for its meaning
|
2003-03-27 17:57:44 +00:00
|
|
|
unsigned II;
|
|
|
|
|
2003-04-09 21:51:34 +00:00
|
|
|
// The vector containing the nodes which have been scheduled
|
2003-03-27 17:57:44 +00:00
|
|
|
NodeVec nodeScheduled;
|
2003-04-09 21:51:34 +00:00
|
|
|
|
|
|
|
// The remaining unscheduled nodes
|
|
|
|
const NodeVec &oNodes;
|
|
|
|
|
|
|
|
// The machine resource table
|
|
|
|
std::vector<std::vector<std::pair<int,int> > > resourceTable;
|
|
|
|
|
2003-03-27 17:57:44 +00:00
|
|
|
///the schedule( with many schedule stage)
|
|
|
|
std::vector<std::vector<ModuloSchedGraphNode*> > schedule;
|
2003-04-09 21:51:34 +00:00
|
|
|
|
2003-03-27 17:57:44 +00:00
|
|
|
///the kernel(core) schedule(length = II)
|
|
|
|
std::vector<std::vector<ModuloSchedGraphNode*> > coreSchedule;
|
|
|
|
|
2003-04-09 21:51:34 +00:00
|
|
|
typedef BasicBlock::InstListType InstListType;
|
|
|
|
typedef std::vector<std::vector<ModuloSchedGraphNode*> > vvNodeType;
|
2003-03-27 17:57:44 +00:00
|
|
|
|
|
|
|
public:
|
2003-04-09 21:51:34 +00:00
|
|
|
|
|
|
|
ModuloScheduling(ModuloSchedGraph & _graph):
|
|
|
|
graph(_graph), target(graph.getTarget()), oNodes(graph.getONodes())
|
|
|
|
{
|
|
|
|
II = graph.getMII();
|
|
|
|
bb = (BasicBlock *) graph.getBasicBlocks()[0];
|
|
|
|
instrScheduling();
|
|
|
|
};
|
|
|
|
|
|
|
|
~ModuloScheduling() {};
|
2003-03-27 17:57:44 +00:00
|
|
|
|
|
|
|
///the method to compute schedule and instert epilogue and prologue
|
|
|
|
void instrScheduling();
|
|
|
|
|
|
|
|
///debug functions:
|
|
|
|
///dump the schedule and core schedule
|
2003-04-09 21:51:34 +00:00
|
|
|
void
|
|
|
|
dumpScheduling();
|
|
|
|
|
2003-03-27 17:57:44 +00:00
|
|
|
///dump the input vector of nodes
|
|
|
|
//sch: the input vector of nodes
|
2003-04-09 21:51:34 +00:00
|
|
|
void dumpSchedule(std::vector<std::vector<ModuloSchedGraphNode*>> sch);
|
2003-03-27 17:57:44 +00:00
|
|
|
|
|
|
|
///dump the resource usage table
|
|
|
|
void dumpResourceUsageTable();
|
|
|
|
|
2003-04-09 21:51:34 +00:00
|
|
|
//*******************internal functions*******************************
|
2003-03-27 17:57:44 +00:00
|
|
|
private:
|
|
|
|
//clear memory from the last round and initialize if necessary
|
2003-04-09 21:51:34 +00:00
|
|
|
void clearInitMem(const TargetSchedInfo&);
|
2003-03-27 17:57:44 +00:00
|
|
|
|
|
|
|
//compute schedule and coreSchedule with the current II
|
|
|
|
bool computeSchedule();
|
|
|
|
|
2003-04-09 21:51:34 +00:00
|
|
|
BasicBlock *getSuccBB(BasicBlock *);
|
|
|
|
BasicBlock *getPredBB(BasicBlock *);
|
|
|
|
void constructPrologue(BasicBlock *prologue);
|
|
|
|
void constructKernel(BasicBlock *prologue,
|
|
|
|
BasicBlock *kernel,
|
|
|
|
BasicBlock *epilogue);
|
|
|
|
void constructEpilogue(BasicBlock *epilogue, BasicBlock *succ_bb);
|
|
|
|
|
|
|
|
// update the resource table at the startCycle
|
|
|
|
// vec: the resouce usage
|
|
|
|
// startCycle: the start cycle the resouce usage is
|
|
|
|
void updateResourceTable(std::vector<std::vector<unsigned int>> vec,
|
|
|
|
int startCycle);
|
|
|
|
|
|
|
|
// un-do the update in the resource table in the startCycle
|
|
|
|
// vec: the resouce usage
|
|
|
|
// startCycle: the start cycle the resouce usage is
|
|
|
|
void undoUpdateResourceTable(std::vector<vector<unsigned int>> vec,
|
|
|
|
int startCycle);
|
|
|
|
|
|
|
|
// return whether the resourcetable has negative element
|
|
|
|
// this function is called after updateResouceTable() to determine whether a
|
|
|
|
// node can be scheduled at certain cycle
|
2003-03-27 17:57:44 +00:00
|
|
|
bool resourceTableNegative();
|
|
|
|
|
2003-04-09 21:51:34 +00:00
|
|
|
// try to Schedule the node starting from start to end cycle(inclusive)
|
|
|
|
// if it can be scheduled, put it in the schedule and update nodeScheduled
|
|
|
|
// node: the node to be scheduled
|
|
|
|
// start: start cycle
|
|
|
|
// end : end cycle
|
|
|
|
// nodeScheduled: a vector storing nodes which has been scheduled
|
|
|
|
bool ScheduleNode(ModuloSchedGraphNode * node, unsigned start,
|
|
|
|
unsigned end, NodeVec &nodeScheduled);
|
2003-03-27 17:57:44 +00:00
|
|
|
|
|
|
|
//each instruction has a memory of the latest clone instruction
|
|
|
|
//the clone instruction can be get using getClone()
|
2003-04-09 21:51:34 +00:00
|
|
|
//this function clears the memory, i.e. getClone() after calling this function
|
|
|
|
//returns null
|
2003-03-27 17:57:44 +00:00
|
|
|
void clearCloneMemory();
|
|
|
|
|
2003-04-09 21:51:34 +00:00
|
|
|
//this fuction make a clone of this input Instruction and update the clone
|
|
|
|
//memory
|
2003-03-27 17:57:44 +00:00
|
|
|
//inst: the instrution to be cloned
|
2003-04-09 21:51:34 +00:00
|
|
|
Instruction *cloneInstSetMemory(Instruction *inst);
|
2003-03-27 17:57:44 +00:00
|
|
|
|
|
|
|
//this function update each instrutions which uses ist as its operand
|
|
|
|
//after update, each instruction will use ist's clone as its operand
|
2003-04-09 21:51:34 +00:00
|
|
|
void updateUseWithClone(Instruction * ist);
|
2003-03-27 17:57:44 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2003-04-09 21:51:34 +00:00
|
|
|
class ModuloSchedulingSet:
|
|
|
|
NonCopyable {
|
|
|
|
private:
|
|
|
|
|
2003-03-27 17:57:44 +00:00
|
|
|
//the graphSet to feed in
|
2003-04-09 21:51:34 +00:00
|
|
|
ModuloSchedGraphSet & graphSet;
|
|
|
|
|
|
|
|
public:
|
2003-03-27 17:57:44 +00:00
|
|
|
|
|
|
|
//constructor
|
|
|
|
//Scheduling graph one by one
|
2003-04-09 21:51:34 +00:00
|
|
|
ModuloSchedulingSet(ModuloSchedGraphSet _graphSet): graphSet(_graphSet) {
|
|
|
|
for (unsigned i = 0; i < graphSet.size(); i++) {
|
|
|
|
ModuloSchedGraph & graph = *(graphSet[i]);
|
|
|
|
if (graph.isLoop())
|
|
|
|
ModuloScheduling ModuloScheduling(graph);
|
2003-03-27 17:57:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2003-04-09 21:51:34 +00:00
|
|
|
~ModuloSchedulingSet() {};
|
|
|
|
};
|
2003-03-27 17:57:44 +00:00
|
|
|
|
|
|
|
#endif
|