souffle  2.0.2-371-g6315b36
Complexity.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2019, 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 Complexity.h
12  *
13  * Get the complexity of an expression/condition in terms of
14  * database operations. The complexity of an expression/condition is a
15  * weighted sum. The weights express the complexity of the terms.
16  ***********************************************************************/
17 
18 #pragma once
19 
20 #include "ram/Node.h"
21 #include "ram/TranslationUnit.h"
22 #include "ram/analysis/Analysis.h"
23 #include "ram/analysis/Relation.h"
24 
25 namespace souffle::ram::analysis {
26 
27 /**
28  * @class ComplexityAnalysis
29  * @brief A Ram Analysis for determining the number of relational
30  * operations in a condition / expression.
31  *
32  *
33  */
34 class ComplexityAnalysis : public Analysis {
35 public:
36  ComplexityAnalysis(const char* id) : Analysis(id) {}
37 
38  static constexpr const char* name = "complexity-analysis";
39 
40  void run(const TranslationUnit& tUnit) override {
41  ra = tUnit.getAnalysis<RelationAnalysis>();
42  }
43 
44  /**
45  * @brief Get complexity of a RAM expression/condition
46  */
47  int getComplexity(const Node* value) const;
48 
49 protected:
50  RelationAnalysis* ra{nullptr};
51 };
52 
53 } // namespace souffle::ram::analysis
souffle::ram::analysis
Definition: Analysis.h:32
souffle::ram::analysis::ComplexityAnalysis::getComplexity
int getComplexity(const Node *value) const
Get complexity of a RAM expression/condition.
Definition: Complexity.cpp:38
souffle::ram::analysis::ComplexityAnalysis::run
void run(const TranslationUnit &tUnit) override
Run analysis for a RAM translation unit.
Definition: Complexity.h:47
souffle::ram::Node
Node is a superclass for all RAM IR classes.
Definition: Node.h:42
Relation.h
souffle::ram::analysis::ComplexityAnalysis::name
static constexpr const char * name
Definition: Complexity.h:45
souffle::ram::analysis::ComplexityAnalysis::ra
RelationAnalysis * ra
Definition: Complexity.h:57
Analysis.h
TranslationUnit.h
souffle::ram::analysis::Analysis::Analysis
Analysis(const char *id)
Definition: Analysis.h:40
Node.h
souffle::ram::analysis::RelationAnalysis
A RAM Analysis for finding relations by name.
Definition: Relation.h:36
id
void id(std::string col)
Definition: Tui.h:1124
souffle::ram::analysis::ComplexityAnalysis::ComplexityAnalysis
ComplexityAnalysis(const char *id)
Definition: Complexity.h:43