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

scheduling_utilities.C

Go to the documentation of this file.
00001 #include <iostream.h>
00002 #include <stdlib.h>
00003 #include "scheduling_utilities.H"
00004 
00005 /* Debugging support, courtesy of Sumedh */
00006 // #define _SCHEDULING_UTIL_DEBUG_
00007 #if defined (_SCHEDULING_UTIL_DEBUG_)
00008 #define derr(s)         cerr << s
00009 #else
00010 #define derr(s)
00011 #endif
00012 
00013 extern int MaxRegNum;
00014 int inp_start, inp_end;
00015 
00016 int IsDominatorParallel(legoOp *op, int readytime, legoTreegion* treegion)
00017 {
00018   legoOp *dupop;
00019   opList *dupops = op->GetDuplicateOpsPtr();
00020   int dpoptime = 0;
00021   legoRegion *dupop_block_ptr, *op_block_ptr, *root_block_ptr;
00022   regionList *region_list;
00023 
00024   derr( ">> IsDominatorParallel\n" );
00025   if (dupops == NULL)
00026     return dpoptime;
00027   derr( "Op " << op->GetOpId() << " has duplicates.\n" );
00028   for ( ; dupops != NULL && dpoptime == 0; dupops = dupops->GetNextListPtr())
00029   {
00030     dupop = dupops->GetOpPtr();
00031     if (dupop == NULL) continue;  // skip if op is missing
00032     if (dupop->GetOpId() == op->GetOpId()) continue;  // op not dp with self
00033     // Check if dupop BB dominates the BB of candidate op
00034     dupop_block_ptr = (legoRegion *) dupop->GetParentBlockPtr();
00035     op_block_ptr = (legoRegion *) op->GetParentBlockPtr();
00036     root_block_ptr = treegion->GetRoot();
00037     while ( (op_block_ptr != dupop_block_ptr) && (op_block_ptr != NULL) ) {
00038       if (op_block_ptr == root_block_ptr)
00039         break;
00040       region_list = op_block_ptr->GetParents();
00041       // blocks in a treegion have one and only one parent, except root block 
00042       // which has no parents. 
00043       if (region_list != NULL) 
00044         op_block_ptr = region_list->GetRegionPtr();
00045       else 
00046         op_block_ptr = NULL;
00047     }
00048     if ( (op_block_ptr == dupop_block_ptr) && (readytime <= dupop->GetSchedTime()) ) {
00049       dpoptime = dupop->GetSchedTime();
00050       break;
00051     }
00052   }
00053   derr ("Op " << op->GetOpId() << " is " << (!dpoptime ? "not " : "")
00054         << "dominator parallel" << (dpoptime ? " with op " : "")
00055         << (dpoptime ? dupop->GetOpId() : 0) << "\n");
00056   return dpoptime;
00057 }
00058 
00059 
00060 // GetFlowDepOprd: returns a ptr to the legoOprd that forms a flow
00061 //    dep between the Producer and Consumer operands. If Producer produces
00062 //    multiple values, the _first_ legoOprd is returned. If no flow-dep
00063 //    is found, NULL is returned.
00064 legoOprd *GetFlowDepOprd( legoOp *Producer, legoOp *Consumer )
00065 {
00066    int match, j;
00067    legoOprd *DestOprd;
00068 
00069 
00070    // A flow-dep between a BRL and a consumer is a special case. The
00071    // consumer is waiting on the BRL's return code. So set up the Consumer
00072    // to use what Producer dest oprd has the phrase 'ret' in it.
00073    if ( Producer->GetOpcode() == BRL ) {
00074 
00075       attrList *atl;
00076       attrs *a;
00077       legoOprd *oprd = NULL;
00078 
00079       for ( atl = Producer->GetOpAttrListPtr(); atl != NULL;
00080             atl = atl->GetNextListPtr() ) {
00081          if ( atl->GetAttrType() != ATTR_LC ) continue;
00082          for ( a = atl->GetAttrPtr(); a != NULL; a = a->GetNextLcEntryPtr()) {
00083             if ( strcmp( a->GetAttrString(), "ret" ) != 0 ) continue;
00084             return a->GetAttrOprdPtr();
00085          } // for
00086       } // for
00087       return NULL;
00088    } // if
00089 
00090 
00091    // Inspect all of Node's destination operands
00092    for ( match = j = 0, DestOprd = Producer->GetDestOprdPtr();
00093          DestOprd != NULL && match == 0;
00094          j++, DestOprd = DestOprd->GetNextOprdPtr() ) {
00095 
00096       int DestOprdType = DestOprd->GetOprdType();
00097 
00098       derr( "      Checking dest oprd # " << j << "\n" );
00099       if ( DestOprdType == OT_REG || DestOprdType == OT_MACRO ) {
00100 
00101          int dest_regid = DestOprd->GetOprdRegNum();
00102          int dest_reg_file_type = DestOprdType == OT_MACRO ? -1 :
00103                                         DestOprd->GetOprdFileType();
00104          legoOprd *SrcOprd;
00105          int k;
00106 
00107          // Compare the current dest. operand with all of the src
00108          // operands
00109          for ( k = 0, SrcOprd = Consumer->GetSrcOprdPtr();
00110                SrcOprd != NULL && match == 0;
00111                k++, SrcOprd = SrcOprd->GetNextOprdPtr() ) {
00112 
00113             int SrcOprdType = SrcOprd->GetOprdType();
00114 
00115             derr( "      Checking src oprd # " << k << "\n" );
00116             // if ( SrcOprdType == OT_REG || SrcOprdType == OT_MACRO ) {
00117             if ( SrcOprdType == DestOprdType ) {
00118 
00119                int src_regid = SrcOprd->GetOprdRegNum();
00120                int src_reg_file_type = SrcOprdType == OT_MACRO ? -1 :
00121                                        SrcOprd->GetOprdFileType();
00122 
00123                // if ( DestOprdType == SrcOprdType &&
00124                if ( dest_regid == src_regid &&
00125                     dest_reg_file_type == src_reg_file_type ) {
00126 
00127                   legoOprd *Src = new legoOprd( *DestOprd ),
00128                            *Dest = new legoOprd( *DestOprd );
00129 
00130                   match = 1;
00131                   derr( "   !! Match !!\n" );
00132                   return DestOprd;
00133                } // if - regid & regfiletype match
00134             } // if - operand types match
00135          } // for - all src operands
00136       } // if - dest operand is reg or macros
00137    } // for - all dest operands
00138 
00139    return NULL; // Nothing found
00140 }
00141 
00142 
00143 // ResetS_Times: Resets s_times for all operations in a procedure to -1 so 
00144 // that another pass of scheduling may follow
00145 void ResetSchedTimes( legoProc *proc )
00146 {
00147 
00148   legoOp *op; 
00149 
00150   for (op = proc->GetListOpPtr(); op != NULL; op = op->GetListOpPtr())
00151     op->SetSchedTime( -1 );
00152   
00153 }
00154 
00155 // BuildDagForRegion: builds a dag for the region
00156 void BuildDagForRegion( legoRegion *Region, machine *Machine, knobs *Knobs)
00157 {
00158    dag *DPG;
00159    
00160    derr( ">> BuildDagsForRegion: " << Region->GetRegionId() << "\n" );
00161    //DPG = new dag( Machine, Knobs );
00162 #ifdef IA64_SUPPORT
00163    printf("IA64_SUPPORT\n");
00164    DPG = new dag( Machine, Knobs, inp_start, inp_end, 8, 11, 8, 15);
00165 #endif
00166 #ifndef IA64_SUPPORT
00167    printf("NO IA64 SUPPORT\n");
00168    DPG = new dag( Machine, Knobs, 0, 0, 0, 0, 0, 0);
00169 #endif
00170    
00171 // Moved FullyResolvePredicates to LegoUtil, called during treeform
00172 //   if (Region->GetRegionType() == RT_TREE) {
00173 //     ClearMarks (RM_GENERAL, Region);
00174 //     DPG->FullyResolvePredicates( ((legoTreegion *)Region)->GetRoot(), NULL );
00175 //   }
00176    ClearMarks (RM_GENERAL, Region);
00177    printf("ClearMarks\n");
00178    DPG->ConstructDag( Region );
00179    printf("ConstructDag\n");
00180    Region->SetDAG( (dag *) DPG );
00181    printf("SetDAG\n");
00182    derr( "<< BuildDagsForRegion\n" );
00183 }
00184 
00185 
00186 // BuildDagsForProc: build dags for the regions contained within ProcPtr
00187 void BuildDagsForProc( legoProc *ProcPtr, machine *Machine, knobs *Knobs )
00188 {
00189    int i, RegionCount;
00190    legoRegion *Region;
00191    
00192    derr( ">> BuildDagsForProc: " << ProcPtr->GetProcName() << "\n" );
00193 
00194    //HZ: In constucting the DDG, we must consider the implicit dependence dewteen
00195    // arguments/returns and function calls. In IA64 assembly, 
00196    // the alloc insn, if there is one, will tell this information.   
00197    inp_start = FindFirstOutGoingReg(ProcPtr);
00198    inp_end = FindLastOutGoingReg(ProcPtr);   
00199    
00200    MaxRegNum = FindMaxRegNum (ProcPtr);
00201 
00202    for ( i = 0, RegionCount = ProcPtr->GetCount(); i < RegionCount; i++ ) {
00203      Region = (legoRegion *) ProcPtr->GetItem( i );
00204      BuildDagForRegion( Region, Machine, Knobs);
00205    }
00206    derr( "<< BuildDagsForProc\n" );
00207 }
00208 
00209 
00210 // PrintDagsForProc: prints dags for the regions contained within ProcPtr
00211 void PrintDagsForProc( legoProc *ProcPtr )
00212 {
00213    int i, RegionCount;
00214    legoRegion *Region;
00215    dag *DPG;
00216 
00217 
00218    for ( i = 0, RegionCount = ProcPtr->GetCount(); i < RegionCount; i++ ) {
00219       Region = (legoRegion *) ProcPtr->GetItem( i );
00220       DPG = (dag *) Region->GetDAG();
00221       DPG->PrintDag();
00222    }
00223 }
00224 
00225 //HZ: 08/25/00
00226 //Add function to print DAG to a file stream
00227 void PrintDagsForProc( legoProc *ProcPtr, ofstream & os1 )
00228 {
00229    int i, RegionCount;
00230    legoRegion *Region;
00231    dag *DPG;
00232 
00233    os1 << "Proc " << ProcPtr->GetProcName() << endl;
00234    for ( i = 0, RegionCount = ProcPtr->GetCount(); i < RegionCount; i++ ) 
00235    {
00236       Region = (legoRegion *) ProcPtr->GetItem( i );
00237       os1 << endl << "Region " << Region->GetRegionId() << endl;      
00238       DPG = (dag *) Region->GetDAG();
00239       if (DPG == NULL) 
00240           LegoFatal("", "DAG not constructed yet.\n");
00241       DPG->PrintDag(os1);      
00242    }
00243 }
00244 
00245 
00246 // SetNodeHeightsAndDepthsForRegion: as the name says, sets these fields for
00247 //    use by later scheduling passes
00248 void SetNodeHeightsAndDepthsForRegion( legoRegion *Region )
00249 {
00250    dag *DPG = (dag *) Region->GetDAG();
00251  
00252    DPG->SetNodeHeights();
00253    DPG->SetNodeDepths();
00254 }
00255 
00256 
00257 // SetNodeHeightsAndDepthsForProc: as the name says, sets these fields for
00258 //    use by later scheduling passes
00259 void SetNodeHeightsAndDepthsForProc( legoProc *ProcPtr )
00260 {
00261    int i, RegionCount;
00262    legoRegion *Region;
00263  
00264    for ( i = 0, RegionCount = ProcPtr->GetCount(); i < RegionCount; i++ ) {
00265       Region = (legoRegion *) ProcPtr->GetItem( i );
00266       SetNodeHeightsAndDepthsForRegion( Region );
00267    }
00268 }
00269 
00270 
00271 // SetValuesForRegion: as the name says, set Value field for each Op for
00272 //    use by later scheduling passes
00273 void SetValuesForRegion( legoRegion *Region, knobs *Knobs )
00274 {
00275    dag_node_ordering *NodeOrder = new dag_node_ordering( Region );
00276 
00277    NodeOrder->SetKnobs( Knobs ); 
00278    NodeOrder->SetDagValues();
00279    delete NodeOrder;
00280 }
00281 
00282 
00283 // SetValuesForProc: as the name says, set the Value field for each Op for
00284 //    use by later scheduling passes
00285 void SetValuesForProc( legoProc *ProcPtr, knobs *Knobs )
00286 {
00287    int i, RegionCount;
00288    legoRegion *Region;
00289 
00290 
00291 
00292    for ( i = 0, RegionCount = ProcPtr->GetCount(); i < RegionCount; i++ ) {
00293       Region = (legoRegion *) ProcPtr->GetItem( i );
00294       SetValuesForRegion( Region, Knobs );
00295    }
00296 }
00297 
00298 
00299 // MakeValueListForRegion: do a Value-based sorting on nodes
00300 //    within the Region
00301 void MakeValueListForRegion( legoRegion *Region )
00302 {
00303    dag *DPG = (dag *) Region->GetDAG();
00304  
00305    DPG->SortByValue();
00306 }
00307 
00308 
00309 // MakeValueListForProc: do a Value-based sortiing on nodes
00310 //    within the Proc
00311 void MakeValueListForProc( legoProc *ProcPtr )
00312 {
00313    int i, RegionCount;
00314    legoRegion *Region;
00315 
00316 
00317    for ( i = 0, RegionCount = ProcPtr->GetCount(); i < RegionCount; i++ ) {
00318       Region = (legoRegion *) ProcPtr->GetItem( i );
00319       MakeValueListForRegion( Region );
00320    }
00321 }
00322 
00323 // RemoveExtraAttributes: deletes non-standard attributes from Ops in Proc
00324 void RemoveExtraAttributes( legoProc *Proc )
00325 {
00326 
00327   legoOp *op; 
00328 
00329   op = Proc->GetListOpPtr();
00330   while (op != NULL) {
00331     RemoveLcAttribute( "need_duplicate", op, Proc );
00332     RemoveLcAttribute( "orig_fallthru_pred", op, Proc );
00333     RemoveLcAttribute( "no_longer_speculative", op, Proc );
00334     // RemoveLcAttribute( "inter-cluster-copy", Op, Proc );
00335     // RemoveLcAttribute( "clusterid", Op, Proc );
00336     op = op->GetListOpPtr(); 
00337   }
00338 }
00339 
00340 
00341 // DeleteRegionDag: Delete the dag for the block
00342 void DeleteRegionDag( legoRegion *Region )
00343 {
00344    dag *DPG = (dag *) Region->GetDAG();
00345 
00346    if ( DPG != NULL ) delete DPG;
00347 }
00348 
00349 
00350 // DeleteDagsInProc: Delete all dags in the proc
00351 void DeleteDagsInProc( legoProc *ProcPtr )
00352 {
00353    int i, RegionCount;
00354    legoRegion *Region;
00355 
00356 
00357    for ( i = 0, RegionCount = ProcPtr->GetCount(); i < RegionCount; i++ ) {
00358       Region = (legoRegion *) ProcPtr->GetItem( i );
00359       DeleteRegionDag( Region );
00360    }
00361 }

Generated on Mon Jul 21 20:28:54 2003 for TINKER LEGO DOC by doxygen 1.3.2