souffle  2.0.2-371-g6315b36
RelationSchedule.h
Go to the documentation of this file.
1 /*
2  * Souffle - A Datalog Compiler
3  * Copyright (c) 2013, 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 RelationSchedule.h
12  *
13  * Defines the class to build the precedence graph,
14  * compute strongly connected components of the precedence graph, and
15  * build the strongly connected component graph.
16  *
17  ***********************************************************************/
18 
19 #pragma once
20 
21 #include "ast/Relation.h"
22 #include "ast/TranslationUnit.h"
23 #include "ast/analysis/Analysis.h"
26 #include <ostream>
27 #include <set>
28 #include <string>
29 #include <utility>
30 #include <vector>
31 
32 namespace souffle::ast::analysis {
33 
34 /**
35  * A single step in a relation schedule, consisting of the relations computed in the step
36  * and the relations that are no longer required at that step.
37  */
38 class RelationScheduleAnalysisStep {
39 public:
40  RelationScheduleAnalysisStep(std::set<const Relation*> computedRelations,
41  std::set<const Relation*> expiredRelations, const bool isRecursive)
44 
45  const std::set<const Relation*>& computed() const {
47  }
48 
49  const std::set<const Relation*>& expired() const {
50  return expiredRelations;
51  }
52 
53  bool recursive() const {
54  return isRecursive;
55  }
56 
57  void print(std::ostream& os) const;
58 
59  /** Add support for printing nodes */
60  friend std::ostream& operator<<(std::ostream& out, const RelationScheduleAnalysisStep& other) {
61  other.print(out);
62  return out;
63  }
64 
65 private:
66  std::set<const Relation*> computedRelations;
67  std::set<const Relation*> expiredRelations;
68  const bool isRecursive;
69 };
70 
71 /**
72  * Analysis pass computing a schedule for computing relations.
73  */
74 class RelationScheduleAnalysis : public Analysis {
75 public:
76  static constexpr const char* name = "relation-schedule";
77 
79 
80  void run(const TranslationUnit& translationUnit) override;
81 
82  const std::vector<RelationScheduleAnalysisStep>& schedule() const {
84  }
85 
86  /** Dump this relation schedule to standard error. */
87  void print(std::ostream& os) const override;
88 
89 private:
92 
93  /** Relations computed and expired relations at each step */
94  std::vector<RelationScheduleAnalysisStep> relationSchedule;
95 
96  std::vector<std::set<const Relation*>> computeRelationExpirySchedule(
97  const TranslationUnit& translationUnit);
98 };
99 
100 } // namespace souffle::ast::analysis
souffle::ast::analysis::RelationScheduleAnalysisStep::recursive
bool recursive() const
Definition: RelationSchedule.h:69
souffle::ast::analysis::RelationScheduleAnalysisStep::expiredRelations
std::set< const Relation * > expiredRelations
Definition: RelationSchedule.h:83
TranslationUnit.h
souffle::ast::analysis::RelationScheduleAnalysis::RelationScheduleAnalysis
RelationScheduleAnalysis()
Definition: RelationSchedule.h:86
souffle::ast::analysis::RelationScheduleAnalysisStep::print
void print(std::ostream &os) const
Definition: RelationSchedule.cpp:43
souffle::ast::analysis::RelationScheduleAnalysis::print
void print(std::ostream &os) const override
Dump this relation schedule to standard error.
Definition: RelationSchedule.cpp:117
souffle::ast::analysis::RelationScheduleAnalysis::computeRelationExpirySchedule
std::vector< std::set< const Relation * > > computeRelationExpirySchedule(const TranslationUnit &translationUnit)
Definition: RelationSchedule.cpp:79
souffle::ast::analysis::RelationScheduleAnalysis
Analysis pass computing a schedule for computing relations.
Definition: RelationSchedule.h:82
souffle::ast::analysis::RelationScheduleAnalysisStep::isRecursive
const bool isRecursive
Definition: RelationSchedule.h:84
Relation.h
souffle::ast::analysis::RelationScheduleAnalysis::schedule
const std::vector< RelationScheduleAnalysisStep > & schedule() const
Definition: RelationSchedule.h:90
souffle::ast::analysis::RelationScheduleAnalysis::relationSchedule
std::vector< RelationScheduleAnalysisStep > relationSchedule
Relations computed and expired relations at each step.
Definition: RelationSchedule.h:102
souffle::ast::analysis::TopologicallySortedSCCGraphAnalysis
Analysis pass computing a topologically sorted strongly connected component (SCC) graph.
Definition: TopologicallySortedSCCGraph.h:49
TopologicallySortedSCCGraph.h
souffle::ast::analysis::RelationScheduleAnalysis::name
static constexpr const char * name
Definition: RelationSchedule.h:84
souffle::ast::analysis::RelationScheduleAnalysis::topsortSCCGraphAnalysis
TopologicallySortedSCCGraphAnalysis * topsortSCCGraphAnalysis
Definition: RelationSchedule.h:98
souffle::ast::analysis::RelationScheduleAnalysis::precedenceGraph
PrecedenceGraphAnalysis * precedenceGraph
Definition: RelationSchedule.h:99
souffle::ast::TranslationUnit
Translation unit class for the translation pipeline.
Definition: TranslationUnit.h:51
souffle::ast::analysis::RelationScheduleAnalysisStep::operator<<
friend std::ostream & operator<<(std::ostream &out, const RelationScheduleAnalysisStep &other)
Add support for printing nodes.
Definition: RelationSchedule.h:76
souffle::ast::analysis::RelationScheduleAnalysisStep::computedRelations
std::set< const Relation * > computedRelations
Definition: RelationSchedule.h:82
souffle::ast::analysis::RelationScheduleAnalysisStep::computed
const std::set< const Relation * > & computed() const
Definition: RelationSchedule.h:61
souffle::ast::analysis::Analysis
Abstract class for a AST Analysis.
Definition: Analysis.h:38
souffle::ast::analysis::RelationScheduleAnalysis::run
void run(const TranslationUnit &translationUnit) override
run analysis for a Ast translation unit
Definition: RelationSchedule.cpp:61
std
Definition: Brie.h:3053
souffle::ast::analysis::RelationScheduleAnalysisStep::expired
const std::set< const Relation * > & expired() const
Definition: RelationSchedule.h:65
souffle::ast::analysis::PrecedenceGraphAnalysis
Analysis pass computing the precedence graph of the relations of the datalog progam.
Definition: PrecedenceGraph.h:43
souffle::ast::analysis
Definition: Aggregate.cpp:39
souffle::ast::analysis::RelationScheduleAnalysisStep
A single step in a relation schedule, consisting of the relations computed in the step and the relati...
Definition: RelationSchedule.h:46
PrecedenceGraph.h
souffle::ast::analysis::RelationScheduleAnalysisStep::RelationScheduleAnalysisStep
RelationScheduleAnalysisStep(std::set< const Relation * > computedRelations, std::set< const Relation * > expiredRelations, const bool isRecursive)
Definition: RelationSchedule.h:56
Analysis.h