Exemple #1
0
bool SplitEquation( CoeffVec& cur, 
                      const SymbolicVal& cut, const BoundVec& bounds, 
                      BoundOp& boundop, CoeffVec& split)
 {
     int dim = cur.size()-1; 
     SymbolicVal leftval = cur[dim]; // obtain the last coefficient, which is right side terms without using loop index variable
     if (leftval != 0) {
       CompareRel r1 = CompareVal(leftval,-cut, &boundop);
       CompareRel r2 = CompareVal(leftval,cut, &boundop);
       bool lt = ((r1 & REL_GT) && (r2 & REL_LT)) || ((r1 & REL_LT) && (r2 & REL_GT)); 
       if (!lt) { // relation of r1 and r2 must be reversed pair, or error
         if (DebugDep())
           std::cerr << "unable to split because " << leftval.toString() << " ? " << cut.toString() << std::endl;
         return false;   
       }
     }

     bool succ = false;
     split.clear();
     int j =0;
     for (; j < dim; ++j) {
        SymbolicVal left = cur[j] / cut;
        if (HasFraction(left))  
            split.push_back(0);
        else {
            split.push_back(left);
            succ = true;
        }
     }  
     split.push_back(0); // right-hand side value
     if (succ) {
        SymbolicVal left = 0;
        for (j = 0; j < dim; ++j) {
           if (split[j]== 0) 
             switch (CompareVal(cur[j],0,&boundop)) {
              case REL_LE:
                 left = left + cur[j] * bounds[j].lb; break;
              case REL_GE:
                 left = left + cur[j] * bounds[j].ub; break;
              default: break;
             }
        }
        if (j == dim && (left == 0 || (CompareVal(left,cut) & REL_LT)))  {
          for (j = 0; j < dim; ++j) {
             if (split[j] != 0)
                cur[j] = 0; // clear some coefficency values
          }
        
          return true;
        }
        else if (DebugDep()) { 
            if (j == dim)
               std::cerr << "unable to decide left " << left.toString() << " ? " << cut.toString() << std::endl;
            else
               std::cerr << "unable to decide cur[" << j << "] ? 0\n";
        }
     }
     split.clear();
     return false;
}
CompareRel CompareVal(const SymbolicVal &v1, const SymbolicVal &v2, 
                      MapObject<SymbolicVal,SymbolicBound>* f)
   { 
     if ( v1.IsNIL() && v2.IsNIL()) return REL_UNKNOWN;
     if (DebugCompareVal())
         std::cerr << "comparing " << v1.toString() << " with " << v2.toString() << " under " <<  f << std::endl;
     comparetime = 0;
     return CompareValHelp(v1,v2,f);
   }
CompareRel CompareValHelp(const SymbolicVal &v1, const SymbolicVal &v2, 
                      MapObject<SymbolicVal,SymbolicBound>* f)
{
    CompareRel r = REL_UNKNOWN;
    if (++comparetime < COMPARE_MAX)
        r = ValCompare(f)(v1,v2); 
    if (DebugCompareVal())
         std::cerr << v1.toString() << RelToString(r) << v2.toString() << " under " << f << std::endl;
     return r;
   }
Exemple #4
0
LoopTreeNode* LoopBlocking::
ApplyBlocking( const CompSliceDepGraphNode::FullNestInfo& nestInfo, 
              LoopTreeDepComp& comp, DependenceHoisting &op, LoopTreeNode *&top)
{
  const CompSliceNest& slices = *nestInfo.GetNest();
  if (DebugLoop()) {
     std::cerr << "\n Blocking slices: " << slices.toString() << "\n";
  }
  LoopTreeNode *head = 0;
  AstInterface& fa = LoopTransformInterface::getAstInterface();
  for (int j = FirstIndex(); j >= 0; j = NextIndex(j))  {
     top = op.Transform( comp, slices[j], top);
     SymbolicVal b = BlockSize(j);
     if (DebugLoop()) {
        std::cerr << "\n after slice " << j << " : \n";
        //top->DumpTree();
        comp.DumpTree();
        comp.DumpDep();
        std::cerr << "\n blocking size for this loop is " << b.toString() << "\n";
     }
      
     if (!(b == 1)) {
         LoopTreeNode *n = LoopTreeBlockLoop()( top, SymbolicVar(fa.NewVar(fa.GetType("int")), AST_NULL), b);
         if (DebugLoop()) {
            std::cerr << "\n after tiling loop with size " << b.toString() << " : \n";
            //top->DumpTree();
            comp.DumpTree();
            comp.DumpDep();
         }
         if (head == 0)
             head = n;
         else {
           while (n->FirstChild() != head)
              LoopTreeSwapNodePos()( n->Parent(), n);
         }
       }
   }
  return head;
}
 void Default0( const SymbolicVal &v1, const SymbolicVal &v2)
 {  
   Default1(v1,v2);
   if (DebugCompareVal())
       std::cerr << " in CompareOperator::Default \n";
   if (result == REL_UNKNOWN) {
     int tmp = comparetime;
     SymbolicVal diff = v1 - v2;
     comparetime = tmp;
     if (diff.GetValType() == VAL_CONST) {
        int diffval = atoi( diff.toString().c_str());
        if (diffval  < 0) 
            result = REL_LT;
        else if (diffval > 0)
            result = REL_GT;
        else 
            result = REL_EQ; 
    }
    else if (func != 0) {
       int tmp = comparetime;
       SymbolicBound b1 = GetValBound(v1,*func), b2 = GetValBound(v2,*func);
       comparetime = tmp;
       CompareRel ge1 = (b1.lb != v1)? CompareValHelp(b1.lb,v2,func) : REL_UNKNOWN;
       CompareRel le2 = (b2.ub != v2)? CompareValHelp(b2.ub,v1,func) : REL_UNKNOWN; 
       CompareRel le1 = (b1.ub != v1)? CompareValHelp(b1.ub,v2,func) : REL_UNKNOWN;
       CompareRel ge2 = (b2.lb != v2)? CompareValHelp(b2.lb,v1,func) : REL_UNKNOWN; 
       if (CountGT(ge1) || CountLT(le2))
            result = REL_GT; 
       else if (CountGE(ge1) || CountLE(le2))
            result = REL_GE; 
       else if (CountLT(le1) || CountGT(ge2))
            result = REL_LT; 
       else if (CountLE(le1) || CountGE(ge2))
            result = REL_LE; 
   }
  }
 }
SymbolicVal ApplyBinOP( SymOpType t, const SymbolicVal &v1,
                               const SymbolicVal &v2)
{
  SymbolicVal r;
  switch (t) {
  case SYMOP_PLUS: 
     {
      PlusApplicator op; 
      r = ApplyBinOP(op, v1, v2);
      if (DebugOp())
         std::cerr << v1.toString() << " + " << v2.toString() << " = " << r.toString() << std::endl;  
      return r;
     }
  case SYMOP_MULTIPLY: 
    {
      MultiplyApplicator op; 
      r = ApplyBinOP(op, v1, v2);
      if (DebugOp())
         std::cerr << v1.toString() << " * " << v2.toString() << " = " << r.toString() << std::endl;  
      return r;
    }
  case SYMOP_MIN: 
      r = Min(v1,v2);
      if (DebugOp())
         std::cerr << "Min( " << v1.toString() << " , " << v2.toString() << ") = " << r.toString() << std::endl;  
      return r;
  case SYMOP_MAX: return Max(v1, v2);
      r = Max(v1,v2);
      if (DebugOp())
         std::cerr << "Max( " << v1.toString() << " , " << v2.toString() << ") = " << r.toString() << std::endl;  
      return r;
  case SYMOP_POW: 
     {
      int val2;
      int vu1, vd1;
      if (!v2.isConstInt(val2))
         assert(false);
      if (v1 == 1 || val2 == 1)
         r =  v1;
      else if (val2 == -1 && v1.isConstInt(vu1, vd1)) 
         r = new SymbolicConst(vd1, vu1);
      else   
         r = new SymbolicPow(v1, val2);
      if (DebugOp())
         std::cerr << "Pow( " << v1.toString() << " , " << v2.toString() << ") = " << r.toString() << std::endl;  
      return r;
     }
  default:
    assert(false);
  }
}