ScalarizedRefTab.cxx
Go to the documentation of this file.00001
00002
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;
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
00054
00055
00056
00057 ScalarizedRefTab<ScalarizedRefTab_Base::W2X>::
00058 ScalarizedRefTab()
00059 {
00060 }
00061
00062 ScalarizedRefTab<ScalarizedRefTab_Base::W2X>::
00063 ~ScalarizedRefTab()
00064 {
00065
00066 for (ScalarizedRefPoolTy::iterator it = scalarizedRefPool.begin();
00067 it != scalarizedRefPool.end(); ++it) {
00068 delete (*it);
00069 }
00070 scalarizedRefPool.clear();
00071
00072
00073 clear();
00074 }
00075
00076
00077 void
00078 ScalarizedRefTab<ScalarizedRefTab_Base::W2X>::
00079 Create(PU_Info* pu)
00080 {
00081 WN* wn_pu = PU_Info_tree_ptr(pu);
00082 WN* fbody = WN_func_body(wn_pu);
00083 AddToScalarizedRefTabOp op(this, pu);
00084 ForAllScalarizableRefs(fbody, op);
00085 }
00086
00087 void
00088 ScalarizedRefTab<ScalarizedRefTab_Base::W2X>::
00089 Dump(std::ostream& o) const
00090 {
00091 DumpFmt(std::cerr);
00092 }
00093
00094 void
00095 ScalarizedRefTab<ScalarizedRefTab_Base::W2X>::
00096 DDump() const
00097 {
00098 Dump(std::cerr);
00099 }
00100
00101 void
00102 ScalarizedRefTab<ScalarizedRefTab_Base::W2X>::
00103 DumpFmt(std::ostream& o, const char* pre) const
00104 {
00105 std::string p = pre;
00106 std::string p1 = p + " ";
00107
00108 o << p << "{ ================== Begin ScalarizedRefTab Dump ("
00109 << size() << " Entries):\n";
00110
00111 for (const_iterator it = begin(); it != end(); ++it) {
00112 WN* wn = (*it).first;
00113 ScalarizedRef* sym = (*it).second;
00114 o << p1 << wn << " --> ";
00115 sym->dump(o);
00116 o << std::endl;
00117 }
00118 o << p << "End ScalarizedRefTab Dump ================== }\n";
00119 }
00120
00121
00122 void
00123 ForAllScalarizableRefs(const WN* wn, ForAllScalarizableRefsOp& op)
00124 {
00125
00126 if (wn == NULL) { return; }
00127
00128 OPERATOR opr = WN_operator(wn);
00129 if (ScalarizedRef::isRefScalarizable(wn)) {
00130
00131
00132 int ret = op(wn);
00133
00134
00135
00136
00137
00138 if (OPERATOR_is_store(opr)) {
00139 ForAllScalarizableRefs(WN_kid0(wn), op);
00140 }
00141
00142 }
00143 else if (!OPERATOR_is_leaf(opr)) {
00144
00145
00146 if (WN_operator(wn) == OPR_BLOCK) {
00147 WN *kid = WN_first(wn);
00148 while (kid) {
00149 ForAllScalarizableRefs(kid, op);
00150 kid = WN_next(kid);
00151 }
00152 }
00153 else {
00154 for (INT kidno = 0; kidno < WN_kid_count(wn); kidno++) {
00155 WN* kid = WN_kid(wn, kidno);
00156 ForAllScalarizableRefs(kid, op);
00157 }
00158 }
00159
00160 }
00161 }
00162
00163
00164 AddToScalarizedRefTabOp::
00165 AddToScalarizedRefTabOp(ScalarizedRefTab_W2X* tab_, PU_Info* curpu_)
00166 : tab(tab_), curpu(curpu_)
00167 {
00168 FORTTK_ASSERT(tab_, fortTkSupport::Diagnostics::UnexpectedInput);
00169 ir = new Open64IRInterface();
00170 }
00171
00172 AddToScalarizedRefTabOp::~AddToScalarizedRefTabOp()
00173 {
00174 workmap.clear();
00175 }
00176
00177
00178
00179
00180 int
00181 AddToScalarizedRefTabOp::operator()(const WN* wn)
00182 {
00183
00184 OA::OA_ptr<OA::ExprTree> e =
00185 ir->getExprTree(OA::ExprHandle((OA::irhandle_t)wn));
00186 ostringstream o;
00187 e->dump(o, ir);
00188 string s = o.str();
00189
00190
00191 ScalarizedRef* sym = NULL;
00192 WorkMapTy::iterator it = workmap.find(s);
00193 if (it == workmap.end()) {
00194 sym = new ScalarizedRef(const_cast<WN*>(wn));
00195 workmap.insert(make_pair(s, sym));
00196 }
00197 else {
00198 sym = (*it).second;
00199 }
00200
00201 #if 0
00202 cout << "Ref: '" << s << "' --> "; sym->Dump(cout); cout << endl;
00203 fdump_tree(stdout, (WN*)wn);
00204 #endif
00205
00206
00207 tab->Insert(wn, sym);
00208 return 0;
00209 }
00210
00211 }