2004-03-01 02:50:57 +00:00
|
|
|
//===-- ModuloScheduling.h - Swing Modulo Scheduling------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// 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
|
|
|
//
|
|
|
|
//
|
2004-03-01 02:50:57 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_MODULOSCHEDULING_H
|
|
|
|
#define LLVM_MODULOSCHEDULING_H
|
|
|
|
|
|
|
|
#include "MSchedGraph.h"
|
2004-05-26 06:27:18 +00:00
|
|
|
#include "MSSchedule.h"
|
2004-03-01 02:50:57 +00:00
|
|
|
#include "llvm/Function.h"
|
|
|
|
#include "llvm/Pass.h"
|
2005-03-29 20:35:10 +00:00
|
|
|
#include "DependenceAnalyzer.h"
|
2005-03-23 01:47:20 +00:00
|
|
|
#include "llvm/Target/TargetData.h"
|
2005-04-22 06:32:48 +00:00
|
|
|
#include "llvm/Analysis/LoopInfo.h"
|
|
|
|
#include "llvm/Analysis/ScalarEvolution.h"
|
2004-03-01 02:50:57 +00:00
|
|
|
#include <set>
|
|
|
|
|
|
|
|
namespace llvm {
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-03-01 02:50:57 +00:00
|
|
|
|
|
|
|
//Struct to contain ModuloScheduling Specific Information for each node
|
|
|
|
struct MSNodeAttributes {
|
|
|
|
int ASAP; //Earliest time at which the opreation can be scheduled
|
|
|
|
int ALAP; //Latest time at which the operation can be scheduled.
|
|
|
|
int MOB;
|
|
|
|
int depth;
|
|
|
|
int height;
|
2005-04-21 23:30:14 +00:00
|
|
|
MSNodeAttributes(int asap=-1, int alap=-1, int mob=-1,
|
|
|
|
int d=-1, int h=-1) : ASAP(asap), ALAP(alap),
|
|
|
|
MOB(mob), depth(d),
|
2004-03-01 02:50:57 +00:00
|
|
|
height(h) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class ModuloSchedulingPass : public FunctionPass {
|
|
|
|
const TargetMachine ⌖
|
|
|
|
|
2004-11-02 21:04:56 +00:00
|
|
|
//Map to hold Value* defs
|
|
|
|
std::map<const Value*, MachineInstr*> defMap;
|
|
|
|
|
2005-03-23 01:47:20 +00:00
|
|
|
//Map to hold list of instructions associate to the induction var for each BB
|
|
|
|
std::map<const MachineBasicBlock*, std::map<const MachineInstr*, unsigned> > indVarInstrs;
|
|
|
|
|
2005-03-29 20:35:10 +00:00
|
|
|
//Map to hold machine to llvm instrs for each valid BB
|
|
|
|
std::map<const MachineBasicBlock*, std::map<MachineInstr*, Instruction*> > machineTollvm;
|
|
|
|
|
2004-11-02 21:04:56 +00:00
|
|
|
//LLVM Instruction we know we can add TmpInstructions to its MCFI
|
|
|
|
Instruction *defaultInst;
|
|
|
|
|
2004-03-01 02:50:57 +00:00
|
|
|
//Map that holds node to node attribute information
|
|
|
|
std::map<MSchedGraphNode*, MSNodeAttributes> nodeToAttributesMap;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-05-08 16:12:10 +00:00
|
|
|
//Map to hold all reccurrences
|
|
|
|
std::set<std::pair<int, std::vector<MSchedGraphNode*> > > recurrenceList;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-05-08 16:12:10 +00:00
|
|
|
//Set of edges to ignore, stored as src node and index into vector of successors
|
|
|
|
std::set<std::pair<MSchedGraphNode*, unsigned> > edgesToIgnore;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-05-08 16:12:10 +00:00
|
|
|
//Vector containing the partial order
|
2004-10-30 00:39:07 +00:00
|
|
|
std::vector<std::set<MSchedGraphNode*> > partialOrder;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-05-08 16:12:10 +00:00
|
|
|
//Vector containing the final node order
|
|
|
|
std::vector<MSchedGraphNode*> FinalNodeOrder;
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-05-08 16:12:10 +00:00
|
|
|
//Schedule table, key is the cycle number and the vector is resource, node pairs
|
2004-05-26 06:27:18 +00:00
|
|
|
MSSchedule schedule;
|
2004-05-08 16:12:10 +00:00
|
|
|
|
|
|
|
//Current initiation interval
|
|
|
|
int II;
|
|
|
|
|
2004-03-01 02:50:57 +00:00
|
|
|
//Internal functions
|
2005-02-10 17:02:58 +00:00
|
|
|
bool CreateDefMap(MachineBasicBlock *BI);
|
2004-03-01 02:50:57 +00:00
|
|
|
bool MachineBBisValid(const MachineBasicBlock *BI);
|
2005-04-21 23:30:14 +00:00
|
|
|
bool assocIndVar(Instruction *I, std::set<Instruction*> &indVar,
|
2005-03-23 01:47:20 +00:00
|
|
|
std::vector<Instruction*> &stack, BasicBlock *BB);
|
2004-03-01 02:50:57 +00:00
|
|
|
int calculateResMII(const MachineBasicBlock *BI);
|
2004-05-08 16:12:10 +00:00
|
|
|
int calculateRecMII(MSchedGraph *graph, int MII);
|
2004-03-01 02:50:57 +00:00
|
|
|
void calculateNodeAttributes(MSchedGraph *graph, int MII);
|
2004-05-08 16:12:10 +00:00
|
|
|
|
|
|
|
bool ignoreEdge(MSchedGraphNode *srcNode, MSchedGraphNode *destNode);
|
|
|
|
|
|
|
|
int calculateASAP(MSchedGraphNode *node, int MII,MSchedGraphNode *destNode);
|
|
|
|
int calculateALAP(MSchedGraphNode *node, int MII, int maxASAP, MSchedGraphNode *srcNode);
|
|
|
|
|
|
|
|
int calculateHeight(MSchedGraphNode *node,MSchedGraphNode *srcNode);
|
|
|
|
int calculateDepth(MSchedGraphNode *node, MSchedGraphNode *destNode);
|
2004-03-01 02:50:57 +00:00
|
|
|
|
|
|
|
int findMaxASAP();
|
2004-05-08 16:12:10 +00:00
|
|
|
void orderNodes();
|
2005-04-21 23:30:14 +00:00
|
|
|
void findAllReccurrences(MSchedGraphNode *node,
|
2004-05-08 16:12:10 +00:00
|
|
|
std::vector<MSchedGraphNode*> &visitedNodes, int II);
|
|
|
|
void addReccurrence(std::vector<MSchedGraphNode*> &recurrence, int II, MSchedGraphNode*, MSchedGraphNode*);
|
|
|
|
|
2005-02-10 17:02:58 +00:00
|
|
|
void findAllCircuits(MSchedGraph *MSG, int II);
|
2005-04-21 23:30:14 +00:00
|
|
|
bool circuit(MSchedGraphNode *v, std::vector<MSchedGraphNode*> &stack,
|
|
|
|
std::set<MSchedGraphNode*> &blocked,
|
2005-02-10 17:02:58 +00:00
|
|
|
std::vector<MSchedGraphNode*> &SCC, MSchedGraphNode *s,
|
|
|
|
std::map<MSchedGraphNode*, std::set<MSchedGraphNode*> > &B, int II,
|
|
|
|
std::map<MSchedGraphNode*, MSchedGraphNode*> &newNodes);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-02-10 17:02:58 +00:00
|
|
|
void unblock(MSchedGraphNode *u, std::set<MSchedGraphNode*> &blocked,
|
|
|
|
std::map<MSchedGraphNode*, std::set<MSchedGraphNode*> > &B);
|
|
|
|
|
2005-04-22 06:32:48 +00:00
|
|
|
void addRecc(std::vector<MSchedGraphNode*> &stack, std::map<MSchedGraphNode*, MSchedGraphNode*> &newNodes);
|
|
|
|
|
|
|
|
void searchPath(MSchedGraphNode *node,
|
2005-02-23 02:01:42 +00:00
|
|
|
std::vector<MSchedGraphNode*> &path,
|
|
|
|
std::set<MSchedGraphNode*> &nodesToAdd);
|
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
void pathToRecc(MSchedGraphNode *node,
|
2005-03-23 01:47:20 +00:00
|
|
|
std::vector<MSchedGraphNode*> &path,
|
|
|
|
std::set<MSchedGraphNode*> &poSet, std::set<MSchedGraphNode*> &lastNodes);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-05-08 16:12:10 +00:00
|
|
|
void computePartialOrder();
|
2005-02-23 02:01:42 +00:00
|
|
|
|
2005-04-22 06:32:48 +00:00
|
|
|
bool computeSchedule(const MachineBasicBlock *BB, MSchedGraph *MSG);
|
|
|
|
bool scheduleNode(MSchedGraphNode *node,
|
2004-05-08 16:12:10 +00:00
|
|
|
int start, int end);
|
|
|
|
|
2004-10-30 00:39:07 +00:00
|
|
|
void predIntersect(std::set<MSchedGraphNode*> &CurrentSet, std::set<MSchedGraphNode*> &IntersectResult);
|
|
|
|
void succIntersect(std::set<MSchedGraphNode*> &CurrentSet, std::set<MSchedGraphNode*> &IntersectResult);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-07-30 23:36:10 +00:00
|
|
|
void reconstructLoop(MachineBasicBlock*);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-05-26 06:27:18 +00:00
|
|
|
//void saveValue(const MachineInstr*, const std::set<Value*>&, std::vector<Value*>*);
|
|
|
|
|
2005-04-21 23:30:14 +00:00
|
|
|
void fixBranches(std::vector<MachineBasicBlock *> &prologues, std::vector<BasicBlock*> &llvm_prologues, MachineBasicBlock *machineBB, BasicBlock *llvmBB, std::vector<MachineBasicBlock *> &epilogues, std::vector<BasicBlock*> &llvm_epilogues, MachineBasicBlock*);
|
2004-11-29 04:39:47 +00:00
|
|
|
|
2005-03-23 01:47:20 +00:00
|
|
|
void writePrologues(std::vector<MachineBasicBlock *> &prologues, MachineBasicBlock *origBB, std::vector<BasicBlock*> &llvm_prologues, std::map<const Value*, std::pair<const MachineInstr*, int> > &valuesToSave, std::map<Value*, std::map<int, Value*> > &newValues, std::map<Value*, MachineBasicBlock*> &newValLocation);
|
2004-05-08 16:12:10 +00:00
|
|
|
|
2005-03-23 01:47:20 +00:00
|
|
|
void writeEpilogues(std::vector<MachineBasicBlock *> &epilogues, const MachineBasicBlock *origBB, std::vector<BasicBlock*> &llvm_epilogues, std::map<const Value*, std::pair<const MachineInstr*, int> > &valuesToSave,std::map<Value*, std::map<int, Value*> > &newValues, std::map<Value*, MachineBasicBlock*> &newValLocation, std::map<Value*, std::map<int, Value*> > &kernelPHIs);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
|
|
|
|
2005-03-23 01:47:20 +00:00
|
|
|
void writeKernel(BasicBlock *llvmBB, MachineBasicBlock *machineBB, std::map<const Value*, std::pair<const MachineInstr*, int> > &valuesToSave, std::map<Value*, std::map<int, Value*> > &newValues, std::map<Value*, MachineBasicBlock*> &newValLocation, std::map<Value*, std::map<int, Value*> > &kernelPHIs);
|
2004-07-30 23:36:10 +00:00
|
|
|
|
|
|
|
void removePHIs(const MachineBasicBlock *origBB, std::vector<MachineBasicBlock *> &prologues, std::vector<MachineBasicBlock *> &epilogues, MachineBasicBlock *kernelBB, std::map<Value*, MachineBasicBlock*> &newValLocation);
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2004-10-30 00:39:07 +00:00
|
|
|
void connectedComponentSet(MSchedGraphNode *node, std::set<MSchedGraphNode*> &ccSet, std::set<MSchedGraphNode*> &lastNodes);
|
|
|
|
|
2004-03-01 02:50:57 +00:00
|
|
|
public:
|
|
|
|
ModuloSchedulingPass(TargetMachine &targ) : target(targ) {}
|
|
|
|
virtual bool runOnFunction(Function &F);
|
2004-11-22 20:41:24 +00:00
|
|
|
virtual const char* getPassName() const { return "ModuloScheduling"; }
|
2005-04-21 23:30:14 +00:00
|
|
|
|
2005-03-23 01:47:20 +00:00
|
|
|
// getAnalysisUsage
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
2005-04-22 06:32:48 +00:00
|
|
|
/// HACK: We don't actually need loopinfo or scev, but we have
|
|
|
|
/// to say we do so that the pass manager does not delete it
|
|
|
|
/// before we run.
|
|
|
|
AU.addRequired<LoopInfo>();
|
|
|
|
AU.addRequired<ScalarEvolution>();
|
|
|
|
|
2005-03-29 20:35:10 +00:00
|
|
|
AU.addRequired<DependenceAnalyzer>();
|
2005-03-23 01:47:20 +00:00
|
|
|
}
|
|
|
|
|
2004-03-01 02:50:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|