souffle  2.0.2-371-g6315b36
Public Member Functions | Private Member Functions
souffle::ast::transform::InlineRelationsTransformer Class Reference

Transformation pass to inline marked relations. More...

#include <InlineRelations.h>

Inheritance diagram for souffle::ast::transform::InlineRelationsTransformer:
Inheritance graph
Collaboration diagram for souffle::ast::transform::InlineRelationsTransformer:
Collaboration graph

Public Member Functions

InlineRelationsTransformerclone () const override
 
std::string getName () const override
 
- Public Member Functions inherited from souffle::ast::transform::Transformer
bool apply (TranslationUnit &translationUnit)
 
virtual ~Transformer ()=default
 

Private Member Functions

bool transform (TranslationUnit &translationUnit) override
 

Detailed Description

Transformation pass to inline marked relations.

Definition at line 34 of file InlineRelations.h.

Member Function Documentation

◆ clone()

InlineRelationsTransformer* souffle::ast::transform::InlineRelationsTransformer::clone ( ) const
inlineoverridevirtual

Implements souffle::ast::transform::Transformer.

Definition at line 46 of file InlineRelations.h.

◆ getName()

std::string souffle::ast::transform::InlineRelationsTransformer::getName ( ) const
inlineoverridevirtual

Implements souffle::ast::transform::Transformer.

Definition at line 42 of file InlineRelations.h.

◆ transform()

bool souffle::ast::transform::InlineRelationsTransformer::transform ( TranslationUnit translationUnit)
overrideprivatevirtual

Implements souffle::ast::transform::Transformer.

Definition at line 1002 of file InlineRelations.cpp.

1011  {
1012  std::set<Clause*> clausesToDelete;
1013  clausesChanged = false;
1014 
1015  // Go through each relation in the program and check if we need to inline any of its clauses
1016  for (Relation* rel : program.getRelations()) {
1017  // Skip if the relation is going to be inlined
1018  if (rel->hasQualifier(RelationQualifier::INLINE)) {
1019  continue;
1020  }
1021 
1022  // Go through the relation's clauses and try inlining them
1023  for (Clause* clause : getClauses(program, *rel)) {
1024  if (containsInlinedAtom(program, *clause)) {
1025  // Generate the inlined versions of this clause - the clause will be replaced by these
1026  std::vector<Clause*> newClauses = getInlinedClause(program, *clause);
1027 
1028  // Replace the clause with these equivalent versions
1029  clausesToDelete.insert(clause);
1030  for (Clause* replacementClause : newClauses) {
1031  program.addClause(Own<Clause>(replacementClause));
1032  }
1033 
1034  // We've changed the program this iteration
1035  clausesChanged = true;
1036  changed = true;
1037  }
1038  }
1039  }
1040 
1041  // Delete all clauses that were replaced
1042  for (const Clause* clause : clausesToDelete) {
1043  program.removeClause(clause);
1044  changed = true;
1045  }
1046  }
1047 
1048  return changed;
1049 }
1050 
1051 } // namespace souffle::ast::transform

The documentation for this class was generated from the following files:
souffle::ast::transform::containsInlinedAtom
bool containsInlinedAtom(const Program &program, const Clause &clause)
Checks if a given clause contains an atom that should be inlined.
Definition: InlineRelations.cpp:202
souffle::ast::transform::getInlinedClause
std::vector< Clause * > getInlinedClause(Program &program, const Clause &clause)
Returns a list of clauses that should replace the given clause after one step of inlining.
Definition: InlineRelations.cpp:911
souffle::ast::getClauses
std::vector< Clause * > getClauses(const Program &program, const QualifiedName &relationName)
Returns a vector of clauses in the program describing the relation with the given name.
Definition: Utils.cpp:77
souffle::RelationQualifier::INLINE
@ INLINE
rel
void rel(size_t limit, bool showLimit=true)
Definition: Tui.h:1086