souffle  2.0.2-371-g6315b36
TupleId.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 TupleId.h
12  *
13  ***********************************************************************/
14 
15 #pragma once
16 
17 #include "ram/Program.h"
18 #include "ram/TranslationUnit.h"
20 #include <string>
21 
22 namespace souffle::ram::transform {
23 
24 /**
25  * @class TupleIdTransformer
26  * @brief Ordering tupleIds in TupleOperation operations correctly
27  *
28  * Transformations, like MakeIndex and IfConversion do not
29  * ensure that TupleOperations maintain an appropriate order
30  * with respect to their tupleId's
31  *
32  * For example:
33  * SEARCH ... (tupleId = 2)
34  * ...
35  * SEARCH ... (tupleId = 1)
36  * ...
37  *
38  * Will be converted to
39  * SEARCH ... (tupleId = 0)
40  * ...
41  * SEARCH ... (tupleId = 1)
42  * ...
43  *
44  */
45 class TupleIdTransformer : public Transformer {
46 public:
47  std::string getName() const override {
48  return "TupleIdTransformer";
49  }
50 
51  /**
52  * @brief Apply tupleId reordering to the whole program
53  * @param RAM program
54  * @result A flag indicating whether the RAM program has been changed.
55  *
56  * Search for TupleOperations and TupleElements and rewrite their tupleIds
57  */
58  bool reorderOperations(Program& program);
59 
60 protected:
61  bool transform(TranslationUnit& translationUnit) override {
62  return reorderOperations(translationUnit.getProgram());
63  }
64 };
65 
66 } // namespace souffle::ram::transform
souffle::ram::transform
Definition: ChoiceConversion.cpp:30
souffle::ram::Program
RAM program relation declaration and functions.
Definition: Program.h:58
Program.h
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
souffle::ram::transform::TupleIdTransformer::getName
std::string getName() const override
@Brief get name of the transformer
Definition: TupleId.h:51
souffle::ram::transform::TupleIdTransformer::transform
bool transform(TranslationUnit &translationUnit) override
@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed...
Definition: TupleId.h:65
TranslationUnit.h
Transformer.h
souffle::ram::transform::TupleIdTransformer::reorderOperations
bool reorderOperations(Program &program)
Apply tupleId reordering to the whole program.
Definition: TupleId.cpp:33