souffle  2.0.2-371-g6315b36
Public Member Functions | Protected Member Functions
souffle::ram::transform::IfConversionTransformer Class Reference

Convert IndexScan operations to Filter/Existence Checks. More...

#include <IfConversion.h>

Inheritance diagram for souffle::ram::transform::IfConversionTransformer:
Inheritance graph
Collaboration diagram for souffle::ram::transform::IfConversionTransformer:
Collaboration graph

Public Member Functions

bool convertIndexScans (Program &program)
 Apply if-conversion to the whole program. More...
 
std::string getName () const override
 @Brief get name of the transformer More...
 
Own< OperationrewriteIndexScan (const IndexScan *indexScan)
 Rewrite IndexScan operations. More...
 
- Public Member Functions inherited from souffle::ram::transform::Transformer
bool apply (TranslationUnit &translationUnit)
 @Brief apply the transformer to a translation unit @Param translationUnit that will be transformed. More...
 
virtual ~Transformer ()=default
 

Protected Member Functions

bool transform (TranslationUnit &translationUnit) override
 @Brief transform the translation unit / used by apply @Param translationUnit that will be transformed. More...
 

Detailed Description

Convert IndexScan operations to Filter/Existence Checks.

If there exists IndexScan operations in the RAM, and their tuples are not further used in subsequent operations, the IndexScan operations will be rewritten to Filter/Existence Checks.

For example,

QUERY
...
FOR t1 IN X ON INDEX t1.x = 10 AND t1.y = 20
... // no occurrence of t1

will be rewritten to

QUERY
...
IF (10,20) NOT IN A
...

Definition at line 58 of file IfConversion.h.

Member Function Documentation

◆ convertIndexScans()

bool souffle::ram::transform::IfConversionTransformer::convertIndexScans ( Program program)

Apply if-conversion to the whole program.

Parameters
RAMprogram
Returns
A flag indicating whether the RAM program has been changed.

Search for queries and rewrite their IndexScan operations if possible.

Definition at line 80 of file IfConversion.cpp.

80  {
81  if (Own<Operation> op = rewriteIndexScan(scan)) {
82  changed = true;
83  node = std::move(op);
84  }
85  }
86  node->apply(makeLambdaRamMapper(scanRewriter));
87  return node;
88  };
89  const_cast<Query*>(&query)->apply(makeLambdaRamMapper(scanRewriter));
90  });
91  return changed;
92 }
93 
94 } // namespace souffle::ram::transform

References rewriteIndexScan().

Here is the call graph for this function:

◆ getName()

std::string souffle::ram::transform::IfConversionTransformer::getName ( ) const
inlineoverridevirtual

@Brief get name of the transformer

Implements souffle::ram::transform::Transformer.

Definition at line 60 of file IfConversion.h.

79  :
80  bool transform(TranslationUnit& translationUnit) override {

◆ rewriteIndexScan()

Own< Operation > souffle::ram::transform::IfConversionTransformer::rewriteIndexScan ( const IndexScan indexScan)

Rewrite IndexScan operations.

Parameters
indexScanAn index operation
Returns
The old operation if the if-conversion fails; otherwise the filter/existence check

Rewrites IndexScan operations to a filter/existence check if the IndexScan's tuple is not used in a consecutive RAM operation

Definition at line 37 of file IfConversion.cpp.

37  {
38  tupleNotUsed = false;
39  }
40  });
41 
42  // if not used, transform the IndexScan operation to an existence check
43  if (tupleNotUsed) {
44  // replace IndexScan with an Filter/Existence check
45  VecOwn<Expression> newValues;
46 
47  size_t arity = indexScan->getRangePattern().first.size();
48  for (size_t i = 0; i < arity; ++i) {
49  if (*(indexScan->getRangePattern().first[i]) != *(indexScan->getRangePattern().second[i])) {
50  return nullptr;
51  }
52  }
53 
54  for (auto& cur : indexScan->getRangePattern().second) {
55  Expression* val = nullptr;
56  if (cur != nullptr) {
57  val = cur->clone();
58  }
59  newValues.emplace_back(val);
60  }
61 
62  // check if there is a break statement nested in the Scan - if so, remove it
63  Operation* newOp;
64  if (const auto* breakOp = dynamic_cast<const Break*>(&indexScan->getOperation())) {
65  newOp = breakOp->getOperation().clone();
66  } else {
67  newOp = indexScan->getOperation().clone();
68  }
69 
70  return mk<Filter>(mk<ExistenceCheck>(indexScan->getRelation(), std::move(newValues)),
71  Own<Operation>(newOp), indexScan->getProfileText());
72  }
73  return nullptr;
74 }
75 
76 bool IfConversionTransformer::convertIndexScans(Program& program) {
77  bool changed = false;
78  visitDepthFirst(program, [&](const Query& query) {

Referenced by convertIndexScans().

◆ transform()

bool souffle::ram::transform::IfConversionTransformer::transform ( TranslationUnit translationUnit)
inlineoverrideprotectedvirtual

@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed.

@Return flag reporting whether the RAM program has changed

Implements souffle::ram::transform::Transformer.

Definition at line 84 of file IfConversion.h.


The documentation for this class was generated from the following files:
souffle::ram::transform::IfConversionTransformer::convertIndexScans
bool convertIndexScans(Program &program)
Apply if-conversion to the whole program.
Definition: IfConversion.cpp:80
souffle::ram::transform::Transformer::apply
bool apply(TranslationUnit &translationUnit)
@Brief apply the transformer to a translation unit @Param translationUnit that will be transformed.
Definition: Transformer.cpp:39
i
size_t i
Definition: json11.h:663
souffle::ram::transform::IfConversionTransformer::transform
bool transform(TranslationUnit &translationUnit) override
@Brief transform the translation unit / used by apply @Param translationUnit that will be transformed...
Definition: IfConversion.h:84
souffle::ram::visitDepthFirst
void visitDepthFirst(const Node &root, Visitor< R, Ps... > &visitor, Args &... args)
A utility function visiting all nodes within the RAM fragments rooted by the given node recursively i...
Definition: Visitor.h:357
souffle::ram::transform::IfConversionTransformer::rewriteIndexScan
Own< Operation > rewriteIndexScan(const IndexScan *indexScan)
Rewrite IndexScan operations.
Definition: IfConversion.cpp:37
souffle::ram::makeLambdaRamMapper
LambdaNodeMapper< Lambda > makeLambdaRamMapper(const Lambda &lambda)
Creates a node mapper based on a corresponding lambda expression.
Definition: LambdaNodeMapper.h:67