souffle  2.0.2-371-g6315b36
Public Member Functions | Protected Member Functions | Protected Attributes
souffle::ram::transform::ReorderConditionsTransformer Class Reference

Reorders conjunctive terms depending on cost, i.e., cheap terms should be executed first. More...

#include <ReorderConditions.h>

Inheritance diagram for souffle::ram::transform::ReorderConditionsTransformer:
Inheritance graph
Collaboration diagram for souffle::ram::transform::ReorderConditionsTransformer:
Collaboration graph

Public Member Functions

std::string getName () const override
 @Brief get name of the transformer More...
 
bool reorderConditions (Program &program)
 Reorder conjunctive terms in filter operations. More...
 
- Public Member Functions inherited from souffle::ram::transform::Transformer
bool apply (TranslationUnit &translationUnit)
 @Brief apply the transformer to a translation unit @Param translationUnit that will be transformed. More...
 
virtual ~Transformer ()=default
 

Protected Member Functions

bool transform (TranslationUnit &translationUnit) override
 @Brief transform the translation unit / used by apply @Param translationUnit that will be transformed. More...
 

Protected Attributes

analysis::ComplexityAnalysisrca {nullptr}
 

Detailed Description

Reorders conjunctive terms depending on cost, i.e., cheap terms should be executed first.

For example ..

QUERY
...
IF C(1) /\ C(2) /\ ... /\ C(N) then
...

will be rewritten to

QUERY
...
IF C(i(1)) /\ C(i(2)) /\ ... /\ C(i(N)) then
...

where C(i(1)) <= C(i(2)) <= .... <= C(i(N)).

The terms are sorted according to their complexity class.

Definition at line 58 of file ReorderConditions.h.

Member Function Documentation

◆ getName()

std::string souffle::ram::transform::ReorderConditionsTransformer::getName ( ) const
inlineoverridevirtual

@Brief get name of the transformer

Implements souffle::ram::transform::Transformer.

Definition at line 60 of file ReorderConditions.h.

68  :
69  analysis::ComplexityAnalysis* rca{nullptr};

◆ reorderConditions()

bool souffle::ram::transform::ReorderConditionsTransformer::reorderConditions ( Program program)

Reorder conjunctive terms in filter operations.

Parameters
programProgram that is transformed
Returns
Flag showing whether the program has been changed by the transformation

Definition at line 36 of file ReorderConditions.cpp.

36  {
37  const Condition* condition = &filter->getCondition();
38  VecOwn<Condition> sortedConds;
39  VecOwn<Condition> condList = toConjunctionList(condition);
40  for (auto& cond : condList) {
41  sortedConds.emplace_back(cond->clone());
42  }
43  std::sort(sortedConds.begin(), sortedConds.end(), [&](Own<Condition>& a, Own<Condition>& b) {
44  return rca->getComplexity(a.get()) < rca->getComplexity(b.get());
45  });
46 
47  if (!std::equal(sortedConds.begin(), sortedConds.end(), condList.begin(),
48  [](Own<Condition>& a, Own<Condition>& b) { return *a == *b; })) {
49  changed = true;
50  node = mk<Filter>(Own<Condition>(toCondition(sortedConds)),
51  souffle::clone(&filter->getOperation()));
52  }
53  }
54  node->apply(makeLambdaRamMapper(filterRewriter));
55  return node;
56  };
57  const_cast<Query*>(&query)->apply(makeLambdaRamMapper(filterRewriter));
58  });
59  return changed;
60 }
61 
62 } // namespace souffle::ram::transform

References b, souffle::clone(), souffle::filter(), souffle::ram::toCondition(), and souffle::ram::toConjunctionList().

Here is the call graph for this function:

◆ transform()

bool souffle::ram::transform::ReorderConditionsTransformer::transform ( TranslationUnit translationUnit)
inlineoverrideprotectedvirtual

@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed.

@Return flag reporting whether the RAM program has changed

Implements souffle::ram::transform::Transformer.

Definition at line 75 of file ReorderConditions.h.

Field Documentation

◆ rca

analysis::ComplexityAnalysis* souffle::ram::transform::ReorderConditionsTransformer::rca {nullptr}
protected

Definition at line 73 of file ReorderConditions.h.


The documentation for this class was generated from the following files:
souffle::ram::toCondition
Own< Condition > toCondition(const VecOwn< Condition > &conds)
Convert list of conditions to a conjunction.
Definition: Utils.h:84
souffle::ram::toConjunctionList
VecOwn< Condition > toConjunctionList(const Condition *condition)
Convert terms of a conjunction to a list.
Definition: Utils.h:57
souffle::ram::transform::Transformer::apply
bool apply(TranslationUnit &translationUnit)
@Brief apply the transformer to a translation unit @Param translationUnit that will be transformed.
Definition: Transformer.cpp:39
souffle::ram::transform::ReorderConditionsTransformer::rca
analysis::ComplexityAnalysis * rca
Definition: ReorderConditions.h:73
souffle::clone
auto clone(const std::vector< A * > &xs)
Definition: ContainerUtil.h:172
i
size_t i
Definition: json11.h:663
souffle::filter
std::vector< A > filter(std::vector< A > xs, F &&f)
Filter a vector to include certain elements.
Definition: FunctionalUtil.h:155
b
l j a showGridBackground &&c b raw series this eventEmitter b
Definition: htmlJsChartistMin.h:15
souffle::ram::makeLambdaRamMapper
LambdaNodeMapper< Lambda > makeLambdaRamMapper(const Lambda &lambda)
Creates a node mapper based on a corresponding lambda expression.
Definition: LambdaNodeMapper.h:67