oagTimerOpt.h

Go to the documentation of this file.
00001 /************************************************************
00002 * 
00003 * File: oagTimerPeepHole.h
00004 * Author: Santiago Mok (smok@ee.ucla.edu)
00005 * Created: 09-29-2009
00006 * Last Modified: Wed 06 Oct 2010 06:16:31 PM PDT
00007 *
00008 ************************************************************/
00009 #if !defined(oagTimerOpt_P)
00010 #define oagTimerOpt_P
00011 
00012 #include <vector>
00013 #include <map>
00014 #include <algorithm>
00015 #include <iostream>
00016 
00017 #include "oaDesignDB.h"
00018 #include "oagTimerCellData.h"
00019 #include "oagTimerDesignData.h"
00020 #include "oagTimerDesignTool.h"
00021 #include "oagTimerSensitivity.h"
00022 #include "oagTimerPeepHole.h"
00023 #include "oagTimerUtil.h"
00024 
00025 namespace oagTimer{
00026 /*---------------------------------------------------------*/
00027 using namespace oa;
00028 using namespace std;
00029 /*---------------------------------------------------------*/
00030 typedef enum {
00031     UPSIZE_ROOT,
00032     DOWNSIZE_ROOT,
00033     /*IMPROVING, //Account for improving moves only
00034     NON_IMPROVING, //Account for non improving peephole candidates
00035     TRANSITIVE_CHECK, //Check for transitive fanouts
00036     */
00037 } Modes;
00038 /*---------------------------------------------------------*/
00039 typedef map<oaModInst*,oaString> CellSizingMap;
00040 /*---------------------------------------------------------*/
00041 struct FOCnt{
00042     oaModInst *inst;
00043     int numFO;
00044     int weight;
00045 };
00046 struct SizingData{
00047     CellSizingMap sizes;
00048     double leakage;
00049 };
00050 struct optData{
00051     int oneOptData;
00052     int twoOptData;
00053     int moreOptData;
00054 };
00055 /*---------------------------------------------------------*/
00056 struct cellScore{
00057     oaModInst *inst;
00058     double score;
00059 };
00060 struct combTimingData{
00061     //instVector insts;
00062     oaModInst *inst;
00063     DelayType score;
00064 };
00065 struct rootData{
00066     oaModInst *inst;
00067     double score;
00068     int fanoutLevel;
00069 };
00070 
00071 bool rankHigh(rootData a, rootData b){
00072     if(a.score > b.score) return true;
00073     return false;
00074 }
00075 
00076 bool rank_cell_score(cellScore a, cellScore b){
00077     if(a.score > b.score) return true;
00078     return false;
00079 }
00080 bool rank_high(combTimingData a, combTimingData b){
00081     if(a.score > b.score) return true;
00082     return false;
00083 }
00084 bool rank_low(combTimingData a, combTimingData b){
00085     if(a.score < b.score) return true;
00086     return false;
00087 }
00088 bool compare_nFO(const FOCnt& a, const FOCnt& b){
00089     return a.numFO < b.numFO;
00090 }
00091 bool compare_weightFO(const FOCnt& a, const FOCnt& b){
00092     return a.weight < b.weight;
00093 }
00094 static bool incr_slack_func(sensitivityData a, sensitivityData b){
00095     if(a.sensitivity < b.sensitivity) return true;
00096     else return false;
00097 }
00098 /*---------------------------------------------------------*/
00099 class Opt {  
00100     friend class PeepHole;
00101 
00102     public:
00103         Opt(oaDesign *d, Timer* t);
00104         ~Opt();
00105         
00106         //float getSensitivity(oaInst *old_inst, oaInst *new_inst){}
00107 
00108         /* Perform PeepHole Optimization */
00109         void run();
00110         void peepHoleOpt(int lvl, int i);
00111         void doOneOPT();
00112 
00113     private:
00114         bool retry();
00115         bool isValidTiming(TimeType new_arr, TimeType new_slack, double curr_arr);
00116         bool validComb(float val);
00117         /* Create list of all inst (cells) in the design 
00118          * and initialize visited flag to 0
00119          */
00120         void initDesign();
00121         void querySensitivities();
00122         //bool scanDesign();
00123 
00124         void markSwappedFanouts(instVector insts);
00125         bool isAllVisited(vector<oaModInst*> insts);
00126         bool isFanoutMarked(instVector insts);
00127 
00128         bool scanPeepHoles(sensitivityData s);
00129         void scanPeepHoles(oaModInst*);
00130         void scanPeepHoles(oaModInst* root, instVector fo,int size);
00131 
00139         bool setNewMaster(CellData *cell, oaString newMaster);
00140 
00148         void doSizing();
00149 
00150         /*Check this*/
00151         bool isVisited(oaModInst* inst);
00152 
00153         /* Swap the given combination list within 
00154          * the peephole and keep the configuration 
00155          * that meet min(leakage and delay)
00156          * return - true: swap was commmitted
00157          *          false: swap was reversed
00158          */
00159         bool doSwap(SizingData list);
00160         bool doSwap(sensitivityData d);
00161 
00162         /* Mark current and immediate fanout cells
00163          * as visited
00164          */
00165         void markVisited(vector<oaModInst*> f);
00166         
00167         /* Query for the possible set of swaps in 
00168          * the peephole
00169          */
00170         void genAllCombinations();
00171         bool genCombinations(vector<oaModInst*>::iterator &list_iter,
00172                 SizingData &data_list);
00173         /* Clear current sizing combination */
00174         void initDataStruct(SizingData &_data);
00175 
00185         instVector Preprocess_Peepholes(oaModInst* root, instVector vec);
00186 
00193         vector<combTimingData> PreprocessComb_Slack(vector<instVector> vec);
00194 
00201         vector<combTimingData> PreprocessComb_Slew(vector<instVector> vec);
00202 
00203         vector<combTimingData> rankFanoutWeight(vector<instVector> vec);
00209         double getDownSizeDelaySensitivity(CellData *c);
00210 
00211         double getUpSizeSensitivity(oaModInst* i);
00212         double getDownSizeSensitivity(oaModInst* i);
00213 
00214         void getUpSizeSensitivities(CellData *c);
00215         double getDownSizeSensitivities(CellData *c);
00216 
00217         double getInInstTermSlack(oaModInst* inst);
00218         void clearContainers();
00219 
00220         /* Debugging */
00221         void printVisitedCells();
00222         void printCombinations(SizingData _s);
00223         void printAllFanouts(vector<InstsMap> vm);
00224         void printKOptTable(oaModInst* h, vector<instVector> T);
00225         void printRootNodeSorting(vector<instTimingData> data_vector, int type);
00226         map<oaOccInstTerm*,double> getTimingInformation(vector<oaModInst*> insts);
00227         void printTimingData(map<oaOccInstTerm*,double> list);
00228         void printSensitivityList();
00229     private:
00230         oaDesign *design;
00231         Timer* timing;
00232 
00233         // Peephole width
00234         PeepHole *ph;
00235         Util ut;
00236         int level;
00237         int currFanoutLevel;
00238         int currRankLevel;
00239         bool any_move_taken;
00240         bool currPHMoveTaken;
00241         Modes mode;
00242         vector<oaModInst*> currPH_list;
00243         int max_fo;
00244         int currNotTaken;
00245 
00246         //Cells in current Design
00247         instVector design_Insts;
00248         instVector takenSwapInstsChecklist;
00249         vector<instTimingData> design_Insts_type2;
00250         vector<rootData> multiLevelRootInstances;
00251 
00252         vector<sensitivityData> sensitivity_sorted_Insts;
00253         vector<sensitivityData> upsized_sensitivity_Insts;
00254         vector<sensitivityData> downsized_sensitivity_Insts;
00255         instVector PeepholeChecklist;
00256 
00257     /* Statistic Info*/
00258         int totalNumOfTrials;
00259         int numOfTrials;
00260         int numOfTaken;
00261 
00262         int totalNumOfTaken;
00263         int numOfZeroOPTMove;
00264         int numOfOneOPTMove;
00265         int numOfTwoOPTMove;
00266         map<oaModInst*,int> sizedRootNodeCount;
00267 
00268         int numOfOneTaken;
00269         int numOfTimingInfeasiblePH;
00270         int curr_counter;
00271         int numOfPeepholeTrials;
00272         int curr_ph_counter;
00273         int total_ph_counter;
00274         double numOfTakeninBucket;
00275         double numOfTrialinBucket;
00276         int numOfFanoutsTakenTwice;
00277 
00278         bool fo_taken;
00279         //bool flag;
00280         bool issueReturn;
00281         vector<int> takenFanoutCounter;
00282 };
00283 
00284 }//namespace
00285 #endif

Generated on Thu Aug 25 14:24:05 2011 by  doxygen 1.3.9.1