LinearityDepsSet.cpp

Go to the documentation of this file.
00001 
00016 #include "LinearityDepsSet.hpp"
00017 using namespace OA;
00019 namespace OA {
00020   namespace Linearity {
00021 
00022 //************************************************************
00023 //LinearityDepsSet Definitions
00024 //************************************************************
00025 //Create a New Empty LinearityDepsSet
00026 LinearityDepsSet::LinearityDepsSet() 
00027 {
00028      vcSet= new std::set<OA_ptr<VarClassPair> >; 
00029 }
00030 
00031 /* k -> { <v,T> | v E V } */
00032 //Expression is a Constant, 
00033 //  No difference in Linearity(NODEP), just create new Set
00034 LinearityDepsSet::LinearityDepsSet(double) 
00035 {
00036      vcSet= new std::set<OA_ptr<VarClassPair> >;
00037 }
00038 
00039 /* v -> { <v,linear> } U { < w,class> | <<v,w>,class> E IN(b) } */
00040 //Expression is a Variable,
00041 //  v becomes linear, then union v,linear with the rest of VarClassPairs
00042 //  containing v in thier dependance chain.
00043 LinearityDepsSet::LinearityDepsSet(OA_ptr<Location> v, OA_ptr<LinearityDepsSet> deps) 
00044 {
00045      //Create New Set
00046      vcSet= new std::set<OA_ptr<VarClassPair> >;
00047      //Create LinearityClass with Linear
00048      LinearityClass lc(LinearityClass::LCLASS_LINEAR);
00049      //Create new VarClassPair with v and LinearityClass
00050      OA_ptr<VarClassPair> vcp;
00051      vcp = new VarClassPair(v,lc);
00052 
00053      //Inset VarClassPair with the Rest (v,linear Union deps)
00054      deps->insert(vcp);
00055      vcSet = deps->getSet();
00056 }
00057 
00058 /* e1(* /)e2 -> {<v,nonlinear> | <v,class> E DEPS(e1) OR <v,class> E DEPS(e2) */
00059 //Expression1 * Expresion2, or Expresion1 / Expresion2,
00060 //  Expresion v becomes nonlinear for both expressions
00061 //  such that there is a v1 in deps(expression1) or
00062 //  there is a v2 in deps(expression2). All the v's in
00063 //  both expression dependance chain become nonlinear
00064 OA_ptr<LinearityDepsSet> LinearityDepsSet::multdiv(OA_ptr<LinearityDepsSet> deps) 
00065 {
00066      //V is Nonlinear if it exist in either DEPS
00067      //Create Return Value for LinearityDepsSet
00068      OA_ptr<LinearityDepsSet> retval;
00069      retval = new LinearityDepsSet;
00070 
00071      //Create LinearityClass with Nonlinear
00072      LinearityClass lc(LinearityClass::LCLASS_NONLINEAR);
00073 
00074      //Get the Iterator for this VarClassPair Set
00075      OA_ptr<VarClassPairIterator> thisIter; 
00076      thisIter = new VarClassPairIterator(vcSet);
00077      //Get the Iterator for deps VarClassPair Set
00078      OA_ptr<VarClassPairIterator> otherIter;
00079      otherIter = deps->getVarClassPairIterator();
00080 
00081      OA_ptr<VarClassPair> vcp;
00082 
00083      for ( ; thisIter->isValid(); (*thisIter)++){
00084       //get varclasspair and create a new varclass
00085       //pair using its var and linearityclass nonlinear
00086       vcp = new VarClassPair(thisIter->current()->getVar(),lc);
00087       retval->insert(vcp);
00088      }
00089      for ( ; otherIter->isValid(); (*otherIter)++){
00090       //get varclasspair and create a new varclass
00091           //pair using its var and linearityclass nonlinear
00092       vcp = new VarClassPair(otherIter->current()->getVar(),lc);
00093       retval->insert(vcp);
00094      }
00095 
00096 
00097      return retval;
00098 }
00099 
00100 /* e1(+ -)e2 -> {<v1,(class1 meet class2)> */
00101 //Expression1 + Expression2, or Expression1 - Expression2,
00102 //  Expression v becomes the meet of its classes for all its dependance chain
00103 //  if Expression1 v1 and Expression2 v2 are both equal,
00104 //  otherwise Expression v stays the same
00105 OA_ptr<LinearityDepsSet> LinearityDepsSet::addsub(OA_ptr<LinearityDepsSet> deps) 
00106 {
00107      //Meet V with other and this lclass if both V's are
00108      //equal where V1 is in this Deps and V2 is in other
00109      //Deps, otherwise lclass stays the same.
00110      //Create Return Value for LinearityDepsSet
00111      OA_ptr<LinearityDepsSet> retval;
00112      retval = new LinearityDepsSet;
00113      
00114      retval = deps;
00115 
00116      //Get the Iterator for this VarClassPair Set
00117      OA_ptr<VarClassPairIterator> thisIter; 
00118      thisIter = new VarClassPairIterator(vcSet);
00119      //Get the Iterator for deps VarClassPair Set
00120      OA_ptr<VarClassPairIterator> otherIter;
00121      otherIter = deps->getVarClassPairIterator();
00122 
00123      OA_ptr<VarClassPair> vcp;
00124 
00125      for ( ; thisIter->isValid(); (*thisIter)++){
00126       //Compare VarClassPairs
00127       OA_ptr<VarClassPair> vcthis;
00128       vcthis = thisIter->current();
00129       //look for this VarClassPair match in the other set
00130       otherIter->findIter(vcthis);
00131 
00132       //check for a match in VarClassPair
00133       if (otherIter->isValid()){
00134            OA_ptr<VarClassPair> vcother;
00135            vcother = otherIter->current();
00136                
00137            //There was a Match between both Deps
00138            //VarClass, Do A meet between LClasses
00139            LinearityClass lc = vcthis->getLClass().meet(vcother->getLClass());
00140            vcp = new VarClassPair(vcother->getVar(),lc);
00141            retval->erase(vcp);
00142            retval->insert(vcp);
00143       } else {
00144            retval->insert(vcthis);
00145       }
00146 }
00147 
00148 
00149 
00150      return retval;
00151 }
00152 
00153 /* function(v) -> {<v,nonlinear>} */
00154 //Expression v is a variable in a function,
00155 //  v becomes nonlinear for all its dependace chain
00156 //  that is contain in deps(expression)
00157 OA_ptr<LinearityDepsSet> LinearityDepsSet::func(OA_ptr<LinearityDepsSet> deps) 
00158 {
00159      //V is Nonlinear if it exist in either DEPS
00160      //Create Return Value for LinearityDepsSet
00161      OA_ptr<LinearityDepsSet> retval;
00162      retval = new LinearityDepsSet;
00163 
00164      //Create LinearityClass with Nonlinear
00165      LinearityClass lc(LinearityClass::LCLASS_NONLINEAR);
00166 
00167 //     //Get the Iterator for this VarClassPair Set
00168 //     OA_ptr<VarClassPairIterator> thisIter; 
00169 //     thisIter = new VarClassPairIterator(vcSet);
00170      //Get the Iterator for deps VarClassPair Set
00171      OA_ptr<VarClassPairIterator> otherIter;
00172      otherIter = deps->getVarClassPairIterator();
00173 
00174      OA_ptr<VarClassPair> vcp;
00175 
00176 //     for ( ; thisIter->isValid(); (*thisIter)++){
00177 //          //get varclasspair and create a new varclass
00178 //        //pair using its var and linearityclass nonlinear
00179 //        vcp = new VarClassPair(thisIter->current()->getVar(),lc);
00180 //        retval->insert(vcp);
00181 //    }
00182       for ( ; otherIter->isValid(); (*otherIter)++){
00183       //get varclasspair and create a new varclass
00184           //pair using its var and linearityclass nonlinear
00185           vcp = new VarClassPair(otherIter->current()->getVar(),lc);
00186           retval->insert(vcp);
00187      }
00188 
00189 
00190      return retval;
00191 }
00192 
00193 /* e1^1 -> {<v1,(linear meet class)> | <v,class> E DEPS(e1) */
00194 //Expression1 to the Power of 1,
00195 //  Expression v becomes the meet between linear and v.class
00196 //  if Expression1 v.class is NODEP then v.cass becomes linear
00197 //  for all its dependance chain
00198 OA_ptr<LinearityDepsSet> LinearityDepsSet::power1(OA_ptr<LinearityDepsSet> deps) 
00199 {
00200      //Create Return Value for LinearityDepsSet
00201      OA_ptr<LinearityDepsSet> retval;
00202      retval = new LinearityDepsSet;
00203 
00204      //Create LinearityClass with Nonlinear
00205      LinearityClass lc1(LinearityClass::LCLASS_LINEAR);
00206 
00207      //Get the Iterator for deps VarClassPair Set
00208      OA_ptr<VarClassPairIterator> otherIter;
00209      otherIter = deps->getVarClassPairIterator();
00210 
00211      OA_ptr<VarClassPair> vcp;
00212 
00213      for ( ; otherIter->isValid(); (*otherIter)++){
00214       //get varclasspair and create a new varclass
00215       //pair using its var and linearityclass nonlinear
00216       LinearityClass lc = lc1.meet(otherIter->current()->getLClass());
00217       vcp = new VarClassPair(otherIter->current()->getVar(),lc);
00218       retval->insert(vcp);
00219      }
00220 
00221      return retval;
00222 }
00223 
00224 /* e1^k -> {<v1,(nonlinear meet class)> | <v,class> E DEPS(e1) */
00225 //Expression1 to the Power of k(constant),
00226 //  Expression v becomes the meet between nonlinear and v.class
00227 //  if Expression1 v.class is NODEP then v.class becomes nonlinear
00228 //  for all its dependance chain
00229 OA_ptr<LinearityDepsSet> LinearityDepsSet::powerk(OA_ptr<LinearityDepsSet> deps) 
00230 {
00231      //Create Return Value for LinearityDepsSet
00232      OA_ptr<LinearityDepsSet> retval;
00233      retval = new LinearityDepsSet;
00234 
00235      //Create LinearityClass with Nonlinear
00236      LinearityClass lc1(LinearityClass::LCLASS_NONLINEAR);
00237 
00238      //Get the Iterator for deps VarClassPair Set
00239      OA_ptr<VarClassPairIterator> otherIter;
00240      otherIter = deps->getVarClassPairIterator();
00241 
00242      OA_ptr<VarClassPair> vcp;
00243 
00244      for ( ; otherIter->isValid(); (*otherIter)++){
00245       //get varclasspair and create a new varclass
00246       //pair using its var and linearityclass nonlinear
00247       LinearityClass lc = lc1.meet(otherIter->current()->getLClass());
00248       vcp = new VarClassPair(otherIter->current()->getVar(),lc);
00249       retval->insert(vcp);
00250      }
00251 
00252      return retval;
00253 }
00254 
00255 /* e1 anyop k -> {<v1,(linear meet class)> | <v,class> E DEPS(e1) */
00256 //Expression1 using * / - + with a constant,
00257 //  Expression v becomes the meet between linear and v.class
00258 //  if Expression1 v.class is NODEP then v.cass becomes linear
00259 //  for all its dependance chain
00260 OA_ptr<LinearityDepsSet> LinearityDepsSet::anyopk() 
00261 {
00262      //Create Return Value for LinearityDepsSet
00263      OA_ptr<LinearityDepsSet> retval;
00264      retval = new LinearityDepsSet;
00265 
00266      //Create LinearityClass with Nonlinear
00267      LinearityClass lc1(LinearityClass::LCLASS_LINEAR);
00268 
00269      //Get the Iterator for this VarClassPair Set
00270      OA_ptr<VarClassPairIterator> thisIter; 
00271      thisIter = new VarClassPairIterator(vcSet);
00272 
00273      OA_ptr<VarClassPair> vcp;
00274 
00275      for ( ; thisIter->isValid(); (*thisIter)++){
00276       //get varclasspair and create a new varclass
00277       //pair using its var and linearityclass nonlinear
00278       LinearityClass lc = lc1.meet(thisIter->current()->getLClass());
00279       vcp = new VarClassPair(thisIter->current()->getVar(),lc);
00280       retval->insert(vcp);
00281      }
00282 
00283      return retval;
00284 }
00285 
00286 /* General LINEAR -> {<v1,(linear meet class)> | <v,class> E DEPS(e1) */
00287 //A General Linear Single Varaible Definition,
00288 //  Expression v becomes the meet between linear and v.class
00289 //  if Expression1 v.class is NODEP then v.cass becomes linear
00290 //  for all its dependance chain
00291 OA_ptr<LinearityDepsSet> LinearityDepsSet::linear() 
00292 {
00293      //Create Return Value for LinearityDepsSet
00294      OA_ptr<LinearityDepsSet> retval;
00295      retval = new LinearityDepsSet;
00296 
00297      //Create LinearityClass with Nonlinear
00298      LinearityClass lc1(LinearityClass::LCLASS_LINEAR);
00299 
00300      //Get the Iterator for this VarClassPair Set
00301      OA_ptr<VarClassPairIterator> thisIter; 
00302      thisIter = new VarClassPairIterator(vcSet);
00303 
00304      OA_ptr<VarClassPair> vcp;
00305 
00306      for ( ; thisIter->isValid(); (*thisIter)++){
00307       //get varclasspair and create a new varclass
00308       //pair using its var and linearityclass nonlinear
00309       LinearityClass lc = lc1.meet(thisIter->current()->getLClass());
00310       vcp = new VarClassPair(thisIter->current()->getVar(),lc);
00311       retval->insert(vcp);
00312      }
00313 
00314      return retval;
00315 }
00316 
00317 /* General NONLINEAR -> {<v1,(nonlinear meet class)> | <v,class> E DEPS(e1) */
00318 //A General NonLinear Single Varaible Definition,
00319 //  Expression v becomes the meet between nonlinear and v.class
00320 //  if Expression1 v.class is NODEP then v.cass becomes nonlinear
00321 //  for all its dependance chain
00322 OA_ptr<LinearityDepsSet> LinearityDepsSet::nonlinear() 
00323 {
00324      //Create Return Value for LinearityDepsSet
00325      OA_ptr<LinearityDepsSet> retval;
00326      retval = new LinearityDepsSet;
00327 
00328      //Create LinearityClass with Nonlinear
00329      LinearityClass lc1(LinearityClass::LCLASS_NONLINEAR);
00330 
00331      //Get the Iterator for this VarClassPair Set
00332      OA_ptr<VarClassPairIterator> thisIter; 
00333      thisIter = new VarClassPairIterator(vcSet);
00334 
00335      OA_ptr<VarClassPair> vcp;
00336 
00337      for ( ; thisIter->isValid(); (*thisIter)++){
00338       //get varclasspair and create a new varclass
00339       //pair using its var and linearityclass nonlinear
00340       LinearityClass lc = lc1.meet(thisIter->current()->getLClass());
00341       vcp = new VarClassPair(thisIter->current()->getVar(),lc);
00342       retval->insert(vcp);
00343      }
00344 
00345      return retval;
00346 }
00347 
00348 
00349 // meet operation between two LinearityDepsSet objects
00350 OA_ptr<LinearityDepsSet> LinearityDepsSet::meet( OA_ptr<LinearityDepsSet> other )
00351 {
00352      //create a result depsset
00353      OA_ptr<LinearityDepsSet> result;
00354      result = new LinearityDepsSet();
00355      //start by copying the other depsset into result, then overwrite
00356      //other specific varclasspairs if nessesary
00357      if (other.ptrEqual(0)) {
00358        assert(0);
00359      }
00360      result = other;
00361      
00362      //create set iterator for this set
00363      OA_ptr<VarClassPairIterator> thisIter;
00364      thisIter = new VarClassPairIterator(vcSet);
00365      //create set iterator for other set
00366      OA_ptr<VarClassPairIterator> vcIter;
00367      vcIter = other->getVarClassPairIterator();
00368 
00369      //Iterate throught the set
00370      for( ; thisIter->isValid(); (*thisIter)++)
00371      {
00372          OA_ptr<VarClassPair> vcthis;
00373          vcthis = thisIter->current();
00374          //look for this VarClassPair match in otherset
00375          vcIter->findIter(vcthis);
00376 
00377          //check for a match
00378          if (vcIter->isValid())
00379          {
00380              OA_ptr<VarClassPair> vcp;
00381              vcp = vcIter->current();
00382 
00383              //put VarClassPair in result after meeting its LClasses
00384              LinearityClass lc = vcthis->getLClass().meet(vcp->getLClass());
00385              if (lc == vcthis->getLClass()) { result->insert(vcthis); }
00386              else { result->insert(vcp); }
00387          } else {
00388              //there was no match
00389              result->insert(vcthis);
00390          }//end if match
00391      }//end for set
00392      return result;
00393 }
00394 
00395 void LinearityDepsSet::insert(OA_ptr<VarClassPair> vcp) 
00396 {
00397      vcSet->insert(vcp);
00398 }
00399 
00400 void LinearityDepsSet::erase(OA_ptr<VarClassPair> vcp) 
00401 {
00402      vcSet->erase(vcp);
00403 }
00404 
00405 // all vars and their classes that we have info on
00406 OA_ptr<VarClassPairIterator> LinearityDepsSet::getVarClassPairIterator( )
00407 {
00408      //Return the Iterator to the list of all VarClassPair
00409      OA_ptr<VarClassPairIterator> retval;
00410      retval = new VarClassPairIterator(vcSet);
00411      return retval;
00412 }
00413 
00414 //Converts all Current VarClassPairs in this instance into 
00415 //LinearityPairs with *v being its first argument 
00416 OA_ptr<std::set<OA_ptr<LinearityPair> > > LinearityDepsSet::convertToLinearityPair(OA_ptr<Location> v)
00417 {
00418      OA_ptr<std::set<OA_ptr<LinearityPair> > > result; 
00419      result = new std::set<OA_ptr<LinearityPair> >;
00420      OA_ptr<VarClassPairIterator> ldsIter; 
00421      ldsIter = new VarClassPairIterator(vcSet);
00422                         
00423      for ( ;ldsIter->isValid();(*ldsIter)++) {
00424           OA_ptr<VarClassPair> vcPair = ldsIter->current();
00425                                 
00426           OA_ptr<LinearityPair> lp;
00427           lp = new LinearityPair(v,vcPair->getVar(),vcPair->getLClass());
00428                 
00429           result->insert(lp);   
00430      }
00431      return result;
00432 }
00433 
00434 void LinearityDepsSet::output(IRHandlesIRInterface& ir) {
00435      
00436     sOutBuild->objStart("LinearityDepsSet");
00437      sOutBuild->listStart();
00438 
00439      OA_ptr<VarClassPairIterator> thisIter; 
00440      thisIter = new VarClassPairIterator(vcSet);
00441      for ( ; thisIter->isValid(); (*thisIter)++)
00442      {
00443          OA_ptr<VarClassPair> vcthis;
00444          vcthis = thisIter->current();
00445          sOutBuild->listItemStart();
00446             vcthis->output(ir);
00447          sOutBuild->listItemEnd();
00448 
00449          //std::cout << "\t<" << vcthis->getVar()->getVar() << ",";
00450          //     if (vcthis->getLClass().getLClass() == 1) {
00451          //     std::cout << "Linear" << ">\n";
00452          //     } else {
00453          //     std::cout << "Nonlinear" << ">\n"; }
00454      }
00455      sOutBuild->listEnd();
00456     sOutBuild->objEnd("LinearityDepsSet");
00457 }
00458 
00459 OA_ptr<std::set<OA_ptr<VarClassPair> > > LinearityDepsSet::getSet()
00460 {
00461      return vcSet;
00462 }
00463 
00464 LinearityDepsSet& LinearityDepsSet::operator= (const LinearityDepsSet& other)
00465 {
00466     vcSet = other.vcSet;
00467     return *this;
00468 }
00469 
00470 OA_ptr<LinearityDepsSet> LinearityDepsSet::operator=( OA_ptr<LinearityDepsSet> other )
00471 {
00472     std::cout << "\n\nCALLING DEPS OPERATOR=\n-=-=-=-=-=-=-=-=-=-==-=-=-=-=-\n\n";
00473     (*vcSet) = *(other->getSet());     
00474 }
00475 
00476   } // end of namespace Linearity
00477 } // end of namespace OA
00478