souffle
2.0.2-371-g6315b36
|
Go to the documentation of this file.
36 #include <unordered_map>
45 namespace interpreter {
47 struct RelationWrapper;
55 #define FOR_EACH_INTERPRETER_TOKEN(Forward, Expand)\
57 Forward(TupleElement)\
58 Forward(AutoIncrement)\
59 Forward(IntrinsicOperator)\
60 Forward(UserDefinedOperator)\
61 Forward(NestedIntrinsicOperator)\
63 Forward(SubroutineArgument)\
68 FOR_EACH(Expand, EmptinessCheck)\
69 FOR_EACH(Expand, RelationSize)\
70 FOR_EACH(Expand, ExistenceCheck)\
71 FOR_EACH_PROVENANCE(Expand, ProvenanceExistenceCheck)\
73 Forward(TupleOperation)\
74 FOR_EACH(Expand, Scan)\
75 FOR_EACH(Expand, ParallelScan)\
76 FOR_EACH(Expand, IndexScan)\
77 FOR_EACH(Expand, ParallelIndexScan)\
78 FOR_EACH(Expand, Choice)\
79 FOR_EACH(Expand, ParallelChoice)\
80 FOR_EACH(Expand, IndexChoice)\
81 FOR_EACH(Expand, ParallelIndexChoice)\
82 Forward(UnpackRecord)\
83 FOR_EACH(Expand, Aggregate)\
84 FOR_EACH(Expand, ParallelAggregate)\
85 FOR_EACH(Expand, IndexAggregate)\
86 FOR_EACH(Expand, ParallelIndexAggregate)\
89 FOR_EACH(Expand, Project)\
90 Forward(SubroutineReturn)\
95 Forward(LogRelationTimer)\
98 FOR_EACH(Expand, Clear)\
106 #define SINGLE_TOKEN(tok) I_##tok,
108 #define EXPAND_TOKEN(structure, arity, tok)\
109 I_##tok##_##structure##_##arity,
123 #define __TO_STRING(a) #a
124 #define SINGLE_TOKEN_ENTRY(tok) {__TO_STRING(I_##tok), I_##tok},
125 #define EXPAND_TOKEN_ENTRY(Structure, arity, tok) \
126 {__TO_STRING(I_##tok##_##Structure##_##arity), I_##tok##_##Structure##_##arity},
136 static const std::unordered_map<std::string, NodeType>
map = {
140 std::string arity = std::to_string(
rel.getArity());
142 return map.at(
"I_" + tokBase +
"_Eqrel_" + arity);
143 }
else if (isProvenance) {
144 return map.at(
"I_" + tokBase +
"_Provenance_" + arity);
146 return map.at(
"I_" + tokBase +
"_Btree_" + arity);
149 fatal(
"Unrecognized node type: base:%s arity:%s.", tokBase, arity);
153 #undef EXPAND_TOKEN_ENTRY
154 #undef SINGLE_TOKEN_ENTRY
171 virtual ~Node() =
default;
185 assert(
relHandle &&
"No relation cached\n");
186 return (*relHandle).get();
280 std::vector<RamDomain>
first;
282 std::vector<RamDomain>
second;
284 std::vector<std::array<size_t, 3>>
tupleFirst;
288 std::vector<std::pair<size_t, Own<Node>>>
exprFirst;
290 std::vector<std::pair<size_t, Own<Node>>>
exprSecond;
323 inline void setViewContext(
const std::shared_ptr<ViewContext>& v) {
616 class ParallelChoice :
public Choice,
public AbstractParallel {
const NodePtrVec & getChildren() const
get list of all children
Call(enum NodeType ty, const ram::Node *sdw, size_t subroutineId)
SuperOperation(SuperInstruction superInst)
std::vector< RamDomain > second
constant value in the upper bound
const std::string & getRelationName() const
node that utilizes parallel execution should inherit from this class. Enable node with its own view c...
Encode a nested operation for the interpreter node. E.g. Loop, IndexScan.
SuperInstruction(size_t i)
This is a shadow node for a ram::Node that is enriched for with local information so that the interpr...
enum NodeType getType() const
get node type
const Node * getNestedOperation() const
const Node * getExpr() const
const Node * getCondition() const
auto map(const std::vector< A > &xs, F &&f)
Applies a function to each element of a vector and returns the results.
const Node * getRhs() const
get right child of node
Aggregate(enum NodeType ty, const ram::Node *sdw, RelationHandle *relHandle, Own< Node > expr, Own< Node > filter, Own< Node > nested)
Extend(enum NodeType ty, const ram::Node *sdw, size_t src, size_t target)
Filter(enum NodeType ty, const ram::Node *sdw, Own< Node > cond, Own< Node > nested)
const std::string relationName
size_t getTupleId() const
This class contains information for views (Hints) creation for ram::Query and ram::Parallel operation...
std::vector< RamDomain > first
constant value in the lower bound/pattern
const Node * getExpr() const
Encode a conditional operation for the interpreter node. E.g. Exit, Filter.
node that utilizes the super instruction optimization should inherit from this class....
std::vector< std::array< size_t, 3 > > tupleFirst
Encoded tupleElement expressions in the lower bound/pattern.
CompoundNode(enum NodeType ty, const ram::Node *sdw, NodePtrVec children={}, RelationHandle *relHandle=nullptr)
RelationHandle *const relHandle
Node is a superclass for all RAM IR classes.
Node(enum NodeType ty, const ram::Node *sdw, RelationHandle *relHandle=nullptr)
ViewContext * getViewContext() const
get view context for operations
size_t getElement() const
std::vector< A > filter(std::vector< A > xs, F &&f)
Filter a vector to include certain elements.
std::vector< std::pair< size_t, Own< Node > > > exprSecond
Generic expressions in the upper bound.
Own< RelationWrapper > RelationHandle
IndexAggregate(enum NodeType ty, const ram::Node *sdw, RelationHandle *relHandle, Own< Node > expr, Own< Node > filter, Own< Node > nested, size_t viewId, SuperInstruction superInst)
const size_t subroutineId
An abstract class for performing indexed operations.
TupleElement(enum NodeType ty, const ram::Node *sdw, size_t tupleId, size_t elementId)
NestedOperation(Own< Node > nested)
IndexScan(enum NodeType ty, const ram::Node *sdw, RelationHandle *relHandle, Own< Node > nested, size_t viewId, SuperInstruction superInst)
ExistenceCheck(enum NodeType ty, const ram::Node *sdw, bool totalSearch, size_t viewId, SuperInstruction superInst, bool tempRelation, std::string relationName)
std::vector< std::array< size_t, 3 > > tupleSecond
Encoded tupleElement expressions in the upper bound.
SuperInstruction & operator=(const SuperInstruction &)=delete
Unary node represents interpreter node with a single child.
void setViewContext(const std::shared_ptr< ViewContext > &v)
set view context
IndexChoice(enum NodeType ty, const ram::Node *sdw, RelationHandle *relHandle, Own< Node > cond, Own< Node > nested, size_t viewId, SuperInstruction superInst)
UnpackRecord(enum NodeType ty, const ram::Node *sdw, Own< Node > expr, Own< Node > nested)
#define SINGLE_TOKEN(tok)
const ram::Node * getShadow() const
get shadow node, i.e., RAM node
std::vector< std::pair< size_t, Own< Node > > > exprFirst
Generic expressions in the lower bound/pattern.
size_t getSourceId() const
NodeType constructNodeType(std::string tokBase, const ram::Relation &rel)
Construct interpreterNodeType by looking at the representation and the arity of the given rel.
This class encodes information for a super-instruction, which is used to eliminate Number and TupleEl...
VecOwn< Node > NodePtrVec
static MainConfig & config()
#define FOR_EACH_INTERPRETER_TOKEN(Forward, Expand)
Project(enum NodeType ty, const ram::Node *sdw, RelationHandle *relHandle, SuperInstruction superInst)
Break(enum NodeType ty, const ram::Node *sdw, Own< Node > cond, Own< Node > nested)
size_t getTargetId() const
std::shared_ptr< ViewContext > viewContext
Own< RelationWrapper > RelationHandle
#define SINGLE_TOKEN_ENTRY(tok)
#define EXPAND_TOKEN_ENTRY(Structure, arity, tok)
void fatal(const char *format, const Args &... args)
UnaryNode(enum NodeType ty, const ram::Node *sdw, Own< Node > child, RelationHandle *relHandle=nullptr)
Compound node represents interpreter node with a list of children.
operation that utilizes the index view from underlying relation should inherit from this class.
const SuperInstruction & getSuperInst() const
Wrapper for InterpreterRelation.
const Node * getLhs() const
get left child of node
const Node * getChild(size_t i) const
get children of node
size_t getSubroutineId() const
operation that involves with two relations should inherit from this class. E.g. Swap,...
ConditionalOperation(Own< Node > cond)
BinaryNode(enum NodeType ty, const ram::Node *sdw, Own< Node > lhs, Own< Node > rhs, RelationHandle *relHandle=nullptr)
void rel(size_t limit, bool showLimit=true)
Choice(enum NodeType ty, const ram::Node *sdw, RelationHandle *relHandle, Own< Node > cond, Own< Node > nested)
#define EXPAND_TOKEN(structure, arity, tok)
std::vector< NodePtr > NodePtrVec
RelationWrapper * getRelation() const
get relation from handle
const Node * getChild() const
bool isTotalSearch() const
std::vector< Own< A > > VecOwn
Swap(enum NodeType ty, const ram::Node *sdw, size_t src, size_t target)
ProvenanceExistenceCheck(enum NodeType ty, const ram::Node *sdw, Own< Node > child, size_t viewId, SuperInstruction superInst)
Scan(enum NodeType ty, const ram::Node *sdw, RelationHandle *relHandle, Own< Node > nested)
const SuperInstruction superInst
Binary node represents interpreter node with two children.
BinRelOperation(size_t src, size_t target)