souffle
2.0.2-371-g6315b36
ram
analysis
Complexity.cpp
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.cpp
12
*
13
* Implementation of RAM Complexity Analysis
14
*
15
***********************************************************************/
16
17
#include "
ram/analysis/Complexity.h
"
18
#include "
ram/Condition.h
"
19
#include "
ram/Conjunction.h
"
20
#include "
ram/EmptinessCheck.h
"
21
#include "
ram/ExistenceCheck.h
"
22
#include "
ram/Expression.h
"
23
#include "
ram/Negation.h
"
24
#include "
ram/Node.h
"
25
#include "
ram/ProvenanceExistenceCheck.h
"
26
#include "
ram/Relation.h
"
27
#include "
ram/utility/Visitor.h
"
28
#include <cassert>
29
30
namespace
souffle::ram::analysis
{
31
32
int
ComplexityAnalysis::getComplexity
(
const
Node* node)
const
{
33
// visitor
34
class
ValueComplexityVisitor :
public
Visitor<int> {
35
public
:
36
ValueComplexityVisitor(RelationAnalysis* relAnalysis) :
ra
(relAnalysis) {}
37
38
// conjunction
39
int
visitConjunction(
const
Conjunction
& conj)
override
{
40
return
visit(conj.
getLHS
()) + visit(conj.
getRHS
());
41
}
42
43
// negation
44
int
visitNegation(
const
Negation
& neg)
override
{
45
return
visit(neg.
getOperand
());
46
}
47
48
// existence check
49
int
visitExistenceCheck(
const
ExistenceCheck
&)
override
{
50
return
2;
51
}
52
53
// provenance existence check
54
int
visitProvenanceExistenceCheck(
const
ProvenanceExistenceCheck&)
override
{
55
return
2;
56
}
57
58
// emptiness check
59
int
visitEmptinessCheck(
const
EmptinessCheck& emptiness)
override
{
60
// emptiness check for nullary relations is for free; others have weight one
61
return
(
ra
->
lookup
(emptiness.getRelation()).
getArity
() > 0) ? 1 : 0;
62
}
63
64
// default rule
65
int
visitNode(
const
Node&)
override
{
66
return
0;
67
}
68
69
protected
:
70
RelationAnalysis*
ra
{
nullptr
};
71
};
72
73
assert((isA<Expression>(node) || isA<Condition>(node)) &&
"not an expression/condition/operation"
);
74
return
ValueComplexityVisitor(
ra
).visit(node);
75
}
76
77
}
// namespace souffle::ram::analysis
Negation.h
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::Conjunction::getLHS
const Condition & getLHS() const
Get left-hand side of conjunction.
Definition:
Conjunction.h:62
EmptinessCheck.h
souffle::ram::ExistenceCheck
Existence check for a tuple(-pattern) in a relation.
Definition:
ExistenceCheck.h:49
souffle::ram::Relation::getArity
unsigned getArity() const
Get arity of relation.
Definition:
Relation.h:86
souffle::ram::Conjunction
A conjunction of conditions.
Definition:
Conjunction.h:54
Complexity.h
ProvenanceExistenceCheck.h
Visitor.h
Relation.h
souffle::ram::analysis::ComplexityAnalysis::ra
RelationAnalysis * ra
Definition:
Complexity.h:57
Condition.h
ExistenceCheck.h
souffle::ram::Negation
Negates a given condition.
Definition:
Negation.h:49
Node.h
Expression.h
souffle::ram::Negation::getOperand
const Condition & getOperand() const
Get operand of negation.
Definition:
Negation.h:56
souffle::ram::analysis::RelationAnalysis::lookup
const ram::Relation & lookup(const std::string &name) const
Definition:
Relation.cpp:33
souffle::ram::Conjunction::getRHS
const Condition & getRHS() const
Get right-hand side of conjunction.
Definition:
Conjunction.h:67
Conjunction.h
Generated by
1.8.17