Go to the documentation of this file.00001 #ifndef ManagerAffineExpr_H
00002 #define ManagerAffineExpr_H
00003
00004 #include <OpenAnalysis/ExprTree/ExprTreeVisitor.hpp>
00005 #include <OpenAnalysis/IRInterface/AffineExprIRInterface.hpp>
00006 #include <OpenAnalysis/AffineExpr/AffineExprAbstraction.hpp>
00007 #include <OpenAnalysis/Alias/Interface.hpp>
00008 #include <stack>
00009 using namespace std;
00010
00011 namespace OA {
00012 namespace AffineExpr {
00013
00016 enum AffineAnlState {
00017 INVALID_OPERATOR = 0,
00018 NON_LINEAR_TERM,
00019 INVALID_VAR,
00020 INDIRECT_REF,
00021 VALID_AFFINE_EXP
00022 };
00023
00024
00025
00026
00027 struct StackObj {
00028 bool isVar;
00029
00030
00031
00032 int val;
00033 OA_ptr<NamedLoc> var;
00034 };
00035
00036
00040 class AffineExprExprTreeVisitor : public ExprTreeVisitor {
00041 public:
00042 AffineExprExprTreeVisitor(
00043 OA_ptr<AffineExprAbstraction> afExp,
00044 OA_ptr<AffineExprIRInterface> ir,
00045 ProcHandle hProc,
00046 const set<OA_ptr<NamedLoc> > & indexVars,
00047 const set<OA_ptr<NamedLoc> > & nonConstVars,
00048 OA_ptr<Alias::Interface> aliasResults)
00049 :
00050 mAfExp(afExp),
00051 mIR(ir),
00052 mhProc(hProc),
00053 mIndexVars(indexVars),
00054 mNonConstVars(nonConstVars),
00055 mAliasResults(aliasResults),
00056 mState(VALID_AFFINE_EXP)
00057 { }
00058
00059 virtual ~AffineExprExprTreeVisitor() {}
00060
00061 virtual void visitExprTreeBefore(ExprTree&) { }
00062 virtual void visitExprTreeAfter(ExprTree&) { }
00063 virtual void visitNode(ExprTree::Node& n) { }
00064
00065 virtual void visitOpNode(ExprTree::OpNode& n);
00066 virtual void visitCallNode(ExprTree::CallNode& n);
00067 virtual void visitMemRefNode(ExprTree::MemRefNode& n);
00068 virtual void visitConstSymNode(ExprTree::ConstSymNode& n);
00069 virtual void visitConstValNode(ExprTree::ConstValNode& n);
00070
00071 AffineAnlState getState() { return mState; }
00072
00073 private:
00074 void pushVar(OA_ptr<NamedLoc> var);
00075 void pushScaler(int val);
00076 void factor();
00077 void term();
00078
00079 stack<StackObj> mStack;
00080
00081 OA_ptr<AffineExprAbstraction> mAfExp;
00082 OA_ptr<AffineExprIRInterface> mIR;
00083 ProcHandle mhProc;
00084 const set<OA_ptr<NamedLoc> > & mIndexVars;
00085 const set<OA_ptr<NamedLoc> > & mNonConstVars;
00086 OA_ptr<Alias::Interface> mAliasResults;
00087 AffineAnlState mState;
00088 };
00089
00090
00091
00094 class ManagerAffineExpr {
00095 public:
00097 ManagerAffineExpr(
00098 OA_ptr<AffineExprIRInterface> _ir);
00099
00102 OA_ptr<AffineExprAbstraction> analyzeMemRefExp(
00103 ExprHandle hExp,
00104 ProcHandle hProc,
00105 const set<OA_ptr<NamedLoc> > & indexVars,
00106 const set<OA_ptr<NamedLoc> > & nonConstVars,
00107 OA_ptr<Alias::Interface> aliasResults,
00108 AffineAnlState *state);
00109
00110 static string toString(AffineAnlState state) {
00111 switch(state) {
00112 case INVALID_OPERATOR: return "INVALID_OPERATOR"; break;
00113 case NON_LINEAR_TERM: return "NON_LINEAR_TERM"; break;
00114 case INVALID_VAR: return "INVALID_VAR"; break;
00115 case INDIRECT_REF: return "INDIRECT_REF"; break;
00116 case VALID_AFFINE_EXP: return "VALID_AFFINE_EXP"; break;
00117 };
00118 return "INVALID AffineAnlState!";
00119 }
00120
00121 private:
00122 OA_ptr<AffineExprIRInterface> mIR;
00123 };
00124
00125 } }
00126
00127 #endif