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