00001
00016 #ifndef DUGManagerStandard_h
00017 #define DUGManagerStandard_h
00018
00019
00020
00021 #include <OpenAnalysis/IRInterface/DUGIRInterface.hpp>
00022 #include <OpenAnalysis/Utils/OA_ptr.hpp>
00023 #include <OpenAnalysis/ExprTree/ExprTree.hpp>
00024 #include <OpenAnalysis/CFG/EachCFGInterface.hpp>
00025 #include <OpenAnalysis/CFG/CFGInterface.hpp>
00026 #include <OpenAnalysis/SideEffect/InterSideEffectStandard.hpp>
00027 #include <OpenAnalysis/SideEffect/ManagerInterSideEffectStandard.hpp>
00028 #include <OpenAnalysis/Location/Locations.hpp>
00029 #include <OpenAnalysis/Activity/DepDFSet.hpp>
00030 #include <OpenAnalysis/CSFIActivity/DUGStandard.hpp>
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 namespace OA {
00043 namespace DUG {
00044
00045
00046 class GlobalNode {
00047 public:
00048 GlobalNode(IRSymHandle i, ProcHandle p, CallHandle c, ProcHandle useP)
00049 : mIRnSym(i), mProc(p), mCall(c), mUseProc(useP) {};
00050 GlobalNode(const GlobalNode& gn)
00051 : mIRnSym(gn.mIRnSym), mProc(gn.mProc), mCall(gn.mCall),
00052 mUseProc(gn.mUseProc) {};
00053 ~GlobalNode(){};
00054
00055 bool operator==(const GlobalNode& other) const
00056 {
00057 if (mIRnSym == other.mIRnSym && mProc == other.mProc &&
00058 mCall == other.mCall && mUseProc == other.mUseProc)
00059 return true;
00060 return false;
00061 }
00062
00063 bool operator<(const GlobalNode& other) const
00064 {
00065 if (mIRnSym < other.mIRnSym) return true;
00066 if (mIRnSym != other.mIRnSym) return false;
00067 if (mProc < other.mProc) return true;
00068 if (mProc != other.mProc) return false;
00069 if (mCall < other.mCall) return true;
00070 if (mCall != other.mCall) return false;
00071 if (mUseProc < other.mUseProc) return true;
00072 return false;
00073 }
00074
00075 IRSymHandle mIRnSym;
00076 ProcHandle mProc;
00077 CallHandle mCall;
00078
00079
00080
00081 ProcHandle mUseProc;
00082 };
00083
00084
00085
00091 class ManagerDUGStandard {
00092 public:
00093 ManagerDUGStandard(OA_ptr<DUGIRInterface> _ir,
00094 OA_ptr<Activity::ActivityIRInterface> _air,
00095 std::map<ProcHandle,OA_ptr<UDDUChains::UDDUChainsStandard> >&);
00096 ~ManagerDUGStandard () {}
00097
00098 OA_ptr<DUGStandard> performAnalysis( OA_ptr<IRProcIterator>,
00099 OA_ptr<DataFlow::ParamBindings>,
00100 OA_ptr<OA::CallGraph::CallGraphInterface>);
00101
00102 void transitiveClosureDepMatrix(OA_ptr<OA::CallGraph::CallGraphInterface>);
00103 void connectGlobals();
00104 void printIRSymHandle(IRSymHandle, ostream&, OA_ptr<DUGIRInterface>);
00105 void printEdge(IRSymHandle, IRSymHandle, EdgeType);
00106 void printEdgeDot(IRSymHandle, ProcHandle, IRSymHandle, ProcHandle);
00107
00108 private:
00109
00110 bool stmt_has_call(StmtHandle stmt);
00111 bool isGlobal(SymHandle sym){
00112 return mGlobals.find(sym) != mGlobals.end();
00113 }
00114 bool isFormal(SymHandle sym, ProcHandle proc){
00115 return mProcToFormalSet[proc].find(sym) != mProcToFormalSet[proc].end();
00116 }
00117
00118 SymHandle getModSymFromMRE(OA_ptr<OA::MemRefExpr>);
00119 SymHandle getSymFromMRE(OA_ptr<OA::MemRefExpr>);
00120 void collectDefsUsesInStmt(StmtHandle, ProcHandle);
00121 std::set<SymHandle>& getUses(StmtHandle, ProcHandle);
00122 std::set<SymHandle>& getDefs(StmtHandle, ProcHandle);
00123 std::set<SymHandle>& getCallDefs(StmtHandle, ProcHandle);
00124
00125 void downwardExposedDefs(SymHandle, StmtHandle, ProcHandle, OA_ptr<UDDUChains::UDDUChainsStandard>);
00126 void upwardExposedUses(SymHandle, StmtHandle, ProcHandle, OA_ptr<UDDUChains::UDDUChainsStandard>);
00127 void insertEdge(IRSymHandle, IRSymHandle, EdgeType, CallHandle, ProcHandle,
00128 ProcHandle, ProcHandle);
00129 void labelCallRetEdges(StmtHandle, ProcHandle);
00130 void labelUseDefEdges(StmtHandle, ProcHandle);
00131 void collectIndependentSyms( ProcHandle);
00132 void collectDependentSyms( ProcHandle);
00133 void collectFormalParameters(ProcHandle);
00134 void getCallInfo(StmtHandle, ProcHandle);
00135
00136 void setDepMatrix(ProcHandle, IRSymHandle, IRSymHandle);
00137 void transitiveClosure(ProcHandle proc);
00138 void edgesBetweenFormals(ProcHandle proc);
00139
00140 void setDepMatrix4Globals(IRSymHandle, IRSymHandle, ProcHandle);
00141 bool isPathThruOtherProcs(IRSymHandle, IRSymHandle, ProcHandle);
00142 bool isOutgoingToOtherProcs(IRSymHandle, ProcHandle);
00143 bool isIncomingFromOtherProcs(IRSymHandle, ProcHandle);
00144 void findOutgoingNodes(IRSymHandle, ProcHandle, std::set<IRSymHandle>&);
00145 void findIncomingNodes(IRSymHandle, ProcHandle, std::set<IRSymHandle>&);
00146 bool hasEdgesToOtherProc(IRSymHandle ish, ProcHandle proc);
00147 bool hasEdgesFromOtherProc(IRSymHandle ish, ProcHandle proc);
00148
00149 private:
00150
00151 OA_ptr<DUGIRInterface> mIR;
00152 OA_ptr<Activity::ActivityIRInterface> mActIR;
00153 OA_ptr<DUGStandard> mDUG;
00154 OA_ptr<DataFlow::ParamBindings> mParamBind;
00155 std::map<ProcHandle,OA_ptr<UDDUChains::UDDUChainsStandard> >& mProcToUDDUChainsMap;
00156
00157
00158 std::map<ProcHandle,std::map<IRSymHandle, std::map<IRSymHandle, bool> > >
00159 mProcToMatrix;
00160 std::map<ProcHandle, std::set<IRSymHandle> > mProcToIRSymSet;
00161
00162 std::map<EdgeType,std::map<IRSymHandle,std::map<IRSymHandle,bool> > >
00163 mMatrix;
00164
00165
00166
00167 std::map<ProcHandle, std::set<CallHandle> > mProcToCallsiteSet;
00168
00169 std::map<ProcHandle, std::set<SymHandle> > mProcToFormalSet;
00170
00171 std::map<CallHandle, std::map<IRSymHandle, std::set<IRSymHandle> > >
00172 mFormalToActualMap;
00173
00174 std::map<CallHandle, ProcHandle> mCallsiteToProc;
00175
00176 std::map<CallHandle, std::map<SymHandle, std::set<SymHandle> > > mParamMap;
00177
00178 std::map<StmtHandle, std::set<SymHandle> > mCallByRefActuals;
00179 std::set<StmtHandle> mCallInfoReady;
00180
00181
00182
00183 std::set<ProcHandle> mProcsOfInterest;
00184
00185
00186 std::set<StmtHandle> mDefsUsesCollected;
00187
00188 std::map<StmtHandle, std::set<SymHandle> > mStmtToUsedSyms;
00189
00190 std::map<StmtHandle, std::set<SymHandle> > mStmtToDefdSyms;
00191
00192 std::map<StmtHandle, std::set<SymHandle> > mStmtToCallDefdSyms;
00193
00194 std::set<SymHandle> mGlobals;
00195
00196
00197 std::map<SymHandle, std::set<GlobalNode> > mGlobalUpUses;
00198 std::map<SymHandle, std::set<GlobalNode> > mGlobalDnDefs;
00199 };
00200
00202
00203 class IndepLocVisitor : public virtual LocationVisitor {
00204 public:
00205
00206 IndepLocVisitor(OA_ptr<DUGStandard> dug,
00207 ProcHandle proc,
00208 std::set<ProcHandle> ProcsOfInterest,
00209 OA_ptr<DUGIRInterface> ir
00210 )
00211 : mDUG(dug), mProc(proc), mProcsOfInterest(ProcsOfInterest), mIR(ir)
00212 { }
00213 ~IndepLocVisitor() { }
00214
00215 void visitNamedLoc(NamedLoc& loc);
00216 void visitUnnamedLoc(UnnamedLoc& loc);
00217 void visitInvisibleLoc(InvisibleLoc& loc);
00218 void visitUnknownLoc(UnknownLoc& loc);
00219 void visitLocSubSet(LocSubSet& loc);
00220
00221 std::set<ProcHandle> getmProcsOfInterest()
00222 {
00223 return mProcsOfInterest;
00224 }
00225 private:
00226 OA_ptr<DUGStandard> mDUG;
00227 ProcHandle mProc;
00228 std::set<ProcHandle> mProcsOfInterest;
00229 OA_ptr<DUGIRInterface> mIR;
00230
00231 };
00232
00233 class depLocVisitor : public virtual LocationVisitor {
00234 public:
00235 depLocVisitor(OA_ptr<DUGStandard> dug,
00236 ProcHandle proc,
00237 std::set<ProcHandle> ProcsOfInterest ,
00238 OA_ptr<DUGIRInterface> ir
00239 )
00240 : mDUG(dug), mProc(proc), mProcsOfInterest(ProcsOfInterest), mIR(ir)
00241 { }
00242 ~depLocVisitor() {}
00243
00244 void visitNamedLoc(NamedLoc& loc);
00245 void visitUnnamedLoc(UnnamedLoc& loc);
00246 void visitInvisibleLoc(InvisibleLoc& loc);
00247 void visitUnknownLoc(UnknownLoc& loc);
00248 void visitLocSubSet(LocSubSet& loc);
00249 std::set<ProcHandle> getmProcsOfInterest()
00250 {
00251 return mProcsOfInterest;
00252 }
00253
00254 private:
00255 OA_ptr<DUGStandard> mDUG;
00256 ProcHandle mProc;
00257 std::set<ProcHandle> mProcsOfInterest;
00258 OA_ptr<DUGIRInterface> mIR;
00259 };
00260
00261
00262
00263 }
00264 }
00265
00266 #endif