00001 00015 //-------------------------------------------------------------------- 00016 //-------------------------------------------------------------------- 00017 00018 #ifndef _LINEARITYPAIR_H 00019 #define _LINEARITYPAIR_H 00020 00021 //-------------------------------------------------------------------- 00022 // STL headers 00023 #include <iostream> 00024 #include <map> 00025 #include <set> 00026 #include <list> 00027 00028 //OpenAnalysis headers 00029 #include <OpenAnalysis/Utils/OA_ptr.hpp> 00030 #include <OpenAnalysis/Location/Locations.hpp> 00031 #include <OpenAnalysis/IRInterface/IRHandles.hpp> 00032 #include <OpenAnalysis/OABase/Annotation.hpp> 00033 00035 namespace OA { 00036 namespace Linearity { 00037 00038 class AbstractVar { 00039 public: 00040 AbstractVar() {} 00041 ~AbstractVar() {} 00042 00043 virtual char getVar() = 0; 00044 00045 virtual void operator=( AbstractVar &other) = 0; 00046 // comparison operators 00047 virtual bool operator==( AbstractVar &other ) = 0; 00048 virtual bool operator<( AbstractVar &other ) = 0; 00049 }; 00050 00051 class SimpleAbstractVar : public AbstractVar { 00052 private: 00053 char var; 00054 public: 00055 SimpleAbstractVar() {} 00056 ~SimpleAbstractVar() {} 00057 SimpleAbstractVar(char v) { var = v; } 00058 char getVar() { return var; } 00059 00060 00061 void operator= ( AbstractVar &other ); 00062 bool operator==( AbstractVar &other ); 00063 bool operator<( AbstractVar &other ); 00064 }; 00065 //ampl interpretor -> capable of making C/Fortran Statements 00066 //Talk to Tod About Ampl and TestCases 00067 //*********************************************** 00068 //LinearityClass Starts 00069 //*********************************************** 00070 00071 class LinearityClass { 00072 public: 00073 typedef enum { 00074 LCLASS_NODEP, LCLASS_LINEAR, LCLASS_NONLINEAR 00075 } LClassLatticeVal; 00076 00077 LinearityClass() {} 00078 00079 LinearityClass( LClassLatticeVal init ) { mVal = init; } 00080 LinearityClass( int init ) 00081 { 00082 if (init == 1) { mVal = LCLASS_LINEAR; } 00083 else if (init == 2) { mVal = LCLASS_NONLINEAR; } 00084 } 00085 LClassLatticeVal getLClass(); 00086 void putLClass(LClassLatticeVal init); 00087 void output() { std::cout << "Meet = " << mVal << std::endl; } 00088 00089 LinearityClass meet(LinearityClass other); 00090 bool operator==( LinearityClass other ); 00091 bool operator!=( LinearityClass other ); 00092 00093 private: 00094 LClassLatticeVal mVal; //enum type 00095 }; 00096 00097 //*********************************************** 00098 //VarClass Starts 00099 //*********************************************** 00100 00101 class VarClassPair : public virtual Annotation{ 00102 public: 00103 //<v,class> 00104 VarClassPair( OA_ptr<Location> v1, LinearityClass lclass2 ) 00105 { 00106 //OA_ptr<SymHandle> empty; empty = new SymHandle(); 00107 //v = new NamedLoc(SymHandle(),true); 00108 //*v = *v1; 00109 //v = v1->clone(); 00110 v = v1; 00111 //if (v1->isaNamed()) { 00112 // OA_ptr<NamedLoc> nv1 = v1.convert<NamedLoc>(); 00113 // v = new NamedLoc(*nv1); 00114 //} 00115 lclass = lclass2; 00116 } 00117 00118 OA_ptr<Location> getVar(); 00119 LinearityClass getLClass(); 00120 00121 bool operator==( VarClassPair &other ); 00122 bool operator<( VarClassPair &other ); 00123 void output(IRHandlesIRInterface& ir); 00124 00125 private: 00126 OA_ptr<Location> v; 00127 LinearityClass lclass; 00128 00129 }; 00130 00131 // HINT: while implementing this, look up some of the iterator 00132 // implementations in OpenAnalysis 00133 class VarClassPairIterator { 00134 private: 00135 OA_ptr<std::set<OA_ptr<VarClassPair> > > vcSet; 00136 std::set<OA_ptr<VarClassPair> >::iterator mIter; 00137 00138 public: 00139 VarClassPairIterator(OA_ptr<std::set<OA_ptr<VarClassPair> > > pSet) 00140 { 00141 vcSet = new std::set<OA_ptr<VarClassPair> >(*pSet); 00142 mIter = vcSet->begin(); 00143 //std::cout << "(" << vcSet->size() << ")vc" << std::endl; 00144 } 00145 ~VarClassPairIterator() 00146 { 00147 vcSet = new std::set<OA_ptr<VarClassPair> >; 00148 mIter = vcSet->begin(); 00149 } 00150 00151 // Returns the current item. 00152 //NOTE: Should VarClassPair Return be *? 00153 OA_ptr<VarClassPair> current() const { return (*mIter); } 00154 // False when all items are exhausted. 00155 bool isValid() const {return (mIter != vcSet->end()); }; 00156 00157 // Changes an Iter to Find() 00158 void findIter(OA_ptr<VarClassPair> vcp) { 00159 mIter = (vcSet)->find(vcp); 00160 } 00161 00162 void operator++() { if (mIter != vcSet->end()) mIter++; } 00163 void operator++(int) { ++*this; } ; 00164 00165 void reset(); 00166 }; 00167 00168 //*********************************************** 00169 //LinearityPair Starts 00170 //*********************************************** 00171 00172 class LinearityPair : public virtual Annotation { 00173 public: 00174 //<<v,w>,class> 00175 LinearityPair( OA_ptr<Location> v2, OA_ptr<Location> w2, 00176 LinearityClass lclass2 ) 00177 { 00178 //v = new NamedLoc(SymHandle(),true); 00179 //w = new NamedLoc(SymHandle(),true); 00180 //*v = *v2; *w = *w2; 00181 //if (v2->isaNamed() && w2->isaNamed()) { 00182 // OA_ptr<NamedLoc> nv2 = v2.convert<NamedLoc>(); 00183 // OA_ptr<NamedLoc> nw2 = w2.convert<NamedLoc>(); 00184 // v = new NamedLoc(*nv2); 00185 // w = new NamedLoc(*nw2); 00186 //} 00187 v = v2; 00188 w = w2; 00189 lclass = lclass2; 00190 } 00191 00192 OA_ptr<VarClassPair> getVarClassPair(); 00193 LinearityClass getLClass(); 00194 OA_ptr<Location> getVar1(); 00195 OA_ptr<Location> getVar2(); 00196 00197 void output(IRHandlesIRInterface& ir); 00198 void dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir); 00199 00200 bool operator==( LinearityPair &other ); 00201 bool operator!=( LinearityPair &other ); 00202 bool operator<( LinearityPair &other ); 00203 private: 00204 OA_ptr<Location> v; 00205 OA_ptr<Location> w; 00206 LinearityClass lclass; 00207 }; 00208 00209 00210 // NOTE: Will this actually iterate through VarClassPair's of a Specific 00211 // AbstractVar *v? and Not through just a LinearityPair? 00212 // So in reality, it would be <v,<w,class>> | <w,class> is in v?? 00213 class LinearityPairIterator { 00214 private: 00215 OA_ptr<std::set<OA_ptr<LinearityPair> > > lpSet; 00216 std::set<OA_ptr<LinearityPair> >::iterator mIter; 00217 00218 public: 00219 LinearityPairIterator(OA_ptr<std::set<OA_ptr<LinearityPair> > > pSet) 00220 { 00221 lpSet = new std::set<OA_ptr<LinearityPair> >(*pSet); 00222 mIter = lpSet->begin(); 00223 //std::cout << "(" << lpSet->size() << ")lp" << std::endl; 00224 } 00225 LinearityPairIterator() 00226 { 00227 lpSet = new std::set<OA_ptr<LinearityPair> >; 00228 mIter = lpSet->begin(); 00229 } 00230 ~LinearityPairIterator() { } 00231 00232 // Returns the current item. 00233 OA_ptr<LinearityPair> current() const { return (*mIter); } 00234 // False when all items are exhausted. 00235 bool isValid() const {return (mIter != lpSet->end()); } 00236 00237 // Changes an Iter to Find() 00238 void findIter(OA_ptr<LinearityPair> lp) { 00239 mIter = (lpSet)->find(lp); 00240 } 00241 00242 // Returns the Set of LinearityPairs 00243 OA_ptr<std::set<OA_ptr<LinearityPair> > > getSet() { 00244 return lpSet; 00245 } 00246 00247 void operator ++ () { if (mIter != lpSet->end()) mIter++; } 00248 void operator++(int) { ++*this; } ; 00249 00250 void reset() { mIter = lpSet->begin(); } 00251 00252 }; 00253 00254 } // end of namespace Linearity 00255 } // end of namespace OA 00256 00257 #endif 00258
1.6.1