Exemple #1
0
//___________________________________________________________________________________________
void KVValues::DefineAdditionalValue(KVString name, KVString expr)
{

   if (HasParameter(name.Data())) {
      Warning("DefineAdditionalValue", "le nom de variable %s est deja utilise", name.Data());
      return;
   }

   KVString expr2 = expr;
   KVNumberList* nl = TransformExpression(expr2);

   if (nl) {
      if (nl->IsEmpty()) {
         Warning("DefineAdditionalValue", "la KVNumberList est vide #%s#", nl->GetList());
      }
      else {
         if (AddFormula(name, expr2)) {
            LinkParameters(nl);
            ComputeAdditionalValues(kval_add - 1, kval_add);
         }
      }
   }
   else {
      Error("DefineAdditionalValue", "La traduction de l'expression %s a echouee", expr.Data());
   }
}
Exemple #2
0
void Optimizer::OptimizeExpression(std::shared_ptr<GroupExpression> gexpr,
                                   PropertySet requirements)
{
  LOG_TRACE("Optimizing expression of group %d with op %s",
            gexpr->GetGroupID(), gexpr->Op().name().c_str());

  // Helper function for costing follow up expressions
  auto CostCandidate =
    [this](std::shared_ptr<GroupExpression> candidate,
           PropertySet requirements)
    {
      // Cost the expression
      this->CostExpression(candidate);

      // Only include cost if it meets the property requirements
      if (requirements.IsSubset(candidate->Op().ProvidedOutputProperties())) {
        // Add to group as potential best cost
        Group *group = this->memo.GetGroupByID(candidate->GetGroupID());
        LOG_TRACE("Adding expression cost on group %d with op %s",
                  candidate->GetGroupID(), candidate->Op().name().c_str());
        group->SetExpressionCost(candidate,
                                 candidate->GetCost(),
                                 requirements);
      }
    };

  // Cost the root expression
  if (gexpr->Op().IsPhysical()) {
    CostCandidate(gexpr, requirements);
    // Transformation rules shouldn't match on physical operators so don't apply
    // rules
  } else {
    // Apply transformations and cost those which match the requirements
    for (const std::unique_ptr<Rule> &rule : rules) {
      // Apply all rules to operator which match. We apply all rules to one
      // operator before moving on to the next operator in the group because
      // then we avoid missing the application of a rule e.g. an application
      // of some rule creates a match for a previously applied rule, but it is
      // missed because the prev rule was already checked
      std::vector<std::shared_ptr<GroupExpression>> candidates =
        TransformExpression(gexpr, *(rule.get()));

      for (std::shared_ptr<GroupExpression> candidate : candidates) {
        // If logical...
        if (candidate->Op().IsLogical()) {
          // Optimize the expression
          OptimizeExpression(candidate, requirements);
        }
        if (candidate->Op().IsPhysical()) {
          CostCandidate(candidate, requirements);
        }
      }
    }
  }
}
Exemple #3
0
void Optimizer::ExploreExpression(std::shared_ptr<GroupExpression> gexpr) {
  LOG_TRACE("Exploring expression of group %d with op %s", gexpr->GetGroupID(),
            gexpr->Op().name().c_str());

  for (const std::unique_ptr<Rule> &rule : rules) {
    // See comment in OptimizeExpression
    std::vector<std::shared_ptr<GroupExpression>> candidates =
        TransformExpression(gexpr, *(rule.get()));

    for (std::shared_ptr<GroupExpression> candidate : candidates) {
      // If logical...
      if (candidate->Op().IsLogical()) {
        // Explore the expression
        ExploreExpression(candidate);
      }
    }
  }
}