diff --git a/src/ast2ram/AstToRamTranslator.cpp b/src/ast2ram/AstToRamTranslator.cpp index 309f9de74c7..4230902e0e6 100644 --- a/src/ast2ram/AstToRamTranslator.cpp +++ b/src/ast2ram/AstToRamTranslator.cpp @@ -303,7 +303,7 @@ Own AstToRamTranslator::translateSCC(size_t scc, size_t idx) cons // load all internal input relations from the facts dir with a .facts extension const auto& sccInputRelations = sccGraph->getInternalInputRelations(scc); for (const auto& relation : sccInputRelations) { - makeRamLoad(current, relation); + appendStmt(current, generateLoadRelation(relation)); } // compute the relations themselves @@ -317,7 +317,7 @@ Own AstToRamTranslator::translateSCC(size_t scc, size_t idx) cons // store all internal output relations to the output dir with a .csv extension const auto& sccOutputRelations = sccGraph->getInternalOutputRelations(scc); for (const auto& relation : sccOutputRelations) { - makeRamStore(current, relation); + appendStmt(current, generateStoreRelation(relation)); } // clear expired relations @@ -658,30 +658,38 @@ bool AstToRamTranslator::removeADTs(const ast::TranslationUnit& translationUnit) return mapper.changed; } -void AstToRamTranslator::makeRamLoad(VecOwn& curStmts, const ast::Relation* relation) const { +Own AstToRamTranslator::generateLoadRelation(const ast::Relation* relation) const { + VecOwn loadStmts; for (auto directives : getInputDirectives(relation)) { Own statement = mk(getConcreteRelationName(relation), directives); + if (Global::config().has("profile")) { const std::string logTimerStatement = LogStatement::tRelationLoadTime( toString(relation->getQualifiedName()), relation->getSrcLoc()); statement = mk( std::move(statement), logTimerStatement, getConcreteRelationName(relation)); } - appendStmt(curStmts, std::move(statement)); + + appendStmt(loadStmts, std::move(statement)); } + return mk(std::move(loadStmts)); } -void AstToRamTranslator::makeRamStore(VecOwn& curStmts, const ast::Relation* relation) const { +Own AstToRamTranslator::generateStoreRelation(const ast::Relation* relation) const { + VecOwn storeStmts; for (auto directives : getOutputDirectives(relation)) { Own statement = mk(getConcreteRelationName(relation), directives); + if (Global::config().has("profile")) { const std::string logTimerStatement = LogStatement::tRelationSaveTime( toString(relation->getQualifiedName()), relation->getSrcLoc()); statement = mk( std::move(statement), logTimerStatement, getConcreteRelationName(relation)); } - appendStmt(curStmts, std::move(statement)); + + appendStmt(storeStmts, std::move(statement)); } + return mk(std::move(storeStmts)); } void AstToRamTranslator::createRamRelations(size_t scc) { @@ -703,19 +711,21 @@ void AstToRamTranslator::createRamRelations(size_t scc) { getTypeQualifier(typeEnv->getType(attributes[i]->getTypeName()))); } } + + // Add main relation auto ramRelation = mk( name, arity, auxiliaryArity, attributeNames, attributeTypeQualifiers, representation); addRamRelation(name, std::move(ramRelation)); - // recursive relations also require @delta and @new variants, with the same signature + // Recursive relations also require @delta and @new variants, with the same signature if (isRecursive) { - // add delta relation + // Add delta relation std::string deltaName = getDeltaRelationName(rel); auto deltaRelation = mk(deltaName, arity, auxiliaryArity, attributeNames, attributeTypeQualifiers, representation); addRamRelation(deltaName, std::move(deltaRelation)); - // add new relation + // Add new relation std::string newName = getNewRelationName(rel); auto newRelation = mk( newName, arity, auxiliaryArity, attributeNames, attributeTypeQualifiers, representation); diff --git a/src/ast2ram/AstToRamTranslator.h b/src/ast2ram/AstToRamTranslator.h index a2acda5878b..a2a64957f8b 100644 --- a/src/ast2ram/AstToRamTranslator.h +++ b/src/ast2ram/AstToRamTranslator.h @@ -122,18 +122,12 @@ class AstToRamTranslator { const std::set& expiredRelations) const; RamDomain getConstantRamRepresentation(const ast::Constant& constant) const; - /* translate RAM code for the non-recursive clauses of the given relation */ + /* Translate RAM code for the non-recursive clauses of the given relation */ Own translateNonRecursiveRelation(const ast::Relation& rel) const; - /** translate RAM code for recursive relations in a strongly-connected component */ + /** Translate RAM code for recursive relations in a strongly-connected component */ Own translateRecursiveRelation(const std::set& scc) const; - /** add a statement to drop a relation */ - void makeRamStore(VecOwn& curStmts, const ast::Relation* relation) const; - - /** add a statement to load a relation */ - void makeRamLoad(VecOwn& curStmts, const ast::Relation* relation) const; - void addRamSubroutine(std::string subroutineID, Own subroutine); void addRamRelation(std::string relationName, Own ramRelation); @@ -167,6 +161,9 @@ class AstToRamTranslator { Own generateStratumTableUpdates(const std::set& scc) const; Own generateStratumMainLoop(const std::set& scc) const; Own generateStratumExitSequence(const std::set& scc) const; + + Own generateStoreRelation(const ast::Relation* relation) const; + Own generateLoadRelation(const ast::Relation* relation) const; }; } // namespace souffle::ast2ram