aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/ModuloScheduling
diff options
context:
space:
mode:
authorMisha Brukman <brukman+llvm@gmail.com>2004-10-10 23:33:20 +0000
committerMisha Brukman <brukman+llvm@gmail.com>2004-10-10 23:33:20 +0000
commitf60a149df6d6e10503e49075da455104eb489f5a (patch)
tree7292010ffb1b812749b0dda07c2fe2009aeb3922 /lib/CodeGen/ModuloScheduling
parent708148e41f8f7c1e24c73cfd943645b13a1e05f9 (diff)
ModuloScheduling moved to lib/Target/SparcV9 as it is SparcV9-specific
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16902 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/ModuloScheduling')
-rw-r--r--lib/CodeGen/ModuloScheduling/MSSchedule.cpp196
-rw-r--r--lib/CodeGen/ModuloScheduling/MSSchedule.h66
-rw-r--r--lib/CodeGen/ModuloScheduling/MSchedGraph.cpp429
-rw-r--r--lib/CodeGen/ModuloScheduling/MSchedGraph.h316
-rw-r--r--lib/CodeGen/ModuloScheduling/Makefile15
-rw-r--r--lib/CodeGen/ModuloScheduling/Makefile.am19
-rw-r--r--lib/CodeGen/ModuloScheduling/ModuloScheduling.cpp1967
-rw-r--r--lib/CodeGen/ModuloScheduling/ModuloScheduling.h112
8 files changed, 0 insertions, 3120 deletions
diff --git a/lib/CodeGen/ModuloScheduling/MSSchedule.cpp b/lib/CodeGen/ModuloScheduling/MSSchedule.cpp
deleted file mode 100644
index 4ce85e4949..0000000000
--- a/lib/CodeGen/ModuloScheduling/MSSchedule.cpp
+++ /dev/null
@@ -1,196 +0,0 @@
-//===-- MSSchedule.cpp Schedule ---------------------------------*- 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.
-//
-//===----------------------------------------------------------------------===//
-//
-//
-//
-//===----------------------------------------------------------------------===//
-#define DEBUG_TYPE "ModuloSched"
-
-#include "MSSchedule.h"
-#include "llvm/Support/Debug.h"
-#include "llvm/Target/TargetSchedInfo.h"
-#include "../../Target/SparcV9/SparcV9Internals.h"
-
-using namespace llvm;
-
-bool MSSchedule::insert(MSchedGraphNode *node, int cycle) {
-
- //First, check if the cycle has a spot free to start
- if(schedule.find(cycle) != schedule.end()) {
- if (schedule[cycle].size() < numIssue) {
- if(resourcesFree(node, cycle)) {
- schedule[cycle].push_back(node);
- DEBUG(std::cerr << "Found spot in map, and there is an issue slot\n");
- return false;
- }
- }
- }
- //Not in the map yet so put it in
- else {
- if(resourcesFree(node,cycle)) {
- std::vector<MSchedGraphNode*> nodes;
- nodes.push_back(node);
- schedule[cycle] = nodes;
- DEBUG(std::cerr << "Nothing in map yet so taking an issue slot\n");
- return false;
- }
- }
-
- DEBUG(std::cerr << "All issue slots taken\n");
- return true;
-
-}
-
-bool MSSchedule::resourcesFree(MSchedGraphNode *node, int cycle) {
-
- //Get Resource usage for this instruction
- const TargetSchedInfo *msi = node->getParent()->getTarget()->getSchedInfo();
- int currentCycle = cycle;
- bool success = true;
-
- //Get resource usage for this instruction
- InstrRUsage rUsage = msi->getInstrRUsage(node->getInst()->getOpcode());
- std::vector<std::vector<resourceId_t> > resources = rUsage.resourcesByCycle;
-
- //Loop over resources in each cycle and increments their usage count
- for(unsigned i=0; i < resources.size(); ++i) {
- for(unsigned j=0; j < resources[i].size(); ++j) {
- int resourceNum = resources[i][j];
-
- //Check if this resource is available for this cycle
- std::map<int, std::map<int,int> >::iterator resourcesForCycle = resourceNumPerCycle.find(currentCycle);
-
- //First check map of resources for this cycle
- if(resourcesForCycle != resourceNumPerCycle.end()) {
- //A map exists for this cycle, so lets check for the resource
- std::map<int, int>::iterator resourceUse = resourcesForCycle->second.find(resourceNum);
- if(resourceUse != resourcesForCycle->second.end()) {
- //Check if there are enough of this resource and if so, increase count and move on
- if(resourceUse->second < CPUResource::getCPUResource(resourceNum)->maxNumUsers)
- ++resourceUse->second;
- else {
- success = false;
- }
- }
- //Not in the map yet, so put it
- else
- resourcesForCycle->second[resourceNum] = 1;
-
- }
- else {
- //Create a new map and put in our resource
- std::map<int, int> resourceMap;
- resourceMap[resourceNum] = 1;
- resourceNumPerCycle[cycle] = resourceMap;
- }
- if(!success)
- break;
- }
- if(!success)
- break;
- //Increase cycle
- currentCycle++;
- }
-
- if(!success) {
- int oldCycle = cycle;
- DEBUG(std::cerr << "Backtrack\n");
- //Get resource usage for this instruction
- InstrRUsage rUsage = msi->getInstrRUsage(node->getInst()->getOpcode());
- std::vector<std::vector<resourceId_t> > resources = rUsage.resourcesByCycle;
-
- //Loop over resources in each cycle and increments their usage count
- for(unsigned i=0; i < resources.size(); ++i) {
- if(oldCycle < currentCycle) {
-
- //Check if this resource is available for this cycle
- std::map<int, std::map<int,int> >::iterator resourcesForCycle = resourceNumPerCycle.find(oldCycle);
-
- for(unsigned j=0; j < resources[i].size(); ++j) {
- int resourceNum = resources[i][j];
- //remove from map
- std::map<int, int>::iterator resourceUse = resourcesForCycle->second.find(resourceNum);
- //assert if not in the map.. since it should be!
- //assert(resourceUse != resourcesForCycle.end() && "Resource should be in map!");
- --resourceUse->second;
- }
- }
- else
- break;
- oldCycle++;
- }
- return false;
-
- }
-
- return true;
-
-}
-
-bool MSSchedule::constructKernel(int II) {
- MSchedGraphNode *branchNode = 0;
- MSchedGraphNode *branchANode = 0;
-
- int stageNum = (schedule.rbegin()->first)/ II;
- DEBUG(std::cerr << "Number of Stages: " << stageNum << "\n");
-
- for(int index = 0; index < II; ++index) {
- int count = 0;
- for(int i = index; i <= (schedule.rbegin()->first); i+=II) {
- if(schedule.count(i)) {
- for(std::vector<MSchedGraphNode*>::iterator I = schedule[i].begin(),
- E = schedule[i].end(); I != E; ++I) {
- //Check if its a branch
- if((*I)->isBranch()) {
- if((*I)->getInst()->getOpcode() == V9::BA)
- branchANode = *I;
- else
- branchNode = *I;
- assert(count == 0 && "Branch can not be from a previous iteration");
- }
- else
- //FIXME: Check if the instructions in the earlier stage conflict
- kernel.push_back(std::make_pair(*I, count));
- }
- }
- ++count;
- }
- }
-
- //Add Branch to the end
- kernel.push_back(std::make_pair(branchNode, 0));
-
- //Add Branch Always to the end
- kernel.push_back(std::make_pair(branchANode, 0));
-
-
- if(stageNum > 0)
- maxStage = stageNum;
- else
- maxStage = 0;
-
- return true;
-}
-
-
-void MSSchedule::print(std::ostream &os) const {
- os << "Schedule:\n";
-
- for(schedule_const_iterator I = schedule.begin(), E = schedule.end(); I != E; ++I) {
- os << "Cycle: " << I->first << "\n";
- for(std::vector<MSchedGraphNode*>::const_iterator node = I->second.begin(), nodeEnd = I->second.end(); node != nodeEnd; ++node)
- os << **node << "\n";
- }
-
- os << "Kernel:\n";
- for(std::vector<std::pair<MSchedGraphNode*, int> >::const_iterator I = kernel.begin(),
- E = kernel.end(); I != E; ++I)
- os << "Node: " << *(I->first) << " Stage: " << I->second << "\n";
-}
-
diff --git a/lib/CodeGen/ModuloScheduling/MSSchedule.h b/lib/CodeGen/ModuloScheduling/MSSchedule.h
deleted file mode 100644
index 248a748591..0000000000
--- a/lib/CodeGen/ModuloScheduling/MSSchedule.h
+++ /dev/null
@@ -1,66 +0,0 @@
-//===-- MSSchedule.h - Schedule ------- -------------------------*- 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.
-//
-//===----------------------------------------------------------------------===//
-//
-// The schedule generated by a scheduling algorithm
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_MSSCHEDULE_H
-#define LLVM_MSSCHEDULE_H
-
-#include "MSchedGraph.h"
-#include <vector>
-
-namespace llvm {
-
- class MSSchedule {
- std::map<int, std::vector<MSchedGraphNode*> > schedule;
- unsigned numIssue;
-
- //Internal map to keep track of explicit resources
- std::map<int, std::map<int, int> > resourceNumPerCycle;
-
- //Check if all resources are free
- bool resourcesFree(MSchedGraphNode*, int);
-
- //Resulting kernel
- std::vector<std::pair<MSchedGraphNode*, int> > kernel;
-
- //Max stage count
- int maxStage;
-
- public:
- MSSchedule(int num) : numIssue(num) {}
- MSSchedule() : numIssue(4) {}
- bool insert(MSchedGraphNode *node, int cycle);
- int getStartCycle(MSchedGraphNode *node);
- void clear() { schedule.clear(); resourceNumPerCycle.clear(); kernel.clear(); }
- std::vector<std::pair<MSchedGraphNode*, int> >* getKernel() { return &kernel; }
- bool constructKernel(int II);
- int getMaxStage() { return maxStage; }
-
-
- //iterators
- typedef std::map<int, std::vector<MSchedGraphNode*> >::iterator schedule_iterator;
- typedef std::map<int, std::vector<MSchedGraphNode*> >::const_iterator schedule_const_iterator;
- schedule_iterator begin() { return schedule.begin(); };
- schedule_iterator end() { return schedule.end(); };
- void print(std::ostream &os) const;
-
- typedef std::vector<std::pair<MSchedGraphNode*, int> >::iterator kernel_iterator;
- typedef std::vector<std::pair<MSchedGraphNode*, int> >::const_iterator kernel_const_iterator;
- kernel_iterator kernel_begin() { return kernel.begin(); }
- kernel_iterator kernel_end() { return kernel.end(); }
-
- };
-
-}
-
-
-#endif
diff --git a/lib/CodeGen/ModuloScheduling/MSchedGraph.cpp b/lib/CodeGen/ModuloScheduling/MSchedGraph.cpp
deleted file mode 100644
index 2b246ca674..0000000000
--- a/lib/CodeGen/ModuloScheduling/MSchedGraph.cpp
+++ /dev/null
@@ -1,429 +0,0 @@
-//===-- MSchedGraph.cpp - Scheduling Graph ----------------------*- 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.
-//
-//===----------------------------------------------------------------------===//
-//
-// A graph class for dependencies
-//
-//===----------------------------------------------------------------------===//
-#define DEBUG_TYPE "ModuloSched"
-
-#include "MSchedGraph.h"
-#include "../../Target/SparcV9/SparcV9RegisterInfo.h"
-#include "llvm/CodeGen/MachineBasicBlock.h"
-#include "llvm/Target/TargetInstrInfo.h"
-#include "llvm/Support/Debug.h"
-#include <cstdlib>
-#include <algorithm>
-using namespace llvm;
-
-MSchedGraphNode::MSchedGraphNode(const MachineInstr* inst,
- MSchedGraph *graph,
- unsigned late, bool isBranch)
- : Inst(inst), Parent(graph), latency(late), isBranchInstr(isBranch) {
-
- //Add to the graph
- graph->addNode(inst, this);
-}
-
-void MSchedGraphNode::print(std::ostream &os) const {
- os << "MSchedGraphNode: Inst=" << *Inst << ", latency= " << latency << "\n";
-}
-
-MSchedGraphEdge MSchedGraphNode::getInEdge(MSchedGraphNode *pred) {
- //Loop over all the successors of our predecessor
- //return the edge the corresponds to this in edge
- for (MSchedGraphNode::succ_iterator I = pred->succ_begin(),
- E = pred->succ_end(); I != E; ++I) {
- if (*I == this)
- return I.getEdge();
- }
- assert(0 && "Should have found edge between this node and its predecessor!");
- abort();
-}
-
-unsigned MSchedGraphNode::getInEdgeNum(MSchedGraphNode *pred) {
- //Loop over all the successors of our predecessor
- //return the edge the corresponds to this in edge
- int count = 0;
- for(MSchedGraphNode::succ_iterator I = pred->succ_begin(), E = pred->succ_end();
- I != E; ++I) {
- if(*I == this)
- return count;
- count++;
- }
- assert(0 && "Should have found edge between this node and its predecessor!");
- abort();
-}
-bool MSchedGraphNode::isSuccessor(MSchedGraphNode *succ) {
- for(succ_iterator I = succ_begin(), E = succ_end(); I != E; ++I)
- if(*I == succ)
- return true;
- return false;
-}
-
-
-bool MSchedGraphNode::isPredecessor(MSchedGraphNode *pred) {
- if(std::find( Predecessors.begin(), Predecessors.end(), pred) != Predecessors.end())
- return true;
- else
- return false;
-}
-
-
-void MSchedGraph::addNode(const MachineInstr *MI,
- MSchedGraphNode *node) {
-
- //Make sure node does not already exist
- assert(GraphMap.find(MI) == GraphMap.end()
- && "New MSchedGraphNode already exists for this instruction");
-
- GraphMap[MI] = node;
-}
-
-MSchedGraph::MSchedGraph(const MachineBasicBlock *bb, const TargetMachine &targ)
- : BB(bb), Target(targ) {
-
- //Make sure BB is not null,
- assert(BB != NULL && "Basic Block is null");
-
- //DEBUG(std::cerr << "Constructing graph for " << bb << "\n");
-
- //Create nodes and edges for this BB
- buildNodesAndEdges();
-}
-
-MSchedGraph::~MSchedGraph () {
- for(MSchedGraph::iterator I = GraphMap.begin(), E = GraphMap.end(); I != E; ++I)
- delete I->second;
-}
-
-void MSchedGraph::buildNodesAndEdges() {
-
- //Get Machine target information for calculating latency
- const TargetInstrInfo *MTI = Target.getInstrInfo();
-
- std::vector<MSchedGraphNode*> memInstructions;
- std::map<int, std::vector<OpIndexNodePair> > regNumtoNodeMap;
- std::map<const Value*, std::vector<OpIndexNodePair> > valuetoNodeMap;
-
- //Save PHI instructions to deal with later
- std::vector<const MachineInstr*> phiInstrs;
-
- //Loop over instructions in MBB and add nodes and edges
- for (MachineBasicBlock::const_iterator MI = BB->begin(), e = BB->end(); MI != e; ++MI) {
- //Get each instruction of machine basic block, get the delay
- //using the op code, create a new node for it, and add to the
- //graph.
-
- MachineOpCode opCode = MI->getOpcode();
- int delay;
-
-#if 0 // FIXME: LOOK INTO THIS
- //Check if subsequent instructions can be issued before
- //the result is ready, if so use min delay.
- if(MTI->hasResultInterlock(MIopCode))
- delay = MTI->minLatency(MIopCode);
- else
-#endif
- //Get delay
- delay = MTI->maxLatency(opCode);
-
- //Create new node for this machine instruction and add to the graph.
- //Create only if not a nop
- if(MTI->isNop(opCode))
- continue;
-
- //Add PHI to phi instruction list to be processed later
- if (opCode == TargetInstrInfo::PHI)
- phiInstrs.push_back(MI);
-
- bool isBranch = false;
-
- //We want to flag the branch node to treat it special
- if(MTI->isBranch(opCode))
- isBranch = true;
-
- //Node is created and added to the graph automatically
- MSchedGraphNode *node = new MSchedGraphNode(MI, this, delay, isBranch);
-
- DEBUG(std::cerr << "Created Node: " << *node << "\n");
-
- //Check OpCode to keep track of memory operations to add memory dependencies later.
- if(MTI->isLoad(opCode) || MTI->isStore(opCode))
- memInstructions.push_back(node);
-
- //Loop over all operands, and put them into the register number to
- //graph node map for determining dependencies
- //If an operands is a use/def, we have an anti dependence to itself
- for(unsigned i=0; i < MI->getNumOperands(); ++i) {
- //Get Operand
- const MachineOperand &mOp = MI->getOperand(i);
-
- //Check if it has an allocated register
- if(mOp.hasAllocatedReg()) {
- int regNum = mOp.getReg();
-
- if(regNum != SparcV9::g0) {
- //Put into our map
- regNumtoNodeMap[regNum].push_back(std::make_pair(i, node));
- }
- continue;
- }
-
-
- //Add virtual registers dependencies
- //Check if any exist in the value map already and create dependencies
- //between them.
- if(mOp.getType() == MachineOperand::MO_VirtualRegister || mOp.getType() == MachineOperand::MO_CCRegister) {
-
- //Make sure virtual register value is not null
- assert((mOp.getVRegValue() != NULL) && "Null value is defined");
-
- //Check if this is a read operation in a phi node, if so DO NOT PROCESS
- if(mOp.isUse() && (opCode == TargetInstrInfo::PHI))
- continue;
-
-
- if (const Value* srcI = mOp.getVRegValue()) {
-
- //Find value in the map
- std::map<const Value*, std::vector<OpIndexNodePair> >::iterator V
- = valuetoNodeMap.find(srcI);
-
- //If there is something in the map already, add edges from
- //those instructions
- //to this one we are processing
- if(V != valuetoNodeMap.end()) {
- addValueEdges(V->second, node, mOp.isUse(), mOp.isDef());
-
- //Add to value map
- V->second.push_back(std::make_pair(i,node));
- }
- //Otherwise put it in the map
- else
- //Put into value map
- valuetoNodeMap[mOp.getVRegValue()].push_back(std::make_pair(i, node));
- }
- }
- }
- }
- addMemEdges(memInstructions);
- addMachRegEdges(regNumtoNodeMap);
-
- //Finally deal with PHI Nodes and Value*
- for(std::vector<const MachineInstr*>::iterator I = phiInstrs.begin(), E = phiInstrs.end(); I != E; ++I) {
- //Get Node for this instruction
- MSchedGraphNode *node = find(*I)->second;
-
- //Loop over operands for this instruction and add value edges
- for(unsigned i=0; i < (*I)->getNumOperands(); ++i) {
- //Get Operand
- const MachineOperand &mOp = (*I)->getOperand(i);
- if((mOp.getType() == MachineOperand::MO_VirtualRegister || mOp.getType() == MachineOperand::MO_CCRegister) && mOp.isUse()) {
- //find the value in the map
- if (const Value* srcI = mOp.getVRegValue()) {
-
- //Find value in the map
- std::map<const Value*, std::vector<OpIndexNodePair> >::iterator V
- = valuetoNodeMap.find(srcI);
-
- //If there is something in the map already, add edges from
- //those instructions
- //to this one we are processing
- if(V != valuetoNodeMap.end()) {
- addValueEdges(V->second, node, mOp.isUse(), mOp.isDef(), 1);
- }
- }
- }
- }
- }
-}
-
-void MSchedGraph::addValueEdges(std::vector<OpIndexNodePair> &NodesInMap,
- MSchedGraphNode *destNode, bool nodeIsUse,
- bool nodeIsDef, int diff) {
-
- for(std::vector<OpIndexNodePair>::iterator I = NodesInMap.begin(),
- E = NodesInMap.end(); I != E; ++I) {
-
- //Get node in vectors machine operand that is the same value as node
- MSchedGraphNode *srcNode = I->second;
- MachineOperand mOp = srcNode->getInst()->getOperand(I->first);
-
- //Node is a Def, so add output dep.
- if(nodeIsDef) {
- if(mOp.isUse())
- srcNode->addOutEdge(destNode, MSchedGraphEdge::ValueDep,
- MSchedGraphEdge::AntiDep, diff);
- if(mOp.isDef())
- srcNode->addOutEdge(destNode, MSchedGraphEdge::ValueDep,
- MSchedGraphEdge::OutputDep, diff);
-
- }
- if(nodeIsUse) {
- if(mOp.isDef())
- srcNode->addOutEdge(destNode, MSchedGraphEdge::ValueDep,
- MSchedGraphEdge::TrueDep, diff);
- }
- }
-}
-
-
-void MSchedGraph::addMachRegEdges(std::map<int, std::vector<OpIndexNodePair> >& regNumtoNodeMap) {
- //Loop over all machine registers in the map, and add dependencies
- //between the instructions that use it
- typedef std::map<int, std::vector<OpIndexNodePair> > regNodeMap;
- for(regNodeMap::iterator I = regNumtoNodeMap.begin(); I != regNumtoNodeMap.end(); ++I) {
- //Get the register number
- int regNum = (*I).first;
-
- //Get Vector of nodes that use this register
- std::vector<OpIndexNodePair> Nodes = (*I).second;
-
- //Loop over nodes and determine the dependence between the other
- //nodes in the vector
- for(unsigned i =0; i < Nodes.size(); ++i) {
-
- //Get src node operator index that uses this machine register
- int srcOpIndex = Nodes[i].first;
-
- //Get the actual src Node
- MSchedGraphNode *srcNode = Nodes[i].second;
-
- //Get Operand
- const MachineOperand &srcMOp = srcNode->getInst()->getOperand(srcOpIndex);
-
- bool srcIsUseandDef = srcMOp.isDef() && srcMOp.isUse();
- bool srcIsUse = srcMOp.isUse() && !srcMOp.isDef();
-
-
- //Look at all instructions after this in execution order
- for(unsigned j=i+1; j < Nodes.size(); ++j) {
-
- //Sink node is a write
- if(Nodes[j].second->getInst()->getOperand(Nodes[j].first).isDef()) {
- //Src only uses the register (read)
- if(srcIsUse)
- srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister,
- MSchedGraphEdge::AntiDep);
-
- else if(srcIsUseandDef) {
- srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister,
- MSchedGraphEdge::AntiDep);
-
- srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister,
- MSchedGraphEdge::OutputDep);
- }
- else
- srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister,
- MSchedGraphEdge::OutputDep);
- }
- //Dest node is a read
- else {
- if(!srcIsUse || srcIsUseandDef)
- srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister,
- MSchedGraphEdge::TrueDep);
- }
-
- }
-
- //Look at all the instructions before this one since machine registers
- //could live across iterations.
- for(unsigned j = 0; j < i; ++j) {
- //Sink node is a write
- if(Nodes[j].second->getInst()->getOperand(Nodes[j].first).isDef()) {
- //Src only uses the register (read)
- if(srcIsUse)
- srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister,
- MSchedGraphEdge::AntiDep, 1);
-
- else if(srcIsUseandDef) {
- srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister,
- MSchedGraphEdge::AntiDep, 1);
-
- srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister,
- MSchedGraphEdge::OutputDep, 1);
- }
- else
- srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister,
- MSchedGraphEdge::OutputDep, 1);
- }
- //Dest node is a read
- else {
- if(!srcIsUse || srcIsUseandDef)
- srcNode->addOutEdge(Nodes[j].second, MSchedGraphEdge::MachineRegister,
- MSchedGraphEdge::TrueDep,1 );
- }
-
-
- }
-
- }
-
- }
-
-}
-
-void MSchedGraph::addMemEdges(const std::vector<MSchedGraphNode*>& memInst) {
-
- //Get Target machine instruction info
- const TargetInstrInfo *TMI = Target.getInstrInfo();
-
- //Loop over all memory instructions in the vector
- //Knowing that they are in execution, add true, anti, and output dependencies
- for (unsigned srcIndex = 0; srcIndex < memInst.size(); ++srcIndex) {
-
- //Get the machine opCode to determine type of memory instruction
- MachineOpCode srcNodeOpCode = memInst[srcIndex]->getInst()->getOpcode();
-
- //All instructions after this one in execution order have an iteration delay of 0
- for(unsigned destIndex = srcIndex + 1; destIndex < memInst.size(); ++destIndex) {
-
- //source is a Load, so add anti-dependencies (store after load)
- if(TMI->isLoad(srcNodeOpCode))
- if(TMI->isStore(memInst[destIndex]->getInst()->getOpcode()))
- memInst[srcIndex]->addOutEdge(memInst[destIndex],
- MSchedGraphEdge::MemoryDep,
- MSchedGraphEdge::AntiDep);
-
- //If source is a store, add output and true dependencies
- if(TMI->isStore(srcNodeOpCode)) {
- if(TMI->isStore(memInst[destIndex]->getInst()->getOpcode()))
- memInst[srcIndex]->addOutEdge(memInst[destIndex],
- MSchedGraphEdge::MemoryDep,
- MSchedGraphEdge::OutputDep);
- else
- memInst[srcIndex]->addOutEdge(memInst[destIndex],
- MSchedGraphEdge::MemoryDep,
- MSchedGraphEdge::TrueDep);
- }
- }
-
- //All instructions before the src in execution order have an iteration delay of 1
- for(unsigned destIndex = 0; destIndex < srcIndex; ++destIndex) {
- //source is a Load, so add anti-dependencies (store after load)
- if(TMI->isLoad(srcNodeOpCode))
- if(TMI->isStore(memInst[destIndex]->getInst()->getOpcode()))
- memInst[srcIndex]->addOutEdge(memInst[destIndex],
- MSchedGraphEdge::MemoryDep,
- MSchedGraphEdge::AntiDep, 1);
- if(TMI->isStore(srcNodeOpCode)) {
- if(TMI->isStore(memInst[destIndex]->getInst()->getOpcode()))
- memInst[srcIndex]->addOutEdge(memInst[destIndex],
- MSchedGraphEdge::MemoryDep,
- MSchedGraphEdge::OutputDep, 1);
- else
- memInst[srcIndex]->addOutEdge(memInst[destIndex],
- MSchedGraphEdge::MemoryDep,
- MSchedGraphEdge::TrueDep, 1);
- }
-
- }
-
- }
-}
diff --git a/lib/CodeGen/ModuloScheduling/MSchedGraph.h b/lib/CodeGen/ModuloScheduling/MSchedGraph.h
deleted file mode 100644
index 4ea572a380..0000000000
--- a/lib/CodeGen/ModuloScheduling/MSchedGraph.h
+++ /dev/null
@@ -1,316 +0,0 @@
-//===-- MSchedGraph.h - Scheduling Graph ------------------------*- 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.
-//
-//===----------------------------------------------------------------------===//
-//
-// A graph class for dependencies
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLVM_MSCHEDGRAPH_H
-#define LLVM_MSCHEDGRAPH_H
-
-#include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/Target/TargetMachine.h"
-#include "llvm/ADT/GraphTraits.h"
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/iterator"
-#include <vector>
-
-namespace llvm {
- class MSchedGraph;
- class MSchedGraphNode;
- template<class IteratorType, class NodeType>
- class MSchedGraphNodeIterator;
-
-
- struct MSchedGraphEdge {
- enum DataDepOrderType {
- TrueDep, AntiDep, OutputDep, NonDataDep
- };
-
- enum MSchedGraphEdgeType {
- MemoryDep, ValueDep, MachineRegister
- };
-
- MSchedGraphNode *getDest() const { return dest; }
- unsigned getIteDiff() { return iteDiff; }
- unsigned getDepOrderType() { return depOrderType; }
-
- private:
- friend class MSchedGraphNode;
- MSchedGraphEdge(MSchedGraphNode *destination, MSchedGraphEdgeType type,
- unsigned deptype, unsigned diff)
- : dest(destination), depType(type), depOrderType(deptype), iteDiff(diff) {}
-
- MSchedGraphNode *dest;
- MSchedGraphEdgeType depType;
- unsigned depOrderType;
- unsigned iteDiff;
- };
-
- class MSchedGraphNode {
-
- const MachineInstr* Inst; //Machine Instruction
- MSchedGraph* Parent; //Graph this node belongs to
- unsigned latency; //Latency of Instruction
- bool isBranchInstr; //Is this node the branch instr or not
-
- std::vector<MSchedGraphNode*> Predecessors; //Predecessor Nodes
- std::vector<MSchedGraphEdge> Successors;
-
- public:
- MSchedGraphNode(const MachineInstr *inst, MSchedGraph *graph,
- unsigned late=0, bool isBranch=false);
-
- //Iterators
- typedef std::vector<MSchedGraphNode*>::iterator pred_iterator;
- pred_iterator pred_begin() { return Predecessors.begin(); }
- pred_iterator pred_end() { return Predecessors.end(); }
-
- typedef std::vector<MSchedGraphNode*>::const_iterator pred_const_iterator;
- pred_const_iterator pred_begin() const { return Predecessors.begin(); }
- pred_const_iterator pred_end() const { return Predecessors.end(); }
-
- // Successor iterators.
- typedef MSchedGraphNodeIterator<std::vector<MSchedGraphEdge>::const_iterator,
- const MSchedGraphNode> succ_const_iterator;
- succ_const_iterator succ_begin() const;
- succ_const_iterator succ_end() const;
-
- typedef MSchedGraphNodeIterator<std::vector<MSchedGraphEdge>::iterator,
- MSchedGraphNode> succ_iterator;
- succ_iterator succ_begin();
- succ_iterator succ_end();
-
-
-
- void addOutEdge(MSchedGraphNode *destination,
- MSchedGraphEdge::MSchedGraphEdgeType type,
- unsigned deptype, unsigned diff=0) {
- Successors.push_back(MSchedGraphEdge(destination, type, deptype,diff));
- destination->Predecessors.push_back(this);
- }
- const MachineInstr* getInst() { return Inst; }
- MSchedGraph* getParent() { return Parent; }
- bool hasPredecessors() { return (Predecessors.size() > 0); }
- bool hasSuccessors() { return (Successors.size() > 0); }
- int getLatency() { return latency; }
- MSchedGraphEdge getInEdge(MSchedGraphNode *pred);
- unsigned getInEdgeNum(MSchedGraphNode *pred);
-
- bool isSuccessor(MSchedGraphNode *);
- bool isPredecessor(MSchedGraphNode *);
- bool isBranch() { return isBranchInstr; }
- //Debug support
- void print(std::ostream &os) const;
-
- };
-
- template<class IteratorType, class NodeType>
- class MSchedGraphNodeIterator : public forward_iterator<NodeType*, ptrdiff_t> {
- IteratorType I; // std::vector<MSchedGraphEdge>::iterator or const_iterator
- public:
- MSchedGraphNodeIterator(IteratorType i) : I(i) {}
-
- bool operator==(const MSchedGraphNodeIterator RHS) const { return I == RHS.I; }
- bool operator!=(const MSchedGraphNodeIterator RHS) const { return I != RHS.I; }
-
- const MSchedGraphNodeIterator &operator=(const MSchedGraphNodeIterator &RHS) {
- I = RHS.I;
- return *this;
- }
-
- NodeType* operator*() const {
- return I->getDest();
- }
- NodeType* operator->() const { return operator*(); }
-
- MSchedGraphNodeIterator& operator++() { // Preincrement
- ++I;
- return *this;
- }
- MSchedGraphNodeIterator operator++(int) { // Postincrement
- MSchedGraphNodeIterator tmp = *this; ++*this; return tmp;
- }
-
- MSchedGraphEdge &getEdge() {
- return *I;
- }
- const MSchedGraphEdge &getEdge() const {
- return *I;
- }
- };
-
- inline MSchedGraphNode::succ_const_iterator MSchedGraphNode::succ_begin() const {
- return succ_const_iterator(Successors.begin());
- }
- inline MSchedGraphNode::succ_const_iterator MSchedGraphNode::succ_end() const {
- return succ_const_iterator(Successors.end());
- }
- inline MSchedGraphNode::succ_iterator MSchedGraphNode::succ_begin() {
- return succ_iterator(Successors.begin());
- }
- inline MSchedGraphNode::succ_iterator MSchedGraphNode::succ_end() {
- return succ_iterator(Successors.end());
- }
-
- // ostream << operator for MSGraphNode class
- inline std::ostream &operator<<(std::ostream &os,
- const MSchedGraphNode &node) {
- node.print(os);
- return os;
- }
-
-
-
- class MSchedGraph {
-
- const MachineBasicBlock *BB; //Machine basic block
- const TargetMachine &Target; //Target Machine
-
- //Nodes
- std::map<const MachineInstr*, MSchedGraphNode*> GraphMap;
-
- //Add Nodes and Edges to this graph for our BB
- typedef std::pair<int, MSchedGraphNode*> OpIndexNodePair;
- void buildNodesAndEdges();
- void addValueEdges(std::vector<OpIndexNodePair> &NodesInMap,
- MSchedGraphNode *node,
- bool nodeIsUse, bool nodeIsDef, int diff=0);
- void addMachRegEdges(std::map<int,
- std::vector<OpIndexNodePair> >& regNumtoNodeMap);
- void addMemEdges(const std::vector<MSchedGraphNode*>& memInst);
-
- public:
- MSchedGraph(const MachineBasicBlock *bb, const TargetMachine &targ);
- ~MSchedGraph();
-
- //Add Nodes to the Graph
- void addNode(const MachineInstr* MI, MSchedGraphNode *node);
-
- //iterators
- typedef std::map<const MachineInstr*, MSchedGraphNode*>::iterator iterator;
- typedef std::map<const MachineInstr*, MSchedGraphNode*>::const_iterator const_iterator;
- typedef std::map<const MachineInstr*, MSchedGraphNode*>::reverse_iterator reverse_iterator;
- iterator find(const MachineInstr* I) { return GraphMap.find(I); }
- iterator end() { return GraphMap.end(); }
- iterator begin() { return GraphMap.begin(); }
- reverse_iterator rbegin() { return GraphMap.rbegin(); }
- reverse_iterator rend() { return GraphMap.rend(); }
- const TargetMachine* getTarget() { return &Target; }
- };
-
-
- static MSchedGraphNode& getSecond(std::pair<const MachineInstr* const,
- MSchedGraphNode*> &Pair) {
- return *Pair.second;
- }
-
-
-
- // Provide specializations of GraphTraits to be able to use graph
- // iterators on the scheduling graph!
- //
- template <> struct GraphTraits<MSchedGraph