souffle  2.0.2-371-g6315b36
Public Member Functions | Static Public Attributes | Protected Attributes
souffle::ram::analysis::LevelAnalysis Class Reference

A Ram Analysis for determining the level of a expression/condition. More...

#include <Level.h>

Inheritance diagram for souffle::ram::analysis::LevelAnalysis:
Inheritance graph
Collaboration diagram for souffle::ram::analysis::LevelAnalysis:
Collaboration graph

Public Member Functions

int getLevel (const Node *value) const
 Get level of a RAM expression/condition. More...
 
 LevelAnalysis (const char *id)
 
void run (const TranslationUnit &tUnit) override
 Run analysis for a RAM translation unit. More...
 
- Public Member Functions inherited from souffle::ram::analysis::Analysis
 Analysis (const char *id)
 
virtual const std::string & getName () const
 get name of the analysis More...
 
virtual void print (std::ostream &) const
 Print the analysis result in HTML format. More...
 
virtual ~Analysis ()=default
 

Static Public Attributes

static constexpr const char * name = "level-analysis"
 

Protected Attributes

RelationAnalysisra {nullptr}
 
- Protected Attributes inherited from souffle::ram::analysis::Analysis
std::string identifier
 name of analysis instance More...
 

Detailed Description

A Ram Analysis for determining the level of a expression/condition.

The expression is determined by the TupleElement of an expression/condition with the highest tuple-id number. Note in the implementation we assume that the tuple-id of TupleOperation operations are ordered, i.e., the most-outer loop has the smallest tuple-id and the most inner-loop has the largest tuple-id number.

If an expression/condition does not contain an TupleElement accessing an element of a tuple, the analysis yields -1 for denoting that the expression/condition can be executed outside of the loop-nest, i.e., the expression/condition is independent of data stemming from relations.

Definition at line 51 of file Level.h.

Constructor & Destructor Documentation

◆ LevelAnalysis()

souffle::ram::analysis::LevelAnalysis::LevelAnalysis ( const char *  id)
inline

Definition at line 53 of file Level.h.

58 :
59  RelationAnalysis* ra{nullptr};

Member Function Documentation

◆ getLevel()

int souffle::ram::analysis::LevelAnalysis::getLevel ( const Node value) const

Get level of a RAM expression/condition.

Definition at line 64 of file Level.cpp.

68  {
69  return -1;
70  }
71 
72  // false
73  int visitFalse(const False&) override {
74  return -1;
75  }
76 
77  // tuple element access
78  int visitTupleElement(const TupleElement& elem) override {
79  return elem.getTupleId();
80  }
81 
82  // scan
83  int visitScan(const Scan&) override {
84  return -1;
85  }
86 
87  // index scan
88  int visitIndexScan(const IndexScan& indexScan) override {
89  int level = -1;
90  for (auto& index : indexScan.getRangePattern().first) {
91  level = std::max(level, visit(index));
92  }
93  for (auto& index : indexScan.getRangePattern().second) {
94  level = std::max(level, visit(index));
95  }
96  return level;
97  }
98 
99  // choice
100  int visitChoice(const Choice& choice) override {
101  return std::max(-1, visit(choice.getCondition()));
102  }
103 
104  // index choice
105  int visitIndexChoice(const IndexChoice& indexChoice) override {
106  int level = -1;
107  for (auto& index : indexChoice.getRangePattern().first) {
108  level = std::max(level, visit(index));
109  }
110  for (auto& index : indexChoice.getRangePattern().second) {
111  level = std::max(level, visit(index));
112  }
113  return std::max(level, visit(indexChoice.getCondition()));
114  }
115 
116  // aggregate
117  int visitAggregate(const Aggregate& aggregate) override {
118  return std::max(visit(aggregate.getExpression()), visit(aggregate.getCondition()));
119  }
120 
121  // index aggregate
122  int visitIndexAggregate(const IndexAggregate& indexAggregate) override {
123  int level = -1;
124  for (auto& index : indexAggregate.getRangePattern().first) {
125  level = std::max(level, visit(index));
126  }
127  for (auto& index : indexAggregate.getRangePattern().second) {
128  level = std::max(level, visit(index));
129  }
130  level = std::max(visit(indexAggregate.getExpression()), level);
131  return std::max(level, visit(indexAggregate.getCondition()));
132  }
133 
134  // unpack record
135  int visitUnpackRecord(const UnpackRecord& unpack) override {
136  return visit(unpack.getExpression());
137  }
138 
139  // filter
140  int visitFilter(const Filter& filter) override {
141  return visit(filter.getCondition());
142  }
143 
144  // break
145  int visitBreak(const Break& b) override {
146  return visit(b.getCondition());
147  }
148 
149  // project
150  int visitProject(const Project& project) override {
151  int level = -1;
152  for (auto& exp : project.getValues()) {
153  level = std::max(level, visit(exp));
154  }
155  return level;
156  }
157 
158  // return
159  int visitSubroutineReturn(const SubroutineReturn& ret) override {
160  int level = -1;
161  for (auto& exp : ret.getValues()) {
162  level = std::max(level, visit(exp));
163  }
164  return level;
165  }
166 
167  // auto increment
168  int visitAutoIncrement(const AutoIncrement&) override {
169  return -1;
170  }
171 
172  // undef value
173  int visitUndefValue(const UndefValue&) override {
174  return -1;
175  }
176 
177  // intrinsic functors
178  int visitIntrinsicOperator(const IntrinsicOperator& op) override {
179  int level = -1;
180  for (const auto& arg : op.getArguments()) {
181  level = std::max(level, visit(arg));
182  }
183  return level;
184  }
185 
186  // pack operator
187  int visitPackRecord(const PackRecord& pack) override {
188  int level = -1;
189  for (const auto& arg : pack.getArguments()) {
190  level = std::max(level, visit(arg));
191  }
192  return level;
193  }
194 
195  // argument
196  int visitSubroutineArgument(const SubroutineArgument&) override {
197  return -1;
198  }
199 
200  // user defined operator
201  int visitUserDefinedOperator(const UserDefinedOperator& op) override {
202  int level = -1;
203  for (const auto& arg : op.getArguments()) {
204  level = std::max(level, visit(arg));
205  }
206  return level;
207  }
208 
209  // conjunction
210  int visitConjunction(const Conjunction& conj) override {
211  return std::max(visit(conj.getLHS()), visit(conj.getRHS()));
212  }
213 
214  // negation
215  int visitNegation(const Negation& neg) override {
216  return visit(neg.getOperand());
217  }
218 
219  // constraint
220  int visitConstraint(const Constraint& binRel) override {
221  return std::max(visit(binRel.getLHS()), visit(binRel.getRHS()));
222  }
223 
224  // existence check
225  int visitExistenceCheck(const ExistenceCheck& exists) override {
226  int level = -1;
227  for (const auto& cur : exists.getValues()) {
228  level = std::max(level, visit(cur));
229  }
230  return level;
231  }
232 
233  // provenance existence check
234  int visitProvenanceExistenceCheck(const ProvenanceExistenceCheck& provExists) override {
235  int level = -1;
236  for (const auto& cur : provExists.getValues()) {
237  level = std::max(level, visit(cur));
238  }
239  return level;
240  }
241 
242  // emptiness check
243  int visitEmptinessCheck(const EmptinessCheck&) override {
244  return -1; // can be in the top level
245  }
246 
247  // default rule
248  int visitNode(const Node&) override {
249  fatal("Node not implemented!");
250  }
251  };
252 
253  assert((isA<Expression>(node) || isA<Condition>(node) || isA<Operation>(node)) &&
254  "not an expression/condition/operation");
255  return ValueLevelVisitor().visit(node);
256 }
257 
258 } // namespace souffle::ram::analysis

Referenced by souffle::ram::transform::MakeIndexTransformer::getExpressionPair(), souffle::ram::transform::HoistAggregateTransformer::hoistAggregate(), souffle::ram::transform::ChoiceConversionTransformer::rewriteIndexScan(), and souffle::ram::transform::ChoiceConversionTransformer::rewriteScan().

◆ run()

void souffle::ram::analysis::LevelAnalysis::run ( const TranslationUnit translationUnit)
inlineoverridevirtual

Run analysis for a RAM translation unit.

Implements souffle::ram::analysis::Analysis.

Definition at line 57 of file Level.h.

58  :
59  RelationAnalysis* ra{nullptr};

Field Documentation

◆ name

constexpr const char* souffle::ram::analysis::LevelAnalysis::name = "level-analysis"
staticconstexpr

Definition at line 55 of file Level.h.

◆ ra

RelationAnalysis* souffle::ram::analysis::LevelAnalysis::ra {nullptr}
protected

Definition at line 67 of file Level.h.


The documentation for this class was generated from the following files:
souffle::ram::analysis::LevelAnalysis::ra
RelationAnalysis * ra
Definition: Level.h:67
souffle::filter
std::vector< A > filter(std::vector< A > xs, F &&f)
Filter a vector to include certain elements.
Definition: FunctionalUtil.h:155
souffle::pack
RamDomain pack(RecordTable &recordTab, Tuple< RamDomain, Arity > const &tuple)
helper to convert tuple to record reference for the synthesiser
Definition: RecordTable.h:153
b
l j a showGridBackground &&c b raw series this eventEmitter b
Definition: htmlJsChartistMin.h:15
souffle::fatal
void fatal(const char *format, const Args &... args)
Definition: MiscUtil.h:198