-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1167 from b-scholz/Reordering
Reordering conjunctive terms based on complexity
- Loading branch information
Showing
6 changed files
with
205 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Souffle - A Datalog Compiler | ||
* Copyright (c) 2019, The Souffle Developers. All rights reserved | ||
* Licensed under the Universal Permissive License v 1.0 as shown at: | ||
* - https://opensource.org/licenses/UPL | ||
* - <souffle root>/licenses/SOUFFLE-UPL.txt | ||
*/ | ||
|
||
/************************************************************************ | ||
* | ||
* @file RamComplexityAnalysis.cpp | ||
* | ||
* Implementation of RAM Complexity Analysis | ||
* | ||
***********************************************************************/ | ||
|
||
#include "RamComplexityAnalysis.h" | ||
#include "RamVisitor.h" | ||
#include <algorithm> | ||
|
||
namespace souffle { | ||
|
||
int RamComplexityAnalysis::getComplexity(const RamNode* node) const { | ||
// visitor | ||
class ValueComplexityVisitor : public RamVisitor<int> { | ||
public: | ||
// conjunction | ||
int visitConjunction(const RamConjunction& conj) override { | ||
return visit(conj.getLHS()) + visit(conj.getRHS()); | ||
} | ||
|
||
// negation | ||
int visitNegation(const RamNegation& neg) override { | ||
return visit(neg.getOperand()); | ||
} | ||
|
||
// existence check | ||
int visitExistenceCheck(const RamExistenceCheck& exists) override { | ||
return 2; | ||
} | ||
|
||
// provenance existence check | ||
int visitProvenanceExistenceCheck(const RamProvenanceExistenceCheck& provExists) override { | ||
return 2; | ||
} | ||
|
||
// emptiness check | ||
int visitEmptinessCheck(const RamEmptinessCheck& emptiness) override { | ||
// emptiness check for nullary relations is for free; others have weight one | ||
return (emptiness.getRelation().getArity() > 0) ? 1 : 0; | ||
} | ||
|
||
// default rule | ||
int visitNode(const RamNode& node) override { | ||
return 0; | ||
} | ||
}; | ||
|
||
assert((dynamic_cast<const RamExpression*>(node) != nullptr || | ||
dynamic_cast<const RamCondition*>(node) != nullptr) && | ||
"not an expression/condition/operation"); | ||
return ValueComplexityVisitor().visit(node); | ||
} | ||
|
||
} // end of namespace souffle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Souffle - A Datalog Compiler | ||
* Copyright (c) 2019, The Souffle Developers. All rights reserved | ||
* Licensed under the Universal Permissive License v 1.0 as shown at: | ||
* - https://opensource.org/licenses/UPL | ||
* - <souffle root>/licenses/SOUFFLE-UPL.txt | ||
*/ | ||
|
||
/************************************************************************ | ||
* | ||
* @file RamComplexityAnalysis.h | ||
* | ||
* Get the complexity of an expression/condition in terms of | ||
* database operations. The complexity of an expression/condition is a | ||
* weighted sum. The weights express the complexity of the terms. | ||
***********************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include "RamAnalysis.h" | ||
|
||
namespace souffle { | ||
|
||
class RamNode; | ||
|
||
/** | ||
* @class RamComplexityAnalysis | ||
* @brief A Ram Analysis for determining the number of relational | ||
* operations in a condition / expression. | ||
* | ||
* | ||
*/ | ||
class RamComplexityAnalysis : public RamAnalysis { | ||
public: | ||
RamComplexityAnalysis(const char* id) : RamAnalysis(id) {} | ||
|
||
static constexpr const char* name = "complexity-analysis"; | ||
|
||
void run(const RamTranslationUnit& translationUnit) override {} | ||
|
||
/** | ||
* @brief Get complexity of a RAM expression/condition | ||
*/ | ||
int getComplexity(const RamNode* value) const; | ||
}; | ||
|
||
} // end of namespace souffle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters