Chris seems fond of #include <vector>. Fix these. Also convert use list in
authorChris Lattner <sabre@nondot.org>
Fri, 14 Sep 2001 16:56:32 +0000 (16:56 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 14 Sep 2001 16:56:32 +0000 (16:56 +0000)
Value to a vector instead of a list.

Move SchedGraph.h & SchedPriorities.h into lib/CodeGen/InstrScheduling

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@572 91177308-0d34-0410-b5e6-96231b3b80d8

28 files changed:
include/llvm/CodeGen/InstrSelection.h
include/llvm/CodeGen/MachineInstr.h
include/llvm/CodeGen/SchedGraph.h [deleted file]
include/llvm/CodeGen/SchedPriorities.h [deleted file]
include/llvm/ConstPoolVals.h
include/llvm/DerivedTypes.h
include/llvm/InstrTypes.h
include/llvm/Instruction.h
include/llvm/SymbolTable.h
include/llvm/Target/Data.h
include/llvm/Target/RegInfo.h
include/llvm/User.h
include/llvm/Value.h
include/llvm/iOther.h
lib/CodeGen/InstrSched/InstrScheduling.cpp
lib/CodeGen/InstrSched/SchedGraph.cpp
lib/CodeGen/InstrSched/SchedGraph.h [new file with mode: 0644]
lib/CodeGen/InstrSched/SchedPriorities.cpp
lib/CodeGen/InstrSched/SchedPriorities.h [new file with mode: 0644]
lib/Target/SparcV9/InstrSched/InstrScheduling.cpp
lib/Target/SparcV9/InstrSched/SchedGraph.cpp
lib/Target/SparcV9/InstrSched/SchedGraph.h [new file with mode: 0644]
lib/Target/SparcV9/InstrSched/SchedPriorities.cpp
lib/Target/SparcV9/InstrSched/SchedPriorities.h [new file with mode: 0644]
lib/Target/SparcV9/SparcV9Internals.h
lib/Target/SparcV9/SparcV9RegInfo.h
lib/Target/SparcV9/SparcV9TargetMachine.cpp
lib/VMCore/Value.cpp

index 0a8a92706d0c4975c322ac43fff6cfe5326d7d02..e07ebd7a3330184d5a3caba91cfc3dd6d12eb109 100644 (file)
@@ -13,7 +13,6 @@
 #define LLVM_CODEGEN_INSTR_SELECTION_H
 
 #include "llvm/Instruction.h"
-#include <vector>
 class Method;
 class InstrForest;
 class MachineInstr;
index 9903f09c01ddc9563c8d7ea9b05ddc261c591490..29e832dd5853a987f48a013a4b8e2d2b339c6005 100644 (file)
@@ -19,7 +19,7 @@
 #include "llvm/CodeGen/InstrForest.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/NonCopyable.h"
-#include "llvm/Target/Machine.h"
+#include "llvm/Target/InstInfo.h"
 
 template<class _MI, class _V> class ValOpIterator;
 
diff --git a/include/llvm/CodeGen/SchedGraph.h b/include/llvm/CodeGen/SchedGraph.h
deleted file mode 100644 (file)
index e12d90f..0000000
+++ /dev/null
@@ -1,495 +0,0 @@
-/* -*-C++-*-
- ****************************************************************************
- * File:
- *     SchedGraph.h
- * 
- * Purpose:
- *     Scheduling graph based on SSA graph plus extra dependence edges
- *     capturing dependences due to machine resources (machine registers,
- *     CC registers, and any others).
- * 
- * Strategy:
- *     This graph tries to leverage the SSA graph as much as possible,
- *     but captures the extra dependences through a common interface.
- * 
- * History:
- *     7/20/01  -  Vikram Adve  -  Created
- ***************************************************************************/
-
-#ifndef LLVM_CODEGEN_SCHEDGRAPH_H
-#define LLVM_CODEGEN_SCHEDGRAPH_H
-
-#include "llvm/CFGdecls.h"                     // just for graph iterators
-#include "llvm/Support/NonCopyable.h"
-#include "llvm/Support/HashExtras.h"
-#include <hash_map>
-
-class Value;
-class Instruction;
-class BasicBlock;
-class Method;
-class TargetMachine;
-class SchedGraphEdge; 
-class SchedGraphNode; 
-class SchedGraph; 
-class NodeToRegRefMap;
-
-/******************** Exported Data Types and Constants ********************/
-
-typedef int ResourceId;
-const ResourceId InvalidResourceId = -1;
-
-
-//*********************** Public Class Declarations ************************/
-
-class SchedGraphEdge: public NonCopyable {
-public:
-  enum SchedGraphEdgeDepType {
-    CtrlDep, MemoryDep, DefUseDep, MachineRegister, MachineResource
-  };
-  enum DataDepOrderType {
-    TrueDep, AntiDep, OutputDep, NonDataDep
-  };
-  
-protected:
-  SchedGraphNode*      src;
-  SchedGraphNode*      sink;
-  SchedGraphEdgeDepType depType;
-  DataDepOrderType     depOrderType;
-  int                  minDelay; // cached latency (assumes fixed target arch)
-  
-  union {
-    Value*     val;
-    int                machineRegNum;
-    ResourceId  resourceId;
-  };
-  
-public:        
-  // For all constructors, if minDelay is unspecified, minDelay is
-  // set to _src->getLatency().
-  // constructor for CtrlDep or MemoryDep edges, selected by 3rd argument
-  /*ctor*/             SchedGraphEdge(SchedGraphNode* _src,
-                                      SchedGraphNode* _sink,
-                                      SchedGraphEdgeDepType _depType,
-                                      DataDepOrderType _depOrderType =TrueDep,
-                                      int _minDelay = -1);
-  
-  // constructor for explicit def-use or memory def-use edge
-  /*ctor*/             SchedGraphEdge(SchedGraphNode* _src,
-                                      SchedGraphNode* _sink,
-                                      Value*          _val,
-                                      DataDepOrderType _depOrderType =TrueDep,
-                                      int _minDelay = -1);
-  
-  // constructor for machine register dependence
-  /*ctor*/             SchedGraphEdge(SchedGraphNode* _src,
-                                      SchedGraphNode* _sink,
-                                      unsigned int    _regNum,
-                                      DataDepOrderType _depOrderType =TrueDep,
-                                      int _minDelay = -1);
-  
-  // constructor for any other machine resource dependences.
-  // DataDepOrderType is always NonDataDep.  It it not an argument to
-  // avoid overloading ambiguity with previous constructor.
-  /*ctor*/             SchedGraphEdge(SchedGraphNode* _src,
-                                      SchedGraphNode* _sink,
-                                      ResourceId      _resourceId,
-                                      int _minDelay = -1);
-  
-  /*dtor*/             ~SchedGraphEdge() {}
-  
-  SchedGraphNode*      getSrc          () const { return src; }
-  SchedGraphNode*      getSink         () const { return sink; }
-  int                  getMinDelay     () const { return minDelay; }
-  SchedGraphEdgeDepType getDepType     () const { return depType; }
-  
-  const Value*         getValue        () const {
-    assert(depType == DefUseDep || depType == MemoryDep); return val;
-  }
-  int                  getMachineReg   () const {
-    assert(depType == MachineRegister); return machineRegNum;
-  }
-  int                  getResourceId   () const {
-    assert(depType == MachineResource); return resourceId;
-  }
-  
-public:
-  // 
-  // Debugging support
-  // 
-  friend ostream& operator<<(ostream& os, const SchedGraphEdge& edge);
-  
-  void         dump    (int indent=0) const;
-    
-private:
-  // disable default ctor
-  /*ctor*/             SchedGraphEdge();       // DO NOT IMPLEMENT
-};
-
-
-
-class SchedGraphNode: public NonCopyable {
-private:
-  unsigned int nodeId;
-  const Instruction* instr;
-  const MachineInstr* minstr;
-  vector<SchedGraphEdge*> inEdges;
-  vector<SchedGraphEdge*> outEdges;
-  int latency;
-  
-public:
-  typedef      vector<SchedGraphEdge*>::iterator       iterator;
-  typedef      vector<SchedGraphEdge*>::const_iterator const_iterator;
-  
-public:
-  //
-  // Accessor methods
-  // 
-  unsigned int         getNodeId       () const { return nodeId; }
-  const Instruction*   getInstr        () const { return instr; }
-  const MachineInstr*  getMachineInstr () const { return minstr; }
-  int                  getLatency      () const { return latency; }
-  unsigned int         getNumInEdges   () const { return inEdges.size(); }
-  unsigned int         getNumOutEdges  () const { return outEdges.size(); }
-  bool                 isDummyNode     () const { return (minstr == NULL); }
-  
-  //
-  // Iterators
-  // 
-  iterator             beginInEdges    ()       { return inEdges.begin(); }
-  iterator             endInEdges      ()       { return inEdges.end(); }
-  iterator             beginOutEdges   ()       { return outEdges.begin(); }
-  iterator             endOutEdges     ()       { return outEdges.end(); }
-  
-  const_iterator       beginInEdges    () const { return inEdges.begin(); }
-  const_iterator       endInEdges      () const { return inEdges.end(); }
-  const_iterator       beginOutEdges   () const { return outEdges.begin(); }
-  const_iterator       endOutEdges     () const { return outEdges.end(); }
-  
-  //
-  // Limited modifier methods
-  // 
-  void                 eraseAllEdges   ();
-  
-public:
-  //
-  // Debugging support
-  // 
-  friend ostream& operator<<(ostream& os, const SchedGraphNode& node);
-  
-  void         dump    (int indent=0) const;
-  
-private:
-  friend class SchedGraph;             // give access for ctor and dtor
-  friend class SchedGraphEdge;         // give access for adding edges
-  
-  void                 addInEdge       (SchedGraphEdge* edge);
-  void                 addOutEdge      (SchedGraphEdge* edge);
-  
-  void                 removeInEdge    (const SchedGraphEdge* edge);
-  void                 removeOutEdge   (const SchedGraphEdge* edge);
-  
-  // disable default constructor and provide a ctor for single-block graphs
-  /*ctor*/             SchedGraphNode();       // DO NOT IMPLEMENT
-  /*ctor*/             SchedGraphNode  (unsigned int _nodeId,
-                                        const Instruction* _instr,
-                                        const MachineInstr* _minstr,
-                                        const TargetMachine& _target);
-  /*dtor*/             ~SchedGraphNode ();
-};
-
-
-
-class SchedGraph :
-  public NonCopyable,
-  private hash_map<const MachineInstr*, SchedGraphNode*>
-{
-private:
-  vector<const BasicBlock*> bbVec;     // basic blocks included in the graph
-  SchedGraphNode* graphRoot;           // the root and leaf are not inserted
-  SchedGraphNode* graphLeaf;           //  in the hash_map (see getNumNodes())
-  
-public:
-  typedef hash_map<const MachineInstr*, SchedGraphNode*>::iterator iterator;
-  typedef hash_map<const MachineInstr*, SchedGraphNode*>::const_iterator const_iterator;
-  
-public:
-  //
-  // Accessor methods
-  //
-  const vector<const BasicBlock*>& getBasicBlocks() const { return bbVec; }
-  const unsigned int              getNumNodes()    const { return size()+2; }
-  SchedGraphNode*                 getRoot()        const { return graphRoot; }
-  SchedGraphNode*                 getLeaf()        const { return graphLeaf; }
-  
-  SchedGraphNode* getGraphNodeForInstr(const MachineInstr* minstr) const {
-    const_iterator onePair = this->find(minstr);
-    return (onePair != this->end())? (*onePair).second : NULL;
-  }
-  
-  //
-  // Delete a node from the graph.
-  // 
-  void           eraseNode(SchedGraphNode* node);
-  
-  //
-  // Unordered iterators.
-  // Return values is pair<const MachineIntr*,SchedGraphNode*>.
-  //
-  iterator     begin() {
-    return hash_map<const MachineInstr*, SchedGraphNode*>::begin();
-  }
-  iterator     end() {
-    return hash_map<const MachineInstr*, SchedGraphNode*>::end();
-  }
-  const_iterator begin() const {
-    return hash_map<const MachineInstr*, SchedGraphNode*>::begin();
-  }
-  const_iterator end() const {
-    return hash_map<const MachineInstr*, SchedGraphNode*>::end();
-  }
-  
-  //
-  // Ordered iterators.
-  // Return values is pair<const MachineIntr*,SchedGraphNode*>.
-  //
-  // void                         postord_init();
-  // postorder_iterator           postord_begin();
-  // postorder_iterator           postord_end();
-  // const_postorder_iterator postord_begin() const;
-  // const_postorder_iterator postord_end() const;
-  
-  //
-  // Debugging support
-  // 
-  void         dump    () const;
-  
-private:
-  friend class SchedGraphSet;          // give access to ctor
-  
-  // disable default constructor and provide a ctor for single-block graphs
-  /*ctor*/     SchedGraph              ();     // DO NOT IMPLEMENT
-  /*ctor*/     SchedGraph              (const BasicBlock* bb,
-                                        const TargetMachine& target);
-  /*dtor*/     ~SchedGraph             ();
-  
-  inline void  noteGraphNodeForInstr   (const MachineInstr* minstr,
-                                        SchedGraphNode* node)
-  {
-    assert((*this)[minstr] == NULL);
-    (*this)[minstr] = node;
-  }
-
-  //
-  // Graph builder
-  //
-  void         buildGraph              (const TargetMachine& target);
-  
-  void         addEdgesForInstruction  (SchedGraphNode* node,
-                                        NodeToRegRefMap& regToRefVecMap,
-                                        const TargetMachine& target);
-  
-  void         addCDEdges              (const TerminatorInst* term,
-                                        const TargetMachine& target);
-  
-  void         addMemEdges          (const vector<const Instruction*>& memVec,
-                                     const TargetMachine& target);
-  
-  void         addMachineRegEdges      (NodeToRegRefMap& regToRefVecMap,
-                                        const TargetMachine& target);
-  
-  void         addSSAEdge              (SchedGraphNode* node,
-                                        Value* val,
-                                        const TargetMachine& target);
-  
-  void         addDummyEdges           ();
-};
-
-
-class SchedGraphSet :  
-  public NonCopyable,
-  private hash_map<const BasicBlock*, SchedGraph*>
-{
-private:
-  const Method* method;
-  
-public:
-  typedef hash_map<const BasicBlock*, SchedGraph*>::iterator iterator;
-  typedef hash_map<const BasicBlock*, SchedGraph*>::const_iterator const_iterator;
-  
-public:
-  /*ctor*/     SchedGraphSet           (const Method* _method,
-                                        const TargetMachine& target);
-  /*dtor*/     ~SchedGraphSet          ();
-  
-  //
-  // Accessors
-  //
-  SchedGraph*  getGraphForBasicBlock   (const BasicBlock* bb) const {
-    const_iterator onePair = this->find(bb);
-    return (onePair != this->end())? (*onePair).second : NULL;
-  }
-  
-  //
-  // Iterators
-  //
-  iterator     begin() {
-    return hash_map<const BasicBlock*, SchedGraph*>::begin();
-  }
-  iterator     end() {
-    return hash_map<const BasicBlock*, SchedGraph*>::end();
-  }
-  const_iterator begin() const {
-    return hash_map<const BasicBlock*, SchedGraph*>::begin();
-  }
-  const_iterator end() const {
-    return hash_map<const BasicBlock*, SchedGraph*>::end();
-  }
-  
-  //
-  // Debugging support
-  // 
-  void         dump    () const;
-  
-private:
-  inline void  noteGraphForBlock(const BasicBlock* bb, SchedGraph* graph) {
-    assert((*this)[bb] == NULL);
-    (*this)[bb] = graph;
-  }
-
-  //
-  // Graph builder
-  //
-  void         buildGraphsForMethod    (const Method *method,
-                                        const TargetMachine& target);
-};
-
-
-//********************** Sched Graph Iterators *****************************/
-
-// Ok to make it a template because it shd get instantiated at most twice:
-// for <SchedGraphNode, SchedGraphNode::iterator> and
-// for <const SchedGraphNode, SchedGraphNode::const_iterator>.
-// 
-template <class _NodeType, class _EdgeType, class _EdgeIter>
-class PredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
-protected:
-  _EdgeIter oi;
-public:
-  typedef PredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
-  
-  inline PredIterator(_EdgeIter startEdge) : oi(startEdge) {}
-  
-  inline bool operator==(const _Self& x) const { return oi == x.oi; }
-  inline bool operator!=(const _Self& x) const { return !operator==(x); }
-  
-  // operator*() differs for pred or succ iterator
-  inline _NodeType* operator*() const { return (*oi)->getSrc(); }
-  inline        _NodeType* operator->() const { return operator*(); }
-  
-  inline _EdgeType* getEdge() const { return *(oi); }
-  
-  inline _Self &operator++() { ++oi; return *this; }    // Preincrement
-  inline _Self operator++(int) {                       // Postincrement
-    _Self tmp(*this); ++*this; return tmp; 
-  }
-  
-  inline _Self &operator--() { --oi; return *this; }    // Predecrement
-  inline _Self operator--(int) {                               // Postdecrement
-    _Self tmp = *this; --*this; return tmp;
-  }
-};
-
-template <class _NodeType, class _EdgeType, class _EdgeIter>
-class SuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
-protected:
-  _EdgeIter oi;
-public:
-  typedef SuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
-  
-  inline SuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
-  
-  inline bool operator==(const _Self& x) const { return oi == x.oi; }
-  inline bool operator!=(const _Self& x) const { return !operator==(x); }
-  
-  inline _NodeType* operator*() const { return (*oi)->getSink(); }
-  inline        _NodeType* operator->() const { return operator*(); }
-  
-  inline _EdgeType* getEdge() const { return *(oi); }
-  
-  inline _Self &operator++() { ++oi; return *this; }    // Preincrement
-  inline _Self operator++(int) {                       // Postincrement
-    _Self tmp(*this); ++*this; return tmp; 
-  }
-  
-  inline _Self &operator--() { --oi; return *this; }    // Predecrement
-  inline _Self operator--(int) {                               // Postdecrement
-    _Self tmp = *this; --*this; return tmp;
-  }
-};
-
-// 
-// sg_pred_iterator
-// sg_pred_const_iterator
-//
-typedef PredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
-    sg_pred_iterator;
-typedef PredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
-    sg_pred_const_iterator;
-
-inline sg_pred_iterator       pred_begin(      SchedGraphNode *N) {
-  return sg_pred_iterator(N->beginInEdges());
-}
-inline sg_pred_iterator       pred_end(        SchedGraphNode *N) {
-  return sg_pred_iterator(N->endInEdges());
-}
-inline sg_pred_const_iterator pred_begin(const SchedGraphNode *N) {
-  return sg_pred_const_iterator(N->beginInEdges());
-}
-inline sg_pred_const_iterator pred_end(  const SchedGraphNode *N) {
-  return sg_pred_const_iterator(N->endInEdges());
-}
-
-
-// 
-// sg_succ_iterator
-// sg_succ_const_iterator
-//
-typedef SuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
-    sg_succ_iterator;
-typedef SuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
-    sg_succ_const_iterator;
-
-inline sg_succ_iterator       succ_begin(      SchedGraphNode *N) {
-  return sg_succ_iterator(N->beginOutEdges());
-}
-inline sg_succ_iterator       succ_end(        SchedGraphNode *N) {
-  return sg_succ_iterator(N->endOutEdges());
-}
-inline sg_succ_const_iterator succ_begin(const SchedGraphNode *N) {
-  return sg_succ_const_iterator(N->beginOutEdges());
-}
-inline sg_succ_const_iterator succ_end(  const SchedGraphNode *N) {
-  return sg_succ_const_iterator(N->endOutEdges());
-}
-
-// 
-// po_iterator
-// po_const_iterator
-//
-typedef cfg::POIterator<SchedGraphNode, sg_succ_iterator> sg_po_iterator;
-typedef cfg::POIterator<const SchedGraphNode, 
-                       sg_succ_const_iterator> sg_po_const_iterator;
-
-
-//************************ External Functions *****************************/
-
-
-ostream& operator<<(ostream& os, const SchedGraphEdge& edge);
-
-ostream& operator<<(ostream& os, const SchedGraphNode& node);
-
-
-/***************************************************************************/
-
-#endif
diff --git a/include/llvm/CodeGen/SchedPriorities.h b/include/llvm/CodeGen/SchedPriorities.h
deleted file mode 100644 (file)
index 45f19b4..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-/* -*-C++-*-
- ****************************************************************************
- * File:
- *     SchedPriorities.h
- * 
- * Purpose:
- *     Encapsulate heuristics for instruction scheduling.
- * 
- * Strategy:
- *    Priority ordering rules:
- *    (1) Max delay, which is the order of the heap S.candsAsHeap.
- *    (2) Instruction that frees up a register.
- *    (3) Instruction that has the maximum number of dependent instructions.
- *    Note that rules 2 and 3 are only used if issue conflicts prevent
- *    choosing a higher priority instruction by rule 1.
- * 
- * History:
- *     7/30/01  -  Vikram Adve  -  Created
- ***************************************************************************/
-
-#ifndef LLVM_CODEGEN_SCHEDPRIORITIES_H
-#define LLVM_CODEGEN_SCHEDPRIORITIES_H
-
-#include "llvm/CodeGen/InstrScheduling.h"
-#include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
-#include "llvm/CodeGen/SchedGraph.h"
-#include "llvm/Target/SchedInfo.h"
-
-class Method;
-class MachineInstr;
-class SchedulingManager;
-
-
-struct NodeDelayPair {
-  const SchedGraphNode* node;
-  cycles_t delay;
-  NodeDelayPair(const SchedGraphNode* n, cycles_t d) :  node(n), delay(d) {}
-  inline bool operator< (const NodeDelayPair& np) { return delay < np.delay; }
-};
-
-inline bool
-NDPLessThan(const NodeDelayPair* np1, const NodeDelayPair* np2)
-{
-  return (np1->delay < np2->delay);
-}
-
-class NodeHeap: public list<NodeDelayPair*>, public NonCopyable {
-public:
-  typedef list<NodeDelayPair*>::iterator iterator;
-  typedef list<NodeDelayPair*>::const_iterator const_iterator;
-  
-public:
-  /*ctor*/       NodeHeap      () : list<NodeDelayPair*>(), _size(0) {}
-  /*dtor*/       ~NodeHeap     () {}
-  
-  inline unsigned int  size    () const { return _size; }
-  
-  const SchedGraphNode* getNode        (const_iterator i) const { return (*i)->node; }
-  cycles_t             getDelay(const_iterator i) const { return (*i)->delay;}
-  
-  inline void          makeHeap() { 
-    // make_heap(begin(), end(), NDPLessThan);
-  }
-  
-  inline iterator      findNode(const SchedGraphNode* node) {
-    for (iterator I=begin(); I != end(); ++I)
-      if (getNode(I) == node)
-       return I;
-    return end();
-  }
-  
-  inline void    removeNode    (const SchedGraphNode* node) {
-    iterator ndpPtr = findNode(node);
-    if (ndpPtr != end())
-      {
-       delete *ndpPtr;
-       erase(ndpPtr);
-       --_size;
-      }
-  };
-  
-  void           insert(const SchedGraphNode* node, cycles_t delay) {
-    NodeDelayPair* ndp = new NodeDelayPair(node, delay);
-    if (_size == 0 || front()->delay < delay)
-      push_front(ndp);
-    else
-      {
-       iterator I=begin();
-       for ( ; I != end() && getDelay(I) >= delay; ++I)
-         ;
-       list<NodeDelayPair*>::insert(I, ndp);
-      }
-    _size++;
-  }
-private:
-  unsigned int _size;
-};
-
-
-class SchedPriorities: public NonCopyable {
-public:
-  /*ctor*/     SchedPriorities         (const Method* method,
-                                        const SchedGraph* _graph);
-  
-  // This must be called before scheduling begins.
-  void         initialize              ();
-  
-  cycles_t     getTime                 () const { return curTime; }
-  cycles_t     getEarliestReadyTime    () const { return earliestReadyTime; }
-  unsigned     getNumReady             () const { return candsAsHeap.size(); }
-  bool         nodeIsReady             (const SchedGraphNode* node) const {
-    return (candsAsSet.find(node) != candsAsSet.end());
-  }
-  
-  void         issuedReadyNodeAt       (cycles_t curTime,
-                                        const SchedGraphNode* node);
-  
-  void         insertReady             (const SchedGraphNode* node);
-  
-  void         updateTime              (cycles_t /*unused*/);
-  
-  const SchedGraphNode* getNextHighest (const SchedulingManager& S,
-                                        cycles_t curTime);
-                                       // choose next highest priority instr
-  
-private:
-  typedef NodeHeap::iterator candIndex;
-  
-private:
-  cycles_t curTime;
-  const SchedGraph* graph;
-  MethodLiveVarInfo methodLiveVarInfo;
-  hash_map<const MachineInstr*, bool> lastUseMap;
-  vector<cycles_t> nodeDelayVec;
-  vector<cycles_t> earliestForNode;
-  cycles_t earliestReadyTime;
-  NodeHeap candsAsHeap;                                // candidate nodes, ready to go
-  hash_set<const SchedGraphNode*> candsAsSet;  // same entries as candsAsHeap,
-                                               //   but as set for fast lookup
-  vector<candIndex> mcands;                    // holds pointers into cands
-  candIndex nextToTry;                         // next cand after the last
-                                               //   one tried in this cycle
-  
-  int          chooseByRule1           (vector<candIndex>& mcands);
-  int          chooseByRule2           (vector<candIndex>& mcands);
-  int          chooseByRule3           (vector<candIndex>& mcands);
-  
-  void         findSetWithMaxDelay     (vector<candIndex>& mcands,
-                                        const SchedulingManager& S);
-  
-  void         computeDelays           (const SchedGraph* graph);
-  
-  void         initializeReadyHeap     (const SchedGraph* graph);
-  
-  bool         instructionHasLastUse   (MethodLiveVarInfo& methodLiveVarInfo,
-                                        const SchedGraphNode* graphNode);
-  
-  // NOTE: The next two return references to the actual vector entries.
-  //       Use with care.
-  cycles_t&    getNodeDelayRef         (const SchedGraphNode* node) {
-    assert(node->getNodeId() < nodeDelayVec.size());
-    return nodeDelayVec[node->getNodeId()];
-  }
-  cycles_t&    getEarliestForNodeRef   (const SchedGraphNode* node) {
-    assert(node->getNodeId() < earliestForNode.size());
-    return earliestForNode[node->getNodeId()];
-  }
-};
-
-
-inline void
-SchedPriorities::insertReady(const SchedGraphNode* node)
-{
-  candsAsHeap.insert(node, nodeDelayVec[node->getNodeId()]);
-  candsAsSet.insert(node);
-  mcands.clear(); // ensure reset choices is called before any more choices
-  earliestReadyTime = min(earliestReadyTime,
-                         earliestForNode[node->getNodeId()]);
-  
-  if (SchedDebugLevel >= Sched_PrintSchedTrace)
-    {
-      cout << "    Cycle " << this->getTime() << ": "
-          << " Node " << node->getNodeId() << " is ready; "
-          << " Delay = " << this->getNodeDelayRef(node) << "; Instruction: "
-          << endl;
-      cout << "        " << *node->getMachineInstr() << endl;
-    }
-}
-
-inline void SchedPriorities::updateTime(cycles_t c) {
-  curTime = c;
-  nextToTry = candsAsHeap.begin();
-  mcands.clear();
-}
-
-inline ostream& operator<< (ostream& os, const NodeDelayPair* nd) {
-  return os << "Delay for node " << nd->node->getNodeId()
-           << " = " << nd->delay << endl;
-}
-
-/***************************************************************************/
-
-#endif
index 09260b5cea742b00f62a94809196501249621302..71ca6a7a96df812b8e69e5195dfc3c1b9bbf6cd4 100644 (file)
@@ -10,7 +10,6 @@
 
 #include "llvm/User.h"
 #include "llvm/Support/DataTypes.h"
-#include <vector>
 
 class ArrayType;
 class StructType;
index e024ed3edc47af7895f75b2846589291f763644b..3f93459b23268c31b572237ec808cf396c067a07 100644 (file)
@@ -12,7 +12,6 @@
 #define LLVM_DERIVED_TYPES_H
 
 #include "llvm/Type.h"
-#include <vector>
 
 class DerivedType : public Type {
   // AbstractTypeUsers - Implement a list of the users that need to be notified
index 1f771e635010cacfe0307c3643fab3d8178b1343..75c4943e44504f0b7499be77a6c268e5d38c20cf 100644 (file)
@@ -10,8 +10,6 @@
 #define LLVM_INSTRUCTION_TYPES_H
 
 #include "llvm/Instruction.h"
-#include <list>
-#include <vector>
 
 class Method;
 class SymTabValue;
index 2bb590bc5e5428de8f30b242fafdd86be2811eba..3bbb8e7031eb3f86ca6f84c9e0aaa245077158d7 100644 (file)
@@ -13,7 +13,7 @@
 class Type;
 class BasicBlock;
 class Method;
-class MachineInstr;            // do not include header file MachineInstr.h
+class MachineInstr;
 class MachineCodeForVMInstr;
 
 class Instruction : public User {
index a53608f1d955b01fa963fb463f9e60cb2ae30596..18ccf136c0c8215255578b3837e4a5664c3781cf 100644 (file)
@@ -17,7 +17,6 @@
 #define LLVM_SYMBOL_TABLE_H
 
 #include "llvm/Value.h"
-#include <vector>
 #include <map>
 
 class Value;
index 55739503e7294088b1a394ca3b7062b02b671579..aa0afbcb7d6d6ea48849f05293be8d452747217e 100644 (file)
@@ -14,7 +14,6 @@
 #define LLVM_TARGET_DATA_H
 
 #include "llvm/Type.h"
-#include <vector>
 
 class StructType;
 class StructLayout;
index 726baabf24fe94619292ba2c6a18e02b4a91255f..bb1b029b28cf42f09249c4d9149f20ea30fc5863 100644 (file)
@@ -8,9 +8,14 @@
 #ifndef LLVM_TARGET_REGINFO_H
 #define LLVM_TARGET_REGINFO_H
 
-class LiveRangeInfo;
-class Method;
+#include "llvm/Support/NonCopyable.h"
+#include <hash_map>
+#include <string>
+
+class Value;
 class Instruction;
+class Method;
+class LiveRangeInfo;
 class LiveRange;
 class AddedInstrns;
 class MachineInstr;
index d914b1fc1d8592fe54e5cef28140e1206e1163bf..535dd1e88af93685a3f16c3c3fa07b4c7dd3ad19 100644 (file)
@@ -13,7 +13,6 @@
 #define LLVM_USER_H
 
 #include "llvm/Value.h"
-#include <vector>
 
 class User : public Value {
   User(const User &);             // Do not implement
index dd97d3577d762e9baddea8785faed68928921c86..d2bf4cd5f1993f7bcfbcdf63679a495239513a68 100644 (file)
@@ -8,7 +8,7 @@
 #ifndef LLVM_VALUE_H
 #define LLVM_VALUE_H
 
-#include <list>
+#include <vector>
 #include "llvm/Annotation.h"
 #include "llvm/AbstractTypeUser.h"
 
@@ -44,7 +44,7 @@ public:
   };
 
 private:
-  list<User *> Uses;
+  vector<User *> Uses;
   string Name;
   PATypeHandle<Type> Ty;
   ValueTy VTy;
@@ -130,10 +130,10 @@ public:
   virtual void refineAbstractType(const DerivedType *OldTy, const Type *NewTy);
 
   //----------------------------------------------------------------------
-  // Methods for handling the list of uses of this DEF.
+  // Methods for handling the vector of uses of this Value.
   //
-  typedef list<User*>::iterator       use_iterator;
-  typedef list<User*>::const_iterator use_const_iterator;
+  typedef vector<User*>::iterator       use_iterator;
+  typedef vector<User*>::const_iterator use_const_iterator;
 
   inline unsigned           use_size()  const { return Uses.size();  }
   inline bool               use_empty() const { return Uses.empty(); }
index 97f326258101744252a2d9054315603fcd23bd5d..e723d4e9751617a4f55a9278fbd45cea81b4cdbd 100644 (file)
@@ -10,7 +10,6 @@
 
 #include "llvm/InstrTypes.h"
 #include "llvm/Method.h"
-#include <vector>
 
 //===----------------------------------------------------------------------===//
 //                               PHINode Class
index 494da31cf5be6a91a4aa7caa5e9eb1ee57a40650..382dc3b60bd886007e9c931b2b6de02b6ef42ece 100644 (file)
@@ -9,7 +9,7 @@
 //***************************************************************************
 
 #include "llvm/CodeGen/InstrScheduling.h"
-#include "llvm/CodeGen/SchedPriorities.h"
+#include "SchedPriorities.h"
 #include "llvm/Analysis/LiveVar/BBLiveVar.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Support/CommandLine.h"
index 1ad2b0fb4538219067b3399fe2453905a4b4dedd..5f0de8b9322ff80e7a5b62093f09f8e3feb3dbad 100644 (file)
  *     7/20/01  -  Vikram Adve  -  Created
  ***************************************************************************/
 
+#include "SchedGraph.h"
 #include "llvm/InstrTypes.h"
 #include "llvm/Instruction.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/Method.h"
-#include "llvm/CodeGen/SchedGraph.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Target/InstInfo.h"
 #include "llvm/Support/StringExtras.h"
diff --git a/lib/CodeGen/InstrSched/SchedGraph.h b/lib/CodeGen/InstrSched/SchedGraph.h
new file mode 100644 (file)
index 0000000..e12d90f
--- /dev/null
@@ -0,0 +1,495 @@
+/* -*-C++-*-
+ ****************************************************************************
+ * File:
+ *     SchedGraph.h
+ * 
+ * Purpose:
+ *     Scheduling graph based on SSA graph plus extra dependence edges
+ *     capturing dependences due to machine resources (machine registers,
+ *     CC registers, and any others).
+ * 
+ * Strategy:
+ *     This graph tries to leverage the SSA graph as much as possible,
+ *     but captures the extra dependences through a common interface.
+ * 
+ * History:
+ *     7/20/01  -  Vikram Adve  -  Created
+ ***************************************************************************/
+
+#ifndef LLVM_CODEGEN_SCHEDGRAPH_H
+#define LLVM_CODEGEN_SCHEDGRAPH_H
+
+#include "llvm/CFGdecls.h"                     // just for graph iterators
+#include "llvm/Support/NonCopyable.h"
+#include "llvm/Support/HashExtras.h"
+#include <hash_map>
+
+class Value;
+class Instruction;
+class BasicBlock;
+class Method;
+class TargetMachine;
+class SchedGraphEdge; 
+class SchedGraphNode; 
+class SchedGraph; 
+class NodeToRegRefMap;
+
+/******************** Exported Data Types and Constants ********************/
+
+typedef int ResourceId;
+const ResourceId InvalidResourceId = -1;
+
+
+//*********************** Public Class Declarations ************************/
+
+class SchedGraphEdge: public NonCopyable {
+public:
+  enum SchedGraphEdgeDepType {
+    CtrlDep, MemoryDep, DefUseDep, MachineRegister, MachineResource
+  };
+  enum DataDepOrderType {
+    TrueDep, AntiDep, OutputDep, NonDataDep
+  };
+  
+protected:
+  SchedGraphNode*      src;
+  SchedGraphNode*      sink;
+  SchedGraphEdgeDepType depType;
+  DataDepOrderType     depOrderType;
+  int                  minDelay; // cached latency (assumes fixed target arch)
+  
+  union {
+    Value*     val;
+    int                machineRegNum;
+    ResourceId  resourceId;
+  };
+  
+public:        
+  // For all constructors, if minDelay is unspecified, minDelay is
+  // set to _src->getLatency().
+  // constructor for CtrlDep or MemoryDep edges, selected by 3rd argument
+  /*ctor*/             SchedGraphEdge(SchedGraphNode* _src,
+                                      SchedGraphNode* _sink,
+                                      SchedGraphEdgeDepType _depType,
+                                      DataDepOrderType _depOrderType =TrueDep,
+                                      int _minDelay = -1);
+  
+  // constructor for explicit def-use or memory def-use edge
+  /*ctor*/             SchedGraphEdge(SchedGraphNode* _src,
+                                      SchedGraphNode* _sink,
+                                      Value*          _val,
+                                      DataDepOrderType _depOrderType =TrueDep,
+                                      int _minDelay = -1);
+  
+  // constructor for machine register dependence
+  /*ctor*/             SchedGraphEdge(SchedGraphNode* _src,
+                                      SchedGraphNode* _sink,
+                                      unsigned int    _regNum,
+                                      DataDepOrderType _depOrderType =TrueDep,
+                                      int _minDelay = -1);
+  
+  // constructor for any other machine resource dependences.
+  // DataDepOrderType is always NonDataDep.  It it not an argument to
+  // avoid overloading ambiguity with previous constructor.
+  /*ctor*/             SchedGraphEdge(SchedGraphNode* _src,
+                                      SchedGraphNode* _sink,
+                                      ResourceId      _resourceId,
+                                      int _minDelay = -1);
+  
+  /*dtor*/             ~SchedGraphEdge() {}
+  
+  SchedGraphNode*      getSrc          () const { return src; }
+  SchedGraphNode*      getSink         () const { return sink; }
+  int                  getMinDelay     () const { return minDelay; }
+  SchedGraphEdgeDepType getDepType     () const { return depType; }
+  
+  const Value*         getValue        () const {
+    assert(depType == DefUseDep || depType == MemoryDep); return val;
+  }
+  int                  getMachineReg   () const {
+    assert(depType == MachineRegister); return machineRegNum;
+  }
+  int                  getResourceId   () const {
+    assert(depType == MachineResource); return resourceId;
+  }
+  
+public:
+  // 
+  // Debugging support
+  // 
+  friend ostream& operator<<(ostream& os, const SchedGraphEdge& edge);
+  
+  void         dump    (int indent=0) const;
+    
+private:
+  // disable default ctor
+  /*ctor*/             SchedGraphEdge();       // DO NOT IMPLEMENT
+};
+
+
+
+class SchedGraphNode: public NonCopyable {
+private:
+  unsigned int nodeId;
+  const Instruction* instr;
+  const MachineInstr* minstr;
+  vector<SchedGraphEdge*> inEdges;
+  vector<SchedGraphEdge*> outEdges;
+  int latency;
+  
+public:
+  typedef      vector<SchedGraphEdge*>::iterator       iterator;
+  typedef      vector<SchedGraphEdge*>::const_iterator const_iterator;
+  
+public:
+  //
+  // Accessor methods
+  // 
+  unsigned int         getNodeId       () const { return nodeId; }
+  const Instruction*   getInstr        () const { return instr; }
+  const MachineInstr*  getMachineInstr () const { return minstr; }
+  int                  getLatency      () const { return latency; }
+  unsigned int         getNumInEdges   () const { return inEdges.size(); }
+  unsigned int         getNumOutEdges  () const { return outEdges.size(); }
+  bool                 isDummyNode     () const { return (minstr == NULL); }
+  
+  //
+  // Iterators
+  // 
+  iterator             beginInEdges    ()       { return inEdges.begin(); }
+  iterator             endInEdges      ()       { return inEdges.end(); }
+  iterator             beginOutEdges   ()       { return outEdges.begin(); }
+  iterator             endOutEdges     ()       { return outEdges.end(); }
+  
+  const_iterator       beginInEdges    () const { return inEdges.begin(); }
+  const_iterator       endInEdges      () const { return inEdges.end(); }
+  const_iterator       beginOutEdges   () const { return outEdges.begin(); }
+  const_iterator       endOutEdges     () const { return outEdges.end(); }
+  
+  //
+  // Limited modifier methods
+  // 
+  void                 eraseAllEdges   ();
+  
+public:
+  //
+  // Debugging support
+  // 
+  friend ostream& operator<<(ostream& os, const SchedGraphNode& node);
+  
+  void         dump    (int indent=0) const;
+  
+private:
+  friend class SchedGraph;             // give access for ctor and dtor
+  friend class SchedGraphEdge;         // give access for adding edges
+  
+  void                 addInEdge       (SchedGraphEdge* edge);
+  void                 addOutEdge      (SchedGraphEdge* edge);
+  
+  void                 removeInEdge    (const SchedGraphEdge* edge);
+  void                 removeOutEdge   (const SchedGraphEdge* edge);
+  
+  // disable default constructor and provide a ctor for single-block graphs
+  /*ctor*/             SchedGraphNode();       // DO NOT IMPLEMENT
+  /*ctor*/             SchedGraphNode  (unsigned int _nodeId,
+                                        const Instruction* _instr,
+                                        const MachineInstr* _minstr,
+                                        const TargetMachine& _target);
+  /*dtor*/             ~SchedGraphNode ();
+};
+
+
+
+class SchedGraph :
+  public NonCopyable,
+  private hash_map<const MachineInstr*, SchedGraphNode*>
+{
+private:
+  vector<const BasicBlock*> bbVec;     // basic blocks included in the graph
+  SchedGraphNode* graphRoot;           // the root and leaf are not inserted
+  SchedGraphNode* graphLeaf;           //  in the hash_map (see getNumNodes())
+  
+public:
+  typedef hash_map<const MachineInstr*, SchedGraphNode*>::iterator iterator;
+  typedef hash_map<const MachineInstr*, SchedGraphNode*>::const_iterator const_iterator;
+  
+public:
+  //
+  // Accessor methods
+  //
+  const vector<const BasicBlock*>& getBasicBlocks() const { return bbVec; }
+  const unsigned int              getNumNodes()    const { return size()+2; }
+  SchedGraphNode*                 getRoot()        const { return graphRoot; }
+  SchedGraphNode*                 getLeaf()        const { return graphLeaf; }
+  
+  SchedGraphNode* getGraphNodeForInstr(const MachineInstr* minstr) const {
+    const_iterator onePair = this->find(minstr);
+    return (onePair != this->end())? (*onePair).second : NULL;
+  }
+  
+  //
+  // Delete a node from the graph.
+  // 
+  void           eraseNode(SchedGraphNode* node);
+  
+  //
+  // Unordered iterators.
+  // Return values is pair<const MachineIntr*,SchedGraphNode*>.
+  //
+  iterator     begin() {
+    return hash_map<const MachineInstr*, SchedGraphNode*>::begin();
+  }
+  iterator     end() {
+    return hash_map<const MachineInstr*, SchedGraphNode*>::end();
+  }
+  const_iterator begin() const {
+    return hash_map<const MachineInstr*, SchedGraphNode*>::begin();
+  }
+  const_iterator end() const {
+    return hash_map<const MachineInstr*, SchedGraphNode*>::end();
+  }
+  
+  //
+  // Ordered iterators.
+  // Return values is pair<const MachineIntr*,SchedGraphNode*>.
+  //
+  // void                         postord_init();
+  // postorder_iterator           postord_begin();
+  // postorder_iterator           postord_end();
+  // const_postorder_iterator postord_begin() const;
+  // const_postorder_iterator postord_end() const;
+  
+  //
+  // Debugging support
+  // 
+  void         dump    () const;
+  
+private:
+  friend class SchedGraphSet;          // give access to ctor
+  
+  // disable default constructor and provide a ctor for single-block graphs
+  /*ctor*/     SchedGraph              ();     // DO NOT IMPLEMENT
+  /*ctor*/     SchedGraph              (const BasicBlock* bb,
+                                        const TargetMachine& target);
+  /*dtor*/     ~SchedGraph             ();
+  
+  inline void  noteGraphNodeForInstr   (const MachineInstr* minstr,
+                                        SchedGraphNode* node)
+  {
+    assert((*this)[minstr] == NULL);
+    (*this)[minstr] = node;
+  }
+
+  //
+  // Graph builder
+  //
+  void         buildGraph              (const TargetMachine& target);
+  
+  void         addEdgesForInstruction  (SchedGraphNode* node,
+                                        NodeToRegRefMap& regToRefVecMap,
+                                        const TargetMachine& target);
+  
+  void         addCDEdges              (const TerminatorInst* term,
+                                        const TargetMachine& target);
+  
+  void         addMemEdges          (const vector<const Instruction*>& memVec,
+                                     const TargetMachine& target);
+  
+  void         addMachineRegEdges      (NodeToRegRefMap& regToRefVecMap,
+                                        const TargetMachine& target);
+  
+  void         addSSAEdge              (SchedGraphNode* node,
+                                        Value* val,
+                                        const TargetMachine& target);
+  
+  void         addDummyEdges           ();
+};
+
+
+class SchedGraphSet :  
+  public NonCopyable,
+  private hash_map<const BasicBlock*, SchedGraph*>
+{
+private:
+  const Method* method;
+  
+public:
+  typedef hash_map<const BasicBlock*, SchedGraph*>::iterator iterator;
+  typedef hash_map<const BasicBlock*, SchedGraph*>::const_iterator const_iterator;
+  
+public:
+  /*ctor*/     SchedGraphSet           (const Method* _method,
+                                        const TargetMachine& target);
+  /*dtor*/     ~SchedGraphSet          ();
+  
+  //
+  // Accessors
+  //
+  SchedGraph*  getGraphForBasicBlock   (const BasicBlock* bb) const {
+    const_iterator onePair = this->find(bb);
+    return (onePair != this->end())? (*onePair).second : NULL;
+  }
+  
+  //
+  // Iterators
+  //
+  iterator     begin() {
+    return hash_map<const BasicBlock*, SchedGraph*>::begin();
+  }
+  iterator     end() {
+    return hash_map<const BasicBlock*, SchedGraph*>::end();
+  }
+  const_iterator begin() const {
+    return hash_map<const BasicBlock*, SchedGraph*>::begin();
+  }
+  const_iterator end() const {
+    return hash_map<const BasicBlock*, SchedGraph*>::end();
+  }
+  
+  //
+  // Debugging support
+  // 
+  void         dump    () const;
+  
+private:
+  inline void  noteGraphForBlock(const BasicBlock* bb, SchedGraph* graph) {
+    assert((*this)[bb] == NULL);
+    (*this)[bb] = graph;
+  }
+
+  //
+  // Graph builder
+  //
+  void         buildGraphsForMethod    (const Method *method,
+                                        const TargetMachine& target);
+};
+
+
+//********************** Sched Graph Iterators *****************************/
+
+// Ok to make it a template because it shd get instantiated at most twice:
+// for <SchedGraphNode, SchedGraphNode::iterator> and
+// for <const SchedGraphNode, SchedGraphNode::const_iterator>.
+// 
+template <class _NodeType, class _EdgeType, class _EdgeIter>
+class PredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
+protected:
+  _EdgeIter oi;
+public:
+  typedef PredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
+  
+  inline PredIterator(_EdgeIter startEdge) : oi(startEdge) {}
+  
+  inline bool operator==(const _Self& x) const { return oi == x.oi; }
+  inline bool operator!=(const _Self& x) const { return !operator==(x); }
+  
+  // operator*() differs for pred or succ iterator
+  inline _NodeType* operator*() const { return (*oi)->getSrc(); }
+  inline        _NodeType* operator->() const { return operator*(); }
+  
+  inline _EdgeType* getEdge() const { return *(oi); }
+  
+  inline _Self &operator++() { ++oi; return *this; }    // Preincrement
+  inline _Self operator++(int) {                       // Postincrement
+    _Self tmp(*this); ++*this; return tmp; 
+  }
+  
+  inline _Self &operator--() { --oi; return *this; }    // Predecrement
+  inline _Self operator--(int) {                               // Postdecrement
+    _Self tmp = *this; --*this; return tmp;
+  }
+};
+
+template <class _NodeType, class _EdgeType, class _EdgeIter>
+class SuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
+protected:
+  _EdgeIter oi;
+public:
+  typedef SuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
+  
+  inline SuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
+  
+  inline bool operator==(const _Self& x) const { return oi == x.oi; }
+  inline bool operator!=(const _Self& x) const { return !operator==(x); }
+  
+  inline _NodeType* operator*() const { return (*oi)->getSink(); }
+  inline        _NodeType* operator->() const { return operator*(); }
+  
+  inline _EdgeType* getEdge() const { return *(oi); }
+  
+  inline _Self &operator++() { ++oi; return *this; }    // Preincrement
+  inline _Self operator++(int) {                       // Postincrement
+    _Self tmp(*this); ++*this; return tmp; 
+  }
+  
+  inline _Self &operator--() { --oi; return *this; }    // Predecrement
+  inline _Self operator--(int) {                               // Postdecrement
+    _Self tmp = *this; --*this; return tmp;
+  }
+};
+
+// 
+// sg_pred_iterator
+// sg_pred_const_iterator
+//
+typedef PredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
+    sg_pred_iterator;
+typedef PredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
+    sg_pred_const_iterator;
+
+inline sg_pred_iterator       pred_begin(      SchedGraphNode *N) {
+  return sg_pred_iterator(N->beginInEdges());
+}
+inline sg_pred_iterator       pred_end(        SchedGraphNode *N) {
+  return sg_pred_iterator(N->endInEdges());
+}
+inline sg_pred_const_iterator pred_begin(const SchedGraphNode *N) {
+  return sg_pred_const_iterator(N->beginInEdges());
+}
+inline sg_pred_const_iterator pred_end(  const SchedGraphNode *N) {
+  return sg_pred_const_iterator(N->endInEdges());
+}
+
+
+// 
+// sg_succ_iterator
+// sg_succ_const_iterator
+//
+typedef SuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
+    sg_succ_iterator;
+typedef SuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
+    sg_succ_const_iterator;
+
+inline sg_succ_iterator       succ_begin(      SchedGraphNode *N) {
+  return sg_succ_iterator(N->beginOutEdges());
+}
+inline sg_succ_iterator       succ_end(        SchedGraphNode *N) {
+  return sg_succ_iterator(N->endOutEdges());
+}
+inline sg_succ_const_iterator succ_begin(const SchedGraphNode *N) {
+  return sg_succ_const_iterator(N->beginOutEdges());
+}
+inline sg_succ_const_iterator succ_end(  const SchedGraphNode *N) {
+  return sg_succ_const_iterator(N->endOutEdges());
+}
+
+// 
+// po_iterator
+// po_const_iterator
+//
+typedef cfg::POIterator<SchedGraphNode, sg_succ_iterator> sg_po_iterator;
+typedef cfg::POIterator<const SchedGraphNode, 
+                       sg_succ_const_iterator> sg_po_const_iterator;
+
+
+//************************ External Functions *****************************/
+
+
+ostream& operator<<(ostream& os, const SchedGraphEdge& edge);
+
+ostream& operator<<(ostream& os, const SchedGraphNode& node);
+
+
+/***************************************************************************/
+
+#endif
index c09f9fc24e585e0be5a9672831e97f9d9c6eb5f8..a4396c2d25624bc410501ea041c1ca68ce119cfb 100644 (file)
@@ -18,7 +18,7 @@
  *     7/30/01  -  Vikram Adve  -  Created
  ***************************************************************************/
 
-#include "llvm/CodeGen/SchedPriorities.h"
+#include "SchedPriorities.h"
 
 
 SchedPriorities::SchedPriorities(const Method* method,
diff --git a/lib/CodeGen/InstrSched/SchedPriorities.h b/lib/CodeGen/InstrSched/SchedPriorities.h
new file mode 100644 (file)
index 0000000..1765dba
--- /dev/null
@@ -0,0 +1,203 @@
+/* -*-C++-*-
+ ****************************************************************************
+ * File:
+ *     SchedPriorities.h
+ * 
+ * Purpose:
+ *     Encapsulate heuristics for instruction scheduling.
+ * 
+ * Strategy:
+ *    Priority ordering rules:
+ *    (1) Max delay, which is the order of the heap S.candsAsHeap.
+ *    (2) Instruction that frees up a register.
+ *    (3) Instruction that has the maximum number of dependent instructions.
+ *    Note that rules 2 and 3 are only used if issue conflicts prevent
+ *    choosing a higher priority instruction by rule 1.
+ * 
+ * History:
+ *     7/30/01  -  Vikram Adve  -  Created
+ ***************************************************************************/
+
+#ifndef LLVM_CODEGEN_SCHEDPRIORITIES_H
+#define LLVM_CODEGEN_SCHEDPRIORITIES_H
+
+#include "SchedGraph.h"
+#include "llvm/CodeGen/InstrScheduling.h"
+#include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
+#include "llvm/Target/SchedInfo.h"
+
+class Method;
+class MachineInstr;
+class SchedulingManager;
+
+
+struct NodeDelayPair {
+  const SchedGraphNode* node;
+  cycles_t delay;
+  NodeDelayPair(const SchedGraphNode* n, cycles_t d) :  node(n), delay(d) {}
+  inline bool operator< (const NodeDelayPair& np) { return delay < np.delay; }
+};
+
+inline bool
+NDPLessThan(const NodeDelayPair* np1, const NodeDelayPair* np2)
+{
+  return (np1->delay < np2->delay);
+}
+
+class NodeHeap: public list<NodeDelayPair*>, public NonCopyable {
+public:
+  typedef list<NodeDelayPair*>::iterator iterator;
+  typedef list<NodeDelayPair*>::const_iterator const_iterator;
+  
+public:
+  /*ctor*/       NodeHeap      () : list<NodeDelayPair*>(), _size(0) {}
+  /*dtor*/       ~NodeHeap     () {}
+  
+  inline unsigned int  size    () const { return _size; }
+  
+  const SchedGraphNode* getNode        (const_iterator i) const { return (*i)->node; }
+  cycles_t             getDelay(const_iterator i) const { return (*i)->delay;}
+  
+  inline void          makeHeap() { 
+    // make_heap(begin(), end(), NDPLessThan);
+  }
+  
+  inline iterator      findNode(const SchedGraphNode* node) {
+    for (iterator I=begin(); I != end(); ++I)
+      if (getNode(I) == node)
+       return I;
+    return end();
+  }
+  
+  inline void    removeNode    (const SchedGraphNode* node) {
+    iterator ndpPtr = findNode(node);
+    if (ndpPtr != end())
+      {
+       delete *ndpPtr;
+       erase(ndpPtr);
+       --_size;
+      }
+  };
+  
+  void           insert(const SchedGraphNode* node, cycles_t delay) {
+    NodeDelayPair* ndp = new NodeDelayPair(node, delay);
+    if (_size == 0 || front()->delay < delay)
+      push_front(ndp);
+    else
+      {
+       iterator I=begin();
+       for ( ; I != end() && getDelay(I) >= delay; ++I)
+         ;
+       list<NodeDelayPair*>::insert(I, ndp);
+      }
+    _size++;
+  }
+private:
+  unsigned int _size;
+};
+
+
+class SchedPriorities: public NonCopyable {
+public:
+  /*ctor*/     SchedPriorities         (const Method* method,
+                                        const SchedGraph* _graph);
+  
+  // This must be called before scheduling begins.
+  void         initialize              ();
+  
+  cycles_t     getTime                 () const { return curTime; }
+  cycles_t     getEarliestReadyTime    () const { return earliestReadyTime; }
+  unsigned     getNumReady             () const { return candsAsHeap.size(); }
+  bool         nodeIsReady             (const SchedGraphNode* node) const {
+    return (candsAsSet.find(node) != candsAsSet.end());
+  }
+  
+  void         issuedReadyNodeAt       (cycles_t curTime,
+                                        const SchedGraphNode* node);
+  
+  void         insertReady             (const SchedGraphNode* node);
+  
+  void         updateTime              (cycles_t /*unused*/);
+  
+  const SchedGraphNode* getNextHighest (const SchedulingManager& S,
+                                        cycles_t curTime);
+                                       // choose next highest priority instr
+  
+private:
+  typedef NodeHeap::iterator candIndex;
+  
+private:
+  cycles_t curTime;
+  const SchedGraph* graph;
+  MethodLiveVarInfo methodLiveVarInfo;
+  hash_map<const MachineInstr*, bool> lastUseMap;
+  vector<cycles_t> nodeDelayVec;
+  vector<cycles_t> earliestForNode;
+  cycles_t earliestReadyTime;
+  NodeHeap candsAsHeap;                                // candidate nodes, ready to go
+  hash_set<const SchedGraphNode*> candsAsSet;  // same entries as candsAsHeap,
+                                               //   but as set for fast lookup
+  vector<candIndex> mcands;                    // holds pointers into cands
+  candIndex nextToTry;                         // next cand after the last
+                                               //   one tried in this cycle
+  
+  int          chooseByRule1           (vector<candIndex>& mcands);
+  int          chooseByRule2           (vector<candIndex>& mcands);
+  int          chooseByRule3           (vector<candIndex>& mcands);
+  
+  void         findSetWithMaxDelay     (vector<candIndex>& mcands,
+                                        const SchedulingManager& S);
+  
+  void         computeDelays           (const SchedGraph* graph);
+  
+  void         initializeReadyHeap     (const SchedGraph* graph);
+  
+  bool         instructionHasLastUse   (MethodLiveVarInfo& methodLiveVarInfo,
+                                        const SchedGraphNode* graphNode);
+  
+  // NOTE: The next two return references to the actual vector entries.
+  //       Use with care.
+  cycles_t&    getNodeDelayRef         (const SchedGraphNode* node) {
+    assert(node->getNodeId() < nodeDelayVec.size());
+    return nodeDelayVec[node->getNodeId()];
+  }
+  cycles_t&    getEarliestForNodeRef   (const SchedGraphNode* node) {
+    assert(node->getNodeId() < earliestForNode.size());
+    return earliestForNode[node->getNodeId()];
+  }
+};
+
+
+inline void
+SchedPriorities::insertReady(const SchedGraphNode* node)
+{
+  candsAsHeap.insert(node, nodeDelayVec[node->getNodeId()]);
+  candsAsSet.insert(node);
+  mcands.clear(); // ensure reset choices is called before any more choices
+  earliestReadyTime = min(earliestReadyTime,
+                         earliestForNode[node->getNodeId()]);
+  
+  if (SchedDebugLevel >= Sched_PrintSchedTrace)
+    {
+      cout << "    Cycle " << this->getTime() << ": "
+          << " Node " << node->getNodeId() << " is ready; "
+          << " Delay = " << this->getNodeDelayRef(node) << "; Instruction: "
+          << endl;
+      cout << "        " << *node->getMachineInstr() << endl;
+    }
+}
+
+inline void SchedPriorities::updateTime(cycles_t c) {
+  curTime = c;
+  nextToTry = candsAsHeap.begin();
+  mcands.clear();
+}
+
+inline ostream& operator<< (ostream& os, const NodeDelayPair* nd) {
+  return os << "Delay for node " << nd->node->getNodeId()
+           << " = " << nd->delay << endl;
+}
+
+/***************************************************************************/
+
+#endif
index 494da31cf5be6a91a4aa7caa5e9eb1ee57a40650..382dc3b60bd886007e9c931b2b6de02b6ef42ece 100644 (file)
@@ -9,7 +9,7 @@
 //***************************************************************************
 
 #include "llvm/CodeGen/InstrScheduling.h"
-#include "llvm/CodeGen/SchedPriorities.h"
+#include "SchedPriorities.h"
 #include "llvm/Analysis/LiveVar/BBLiveVar.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Support/CommandLine.h"
index 1ad2b0fb4538219067b3399fe2453905a4b4dedd..5f0de8b9322ff80e7a5b62093f09f8e3feb3dbad 100644 (file)
  *     7/20/01  -  Vikram Adve  -  Created
  ***************************************************************************/
 
+#include "SchedGraph.h"
 #include "llvm/InstrTypes.h"
 #include "llvm/Instruction.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/Method.h"
-#include "llvm/CodeGen/SchedGraph.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Target/InstInfo.h"
 #include "llvm/Support/StringExtras.h"
diff --git a/lib/Target/SparcV9/InstrSched/SchedGraph.h b/lib/Target/SparcV9/InstrSched/SchedGraph.h
new file mode 100644 (file)
index 0000000..e12d90f
--- /dev/null
@@ -0,0 +1,495 @@
+/* -*-C++-*-
+ ****************************************************************************
+ * File:
+ *     SchedGraph.h
+ * 
+ * Purpose:
+ *     Scheduling graph based on SSA graph plus extra dependence edges
+ *     capturing dependences due to machine resources (machine registers,
+ *     CC registers, and any others).
+ * 
+ * Strategy:
+ *     This graph tries to leverage the SSA graph as much as possible,
+ *     but captures the extra dependences through a common interface.
+ * 
+ * History:
+ *     7/20/01  -  Vikram Adve  -  Created
+ ***************************************************************************/
+
+#ifndef LLVM_CODEGEN_SCHEDGRAPH_H
+#define LLVM_CODEGEN_SCHEDGRAPH_H
+
+#include "llvm/CFGdecls.h"                     // just for graph iterators
+#include "llvm/Support/NonCopyable.h"
+#include "llvm/Support/HashExtras.h"
+#include <hash_map>
+
+class Value;
+class Instruction;
+class BasicBlock;
+class Method;
+class TargetMachine;
+class SchedGraphEdge; 
+class SchedGraphNode; 
+class SchedGraph; 
+class NodeToRegRefMap;
+
+/******************** Exported Data Types and Constants ********************/
+
+typedef int ResourceId;
+const ResourceId InvalidResourceId = -1;
+
+
+//*********************** Public Class Declarations ************************/
+
+class SchedGraphEdge: public NonCopyable {
+public:
+  enum SchedGraphEdgeDepType {
+    CtrlDep, MemoryDep, DefUseDep, MachineRegister, MachineResource
+  };
+  enum DataDepOrderType {
+    TrueDep, AntiDep, OutputDep, NonDataDep
+  };
+  
+protected:
+  SchedGraphNode*      src;
+  SchedGraphNode*      sink;
+  SchedGraphEdgeDepType depType;
+  DataDepOrderType     depOrderType;
+  int                  minDelay; // cached latency (assumes fixed target arch)
+  
+  union {
+    Value*     val;
+    int                machineRegNum;
+    ResourceId  resourceId;
+  };
+  
+public:        
+  // For all constructors, if minDelay is unspecified, minDelay is
+  // set to _src->getLatency().
+  // constructor for CtrlDep or MemoryDep edges, selected by 3rd argument
+  /*ctor*/             SchedGraphEdge(SchedGraphNode* _src,
+                                      SchedGraphNode* _sink,
+                                      SchedGraphEdgeDepType _depType,
+                                      DataDepOrderType _depOrderType =TrueDep,
+                                      int _minDelay = -1);
+  
+  // constructor for explicit def-use or memory def-use edge
+  /*ctor*/             SchedGraphEdge(SchedGraphNode* _src,
+                                      SchedGraphNode* _sink,
+                                      Value*          _val,
+                                      DataDepOrderType _depOrderType =TrueDep,
+                                      int _minDelay = -1);
+  
+  // constructor for machine register dependence
+  /*ctor*/             SchedGraphEdge(SchedGraphNode* _src,
+                                      SchedGraphNode* _sink,
+                                      unsigned int    _regNum,
+                                      DataDepOrderType _depOrderType =TrueDep,
+                                      int _minDelay = -1);
+  
+  // constructor for any other machine resource dependences.
+  // DataDepOrderType is always NonDataDep.  It it not an argument to
+  // avoid overloading ambiguity with previous constructor.
+  /*ctor*/             SchedGraphEdge(SchedGraphNode* _src,
+                                      SchedGraphNode* _sink,
+                                      ResourceId      _resourceId,
+                                      int _minDelay = -1);
+  
+  /*dtor*/             ~SchedGraphEdge() {}
+  
+  SchedGraphNode*      getSrc          () const { return src; }
+  SchedGraphNode*      getSink         () const { return sink; }
+  int                  getMinDelay     () const { return minDelay; }
+  SchedGraphEdgeDepType getDepType     () const { return depType; }
+  
+  const Value*         getValue        () const {
+    assert(depType == DefUseDep || depType == MemoryDep); return val;
+  }
+  int                  getMachineReg   () const {
+    assert(depType == MachineRegister); return machineRegNum;
+  }
+  int                  getResourceId   () const {
+    assert(depType == MachineResource); return resourceId;
+  }
+  
+public:
+  // 
+  // Debugging support
+  // 
+  friend ostream& operator<<(ostream& os, const SchedGraphEdge& edge);
+  
+  void         dump    (int indent=0) const;
+    
+private:
+  // disable default ctor
+  /*ctor*/             SchedGraphEdge();       // DO NOT IMPLEMENT
+};
+
+
+
+class SchedGraphNode: public NonCopyable {
+private:
+  unsigned int nodeId;
+  const Instruction* instr;
+  const MachineInstr* minstr;
+  vector<SchedGraphEdge*> inEdges;
+  vector<SchedGraphEdge*> outEdges;
+  int latency;
+  
+public:
+  typedef      vector<SchedGraphEdge*>::iterator       iterator;
+  typedef      vector<SchedGraphEdge*>::const_iterator const_iterator;
+  
+public:
+  //
+  // Accessor methods
+  // 
+  unsigned int         getNodeId       () const { return nodeId; }
+  const Instruction*   getInstr        () const { return instr; }
+  const MachineInstr*  getMachineInstr () const { return minstr; }
+  int                  getLatency      () const { return latency; }
+  unsigned int         getNumInEdges   () const { return inEdges.size(); }
+  unsigned int         getNumOutEdges  () const { return outEdges.size(); }
+  bool                 isDummyNode     () const { return (minstr == NULL); }
+  
+  //
+  // Iterators
+  // 
+  iterator             beginInEdges    ()       { return inEdges.begin(); }
+  iterator             endInEdges      ()       { return inEdges.end(); }
+  iterator             beginOutEdges   ()       { return outEdges.begin(); }
+  iterator             endOutEdges     ()       { return outEdges.end(); }
+  
+  const_iterator       beginInEdges    () const { return inEdges.begin(); }
+  const_iterator       endInEdges      () const { return inEdges.end(); }
+  const_iterator       beginOutEdges   () const { return outEdges.begin(); }
+  const_iterator       endOutEdges     () const { return outEdges.end(); }
+  
+  //
+  // Limited modifier methods
+  // 
+  void                 eraseAllEdges   ();
+  
+public:
+  //
+  // Debugging support
+  // 
+  friend ostream& operator<<(ostream& os, const SchedGraphNode& node);
+  
+  void         dump    (int indent=0) const;
+  
+private:
+  friend class SchedGraph;             // give access for ctor and dtor
+  friend class SchedGraphEdge;         // give access for adding edges
+  
+  void                 addInEdge       (SchedGraphEdge* edge);
+  void                 addOutEdge      (SchedGraphEdge* edge);
+  
+  void                 removeInEdge    (const SchedGraphEdge* edge);
+  void                 removeOutEdge   (const SchedGraphEdge* edge);
+  
+  // disable default constructor and provide a ctor for single-block graphs
+  /*ctor*/             SchedGraphNode();       // DO NOT IMPLEMENT
+  /*ctor*/             SchedGraphNode  (unsigned int _nodeId,
+                                        const Instruction* _instr,
+                                        const MachineInstr* _minstr,
+                                        const TargetMachine& _target);
+  /*dtor*/             ~SchedGraphNode ();
+};
+
+
+
+class SchedGraph :
+  public NonCopyable,
+  private hash_map<const MachineInstr*, SchedGraphNode*>
+{
+private:
+  vector<const BasicBlock*> bbVec;     // basic blocks included in the graph
+  SchedGraphNode* graphRoot;           // the root and leaf are not inserted
+  SchedGraphNode* graphLeaf;           //  in the hash_map (see getNumNodes())
+  
+public:
+  typedef hash_map<const MachineInstr*, SchedGraphNode*>::iterator iterator;
+  typedef hash_map<const MachineInstr*, SchedGraphNode*>::const_iterator const_iterator;
+  
+public:
+  //
+  // Accessor methods
+  //
+  const vector<const BasicBlock*>& getBasicBlocks() const { return bbVec; }
+  const unsigned int              getNumNodes()    const { return size()+2; }
+  SchedGraphNode*                 getRoot()        const { return graphRoot; }
+  SchedGraphNode*                 getLeaf()        const { return graphLeaf; }
+  
+  SchedGraphNode* getGraphNodeForInstr(const MachineInstr* minstr) const {
+    const_iterator onePair = this->find(minstr);
+    return (onePair != this->end())? (*onePair).second : NULL;
+  }
+  
+  //
+  // Delete a node from the graph.
+  // 
+  void           eraseNode(SchedGraphNode* node);
+  
+  //
+  // Unordered iterators.
+  // Return values is pair<const MachineIntr*,SchedGraphNode*>.
+  //
+  iterator     begin() {
+    return hash_map<const MachineInstr*, SchedGraphNode*>::begin();
+  }
+  iterator     end() {
+    return hash_map<const MachineInstr*, SchedGraphNode*>::end();
+  }
+  const_iterator begin() const {
+    return hash_map<const MachineInstr*, SchedGraphNode*>::begin();
+  }
+  const_iterator end() const {
+    return hash_map<const MachineInstr*, SchedGraphNode*>::end();
+  }
+  
+  //
+  // Ordered iterators.
+  // Return values is pair<const MachineIntr*,SchedGraphNode*>.
+  //
+  // void                         postord_init();
+  // postorder_iterator           postord_begin();
+  // postorder_iterator           postord_end();
+  // const_postorder_iterator postord_begin() const;
+  // const_postorder_iterator postord_end() const;
+  
+  //
+  // Debugging support
+  // 
+  void         dump    () const;
+  
+private:
+  friend class SchedGraphSet;          // give access to ctor
+  
+  // disable default constructor and provide a ctor for single-block graphs
+  /*ctor*/     SchedGraph              ();     // DO NOT IMPLEMENT
+  /*ctor*/     SchedGraph              (const BasicBlock* bb,
+                                        const TargetMachine& target);
+  /*dtor*/     ~SchedGraph             ();
+  
+  inline void  noteGraphNodeForInstr   (const MachineInstr* minstr,
+                                        SchedGraphNode* node)
+  {
+    assert((*this)[minstr] == NULL);
+    (*this)[minstr] = node;
+  }
+
+  //
+  // Graph builder
+  //
+  void         buildGraph              (const TargetMachine& target);
+  
+  void         addEdgesForInstruction  (SchedGraphNode* node,
+                                        NodeToRegRefMap& regToRefVecMap,
+                                        const TargetMachine& target);
+  
+  void         addCDEdges              (const TerminatorInst* term,
+                                        const TargetMachine& target);
+  
+  void         addMemEdges          (const vector<const Instruction*>& memVec,
+                                     const TargetMachine& target);
+  
+  void         addMachineRegEdges      (NodeToRegRefMap& regToRefVecMap,
+                                        const TargetMachine& target);
+  
+  void         addSSAEdge              (SchedGraphNode* node,
+                                        Value* val,
+                                        const TargetMachine& target);
+  
+  void         addDummyEdges           ();
+};
+
+
+class SchedGraphSet :  
+  public NonCopyable,
+  private hash_map<const BasicBlock*, SchedGraph*>
+{
+private:
+  const Method* method;
+  
+public:
+  typedef hash_map<const BasicBlock*, SchedGraph*>::iterator iterator;
+  typedef hash_map<const BasicBlock*, SchedGraph*>::const_iterator const_iterator;
+  
+public:
+  /*ctor*/     SchedGraphSet           (const Method* _method,
+                                        const TargetMachine& target);
+  /*dtor*/     ~SchedGraphSet          ();
+  
+  //
+  // Accessors
+  //
+  SchedGraph*  getGraphForBasicBlock   (const BasicBlock* bb) const {
+    const_iterator onePair = this->find(bb);
+    return (onePair != this->end())? (*onePair).second : NULL;
+  }
+  
+  //
+  // Iterators
+  //
+  iterator     begin() {
+    return hash_map<const BasicBlock*, SchedGraph*>::begin();
+  }
+  iterator     end() {
+    return hash_map<const BasicBlock*, SchedGraph*>::end();
+  }
+  const_iterator begin() const {
+    return hash_map<const BasicBlock*, SchedGraph*>::begin();
+  }
+  const_iterator end() const {
+    return hash_map<const BasicBlock*, SchedGraph*>::end();
+  }
+  
+  //
+  // Debugging support
+  // 
+  void         dump    () const;
+  
+private:
+  inline void  noteGraphForBlock(const BasicBlock* bb, SchedGraph* graph) {
+    assert((*this)[bb] == NULL);
+    (*this)[bb] = graph;
+  }
+
+  //
+  // Graph builder
+  //
+  void         buildGraphsForMethod    (const Method *method,
+                                        const TargetMachine& target);
+};
+
+
+//********************** Sched Graph Iterators *****************************/
+
+// Ok to make it a template because it shd get instantiated at most twice:
+// for <SchedGraphNode, SchedGraphNode::iterator> and
+// for <const SchedGraphNode, SchedGraphNode::const_iterator>.
+// 
+template <class _NodeType, class _EdgeType, class _EdgeIter>
+class PredIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
+protected:
+  _EdgeIter oi;
+public:
+  typedef PredIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
+  
+  inline PredIterator(_EdgeIter startEdge) : oi(startEdge) {}
+  
+  inline bool operator==(const _Self& x) const { return oi == x.oi; }
+  inline bool operator!=(const _Self& x) const { return !operator==(x); }
+  
+  // operator*() differs for pred or succ iterator
+  inline _NodeType* operator*() const { return (*oi)->getSrc(); }
+  inline        _NodeType* operator->() const { return operator*(); }
+  
+  inline _EdgeType* getEdge() const { return *(oi); }
+  
+  inline _Self &operator++() { ++oi; return *this; }    // Preincrement
+  inline _Self operator++(int) {                       // Postincrement
+    _Self tmp(*this); ++*this; return tmp; 
+  }
+  
+  inline _Self &operator--() { --oi; return *this; }    // Predecrement
+  inline _Self operator--(int) {                               // Postdecrement
+    _Self tmp = *this; --*this; return tmp;
+  }
+};
+
+template <class _NodeType, class _EdgeType, class _EdgeIter>
+class SuccIterator: public std::bidirectional_iterator<_NodeType, ptrdiff_t> {
+protected:
+  _EdgeIter oi;
+public:
+  typedef SuccIterator<_NodeType, _EdgeType, _EdgeIter> _Self;
+  
+  inline SuccIterator(_EdgeIter startEdge) : oi(startEdge) {}
+  
+  inline bool operator==(const _Self& x) const { return oi == x.oi; }
+  inline bool operator!=(const _Self& x) const { return !operator==(x); }
+  
+  inline _NodeType* operator*() const { return (*oi)->getSink(); }
+  inline        _NodeType* operator->() const { return operator*(); }
+  
+  inline _EdgeType* getEdge() const { return *(oi); }
+  
+  inline _Self &operator++() { ++oi; return *this; }    // Preincrement
+  inline _Self operator++(int) {                       // Postincrement
+    _Self tmp(*this); ++*this; return tmp; 
+  }
+  
+  inline _Self &operator--() { --oi; return *this; }    // Predecrement
+  inline _Self operator--(int) {                               // Postdecrement
+    _Self tmp = *this; --*this; return tmp;
+  }
+};
+
+// 
+// sg_pred_iterator
+// sg_pred_const_iterator
+//
+typedef PredIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
+    sg_pred_iterator;
+typedef PredIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
+    sg_pred_const_iterator;
+
+inline sg_pred_iterator       pred_begin(      SchedGraphNode *N) {
+  return sg_pred_iterator(N->beginInEdges());
+}
+inline sg_pred_iterator       pred_end(        SchedGraphNode *N) {
+  return sg_pred_iterator(N->endInEdges());
+}
+inline sg_pred_const_iterator pred_begin(const SchedGraphNode *N) {
+  return sg_pred_const_iterator(N->beginInEdges());
+}
+inline sg_pred_const_iterator pred_end(  const SchedGraphNode *N) {
+  return sg_pred_const_iterator(N->endInEdges());
+}
+
+
+// 
+// sg_succ_iterator
+// sg_succ_const_iterator
+//
+typedef SuccIterator<SchedGraphNode, SchedGraphEdge, SchedGraphNode::iterator>
+    sg_succ_iterator;
+typedef SuccIterator<const SchedGraphNode, const SchedGraphEdge,SchedGraphNode::const_iterator>
+    sg_succ_const_iterator;
+
+inline sg_succ_iterator       succ_begin(      SchedGraphNode *N) {
+  return sg_succ_iterator(N->beginOutEdges());
+}
+inline sg_succ_iterator       succ_end(        SchedGraphNode *N) {
+  return sg_succ_iterator(N->endOutEdges());
+}
+inline sg_succ_const_iterator succ_begin(const SchedGraphNode *N) {
+  return sg_succ_const_iterator(N->beginOutEdges());
+}
+inline sg_succ_const_iterator succ_end(  const SchedGraphNode *N) {
+  return sg_succ_const_iterator(N->endOutEdges());
+}
+
+// 
+// po_iterator
+// po_const_iterator
+//
+typedef cfg::POIterator<SchedGraphNode, sg_succ_iterator> sg_po_iterator;
+typedef cfg::POIterator<const SchedGraphNode, 
+                       sg_succ_const_iterator> sg_po_const_iterator;
+
+
+//************************ External Functions *****************************/
+
+
+ostream& operator<<(ostream& os, const SchedGraphEdge& edge);
+
+ostream& operator<<(ostream& os, const SchedGraphNode& node);
+
+
+/***************************************************************************/
+
+#endif
index c09f9fc24e585e0be5a9672831e97f9d9c6eb5f8..a4396c2d25624bc410501ea041c1ca68ce119cfb 100644 (file)
@@ -18,7 +18,7 @@
  *     7/30/01  -  Vikram Adve  -  Created
  ***************************************************************************/
 
-#include "llvm/CodeGen/SchedPriorities.h"
+#include "SchedPriorities.h"
 
 
 SchedPriorities::SchedPriorities(const Method* method,
diff --git a/lib/Target/SparcV9/InstrSched/SchedPriorities.h b/lib/Target/SparcV9/InstrSched/SchedPriorities.h
new file mode 100644 (file)
index 0000000..1765dba
--- /dev/null
@@ -0,0 +1,203 @@
+/* -*-C++-*-
+ ****************************************************************************
+ * File:
+ *     SchedPriorities.h
+ * 
+ * Purpose:
+ *     Encapsulate heuristics for instruction scheduling.
+ * 
+ * Strategy:
+ *    Priority ordering rules:
+ *    (1) Max delay, which is the order of the heap S.candsAsHeap.
+ *    (2) Instruction that frees up a register.
+ *    (3) Instruction that has the maximum number of dependent instructions.
+ *    Note that rules 2 and 3 are only used if issue conflicts prevent
+ *    choosing a higher priority instruction by rule 1.
+ * 
+ * History:
+ *     7/30/01  -  Vikram Adve  -  Created
+ ***************************************************************************/
+
+#ifndef LLVM_CODEGEN_SCHEDPRIORITIES_H
+#define LLVM_CODEGEN_SCHEDPRIORITIES_H
+
+#include "SchedGraph.h"
+#include "llvm/CodeGen/InstrScheduling.h"
+#include "llvm/Analysis/LiveVar/MethodLiveVarInfo.h"
+#include "llvm/Target/SchedInfo.h"
+
+class Method;
+class MachineInstr;
+class SchedulingManager;
+
+
+struct NodeDelayPair {
+  const SchedGraphNode* node;
+  cycles_t delay;
+  NodeDelayPair(const SchedGraphNode* n, cycles_t d) :  node(n), delay(d) {}
+  inline bool operator< (const NodeDelayPair& np) { return delay < np.delay; }
+};
+
+inline bool
+NDPLessThan(const NodeDelayPair* np1, const NodeDelayPair* np2)
+{
+  return (np1->delay < np2->delay);
+}
+
+class NodeHeap: public list<NodeDelayPair*>, public NonCopyable {
+public:
+  typedef list<NodeDelayPair*>::iterator iterator;
+  typedef list<NodeDelayPair*>::const_iterator const_iterator;
+  
+public:
+  /*ctor*/       NodeHeap      () : list<NodeDelayPair*>(), _size(0) {}
+  /*dtor*/       ~NodeHeap     () {}
+  
+  inline unsigned int  size    () const { return _size; }
+  
+  const SchedGraphNode* getNode        (const_iterator i) const { return (*i)->node; }
+  cycles_t             getDelay(const_iterator i) const { return (*i)->delay;}
+  
+  inline void          makeHeap() { 
+    // make_heap(begin(), end(), NDPLessThan);
+  }
+  
+  inline iterator      findNode(const SchedGraphNode* node) {
+    for (iterator I=begin(); I != end(); ++I)
+      if (getNode(I) == node)
+       return I;
+    return end();
+  }
+  
+  inline void    removeNode    (const SchedGraphNode* node) {
+    iterator ndpPtr = findNode(node);
+    if (ndpPtr != end())
+      {
+       delete *ndpPtr;
+       erase(ndpPtr);
+       --_size;
+      }
+  };
+  
+  void           insert(const SchedGraphNode* node, cycles_t delay) {
+    NodeDelayPair* ndp = new NodeDelayPair(node, delay);
+    if (_size == 0 || front()->delay < delay)
+      push_front(ndp);
+    else
+      {
+       iterator I=begin();
+       for ( ; I != end() && getDelay(I) >= delay; ++I)
+         ;
+       list<NodeDelayPair*>::insert(I, ndp);
+      }
+    _size++;
+  }
+private:
+  unsigned int _size;
+};
+
+
+class SchedPriorities: public NonCopyable {
+public:
+  /*ctor*/     SchedPriorities         (const Method* method,
+                                        const SchedGraph* _graph);
+  
+  // This must be called before scheduling begins.
+  void         initialize              ();
+  
+  cycles_t     getTime                 () const { return curTime; }
+  cycles_t     getEarliestReadyTime    () const { return earliestReadyTime; }
+  unsigned     getNumReady             () const { return candsAsHeap.size(); }
+  bool         nodeIsReady             (const SchedGraphNode* node) const {
+    return (candsAsSet.find(node) != candsAsSet.end());
+  }
+  
+  void         issuedReadyNodeAt       (cycles_t curTime,
+                                        const SchedGraphNode* node);
+  
+  void         insertReady             (const SchedGraphNode* node);
+  
+  void         updateTime              (cycles_t /*unused*/);
+  
+  const SchedGraphNode* getNextHighest (const SchedulingManager& S,
+                                        cycles_t curTime);
+                                       // choose next highest priority instr
+  
+private:
+  typedef NodeHeap::iterator candIndex;
+  
+private:
+  cycles_t curTime;
+  const SchedGraph* graph;
+  MethodLiveVarInfo methodLiveVarInfo;
+  hash_map<const MachineInstr*, bool> lastUseMap;
+  vector<cycles_t> nodeDelayVec;
+  vector<cycles_t> earliestForNode;
+  cycles_t earliestReadyTime;
+  NodeHeap candsAsHeap;                                // candidate nodes, ready to go
+  hash_set<const SchedGraphNode*> candsAsSet;  // same entries as candsAsHeap,
+                                               //   but as set for fast lookup
+  vector<candIndex> mcands;                    // holds pointers into cands
+  candIndex nextToTry;                         // next cand after the last
+                                               //   one tried in this cycle
+  
+  int          chooseByRule1           (vector<candIndex>& mcands);
+  int          chooseByRule2           (vector<candIndex>& mcands);
+  int          chooseByRule3           (vector<candIndex>& mcands);
+  
+  void         findSetWithMaxDelay     (vector<candIndex>& mcands,
+                                        const SchedulingManager& S);
+  
+  void         computeDelays           (const SchedGraph* graph);
+  
+  void         initializeReadyHeap     (const SchedGraph* graph);
+  
+  bool         instructionHasLastUse   (MethodLiveVarInfo& methodLiveVarInfo,
+                                        const SchedGraphNode* graphNode);
+  
+  // NOTE: The next two return references to the actual vector entries.
+  //       Use with care.
+  cycles_t&    getNodeDelayRef         (const SchedGraphNode* node) {
+    assert(node->getNodeId() < nodeDelayVec.size());
+    return nodeDelayVec[node->getNodeId()];
+  }
+  cycles_t&    getEarliestForNodeRef   (const SchedGraphNode* node) {
+    assert(node->getNodeId() < earliestForNode.size());
+    return earliestForNode[node->getNodeId()];
+  }
+};
+
+
+inline void
+SchedPriorities::insertReady(const SchedGraphNode* node)
+{
+  candsAsHeap.insert(node, nodeDelayVec[node->getNodeId()]);
+  candsAsSet.insert(node);
+  mcands.clear(); // ensure reset choices is called before any more choices
+  earliestReadyTime = min(earliestReadyTime,
+                         earliestForNode[node->getNodeId()]);
+  
+  if (SchedDebugLevel >= Sched_PrintSchedTrace)
+    {
+      cout << "    Cycle " << this->getTime() << ": "
+          << " Node " << node->getNodeId() << " is ready; "
+          << " Delay = " << this->getNodeDelayRef(node) << "; Instruction: "
+          << endl;
+      cout << "        " << *node->getMachineInstr() << endl;
+    }
+}
+
+inline void SchedPriorities::updateTime(cycles_t c) {
+  curTime = c;
+  nextToTry = candsAsHeap.begin();
+  mcands.clear();
+}
+
+inline ostream& operator<< (ostream& os, const NodeDelayPair* nd) {
+  return os << "Delay for node " << nd->node->getNodeId()
+           << " = " << nd->delay << endl;
+}
+
+/***************************************************************************/
+
+#endif
index f9a344b37af90857ea7e438e3204417ed62cdc12..e4f0a8bd10a48105a6d5141bc66cc0e31a8862f5 100644 (file)
@@ -8,11 +8,10 @@
 #ifndef SPARC_INTERNALS_H
 #define SPARC_INTERNALS_H
 
-#include "llvm/Target/Machine.h"
 #include "SparcRegInfo.h"
-
-#include <sys/types.h>
+#include "llvm/Target/SchedInfo.h"
 #include "llvm/Type.h"
+#include <sys/types.h>
 
 class UltraSparc;
 
@@ -39,17 +38,6 @@ enum SparcInstrSchedClass {
   SPARC_NUM_SCHED_CLASSES = SPARC_INV
 };
 
-// inline operator int (const SparcInstrSchedClass& si) {
-//   return (int) si;
-// }
-// 
-// inline operator SparcInstrSchedClass (int i) {
-//   return (SparcInstrSchedClass) si;
-// }
-// 
-// inline operator const SparcInstrSchedClass (int i) {
-//   return (const SparcInstrSchedClass) si;
-// }
 
 //---------------------------------------------------------------------------
 // enum SparcMachineOpCode. 
@@ -60,7 +48,6 @@ enum SparcInstrSchedClass {
 // 
 //---------------------------------------------------------------------------
 
-
 enum SparcMachineOpCode {
 
   NOP,
index 3ebef550f08aeeac04789f1ac7af2dcb7129ee8e..67aa3a62ea3391cfabdfd705ccf247d2c440d5bd 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef SPARC_INT_REG_CLASS_H
 #define SPARC_INT_REG_CLASS_H
 
-#include "llvm/Target/Machine.h"
+#include "llvm/Target/RegInfo.h"
 
 //-----------------------------------------------------------------------------
 // Integer Register Class
index cf09734e81b184a977c7caa263a2d344d6d54c35..f1be4060be1be4c51d67523080faff42e7b961b8 100644 (file)
@@ -8,12 +8,16 @@
 //     7/15/01  -  Vikram Adve  -  Created
 //**************************************************************************/
 
-#include "llvm/CodeGen/Sparc.h"
+#include "llvm/Target/Sparc.h"
 #include "SparcInternals.h"
 #include "llvm/Method.h"
 #include "llvm/CodeGen/InstrScheduling.h"
 #include "llvm/CodeGen/InstrSelection.h"
 
+// allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine
+// that implements the Sparc backend. (the llvm/CodeGen/Sparc.h interface)
+//
+TargetMachine *allocateSparcTargetMachine() { return new UltraSparc(); }
 
 
 //---------------------------------------------------------------------------
@@ -115,7 +119,3 @@ bool UltraSparc::compileMethod(Method *M) {
   return false;
 }
 
-// allocateSparcTargetMachine - Allocate and return a subclass of TargetMachine
-// that implements the Sparc backend.
-//
-TargetMachine *allocateSparcTargetMachine() { return new UltraSparc(); }
index e48341ef51a50531606dbad771cd103b980ca992..a41262d0c64caa3ff0077bab7e88d9a107cc70ea 100644 (file)
@@ -1,6 +1,6 @@
 //===-- Value.cpp - Implement the Value class -----------------------------===//
 //
-// This file implements the Value class. 
+// This file implements the Value, User, and SymTabValue classes. 
 //
 //===----------------------------------------------------------------------===//
 
@@ -44,7 +44,7 @@ void Value::replaceAllUsesWith(Value *D) {
   assert(D && "Value::replaceAllUsesWith(<null>) is invalid!");
   assert(D != this && "V->replaceAllUsesWith(V) is NOT valid!");
   while (!Uses.empty()) {
-    User *Use = Uses.front();
+    User *Use = Uses.back();
 #ifndef NDEBUG
     unsigned NumUses = Uses.size();
 #endif