souffle  2.0.2-371-g6315b36
MinimiseProgram.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 MinimiseProgram.h
12  *
13  * Transformation pass to remove equivalent rules.
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ast/TranslationUnit.h"
22 #include <string>
23 #include <vector>
24 
25 namespace souffle::ast::transform {
26 
27 /**
28  * Transformation pass to remove equivalent rules.
29  */
30 class MinimiseProgramTransformer : public Transformer {
31 public:
32  std::string getName() const override {
33  return "MinimiseProgramTransformer";
34  }
35 
36  // Check whether two normalised clause representations are equivalent.
37  static bool areBijectivelyEquivalent(
38  const analysis::NormalisedClause& left, const analysis::NormalisedClause& right);
39 
40  MinimiseProgramTransformer* clone() const override {
41  return new MinimiseProgramTransformer();
42  }
43 
44 private:
45  bool transform(TranslationUnit& translationUnit) override;
46 
47  /** -- Bijective Equivalence Helper Methods -- */
48 
49  // Check whether a valid variable mapping exists for the given permutation.
50  static bool isValidPermutation(const analysis::NormalisedClause& left,
51  const analysis::NormalisedClause& right, const std::vector<unsigned int>& permutation);
52 
53  // Checks whether a permutation encoded in the given matrix has a valid corresponding variable mapping.
54  static bool existsValidPermutation(const analysis::NormalisedClause& left,
55  const analysis::NormalisedClause& right,
56  const std::vector<std::vector<unsigned int>>& permutationMatrix);
57 
58  /** -- Sub-Transformations -- */
59 
60  /**
61  * Reduces locally-redundant clauses.
62  * A clause is locally-redundant if there is another clause within the same relation
63  * that computes the same set of tuples.
64  */
65  static bool reduceLocallyEquivalentClauses(TranslationUnit& translationUnit);
66 
67  /**
68  * Remove clauses that are only satisfied if they are already satisfied.
69  */
70  static bool removeRedundantClauses(TranslationUnit& translationUnit);
71 
72  /**
73  * Remove redundant literals within a clause.
74  */
75  static bool reduceClauseBodies(TranslationUnit& translationUnit);
76 
77  /**
78  * Removes redundant singleton relations.
79  * Singleton relations are relations with a single clause. A singleton relation is redundant
80  * if there exists another singleton relation that computes the same set of tuples.
81  * @return true iff the program was changed
82  */
83  static bool reduceSingletonRelations(TranslationUnit& translationUnit);
84 };
85 
86 } // namespace souffle::ast::transform
souffle::ast::transform::MinimiseProgramTransformer::removeRedundantClauses
static bool removeRedundantClauses(TranslationUnit &translationUnit)
Remove clauses that are only satisfied if they are already satisfied.
Definition: MinimiseProgram.cpp:369
TranslationUnit.h
souffle::ast::analysis::NormalisedClause
Definition: ClauseNormalisation.h:46
souffle::ast::transform::MinimiseProgramTransformer::reduceClauseBodies
static bool reduceClauseBodies(TranslationUnit &translationUnit)
Remove redundant literals within a clause.
Definition: MinimiseProgram.cpp:394
Transformer.h
souffle::ast::transform::MinimiseProgramTransformer::transform
bool transform(TranslationUnit &translationUnit) override
Definition: MinimiseProgram.cpp:434
souffle::ast::transform::MinimiseProgramTransformer::clone
MinimiseProgramTransformer * clone() const override
Definition: MinimiseProgram.h:52
souffle::ast::transform::MinimiseProgramTransformer
Transformation pass to remove equivalent rules.
Definition: MinimiseProgram.h:36
ClauseNormalisation.h
souffle::ast::transform::MinimiseProgramTransformer::reduceLocallyEquivalentClauses
static bool reduceLocallyEquivalentClauses(TranslationUnit &translationUnit)
– Sub-Transformations –
Definition: MinimiseProgram.cpp:243
souffle::ast::TranslationUnit
Translation unit class for the translation pipeline.
Definition: TranslationUnit.h:51
souffle::ast::transform::MinimiseProgramTransformer::getName
std::string getName() const override
Definition: MinimiseProgram.h:44
souffle::ast::transform
Definition: Program.h:45
souffle::ast::transform::MinimiseProgramTransformer::isValidPermutation
static bool isValidPermutation(const analysis::NormalisedClause &left, const analysis::NormalisedClause &right, const std::vector< unsigned int > &permutation)
– Bijective Equivalence Helper Methods –
Definition: MinimiseProgram.cpp:147
souffle::ast::transform::MinimiseProgramTransformer::areBijectivelyEquivalent
static bool areBijectivelyEquivalent(const analysis::NormalisedClause &left, const analysis::NormalisedClause &right)
Definition: MinimiseProgram.cpp:190
souffle::ast::transform::MinimiseProgramTransformer::existsValidPermutation
static bool existsValidPermutation(const analysis::NormalisedClause &left, const analysis::NormalisedClause &right, const std::vector< std::vector< unsigned int >> &permutationMatrix)
Definition: MinimiseProgram.cpp:53
souffle::ast::transform::MinimiseProgramTransformer::reduceSingletonRelations
static bool reduceSingletonRelations(TranslationUnit &translationUnit)
Removes redundant singleton relations.
Definition: MinimiseProgram.cpp:286