|
OpenADFortTk (basic)
|
00001 // -*-Mode: C++;-*- 00002 // $Header: /Volumes/cvsrep/developer/OpenADFortTk/src/lib/support/ScalarizedRefTab.cxx,v 1.21 2006/05/12 16:12:22 utke Exp $ 00003 00004 #include <sstream> 00005 00006 #include "OpenAnalysis/ExprTree/ExprTree.hpp" 00007 00008 #include "Open64IRInterface/Open64BasicTypes.h" 00009 00010 #include "ir_reader.h" 00011 00012 00013 #include "ScalarizedRefTab.h" 00014 00015 #include "Diagnostics.h" 00016 00017 00018 namespace fortTkSupport { 00019 00020 ScalarizedRefTab_Base::ScalarizedRefTab_Base() 00021 { 00022 } 00023 00024 ScalarizedRefTab_Base::~ScalarizedRefTab_Base() 00025 { 00026 } 00027 00028 ScalarizedRefTabMap_W2X::ScalarizedRefTabMap_W2X() 00029 { 00030 } 00031 00032 ScalarizedRefTabMap_W2X::~ScalarizedRefTabMap_W2X() 00033 { 00034 for (iterator it = begin(); it != end(); ++it) { 00035 delete (*it).second; // ScalarizedRefTab_W2X* 00036 } 00037 clear(); 00038 } 00039 00040 void 00041 ScalarizedRefTabMap_W2X::Create(PU_Info* pu_forest) 00042 { 00043 Open64IRProcIterator procIt(pu_forest); 00044 for ( ; procIt.isValid(); ++procIt) { 00045 PU_Info* pu = (PU_Info*)procIt.current().hval(); 00046 00047 ScalarizedRefTab_W2X* tab = new ScalarizedRefTab_W2X(pu); 00048 Insert(pu, tab); 00049 } 00050 } 00051 00052 00053 // ScalarizedRefTab 00054 ScalarizedRefTab<ScalarizedRefTab_Base::W2X>::ScalarizedRefTab() {} 00055 00056 ScalarizedRefTab<ScalarizedRefTab_Base::W2X>:: ~ScalarizedRefTab() { 00057 // Clear table ref pool 00058 for (ScalarizedRefPoolTy::iterator it = scalarizedRefPool.begin(); 00059 it != scalarizedRefPool.end(); ++it) { 00060 delete (*it); // ScalarizedRef* 00061 } 00062 scalarizedRefPool.clear(); 00063 00064 // Clear Table 00065 clear(); 00066 } 00067 00068 00069 void 00070 ScalarizedRefTab<ScalarizedRefTab_Base::W2X>:: 00071 Create(PU_Info* pu) 00072 { 00073 WN* wn_pu = PU_Info_tree_ptr(pu); 00074 WN* fbody = WN_func_body(wn_pu); 00075 AddToScalarizedRefTabOp op(this, pu); 00076 ForAllScalarizableRefs(fbody, op); 00077 } 00078 00079 void 00080 ScalarizedRefTab<ScalarizedRefTab_Base::W2X>:: 00081 Dump(std::ostream& o) const 00082 { 00083 DumpFmt(std::cerr); 00084 } 00085 00086 void 00087 ScalarizedRefTab<ScalarizedRefTab_Base::W2X>:: 00088 DDump() const 00089 { 00090 Dump(std::cerr); 00091 } 00092 00093 void 00094 ScalarizedRefTab<ScalarizedRefTab_Base::W2X>:: 00095 DumpFmt(std::ostream& o, const char* pre) const 00096 { 00097 std::string p = pre; 00098 std::string p1 = p + " "; 00099 00100 o << p << "{ ================== Begin ScalarizedRefTab Dump (" 00101 << size() << " Entries):\n"; 00102 00103 for (const_iterator it = begin(); it != end(); ++it) { 00104 WN* wn = (*it).first; 00105 ScalarizedRef* sym = (*it).second; 00106 o << p1 << wn << " --> "; 00107 sym->dump(o); 00108 o << std::endl; 00109 } 00110 o << p << "End ScalarizedRefTab Dump ================== }\n"; 00111 } 00112 00113 00114 void 00115 ForAllScalarizableRefs(const WN* wn, ForAllScalarizableRefsOp& op) 00116 { 00117 // Special base case 00118 if (wn == NULL) { return; } 00119 00120 OPERATOR opr = WN_operator(wn); 00121 if (ScalarizedRef::isRefScalarizable(wn)) { 00122 00123 // Base case 00124 int ret = op(wn); // FIXME: what to do on error? 00125 //bool foo = IsRefScalarizable(wn); // for debugging 00126 00127 // Special recursive case: Since WHIRL stores are statements (not 00128 // expressions) we need to check the RHS (kid0) of the implied 00129 // assignment for non-scalar references. 00130 if (OPERATOR_is_store(opr)) { 00131 ForAllScalarizableRefs(WN_kid0(wn), op); 00132 } 00133 00134 } 00135 else if (!OPERATOR_is_leaf(opr)) { 00136 00137 // General recursive case 00138 if (WN_operator(wn) == OPR_BLOCK) { 00139 WN *kid = WN_first(wn); 00140 while (kid) { 00141 ForAllScalarizableRefs(kid, op); 00142 kid = WN_next(kid); 00143 } 00144 } 00145 else { 00146 for (INT kidno = 0; kidno < WN_kid_count(wn); kidno++) { 00147 WN* kid = WN_kid(wn, kidno); 00148 ForAllScalarizableRefs(kid, op); 00149 } 00150 } 00151 00152 } 00153 } 00154 00155 00156 AddToScalarizedRefTabOp:: 00157 AddToScalarizedRefTabOp(ScalarizedRefTab_W2X* tab_, PU_Info* curpu_) 00158 : tab(tab_), curpu(curpu_) 00159 { 00160 FORTTK_ASSERT(tab_, fortTkSupport::Diagnostics::UnexpectedInput); 00161 ir = new Open64IRInterface(); 00162 } 00163 00164 AddToScalarizedRefTabOp::~AddToScalarizedRefTabOp() 00165 { 00166 workmap.clear(); 00167 } 00168 00169 00170 // Given a non-scalar reference 'wn', create a dummy variable and 00171 // add to the map. 00172 int 00173 AddToScalarizedRefTabOp::operator()(const WN* wn) 00174 { 00175 // create a hash of this reference 00176 ostringstream o; 00177 ir->DumpWN((WN*)wn,o); 00178 string hashVal = o.str(); 00179 00180 // if <hash, sym> not already in workmap, insert <hash, new sym> 00181 ScalarizedRef* sym = NULL; 00182 WorkMapTy::iterator it = workmap.find(hashVal); 00183 if (it == workmap.end()) { 00184 sym = new ScalarizedRef(const_cast<WN*>(wn)); 00185 workmap.insert(make_pair(hashVal, sym)); 00186 } 00187 else { 00188 sym = (*it).second; 00189 } 00190 00191 FORTTK_MSG(1, "AddToScalarizedRefTabOp::operator() : hashVal : '" << hashVal.c_str() << "' --> " << sym->getName().c_str() << " (" << sym << ',' << wn << ")"); 00192 00193 tab->Insert(wn, sym); 00194 return 0; 00195 } 00196 00197 }