WhirlIDMaps.cxx

Go to the documentation of this file.
00001 // -*-Mode: C++;-*-
00002 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/lib/support/WhirlIDMaps.cxx,v 1.9 2005/05/16 15:17:39 eraxxon Exp $
00003 
00004 // * BeginCopyright *********************************************************
00005 // *********************************************************** EndCopyright *
00006 
00007 //***************************************************************************
00008 //
00009 // File:
00010 //   $Source: /Volumes/cvsrep/developer/OpenADFortTk/src/lib/support/WhirlIDMaps.cxx,v $
00011 //
00012 // Purpose:
00013 //   [The purpose of this file]
00014 //
00015 // Description:
00016 //   [The set of functions, macros, etc. defined in the file]
00017 //
00018 //***************************************************************************
00019 
00020 //************************* System Include Files ****************************
00021 
00022 //*************************** User Include Files ****************************
00023 
00024 #include "Open64IRInterface/Open64IRInterface.hpp"
00025 #include "WhirlIDMaps.h"
00026 
00027 //************************** Forward Declarations ***************************
00028 
00029 namespace fortTkSupport { 
00030 
00031 //***************************************************************************
00032 // ST_TAB <-> SymTabId maps
00033 //***************************************************************************
00034 
00035 void
00036 SymTabToSymTabIdMap::Create(PU_Info* pu_forest)
00037 {
00038   CreateSymTabIdMaps(pu_forest, this, NULL);
00039 }
00040 
00041 void
00042 SymTabIdToSymTabMap::Create(PU_Info* pu_forest)
00043 {
00044   CreateSymTabIdMaps(pu_forest, NULL, this);
00045 }
00046 
00047 //***************************************************************************
00048 // PU <-> PUId maps
00049 //***************************************************************************
00050 
00051 void
00052 PUToPUIdMap::Create(PU_Info* pu_forest)
00053 {
00054   CreatePUIdMaps(pu_forest, this, NULL);
00055 }
00056 
00057 void
00058 PUIdToPUMap::Create(PU_Info* pu_forest)
00059 {
00060   CreatePUIdMaps(pu_forest, NULL, this);
00061 }
00062 
00063 //***************************************************************************
00064 // WNId <-> WN map
00065 //***************************************************************************
00066 
00067 void
00068 WNToWNIdMap::Create(WN* wn)
00069 {
00070   CreateWhirlIdMaps(wn, this, NULL);
00071 }
00072 
00073 void
00074 WNIdToWNMap::Create(WN* wn)
00075 {
00076   CreateWhirlIdMaps(wn, NULL, this);
00077 }
00078 
00079 
00080 WNToWNIdTabMap::~WNToWNIdTabMap()
00081 {
00082   Destroy();
00083 }
00084 
00085 void 
00086 WNToWNIdTabMap::Create(PU_Info* pu_forest)
00087 {
00088   Open64IRProcIterator procIt(pu_forest);
00089   for ( ; procIt.isValid(); ++procIt) { 
00090     PU_Info* pu = (PU_Info*)procIt.current().hval();
00091     WN* wn_pu = PU_Info_tree_ptr(pu);
00092     WNToWNIdMap* tab = new WNToWNIdMap(wn_pu);
00093 #if 0 
00094     ST* pu_st = ST_ptr(PU_Info_proc_sym(pu));
00095     const char* pu_name = ST_name(pu_st);
00096     std::cout << "JU: WNToWNIdTabMap::Create (" << tab << ") for " << pu_name << std::endl; 
00097 #endif
00098     Insert(pu, tab);
00099   }
00100 }
00101 
00102 void 
00103 WNToWNIdTabMap::Destroy()
00104 {
00105   for (iterator it = begin(); it != end(); ++it) {
00106     delete (*it).second; // WNToWNIdMap*
00107   }
00108   clear();
00109 }
00110 
00111 
00112 WNIdToWNTabMap::~WNIdToWNTabMap()
00113 {
00114   Destroy();
00115 }
00116 
00117 void 
00118 WNIdToWNTabMap::Create(PU_Info* pu_forest)
00119 {
00120   Open64IRProcIterator procIt(pu_forest);
00121   for ( ; procIt.isValid(); ++procIt) { 
00122     PU_Info* pu = (PU_Info*)procIt.current().hval();
00123     WN* wn_pu = PU_Info_tree_ptr(pu);
00124     WNIdToWNMap* tab = new WNIdToWNMap(wn_pu);
00125 #if 0 
00126     ST* pu_st = ST_ptr(PU_Info_proc_sym(pu));
00127     const char* pu_name = ST_name(pu_st);
00128     std::cout << "JU: WNIdToWNTabMap::Create (" << tab << ") for " << pu_name << std::endl; 
00129 #endif
00130     Insert(pu, tab);
00131   }
00132 }
00133 
00134 void 
00135 WNIdToWNTabMap::Destroy()
00136 {
00137   for (iterator it = begin(); it != end(); ++it) {
00138     delete (*it).second; // WNIdToWNMap*
00139   }
00140   clear();
00141 }
00142 
00143 
00144 //***************************************************************************
00145 // Optional routines for map creation
00146 //***************************************************************************
00147 
00148 // CreateSymTabIdMaps: Create id's based on Open64IRProcIterator.
00149 // N.B. this must restore global symtab state for each pu
00150 void
00151 CreateSymTabIdMaps(PU_Info* pu_forest, 
00152                    SymTabToSymTabIdMap* x, SymTabIdToSymTabMap* y)
00153 {
00154   static UINT nextId = 0; // 0 reserved as NULL
00155   
00156   // Enter global symtab
00157   ++nextId; // create new id
00158   if (x) {
00159     x->Insert(Scope_tab[GLOBAL_SYMTAB].st_tab, nextId);
00160   }
00161   if (y) {
00162     y->Insert(nextId, Scope_tab[GLOBAL_SYMTAB].st_tab, NULL);
00163   }
00164   
00165   // Enter all local symtabs (one symtab per PU)
00166   Open64IRProcIterator procIt(pu_forest);
00167   for ( ; procIt.isValid(); ++procIt) { 
00168     PU_Info* pu = (PU_Info*)procIt.current().hval();    
00169     
00170     ++nextId; // create new id
00171     if (x) {
00172       x->Insert(Scope_tab[CURRENT_SYMTAB].st_tab, nextId);
00173     }
00174     if (y) {
00175       y->Insert(nextId, Scope_tab[GLOBAL_SYMTAB].st_tab, pu);
00176     }
00177   }
00178 }
00179 
00180 
00181 // CreatePUIdMaps: Create id's based on Open64IRProcIterator. 
00182 void
00183 CreatePUIdMaps(PU_Info* pu_forest, PUToPUIdMap* x, PUIdToPUMap* y)
00184 {
00185   static UINT nextId = 0; // 0 reserved as NULL
00186   
00187   // Enter all PUs
00188   Open64IRProcIterator procIt(pu_forest);
00189   for ( ; procIt.isValid(); ++procIt) { 
00190     PU_Info* pu = (PU_Info*)procIt.current().hval();    
00191     
00192     ++nextId; // create new id
00193     if (x) {
00194       x->Insert(pu, nextId);
00195     }
00196     if (y) {
00197       y->Insert(nextId, pu);
00198     }
00199   }
00200 }
00201 
00202 
00203 void
00204 CreateWhirlIdMaps(WN* wn, WNToWNIdMap* x, WNIdToWNMap* y)
00205 {
00206   // Note: Do not use a static id because it would then require that
00207   // this function be called in the same order across two different
00208   // runs.
00209   UINT nextId = 0; // 0 reserved as NULL
00210   
00211   // Iterate over the whirl tree finding or assigning persistent ids
00212   WN_TREE_CONTAINER<PRE_ORDER> wtree(wn);
00213   WN_TREE_CONTAINER<PRE_ORDER>::iterator it;
00214   
00215   for (it = wtree.begin(); it != wtree.end(); ++it) {
00216     WN* curWN = it.Wn();
00217     UINT curId = ++nextId; // create new id
00218 
00219     if (x) {
00220       x->Insert(curWN, curId);
00221 #if 0 
00222       std::cout << " JU: CreateWhirlIdMaps (" << x <<"): " << curWN << "(";
00223       Open64IRInterface::DumpWN(curWN,std::cout);
00224       std::cout << ")->" << curId << std::endl; 
00225 #endif
00226     }
00227     if (y) {
00228       y->Insert(curId, curWN);
00229 #if 0 
00230       std::cout << " JU: CreateWhirlIdMaps (" << y <<"): " << curId << "->" <<  curWN << "(";
00231       Open64IRInterface::DumpWN(curWN,std::cout);
00232       std::cout << ")" << std::endl; 
00233 #endif
00234     }
00235   }
00236 }
00237 
00238 //***************************************************************************
00239  
00240 }

Generated on Fri Jul 24 04:29:07 2009 for OpenADFortTk (extended to Open64) by  doxygen 1.5.7.1