souffle  2.0.2-371-g6315b36
ClauseTranslator.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 2015, Oracle and/or its affiliates. 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 ClauseTranslator.h
12  *
13  * Translator for clauses from AST to RAM
14  *
15  ***********************************************************************/
16 
17 #pragma once
18 
19 #include "ram/Relation.h"
21 #include <map>
22 #include <vector>
23 
24 namespace souffle::ast {
25 class Argument;
26 class Clause;
27 class Node;
28 } // namespace souffle::ast
29 
30 namespace souffle::ram {
31 class Operation;
32 class Condition;
33 class Statement;
34 } // namespace souffle::ram
35 
36 namespace souffle::ast2ram {
37 
38 class AstToRamTranslator;
39 class ValueIndex;
40 
42 public:
44 
46  const ast::Clause& clause, const ast::Clause& originalClause, const int version = 0);
47 
48 protected:
50 
51  // value index to keep track of references in the loop nest
52  Own<ValueIndex> valueIndex = mk<ValueIndex>();
53 
54  // current nesting level
55  int level = 0;
56 
57  virtual Own<ram::Operation> createOperation(const ast::Clause& clause);
58  virtual Own<ram::Condition> createCondition(const ast::Clause& originalClause);
59 
60  /** apply constraint filters to a given operation */
61  Own<ram::Operation> filterByConstraints(size_t level, const std::vector<ast::Argument*>& args,
62  Own<ram::Operation> op, bool constrainByFunctors = true);
63 
64 private:
65  std::vector<const ast::Argument*> generators;
66 
67  // the order of processed operations
68  std::vector<const ast::Node*> op_nesting;
69 
70  Own<ast::Clause> getReorderedClause(const ast::Clause& clause, const int version) const;
71 
72  void indexValues(const ast::Node* curNode, const std::vector<ast::Argument*>& curNodeArgs,
73  std::map<const ast::Node*, int>& nodeLevel, const ram::Relation* relation);
74 
75  void createValueIndex(const ast::Clause& clause);
76 };
77 
78 } // namespace souffle::ast2ram
souffle::ast2ram::ClauseTranslator::createValueIndex
void createValueIndex(const ast::Clause &clause)
index values in rule
Definition: ClauseTranslator.cpp:425
souffle::ast2ram::ClauseTranslator::ClauseTranslator
ClauseTranslator(AstToRamTranslator &translator)
Definition: ClauseTranslator.h:43
souffle::ast2ram::ClauseTranslator::translator
AstToRamTranslator & translator
Definition: ClauseTranslator.h:49
souffle::Own
std::unique_ptr< A > Own
Definition: ContainerUtil.h:42
relation
Relation & relation
Definition: Reader.h:130
souffle::ast::Clause
Intermediate representation of a horn clause.
Definition: Clause.h:51
souffle::ast2ram::ClauseTranslator::translateClause
Own< ram::Statement > translateClause(const ast::Clause &clause, const ast::Clause &originalClause, const int version=0)
generate RAM code for a clause
Definition: ClauseTranslator.cpp:61
souffle::ram
Definition: AstToRamTranslator.h:54
ContainerUtil.h
souffle::ram::Relation
An abstract class for performing indexed operations.
Definition: Relation.h:40
Relation.h
souffle::ast2ram::ClauseTranslator::getReorderedClause
Own< ast::Clause > getReorderedClause(const ast::Clause &clause, const int version) const
Definition: ClauseTranslator.cpp:357
souffle::ast2ram::ClauseTranslator
Definition: ClauseTranslator.h:41
souffle::ast2ram::ClauseTranslator::op_nesting
std::vector< const ast::Node * > op_nesting
Definition: ClauseTranslator.h:68
souffle::ast::Node
Abstract class for syntactic elements in an input program.
Definition: Node.h:40
souffle::ast2ram::AstToRamTranslator
Main class for the AST->RAM translator.
Definition: AstToRamTranslator.h:71
souffle::ast2ram::ClauseTranslator::createOperation
virtual Own< ram::Operation > createOperation(const ast::Clause &clause)
Definition: ClauseTranslator.cpp:295
souffle::ast2ram::ClauseTranslator::createCondition
virtual Own< ram::Condition > createCondition(const ast::Clause &originalClause)
Definition: ClauseTranslator.cpp:314
souffle::ast2ram
Definition: AstToRamTranslator.cpp:132
souffle::ast2ram::ClauseTranslator::valueIndex
Own< ValueIndex > valueIndex
Definition: ClauseTranslator.h:52
souffle::ast2ram::ClauseTranslator::generators
std::vector< const ast::Argument * > generators
Definition: ClauseTranslator.h:65
souffle::ast2ram::ClauseTranslator::indexValues
void indexValues(const ast::Node *curNode, const std::vector< ast::Argument * > &curNodeArgs, std::map< const ast::Node *, int > &nodeLevel, const ram::Relation *relation)
Definition: ClauseTranslator.cpp:394
souffle::ast
Definition: Aggregator.h:35
souffle::ast2ram::ClauseTranslator::filterByConstraints
Own< ram::Operation > filterByConstraints(size_t level, const std::vector< ast::Argument * > &args, Own< ram::Operation > op, bool constrainByFunctors=true)
apply constraint filters to a given operation
Definition: ClauseTranslator.cpp:325
souffle::ast2ram::ClauseTranslator::level
int level
Definition: ClauseTranslator.h:55