OpenADFortTk (basic)
src/xaif2whirl/InterfaceData.cxx
Go to the documentation of this file.
00001 #include "InterfaceData.h"
00002 #include "Diagnostics.h"
00003 #include "Open64IRInterface/WhirlGlobalStateUtils.h"
00004 
00005 InterfaceData::PuIFaceRenamePairListPairListPairList InterfaceData::ourInterfacesByPU;
00006 InterfaceData::ChildToParentMap InterfaceData::ourChildToParentMap;
00007 
00008 void InterfaceData::collect(PU_Info* aPUForrest_p) { 
00009   if (!aPUForrest_p) { return; }
00010   // Loop through all the PU_Infos 
00011   PU_Info* aPUInfoTree_p;
00012   for (aPUInfoTree_p=aPUForrest_p; aPUInfoTree_p!= NULL; aPUInfoTree_p=PU_Info_next(aPUInfoTree_p)) {
00013     forPUInfoTree(aPUInfoTree_p);
00014   }
00015 } 
00016 
00017 void InterfaceData::forPUInfoTree(PU_Info* aPUInfoTree_p) { 
00018   if (!aPUInfoTree_p) { return; }
00019   forPUInfo(aPUInfoTree_p);
00020   for (PU_Info *aPUInfosubtree_p = PU_Info_child(aPUInfoTree_p); 
00021        aPUInfosubtree_p != NULL; 
00022        aPUInfosubtree_p = PU_Info_next(aPUInfosubtree_p)) {
00023     ourChildToParentMap[aPUInfosubtree_p]=aPUInfoTree_p;
00024     forPUInfoTree(aPUInfosubtree_p);
00025   }
00026 }
00027 
00028 PU_Info* InterfaceData::getParentOf(PU_Info* child) { 
00029   ChildToParentMap::iterator it(ourChildToParentMap.find(child));
00030   if (it!=ourChildToParentMap.end()) 
00031     return (*it).second;
00032   return NULL; 
00033 } 
00034 
00035 InterfaceData::PuIFaceRenamePairListPairListPair* 
00036 InterfaceData::findPUData(PU_Info* thePU_WN_p) { 
00037   for(PuIFaceRenamePairListPairListPairList::iterator it=ourInterfacesByPU.begin(); 
00038       it!=ourInterfacesByPU.end();
00039       ++it) { 
00040     if (WN_st_idx(PU_Info_tree_ptr(thePU_WN_p))==WN_st_idx(PU_Info_tree_ptr((*it).first))) { 
00041       return &(*it);
00042     }
00043   }
00044   return NULL; 
00045 }
00046 
00047 InterfaceData::IFaceRenamePairListPair* 
00048 InterfaceData::findInterfaceData(PuIFaceRenamePairListPairListPair* moduleData, 
00049                                  WN* theInterface_WN_p) { 
00050   for(IFaceRenamePairListPairList::iterator it=moduleData->second.begin(); 
00051       it!=moduleData->second.end();
00052       ++it) {
00053     if ((*it).first.second==NULL) { // not renamed
00054       if (WN_st_idx(theInterface_WN_p)==WN_st_idx((*it).first.first)) { 
00055         return &(*it);
00056       }
00057     } 
00058     else { // is renamed 
00059       if (WN_st_idx(theInterface_WN_p)==ST_st_idx((*it).first.second)) { 
00060         return &(*it);
00061       }
00062     }
00063   }
00064   return NULL; 
00065 }
00066 
00067 InterfaceData::RenamePair* 
00068 InterfaceData::findSpecific(IFaceRenamePairListPair* interfaceData, 
00069                             WN* theInterface_WN_p) { 
00070   for(RenamePairList::iterator it=interfaceData->second.begin(); 
00071       it!=interfaceData->second.end();
00072       ++it) { 
00073     if ((*it).second==NULL) { // not renamed
00074       if (WN_st_idx(theInterface_WN_p)==WN_st_idx((*it).first)) { 
00075         return &(*it);
00076       }
00077     }
00078     else { // is renamed
00079       if (WN_st_idx(theInterface_WN_p)==ST_st_idx((*it).second)) { 
00080         return &(*it);
00081       }
00082     }      
00083   }
00084   return NULL; 
00085 }
00086 
00087 void InterfaceData::forPUInfo(PU_Info* aPUInfo_p) { 
00088   PU_SetGlobalState(aPUInfo_p);
00089   WN* thePU_WN_p = PU_Info_tree_ptr(aPUInfo_p);
00090   WN_TREE_CONTAINER<PRE_ORDER> aWNPtree(thePU_WN_p);
00091   WN_TREE_CONTAINER<PRE_ORDER>::iterator aWNPtreeIterator=aWNPtree.begin();
00092   bool skipKids=false;
00093   while (aWNPtreeIterator != aWNPtree.end()) { 
00094     WN* curWN_p = aWNPtreeIterator.Wn();
00095     OPERATOR opr = WN_operator(curWN_p);
00096     if (opr==OPR_INTERFACE) {  // interfaces
00097       skipKids=true;
00098       PuIFaceRenamePairListPairListPair* ifDataByModule;
00099       if ((ifDataByModule=findPUData(aPUInfo_p))==NULL) { 
00100         // don't have the module yet
00101         ourInterfacesByPU.push_back(PuIFaceRenamePairListPairListPair(aPUInfo_p,IFaceRenamePairListPairList()));
00102         ifDataByModule=findPUData(aPUInfo_p);
00103       }
00104       IFaceRenamePairListPair* ifDataByInterface;
00105       if ((ifDataByInterface=findInterfaceData(ifDataByModule,curWN_p))==NULL) { 
00106         // don't have the interface yet
00107         ifDataByModule->second.push_back(IFaceRenamePairListPair(RenamePair(curWN_p,NULL),
00108                                                                          RenamePairList()));
00109         ifDataByInterface=findInterfaceData(ifDataByModule,curWN_p);
00110       }
00111       for (int i=0; i< WN_kid_count(curWN_p); ++i) { 
00112         WN* specificWN_p=WN_kid(curWN_p,i);
00113         if (specificWN_p && WN_operator(specificWN_p)==OPR_FUNC_ENTRY) {
00114           RenamePair* specificData;
00115           if ((specificData=findSpecific(ifDataByInterface,specificWN_p))==0) {
00116             // don't have it yet
00117             ifDataByInterface->second.push_back(RenamePair(specificWN_p,NULL));
00118             specificData=findSpecific(ifDataByInterface,specificWN_p);
00119           }
00120         }
00121       }
00122     }
00123     // advance the iterator
00124     if (skipKids){
00125       aWNPtreeIterator.WN_TREE_next_skip();
00126       skipKids=false;
00127     }
00128     else
00129       ++aWNPtreeIterator;
00130   }
00131 }
00132 
00133 void InterfaceData::dump() { 
00134   PU_Info* currentPUI=Current_PU_Info;
00135   std::cout << "InterfaceData::dumpData: start" << std::endl; 
00136   for(PuIFaceRenamePairListPairListPairList::iterator mIt=ourInterfacesByPU.begin(); 
00137       mIt!=ourInterfacesByPU.end();
00138       ++mIt) { 
00139     PU_SetGlobalState((*mIt).first);
00140     std::cout << "\tPU: ";
00141     if (WN_st(PU_Info_tree_ptr((*mIt).first))) { 
00142       std::cout << ST_name(WN_st(PU_Info_tree_ptr((*mIt).first)));
00143     }
00144     else { 
00145       std::cout << "<NULL>";
00146     }
00147     std::cout << std::endl;
00148     for(IFaceRenamePairListPairList::iterator iIt=(*mIt).second.begin(); 
00149         iIt!=(*mIt).second.end();
00150         ++iIt) { 
00151       std::cout << "\t\tIF:(curr:";
00152       if (WN_st((*iIt).first.first)) { 
00153         std::cout << ST_name(WN_st((*iIt).first.first));
00154       }
00155       else { 
00156         std::cout << "<NULL>";
00157       }
00158       std::cout << ",old:";
00159       if ((*iIt).first.second) { 
00160         std::cout << ST_name((*iIt).first.second);
00161       }
00162       else { 
00163         std::cout << "<NULL>";
00164       }
00165       std::cout << ")" <<  std::endl;
00166       for (RenamePairList::iterator sIt=(*iIt).second.begin();
00167            sIt!=(*iIt).second.end();
00168            ++sIt) { 
00169         std::cout << "\t\t\tSpec:(curr:";
00170         if (WN_st((*sIt).first)) { 
00171           std::cout << ST_name(WN_st((*sIt).first));
00172         }
00173         else {
00174           std::cout << "<NULL>";
00175         }
00176         std::cout << ",old:";
00177         if ((*sIt).second){ 
00178           std::cout << ST_name((*sIt).second);
00179         }
00180         else { 
00181           std::cout << "<NULL>";
00182         }
00183         std::cout << ")" <<  std::endl;
00184       }
00185     }
00186   }
00187   std::cout << "InterfaceData::dumpData: stop" << std::endl; 
00188   PU_SetGlobalState(currentPUI);
00189 }
00190  
00191 void InterfaceData::findAndAdjustInterface(PU_Info* pu,WN* oldWN_p, ST* newST_p) {
00192   std::cout << "InterfaceData::findAndAdjustInterface(" 
00193             << ST_name(WN_st(PU_Info_tree_ptr(pu)))
00194             << ", "
00195             << ST_name(WN_st(oldWN_p))
00196             << ","
00197             << ST_name(newST_p)
00198             << ")" << std::endl; 
00199   PuIFaceRenamePairListPairListPair* ifDataByModule;
00200   if ((ifDataByModule=findPUData(pu))==NULL) { 
00201     // don't have the PU
00202     FORTTK_WMSG("InterfaceData::findAndAdjustInterface: PU " 
00203                 << ST_name(WN_st(PU_Info_tree_ptr(pu))) 
00204                 << " unknown");
00205     return;
00206   }
00207   IFaceRenamePairListPair* ifDataByInterface(NULL);
00208   int instancesFound=0;
00209   bool alreadyRenamed=false; 
00210   RenamePair* renamePair(NULL);
00211   if ((ifDataByInterface=findInterfaceData(ifDataByModule,oldWN_p))==NULL) { 
00212     // may be this is a specific name: 
00213     for(IFaceRenamePairListPairList::iterator iIt=ifDataByModule->second.begin(); 
00214         iIt!=ifDataByModule->second.end();
00215         ++iIt) {
00216       RenamePair* tmpRenamePair(NULL);
00217       if (tmpRenamePair=findSpecific(&(*iIt),oldWN_p)) { 
00218         renamePair=tmpRenamePair;
00219         instancesFound+=1;
00220       }
00221     }
00222   }
00223   if (instancesFound>1)
00224     FORTTK_DIE("InterfaceData::findAndAdjustInterface: more than one match for " << ST_name(WN_st(oldWN_p)));
00225   if (ifDataByInterface==NULL and instancesFound==0)  // no interfaces known for 'old'
00226     return; 
00227   if (ifDataByInterface) // is a generic name
00228     renamePair=&(ifDataByInterface->first);
00229   // see if it was renamed already
00230   if (renamePair->second) { 
00231     if (WN_st_idx(renamePair->first)!=ST_st_idx(newST_p)) 
00232           FORTTK_DIE("InterfaceData::findAndAdjustInterface: cannot rename " 
00233                      << ST_name(renamePair->second) 
00234                      << " to "
00235                      << ST_name(newST_p)
00236                      << " because it is already renamed to "
00237                      << ST_name(WN_st(renamePair->first)));
00238     return; // already renamed
00239   }
00240   renamePair->second=WN_st(renamePair->first);
00241   WN_st_idx(renamePair->first)=ST_st_idx(newST_p);
00242 } 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines