Go to the documentation of this file.00001 #include <map>
00002 #include <set>
00003 #include "cleanUpWhirl.h"
00004 #include "wn_tree_util.h"
00005 #include "wn_util.h"
00006 #include "symtab.h"
00007
00008 #define xDEBUG(flag,code) { if (flag) {code; fflush(stdout);} }
00009 #define DEB_CleanUpWhirl 0
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 void cleanUpPUInfo(PU_Info* aPUInfo_p) {
00026 typedef std::map<ST*,std::pair<WN*,int> > STPtoWNPmap;
00027 STPtoWNPmap tempMap;
00028 bool skipKids=false;
00029 WN* thePU_WN_p = PU_Info_tree_ptr(aPUInfo_p);
00030 xDEBUG(DEB_CleanUpWhirl, printf("cleanUpWhirl: doing %s\n",ST_name(WN_st(thePU_WN_p))););
00031 WN* parentWN_p=0;
00032 WN_TREE_CONTAINER<PRE_ORDER> aWNPtree(thePU_WN_p);
00033 WN_TREE_CONTAINER<PRE_ORDER>::iterator aWNPtreeIterator=aWNPtree.begin();
00034 while (aWNPtreeIterator != aWNPtree.end()) {
00035 WN* curWN_p = aWNPtreeIterator.Wn();
00036 OPERATOR opr = WN_operator(curWN_p);
00037 if (opr==OPR_STID) {
00038 if (ST_is_temp_var(WN_st(curWN_p))) {
00039 ST* tempST_p=WN_st(curWN_p);
00040
00041 STPtoWNPmap::iterator mapIter=tempMap.find(tempST_p);
00042 if (mapIter == tempMap.end()) {
00043
00044 tempMap.insert(std::pair<ST*,std::pair<WN*,int> >(tempST_p, std::pair<WN*,int>(WN_kid0(curWN_p),1)));
00045 const char* tmpName = ST_name(tempST_p);
00046 ST* puST_p = ST_ptr(PU_Info_proc_sym(aPUInfo_p));
00047 const char* puName = ST_name(puST_p);
00048 xDEBUG(DEB_CleanUpWhirl, printf("cleanUpWhirl: recorded temporary %s defined in %s\n",tmpName, puName););
00049 }
00050 else {
00051
00052
00053
00054
00055 WN* defWN_p=(*mapIter).second.first;
00056 if (WN_operator(defWN_p)==OPR_INTCONST
00057 &&
00058 WN_operator(WN_kid0(curWN_p))== OPR_INTCONST
00059 && WN_const_val(defWN_p)!=WN_const_val(WN_kid0(curWN_p))) {
00060
00061 Set_ST_keep_in_openad(tempST_p);
00062 ++((*mapIter).second.second);
00063 }
00064 else {
00065 const char* tmpName = ST_name(tempST_p);
00066 ST* puST_p = ST_ptr(PU_Info_proc_sym(aPUInfo_p));
00067 const char* puName = ST_name(puST_p);
00068 DevWarn("cleanUpWhirl: recorded temporary %s is redefined in %s\n",tmpName, puName);
00069 }
00070 }
00071 }
00072 }
00073 if (opr==OPR_LDID){
00074
00075 if (ST_is_temp_var(WN_st(curWN_p))) {
00076
00077
00078 ST* tempST_p=WN_st(curWN_p);
00079 STPtoWNPmap::iterator mapIter=tempMap.find(tempST_p);
00080 if (mapIter==tempMap.end()) {
00081
00082
00083
00084
00085
00086 const char* tmpName = ST_name(tempST_p);
00087 ST* puST_p = ST_ptr(PU_Info_proc_sym(aPUInfo_p));
00088 const char* puName = ST_name(puST_p);
00089 xDEBUG(DEB_CleanUpWhirl, printf("cleanUpWhirl: no (local) definition for temporary %s in %s, probably defined in enclosing PU\n",tmpName,puName););
00090 }
00091 else {
00092
00093 if (!aWNPtreeIterator.Get_parent_wn())
00094 Fatal_Error("cleanUpWhirl: no parent set");
00095 skipKids=true;
00096
00097
00098
00099
00100
00101
00102
00103
00104 if (WN_operator(aWNPtreeIterator.Get_parent_wn())!=OPR_SWITCH && (*mapIter).second.second==1) {
00105
00106 WN_kid(aWNPtreeIterator.Get_parent_wn(),aWNPtreeIterator.Get_kid_index()) = WN_COPY_Tree((*mapIter).second.first);
00107 const char* tmpName = ST_name(tempST_p);
00108 ST* puST_p = ST_ptr(PU_Info_proc_sym(aPUInfo_p));
00109 const char* puName = ST_name(puST_p);
00110 xDEBUG(DEB_CleanUpWhirl, printf("cleanUpWhirl: subsituted temporary %s in %s\n",tmpName, puName););
00111 }
00112 }
00113 }
00114 }
00115
00116 if (skipKids || opr==OPR_XPRAGMA){
00117
00118 aWNPtreeIterator.WN_TREE_next_skip();
00119 skipKids=false;
00120 }
00121 else
00122 ++aWNPtreeIterator;
00123 }
00124 }
00125
00126
00127 extern "C" void cleanUpPUInfoTree(PU_Info* aPUInfoTree_p) {
00128 if (!aPUInfoTree_p) { return; }
00129 cleanUpPUInfo(aPUInfoTree_p);
00130
00131
00132
00133 }