Tanya Lattner | 9b3cbdb | 2004-03-01 02:50:57 +0000 | [diff] [blame] | 1 | //===-- ModuloScheduling.h - Swing Modulo Scheduling------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_MODULOSCHEDULING_H |
| 14 | #define LLVM_MODULOSCHEDULING_H |
| 15 | |
| 16 | #include "MSchedGraph.h" |
Tanya Lattner | 4cffb58 | 2004-05-26 06:27:18 +0000 | [diff] [blame] | 17 | #include "MSSchedule.h" |
Tanya Lattner | 9b3cbdb | 2004-03-01 02:50:57 +0000 | [diff] [blame] | 18 | #include "llvm/Function.h" |
| 19 | #include "llvm/Pass.h" |
| 20 | #include <set> |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | |
| 25 | //Struct to contain ModuloScheduling Specific Information for each node |
| 26 | struct MSNodeAttributes { |
| 27 | int ASAP; //Earliest time at which the opreation can be scheduled |
| 28 | int ALAP; //Latest time at which the operation can be scheduled. |
| 29 | int MOB; |
| 30 | int depth; |
| 31 | int height; |
| 32 | MSNodeAttributes(int asap=-1, int alap=-1, int mob=-1, |
| 33 | int d=-1, int h=-1) : ASAP(asap), ALAP(alap), |
| 34 | MOB(mob), depth(d), |
| 35 | height(h) {} |
| 36 | }; |
| 37 | |
| 38 | |
| 39 | class ModuloSchedulingPass : public FunctionPass { |
| 40 | const TargetMachine ⌖ |
| 41 | |
Tanya Lattner | 80f0855 | 2004-11-02 21:04:56 +0000 | [diff] [blame] | 42 | //Map to hold Value* defs |
| 43 | std::map<const Value*, MachineInstr*> defMap; |
| 44 | |
| 45 | //LLVM Instruction we know we can add TmpInstructions to its MCFI |
| 46 | Instruction *defaultInst; |
| 47 | |
Tanya Lattner | 9b3cbdb | 2004-03-01 02:50:57 +0000 | [diff] [blame] | 48 | //Map that holds node to node attribute information |
| 49 | std::map<MSchedGraphNode*, MSNodeAttributes> nodeToAttributesMap; |
Tanya Lattner | 420025b | 2004-10-10 22:44:35 +0000 | [diff] [blame] | 50 | |
Tanya Lattner | 73e3e2e | 2004-05-08 16:12:10 +0000 | [diff] [blame] | 51 | //Map to hold all reccurrences |
| 52 | std::set<std::pair<int, std::vector<MSchedGraphNode*> > > recurrenceList; |
Tanya Lattner | 420025b | 2004-10-10 22:44:35 +0000 | [diff] [blame] | 53 | |
Tanya Lattner | 73e3e2e | 2004-05-08 16:12:10 +0000 | [diff] [blame] | 54 | //Set of edges to ignore, stored as src node and index into vector of successors |
| 55 | std::set<std::pair<MSchedGraphNode*, unsigned> > edgesToIgnore; |
| 56 | |
| 57 | //Vector containing the partial order |
Tanya Lattner | 260652a | 2004-10-30 00:39:07 +0000 | [diff] [blame] | 58 | std::vector<std::set<MSchedGraphNode*> > partialOrder; |
Tanya Lattner | 420025b | 2004-10-10 22:44:35 +0000 | [diff] [blame] | 59 | |
Tanya Lattner | 73e3e2e | 2004-05-08 16:12:10 +0000 | [diff] [blame] | 60 | //Vector containing the final node order |
| 61 | std::vector<MSchedGraphNode*> FinalNodeOrder; |
Tanya Lattner | 420025b | 2004-10-10 22:44:35 +0000 | [diff] [blame] | 62 | |
Tanya Lattner | 73e3e2e | 2004-05-08 16:12:10 +0000 | [diff] [blame] | 63 | //Schedule table, key is the cycle number and the vector is resource, node pairs |
Tanya Lattner | 4cffb58 | 2004-05-26 06:27:18 +0000 | [diff] [blame] | 64 | MSSchedule schedule; |
Tanya Lattner | 73e3e2e | 2004-05-08 16:12:10 +0000 | [diff] [blame] | 65 | |
| 66 | //Current initiation interval |
| 67 | int II; |
| 68 | |
Tanya Lattner | 9b3cbdb | 2004-03-01 02:50:57 +0000 | [diff] [blame] | 69 | //Internal functions |
Tanya Lattner | ced8222 | 2004-11-16 21:31:37 +0000 | [diff] [blame^] | 70 | void CreateDefMap(MachineBasicBlock *BI); |
Tanya Lattner | 9b3cbdb | 2004-03-01 02:50:57 +0000 | [diff] [blame] | 71 | bool MachineBBisValid(const MachineBasicBlock *BI); |
| 72 | int calculateResMII(const MachineBasicBlock *BI); |
Tanya Lattner | 73e3e2e | 2004-05-08 16:12:10 +0000 | [diff] [blame] | 73 | int calculateRecMII(MSchedGraph *graph, int MII); |
Tanya Lattner | 9b3cbdb | 2004-03-01 02:50:57 +0000 | [diff] [blame] | 74 | void calculateNodeAttributes(MSchedGraph *graph, int MII); |
Tanya Lattner | 73e3e2e | 2004-05-08 16:12:10 +0000 | [diff] [blame] | 75 | |
| 76 | bool ignoreEdge(MSchedGraphNode *srcNode, MSchedGraphNode *destNode); |
| 77 | |
Tanya Lattner | 73e3e2e | 2004-05-08 16:12:10 +0000 | [diff] [blame] | 78 | int calculateASAP(MSchedGraphNode *node, int MII,MSchedGraphNode *destNode); |
| 79 | int calculateALAP(MSchedGraphNode *node, int MII, int maxASAP, MSchedGraphNode *srcNode); |
| 80 | |
| 81 | int calculateHeight(MSchedGraphNode *node,MSchedGraphNode *srcNode); |
| 82 | int calculateDepth(MSchedGraphNode *node, MSchedGraphNode *destNode); |
Tanya Lattner | 9b3cbdb | 2004-03-01 02:50:57 +0000 | [diff] [blame] | 83 | |
| 84 | int findMaxASAP(); |
Tanya Lattner | 73e3e2e | 2004-05-08 16:12:10 +0000 | [diff] [blame] | 85 | void orderNodes(); |
| 86 | void findAllReccurrences(MSchedGraphNode *node, |
| 87 | std::vector<MSchedGraphNode*> &visitedNodes, int II); |
| 88 | void addReccurrence(std::vector<MSchedGraphNode*> &recurrence, int II, MSchedGraphNode*, MSchedGraphNode*); |
| 89 | |
| 90 | void computePartialOrder(); |
| 91 | void computeSchedule(); |
| 92 | bool scheduleNode(MSchedGraphNode *node, |
| 93 | int start, int end); |
| 94 | |
Tanya Lattner | 260652a | 2004-10-30 00:39:07 +0000 | [diff] [blame] | 95 | void predIntersect(std::set<MSchedGraphNode*> &CurrentSet, std::set<MSchedGraphNode*> &IntersectResult); |
| 96 | void succIntersect(std::set<MSchedGraphNode*> &CurrentSet, std::set<MSchedGraphNode*> &IntersectResult); |
Tanya Lattner | 4cffb58 | 2004-05-26 06:27:18 +0000 | [diff] [blame] | 97 | |
Tanya Lattner | 0a88d2d | 2004-07-30 23:36:10 +0000 | [diff] [blame] | 98 | void reconstructLoop(MachineBasicBlock*); |
Tanya Lattner | 4cffb58 | 2004-05-26 06:27:18 +0000 | [diff] [blame] | 99 | |
| 100 | //void saveValue(const MachineInstr*, const std::set<Value*>&, std::vector<Value*>*); |
| 101 | |
Tanya Lattner | 420025b | 2004-10-10 22:44:35 +0000 | [diff] [blame] | 102 | void writePrologues(std::vector<MachineBasicBlock *> &prologues, MachineBasicBlock *origBB, std::vector<BasicBlock*> &llvm_prologues, std::map<const Value*, std::pair<const MSchedGraphNode*, int> > &valuesToSave, std::map<Value*, std::map<int, Value*> > &newValues, std::map<Value*, MachineBasicBlock*> &newValLocation); |
Tanya Lattner | 73e3e2e | 2004-05-08 16:12:10 +0000 | [diff] [blame] | 103 | |
Tanya Lattner | 420025b | 2004-10-10 22:44:35 +0000 | [diff] [blame] | 104 | void writeEpilogues(std::vector<MachineBasicBlock *> &epilogues, const MachineBasicBlock *origBB, std::vector<BasicBlock*> &llvm_epilogues, std::map<const Value*, std::pair<const MSchedGraphNode*, int> > &valuesToSave,std::map<Value*, std::map<int, Value*> > &newValues, std::map<Value*, MachineBasicBlock*> &newValLocation, std::map<Value*, std::map<int, Value*> > &kernelPHIs); |
Tanya Lattner | 0a88d2d | 2004-07-30 23:36:10 +0000 | [diff] [blame] | 105 | |
| 106 | |
Tanya Lattner | 420025b | 2004-10-10 22:44:35 +0000 | [diff] [blame] | 107 | void writeKernel(BasicBlock *llvmBB, MachineBasicBlock *machineBB, std::map<const Value*, std::pair<const MSchedGraphNode*, int> > &valuesToSave, std::map<Value*, std::map<int, Value*> > &newValues, std::map<Value*, MachineBasicBlock*> &newValLocation, std::map<Value*, std::map<int, Value*> > &kernelPHIs); |
Tanya Lattner | 0a88d2d | 2004-07-30 23:36:10 +0000 | [diff] [blame] | 108 | |
| 109 | void removePHIs(const MachineBasicBlock *origBB, std::vector<MachineBasicBlock *> &prologues, std::vector<MachineBasicBlock *> &epilogues, MachineBasicBlock *kernelBB, std::map<Value*, MachineBasicBlock*> &newValLocation); |
Tanya Lattner | 2089083 | 2004-05-28 20:14:12 +0000 | [diff] [blame] | 110 | |
Tanya Lattner | 260652a | 2004-10-30 00:39:07 +0000 | [diff] [blame] | 111 | void connectedComponentSet(MSchedGraphNode *node, std::set<MSchedGraphNode*> &ccSet, std::set<MSchedGraphNode*> &lastNodes); |
| 112 | |
Tanya Lattner | 9b3cbdb | 2004-03-01 02:50:57 +0000 | [diff] [blame] | 113 | public: |
| 114 | ModuloSchedulingPass(TargetMachine &targ) : target(targ) {} |
| 115 | virtual bool runOnFunction(Function &F); |
| 116 | }; |
| 117 | |
| 118 | } |
| 119 | |
| 120 | |
| 121 | #endif |