souffle  2.0.2-371-g6315b36
ValueIndex.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 ValueIndex.h
12  *
13  * Defines the ValueIndex class, which indexes the location of variables
14  * and record references within a loop nest during rule conversion.
15  *
16  ***********************************************************************/
17 
18 #pragma once
19 
21 #include <map>
22 #include <set>
23 #include <string>
24 #include <vector>
25 
26 namespace souffle::ast {
27 class Argument;
28 class RecordInit;
29 class Variable;
30 } // namespace souffle::ast
31 
32 namespace souffle::ast2ram {
33 
34 struct Location;
35 
36 class ValueIndex {
37 public:
38  ValueIndex();
39  ~ValueIndex();
40 
41  /**
42  * The type mapping variables (referenced by their names) to the
43  * locations where they are used.
44  */
45  using variable_reference_map = std::map<std::string, std::set<Location>>;
46 
47  /**
48  * The type mapping record init expressions to their definition points,
49  * hence the point where they get grounded/bound.
50  */
51  using record_definition_map = std::map<const ast::RecordInit*, Location>;
52 
53  /**
54  * A map from generative `ast::Argument`s to storage locations. Note,
55  * since in this case ast::Argument are indexed by their values (not their
56  * address) no standard map can be utilized.
57  * (By-value indexing induces an ad-hoc form of CSE.)
58  */
59  using generator_location_map = std::vector<std::pair<const ast::Argument*, Location>>;
60 
61  // -- variables --
62 
64  return var_references;
65  }
66 
67  void addVarReference(const ast::Variable& var, const Location& l);
68 
69  void addVarReference(const ast::Variable& var, int ident, int pos, std::string rel = "");
70 
71  bool isDefined(const ast::Variable& var) const;
72 
73  const Location& getDefinitionPoint(const ast::Variable& var) const;
74 
75  // -- records --
76 
77  // - definition -
78 
79  void setRecordDefinition(const ast::RecordInit& init, const Location& l);
80 
81  void setRecordDefinition(const ast::RecordInit& init, int ident, int pos, std::string rel = "");
82 
83  const Location& getDefinitionPoint(const ast::RecordInit& init) const;
84 
85  // -- generators (aggregates & some functors) --
86  void setGeneratorLoc(const ast::Argument& arg, const Location& loc);
87 
88  const Location& getGeneratorLoc(const ast::Argument& arg) const;
89 
90  // -- others --
91 
92  bool isGenerator(const int level) const;
93 
94  bool isSomethingDefinedOn(int level) const;
95 
96  void print(std::ostream& out) const;
97 
98 private:
99  /** The index of variable accesses */
101 
102  /** The index of record definition points */
104 
105  /** The level of a nested ram operation that is handling a generator operation */
107 };
108 
109 } // namespace souffle::ast2ram
souffle::ast2ram::ValueIndex::getDefinitionPoint
const Location & getDefinitionPoint(const ast::Variable &var) const
Definition: ValueIndex.cpp:53
souffle::ast2ram::ValueIndex::addVarReference
void addVarReference(const ast::Variable &var, const Location &l)
Definition: ValueIndex.cpp:40
souffle::ast2ram::ValueIndex::arg_generator_locations
generator_location_map arg_generator_locations
The level of a nested ram operation that is handling a generator operation.
Definition: ValueIndex.h:106
souffle::ast2ram::ValueIndex::setGeneratorLoc
void setGeneratorLoc(const ast::Argument &arg, const Location &loc)
Definition: ValueIndex.cpp:59
souffle::ast2ram::Location
Definition: Location.h:29
souffle::ast::analysis::Variable
A variable to be utilized within constraints to be handled by the constraint solver.
Definition: ConstraintSystem.h:41
souffle::ast::Argument
An abstract class for arguments.
Definition: Argument.h:33
l
var l
Definition: htmlJsChartistMin.h:15
souffle::ast2ram::ValueIndex::variable_reference_map
std::map< std::string, std::set< Location > > variable_reference_map
The type mapping variables (referenced by their names) to the locations where they are used.
Definition: ValueIndex.h:45
ContainerUtil.h
souffle::ast2ram::ValueIndex
Definition: ValueIndex.h:36
souffle::ast2ram::ValueIndex::setRecordDefinition
void setRecordDefinition(const ast::RecordInit &init, const Location &l)
Definition: ValueIndex.cpp:82
souffle::ast2ram::ValueIndex::isDefined
bool isDefined(const ast::Variable &var) const
Definition: ValueIndex.cpp:49
souffle::ast2ram::ValueIndex::getGeneratorLoc
const Location & getGeneratorLoc(const ast::Argument &arg) const
Definition: ValueIndex.cpp:63
souffle::ast2ram::ValueIndex::getVariableReferences
const variable_reference_map & getVariableReferences() const
Definition: ValueIndex.h:63
souffle::ast2ram::ValueIndex::record_definition_map
std::map< const ast::RecordInit *, Location > record_definition_map
The type mapping record init expressions to their definition points, hence the point where they get g...
Definition: ValueIndex.h:51
souffle::ast2ram::ValueIndex::isSomethingDefinedOn
bool isSomethingDefinedOn(int level) const
Definition: ValueIndex.cpp:105
souffle::ast2ram::ValueIndex::ValueIndex
ValueIndex()
souffle::ast2ram::ValueIndex::generator_location_map
std::vector< std::pair< const ast::Argument *, Location > > generator_location_map
A map from generative ast::Arguments to storage locations.
Definition: ValueIndex.h:59
souffle::ast2ram::ValueIndex::isGenerator
bool isGenerator(const int level) const
Definition: ValueIndex.cpp:99
souffle::ast2ram::ValueIndex::~ValueIndex
~ValueIndex()
souffle::ast2ram
Definition: AstToRamTranslator.cpp:132
souffle::ast
Definition: Aggregator.h:35
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086
souffle::ast2ram::ValueIndex::record_definitions
record_definition_map record_definitions
The index of record definition points.
Definition: ValueIndex.h:103
souffle::ast::RecordInit
Defines a record initialization class.
Definition: RecordInit.h:42
souffle::ast2ram::ValueIndex::var_references
variable_reference_map var_references
The index of variable accesses.
Definition: ValueIndex.h:100
souffle::ast2ram::ValueIndex::print
void print(std::ostream &out) const
Definition: ValueIndex.cpp:122