Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

dag.H

Go to the documentation of this file.
00001 // dag.H
00002 //
00003 // 2/11/98 WAH:  Broke away from Scheduler package; minor patching up.
00004 // 3/17/98 WAH:  Made drawing routine a friend.
00005 // 3/23/98 WAH:  Added RemoveUndefPredecessors.
00006 // 3/27/98 WAH:  Fixed declaration of DrawDAG (shouldn't contain default
00007 //               parameter.)
00008 // 4/1/98 WAH:   Removed explicit call to DagHashTable destructor in
00009 //               CopyDefUseTable.
00010 
00011 #ifndef _INCLUDE_DAG_H_
00012 #define _INCLUDE_DAG_H_
00013 
00014 #define IA64_SUPPORT //HZ: enable the setting of inp_start, inp_end, etc.,
00015         //intead of using INT_P1, INT_P2, etc.
00016 
00017 /*
00018 Open Issues
00019 ===========
00020 
00021 o When building the DAG, various pointers into MasterList must be
00022   maintained. The <vector> class does not gaurantee that an iterator
00023   that points into the list will point to the same item across vector
00024   insertions. How can I overcome this? Use the 'reserve' function. Could
00025   I alternatively use a ptr to a MasterList element instead?
00026 
00027 4/2/98 WAH
00028   The answer is to reserve big enough to avoid reallocation. If
00029   a vector is reallocated/expanded, iterators will become invalid;
00030   otherwise, a push_back is completely safe, while an insert invalidates
00031   iterators at the insertion point and after. An alternative is to
00032   work things so you can refresh the iterators after an insertion.
00033 
00034   Using a pointer won't work. Reallocation will physically relocate the
00035   vector somewhere else in memory, leaving a bunch of dangling pointers.
00036 
00037   I haven't looked into the code enough to be sure Sanjeev has overcome
00038   this ... I assume he has, since the DAG seems to build OK. Anyway,
00039   future developers should keep this in mind if things start going
00040   screwy. :)
00041 */
00042 
00043 
00044 /* The Eos STL dist is in /afs/eos.ncsu.edu/contrib/gcc272/lib/g++-include */
00045 #include <stl.h>
00046 #include "TinkerKnobs.H"
00047 #include "lego.H"
00048 // #include <machine.h>
00049 class machine;  // wah: replaced include with forward declaration
00050 // #include <vcgdraw.H> wah: not referenced in this file
00051 
00052 /*
00053 The DAG is implemented as an adjacency list. The list has additional
00054 pointers that allow easy graph traversal from an element of one adjacency
00055 list to the all of the successors/predecessor of that element.
00056 
00057 Ths list is organized as:
00058 
00059 
00060      Master     Small
00061      List       List
00062       _____     _       -
00063      |     |   |------>|-----> NULL  The list end
00064      |    ---->| |     | |
00065      |  |  |   | |<------|
00066       --|--     -       -
00067         |
00068         |       Small
00069        \ /      List
00070       _____     _       -
00071      |     |   |------>|-----> NULL  The list end
00072      |    ---->| |     | |
00073      |  |  |   | |<------|
00074       --|--     -       -
00075         |
00076         |
00077        \ /
00078        NULL
00079 
00080 Both sets of lists are actually organized as lists, as defined within
00081 the C++ STL.
00082 */
00083 
00084 /* DAG-specific routines */
00085 #include "DagNode.H"
00086 #include "SmallListNode.H"
00087 #include "SmallListElement.H"
00088 #include "BigListElement.H"
00089 #include "DagHashTable.H"
00090 
00091 //HZ:
00092 
00093 #define MAX_NUM_PATH 1000
00094 
00095 // wah: some forward declarations for classes which are friends of dag
00096 class dag_node_ordering;
00097 class list_scheduler;
00098 class bottom_up_greedy;
00099 
00100 // PrintTable: print entries in the def-use table
00101 void PrintTable( DagHashTable *TablePtr );
00102 
00103 
00104 /* The actual DAG */
00105 class dag {
00106 
00107 friend class dag_node_ordering;
00108 friend class list_scheduler;
00109 friend class bottom_up_greedy;
00110 friend void DrawDAG (dag *, char *);
00111 
00112 public:
00113 
00114    MainList MasterList;                 // The Master List
00115 
00116 
00117 
00118 protected:
00119 
00120    const int Hash_Key_Size = 20, Hash_Reg_Size = 10;
00121 
00122 
00123 #if defined (_STL_LIST_USED_)
00124 #endif
00125    vector < BigListElement > Vector;
00126    int  VectorActive;
00127 
00128    legoRegion           *ParentRegion;
00129    enum regionTypes     ParentRegionType;
00130 
00131    vector <char *> HashKeyList;         // A list of hash keys
00132 
00133    int KillDagFlag;                     // Work-around destructor bug
00134 
00135    MainList::iterator MainListIter,     // For misc.
00136                       BranchBarrier;    // To control branch speculation
00137 
00138    vector <MainList::iterator> StoreList; // non-load store barriers
00139    vector <MainList::iterator> LoadList;  // list of loads
00140 
00141    DagHashTable::const_iterator LookupIter;// For table lookups
00142    RegisterInfo WriteElement,           // For Table insertions
00143                 ReadElement;            // For Table reads
00144 
00145    DagHashTable Table;                  // Def-use table
00146 
00147    int NumNodes;                        // # nodes in the Master List
00148    double ProfileWeight;                // Profile weight of region, for
00149                                         // DAGs built from a single basic
00150                                         // block.
00151 
00152    machine *Machine;                    // For latency-weighted calculations
00153 
00154    int InternalNodes;
00155 
00156    // mdj 5/14/98 setBrDepsFirst patch
00157    int NotRoot;
00158 
00159    // mdj 6/9/98 prev_block_ptr used to create next_block_int attribute
00160    legoRegion *prev_block_ptr;
00161 
00162    char *WriteHashKey, *ReadHashKey,
00163         *WriteHashReg, *ReadHashReg;    // Aid in creating hash keys
00164 private:   
00165    //HZ: added for calculating the max critical path height
00166    double ave_max_height;
00167    double * max_heights;
00168    int num_path;
00169    int * path_BB_ids; 
00170    double * weights;
00171    int * num_ops; 
00172    
00173    //HZ: These parameters are added to make dag analysis aware of the use &
00174    // define of brl & ret.
00175    // These parameters should be set at the construction
00176    int inp_start, inp_end, ret_start, ret_end, fp_ret_start, fp_ret_end;
00177    
00178    
00179    void SetNodeHeightsPath(int end_bb_id);
00180    int SetNodeHeightPath(vector < BigListElement >::iterator, legoRegion
00181            *exit_reg);
00182 protected:
00183    MainList::iterator   InsertOp( BigListElement Element );
00184    void     SetBrDeps( MainList::iterator MasterListIter );
00185    // mdj 5/14/98 setBrDepsFirst patch
00186    void     SetBrDepsFirst( MainList::iterator MasterListIter, legoRegion *Region );
00187    void     SetPBRDeps( MainList::iterator MasterListIter, legoRegion *Region );
00188 
00189    void     SetVectorPtrs( vector < SmallListElement > * );
00190    void     SetSublistPtrs( VectorList *V );
00191    void     CopyVectorToVector( VectorList *v1, VectorList *v2 );
00192    void     CopyListToVector( MainList::iterator, MainList::iterator );
00193    void     CopyListToVector();
00194 
00195    void     AnalyzeFlowDep( legoOprd *, MainList::iterator );
00196    int      OutputDeps( legoOprd *, MainList::iterator );
00197    int      AntiDeps( legoOprd *, MainList::iterator );
00198 
00199    void     FlowDeps( MainList::iterator, BigListElement * );
00200    void     OutputAntiDeps( MainList::iterator, BigListElement * );
00201    void     UpdateUseStatus( MainList::iterator, BigListElement * );
00202    void     RemoveUndefPredecessors();
00203 
00204    void     ConstructLinearDag( legoRegion * );
00205    void     ConstructTreeDag(legoRegion *, DagHashTable *, 
00206                              vector <MainList::iterator> *, 
00207                              vector <MainList::iterator> *);
00208 
00209    int      SetNodeHeight( vector < BigListElement >::iterator );
00210    int      SetNodeDepth( vector < BigListElement >::iterator );
00211 
00212    void     PrintVectorDag( vector < BigListElement> * );
00213    
00214    //HZ: 08/24/00
00215    void     PrintVectorDag( vector < BigListElement> *, ofstream & os1);
00216    
00217    void     ListIntegrity( vector < BigListElement > * );
00218 
00219    void     BubbleSort( vector < BigListElement >::iterator,
00220                         vector < BigListElement >::iterator,
00221                         int (*)( BigListElement *, BigListElement * ) );
00222    void     BubbleSort( int (*)( BigListElement *, BigListElement * ) );
00223 
00224 public:
00225 
00226    // Constructors and functions to help copy info from this dag
00227 
00228    /***** Begin ******/
00229 
00230    // Constructor
00231    dag(int Inp_start, int Inp_end, int Ret_start, int Ret_end, int Fp_ret_start,
00232         int Fp_ret_end)
00233    {
00234        NumNodes = KillDagFlag = 0; 
00235        inp_start = Inp_start;
00236        inp_end = Inp_end;
00237        ret_start = Ret_start;
00238        ret_end = Ret_end;
00239        fp_ret_start = Fp_ret_start;
00240        fp_ret_end = Fp_ret_end;
00241    }
00242 
00243    // Constructor
00244    dag( machine *, int Inp_start, int Inp_end, int Ret_start, int Ret_end, int Fp_ret_start,
00245         int Fp_ret_end );
00246 
00247    // Constructor that takes a machine description and a knobs structure
00248    dag( machine *, knobs *, int Inp_start, int Inp_end, int Ret_start, int Ret_end, int Fp_ret_start,
00249         int Fp_ret_end );
00250 
00251    // Copy constructor that inits the adjacency list from the given dag
00252    void CopyGraph( dag *src );
00253 
00254    // Copy constructor that inits the def-use table from the given dag
00255    void CopyDefUseTable( dag *src )
00256    {
00257      //      Table.map( src->Table);
00258      //     Table.~DagHashTable();  // Remove old elements commented 4/1/98
00259      Table = src->Table;  // wah 3/24/98
00260    }
00261 
00262    // GetMachine
00263    machine *GetMachine()                { return Machine; }
00264 
00265    /****** End *******/
00266 
00267 
00268    // Destructors and functions to reset/free data structures
00269 
00270    /***** Begin ******/
00271 
00272    // Destructor. Calls KillDag().
00273    ~dag();
00274 
00275    // DeleteDefUseTable: delete the def-use table
00276    void     DeleteDefUseTable();
00277 
00278    // DeleteGraphNodes: delete the adjacency list
00279    void     DeleteGraphNodes();
00280 
00281    // The effective destructor. Calls DeleteDefUseTable() and
00282    // DeleteGraphNodes().
00283    void     KillDag();
00284 
00285    /****** End *******/
00286 
00287 
00288    // Dag info
00289    Stats();
00290 
00291    void     SetNumNodes( int Value )            { NumNodes = Value; }
00292    int      GetListSize()                       { return NumNodes; }
00293 
00294    void     ConstructDag( legoRegion * );
00295    vector < BigListElement > *GetList()
00296    {
00297    #if defined (_STL_LIST_USED_)
00298       return &Vector;
00299    #else if defined (_STL_VECTOR_USED_)
00300       return &MasterList;
00301    #endif
00302    }
00303 
00304    void     FullyResolvePredicates( legoRegion *, legoOp* );
00305 
00306    void     SortByOpId();
00307    void     SortByHeight();
00308    void     SortByValue();
00309 
00310    void     SetNodeHeights();
00311    void     SetNodeDepths();
00312    
00313    //HZ:
00314    void     ResetNodeHeights();
00315    void     ResetNodeDepths();
00316    
00317    void MaxHeights(); //calculate the maximum heights for each path and the
00318                           //average as well
00319    double GetAveMaxHeight() {return ave_max_height;}
00320    int GetNumPath() {return num_path;}
00321    int GetAveWidth() 
00322    {
00323        int ave_width = 0;
00324        for(int i = 0; i < num_path; i++)
00325        {
00326            ave_width += num_ops[i];
00327        }
00328        if(num_path > 0)
00329            return ave_width/num_path;
00330        else
00331            return 0;
00332    }
00333 
00334    void     PrintDag();
00335    void     PrintGraphicDag( int print_control_edges = 1 );
00336    void     PrintDag(ofstream & os1);
00337    void     PrintDefUseTable()                  { PrintTable( &Table ); }
00338 
00339    void     ListIntegrity();
00340 
00341    // RemoveDepBetweenOps: remove any edges of type edge_type between Op 1 &
00342    //   Op2. The routine expects Op2 to be a successor of Op1.
00343    //   return code info:
00344    //      0: edges deleted successfully
00345    //     -1: Op1 isn't found
00346    //     -2: edge from Op1->Op2 of dep_type isn't found
00347    //     -3: edge from Op2->Op1 of dep_type isn't found
00348    int RemoveDepBetweenOps( legoOp *Op1, legoOp *Op2, enum edgeTypes dep_type );
00349    int AreVectorsIndependent(bitvector *vector1, bitvector *vector2, int vector_size);
00350    int AreOpsDependent(legoOp *Op1, legoOp *Op2);
00351 };
00352 
00353 #endif  // _INCLUDE_DAG_H_

Generated on Mon Jul 21 20:24:06 2003 for TINKER LEGO DOC by doxygen 1.3.2