souffle  2.0.2-371-g6315b36
ReorderConditions.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2018, The Souffle Developers. All rights reserved
4  * Licensed under the Universal Permissive License v 1.0 as shown at:
5  * - https://opensource.org/licenses/UPL
6  * - <souffle root>/licenses/SOUFFLE-UPL.txt
7  */
8 
9 /************************************************************************
10  *
11  * @file ReorderConditions.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Program.h"
18 #include "ram/TranslationUnit.h"
21 #include <string>
22 
23 namespace souffle::ram::transform {
24 
25 /**
26  * @class ReorderConditionsTransformer
27  * @brief Reorders conjunctive terms depending on cost, i.e.,
28  * cheap terms should be executed first.
29  *
30  * For example ..
31  *
32  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
33  * QUERY
34  * ...
35  * IF C(1) /\ C(2) /\ ... /\ C(N) then
36  * ...
37  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
38  *
39  * will be rewritten to
40  *
41  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
42  * QUERY
43  * ...
44  * IF C(i(1)) /\ C(i(2)) /\ ... /\ C(i(N)) then
45  * ...
46  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~
47  *
48  * where C(i(1)) <= C(i(2)) <= .... <= C(i(N)).
49  *
50  * The terms are sorted according to their complexity class.
51  *
52  */
53 
54 class ReorderConditionsTransformer : public Transformer {
55 public:
56  std::string getName() const override {
57  return "ReorderConditionsTransformer";
58  }
59 
60  /**
61  * @brief Reorder conjunctive terms in filter operations
62  * @param program Program that is transformed
63  * @return Flag showing whether the program has been changed
64  * by the transformation
65  */
66  bool reorderConditions(Program& program);
67 
68 protected:
70 
71  bool transform(TranslationUnit& translationUnit) override {
72  rca = translationUnit.getAnalysis<analysis::ComplexityAnalysis>();
73  return reorderConditions(translationUnit.getProgram());
74  }
75 };
76 
77 } // namespace souffle::ram::transform
souffle::ram::transform
Definition: ChoiceConversion.cpp:30
souffle::ram::Program
RAM program relation declaration and functions.
Definition: Program.h:58
souffle::ram::TranslationUnit::getAnalysis
Analysis * getAnalysis() const
Get an analysis.
Definition: TranslationUnit.h:66
souffle::ram::transform::ReorderConditionsTransformer::getName
std::string getName() const override
@Brief get name of the transformer
Definition: ReorderConditions.h:60
souffle::ram::transform::ReorderConditionsTransformer::transform
bool transform(TranslationUnit &translationUnit) override
@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed...
Definition: ReorderConditions.h:75
Program.h
souffle::ram::transform::ReorderConditionsTransformer::rca
analysis::ComplexityAnalysis * rca
Definition: ReorderConditions.h:73
souffle::ram::TranslationUnit::getProgram
Program & getProgram() const
Get the RAM Program of the translation unit
Definition: TranslationUnit.h:107
souffle::ram::TranslationUnit
Translating a RAM program.
Definition: TranslationUnit.h:55
Complexity.h
souffle::ram::analysis::ComplexityAnalysis
A Ram Analysis for determining the number of relational operations in a condition / expression.
Definition: Complexity.h:41
souffle::ram::transform::ReorderConditionsTransformer::reorderConditions
bool reorderConditions(Program &program)
Reorder conjunctive terms in filter operations.
Definition: ReorderConditions.cpp:36
TranslationUnit.h
Transformer.h