LinearityPair.cpp

Go to the documentation of this file.
00001 
00015 #include "LinearityPair.hpp"
00016 using namespace OA;
00018 namespace OA {
00019   namespace Linearity {
00020 
00021 
00022 //************************************************************
00023 //SimpleAbstractVar Definitions
00024 //************************************************************
00025 void SimpleAbstractVar::operator= ( AbstractVar &other ) {
00026      var = other.getVar();
00027 }
00028 
00029 bool SimpleAbstractVar::operator==(AbstractVar &other) {
00030      //std::cout << "Comparing AbstractVar \t(" << var << ")  and  (" << other.getVar() << ")\n";
00031      return (var == other.getVar());
00032 }
00033 
00034 bool SimpleAbstractVar::operator<(AbstractVar &other) {
00035      if (var < other.getVar()) {
00036           return true;
00037      }
00038      return false;
00039 }
00040 
00041 
00042 //************************************************************
00043 //LinearityClass Definitions
00044 //************************************************************
00045 LinearityClass::LClassLatticeVal LinearityClass::getLClass() 
00046 { 
00047      return mVal; 
00048 }
00049 
00050 void LinearityClass::putLClass(LClassLatticeVal init) 
00051 { 
00052      mVal = init; 
00053 }
00054 
00055 
00056 LinearityClass LinearityClass::meet(LinearityClass other) {
00057      LinearityClass result = mVal;
00058      //Anything w/Nonlinear = Nonlinear
00059      if (other.getLClass() == LCLASS_NONLINEAR) { result.putLClass(LCLASS_NONLINEAR); }  
00060      // Anything w/NoDep = Anything
00061      else if (mVal != LCLASS_NONLINEAR && mVal != LCLASS_LINEAR) { result.putLClass(other.getLClass());
00062      } 
00063      return result;
00064 }
00065 
00066 bool LinearityClass::operator==( LinearityClass other ) {
00067                 return (mVal == other.getLClass());
00068 }
00069 
00070 bool LinearityClass::operator!=( LinearityClass other ) {
00071                 return (mVal != other.getLClass());
00072 }
00073 
00074 //************************************************************
00075 //VarClassPair Definitions
00076 //************************************************************
00077 OA_ptr<Location> VarClassPair::getVar() 
00078 { 
00079      return v; 
00080 }
00081 
00082 LinearityClass VarClassPair::getLClass() 
00083 { 
00084      return lclass; 
00085 }
00086 
00087 bool VarClassPair::operator==( VarClassPair &other )
00088 {
00089      return (*v == *(other.getVar()));
00090 }
00091 
00092 bool VarClassPair::operator<( VarClassPair &other )
00093 {
00094      if (*v < *(other.getVar())) {
00095           return true;
00096      }
00097      return false;
00098 }
00099 
00100 void VarClassPair::output(IRHandlesIRInterface& ir)
00101 {
00102 /*     if (v->isaNamed() && w->isaNamed()) {
00103        OA_ptr<NamedLoc> nv = v.convert<NamedLoc>();
00104        OA_ptr<NamedLoc> nw = w.convert<NamedLoc>();
00105        SymHandle symv = nv->getSymHandle();
00106        SymHandle symw = nw->getSymHandle();
00107 */
00108 //       std::cout << "<<" << char(symv.hval()) << ","
00109 //                 << char(symw.hval()) << ">,";
00110                     sOutBuild->objStart("VarClassPair");
00111                     sOutBuild->fieldStart("Location->V");
00112                     v->output(ir);
00113                     sOutBuild->fieldEnd("LocationV");
00114                     
00115                     sOutBuild->fieldStart("LClass");  
00116                     ostringstream os;
00117                     if (lclass.getLClass() == 1) {
00118                     os << "Linear";
00119                     } else {
00120                     os << "Nonlinear";
00121                     }
00122                     sOutBuild->outputString(os.str());
00123                     sOutBuild->fieldEnd("LClass");
00124                     sOutBuild->objEnd("VarClassPair");
00125      
00126 
00127 
00128 }
00129 
00130 
00131 
00132 //************************************************************
00133 //LinearityPair Definitions
00134 //************************************************************
00135 OA_ptr<VarClassPair> LinearityPair::getVarClassPair() { 
00136      OA_ptr<VarClassPair> retval;
00137      retval = new VarClassPair(w,lclass);
00138      return retval;
00139 }
00140         
00141 LinearityClass LinearityPair::getLClass() 
00142 { 
00143      return lclass; 
00144 }
00145 
00146 OA_ptr<Location> LinearityPair::getVar1() 
00147 { 
00148      return v; 
00149 }
00150 
00151 OA_ptr<Location> LinearityPair::getVar2() 
00152 { 
00153      return w; 
00154 }
00155 
00156 void LinearityPair::output(IRHandlesIRInterface& ir)
00157 {
00158 /*     if (v->isaNamed() && w->isaNamed()) {
00159        OA_ptr<NamedLoc> nv = v.convert<NamedLoc>();
00160        OA_ptr<NamedLoc> nw = w.convert<NamedLoc>();
00161        SymHandle symv = nv->getSymHandle();
00162        SymHandle symw = nw->getSymHandle();
00163 */
00164 //       std::cout << "<<" << char(symv.hval()) << ","
00165 //                 << char(symw.hval()) << ">,";
00166                     sOutBuild->objStart("LinearityPair");
00167                     sOutBuild->fieldStart("Location->V");
00168                     v->output(ir);
00169                     sOutBuild->fieldEnd("LocationV");
00170                     
00171                     sOutBuild->fieldStart("Location->W");
00172                     w->output(ir);
00173                     sOutBuild->fieldEnd("LocationW");
00174                     
00175                     sOutBuild->fieldStart("LClass");  
00176                     ostringstream os;
00177                     if (lclass.getLClass() == 1) {
00178                     os << "Linear";
00179                     } else {
00180                     os << "Nonlinear";
00181                     }
00182                     sOutBuild->outputString(os.str());
00183                     sOutBuild->fieldEnd("LClass");
00184                     sOutBuild->objEnd("LinearityPair");
00185      
00186 
00187 
00188 }
00189 
00190 void LinearityPair::dump(std::ostream& os, OA_ptr<IRHandlesIRInterface> ir)
00191 {
00192     os << "LP=";
00193     w->dump(std::cout,ir);
00194     os << ",";
00195     if (lclass.getLClass() == 1) {
00196         os << "LINEAR";
00197     } else {
00198         os << "NONLINEAR";
00199     }
00200 
00201 }
00202 
00203 bool LinearityPair::operator==( LinearityPair &other )
00204 { 
00205 //std::cout << "Comparing LinearityPair! \t<" << v->getVar() << "," << w->getVar() << ">";
00206 //std::cout << "  With  <" << (other.getVar1()->getVar()) << "," << (other.getVar2()->getVar()) << ">\n";
00207      return (*v == *(other.getVar1()) && *w == *(other.getVar2()));  
00208 }
00209 
00210 bool LinearityPair::operator!=( LinearityPair &other )
00211 {
00212      return !(*v == *(other.getVar1()) && *w == *(other.getVar2()) && lclass == other.getLClass());
00213 }
00214 
00215 bool LinearityPair::operator<( LinearityPair &other ) {
00216      if (*v < *(other.getVar1())) {
00217           return true;
00218      } else if ((*v == *(other.getVar1())) && (*w < *(other.getVar2()))) {
00219           return true;
00220      }
00221      return false;
00222 }
00223 
00224   } // end of namespace Linearity
00225 } // end of namespace OA
00226