Skip to content

Commit

Permalink
Made relation-load + store more consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
azreika committed Nov 18, 2020
1 parent 16147de commit 2cec9d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
28 changes: 19 additions & 9 deletions src/ast2ram/AstToRamTranslator.cpp
Expand Up @@ -303,7 +303,7 @@ Own<ram::Sequence> 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
Expand All @@ -317,7 +317,7 @@ Own<ram::Sequence> 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
Expand Down Expand Up @@ -658,30 +658,38 @@ bool AstToRamTranslator::removeADTs(const ast::TranslationUnit& translationUnit)
return mapper.changed;
}

void AstToRamTranslator::makeRamLoad(VecOwn<ram::Statement>& curStmts, const ast::Relation* relation) const {
Own<ram::Statement> AstToRamTranslator::generateLoadRelation(const ast::Relation* relation) const {
VecOwn<ram::Statement> loadStmts;
for (auto directives : getInputDirectives(relation)) {
Own<ram::Statement> statement = mk<ram::IO>(getConcreteRelationName(relation), directives);

if (Global::config().has("profile")) {
const std::string logTimerStatement = LogStatement::tRelationLoadTime(
toString(relation->getQualifiedName()), relation->getSrcLoc());
statement = mk<ram::LogRelationTimer>(
std::move(statement), logTimerStatement, getConcreteRelationName(relation));
}
appendStmt(curStmts, std::move(statement));

appendStmt(loadStmts, std::move(statement));
}
return mk<ram::Sequence>(std::move(loadStmts));
}

void AstToRamTranslator::makeRamStore(VecOwn<ram::Statement>& curStmts, const ast::Relation* relation) const {
Own<ram::Statement> AstToRamTranslator::generateStoreRelation(const ast::Relation* relation) const {
VecOwn<ram::Statement> storeStmts;
for (auto directives : getOutputDirectives(relation)) {
Own<ram::Statement> statement = mk<ram::IO>(getConcreteRelationName(relation), directives);

if (Global::config().has("profile")) {
const std::string logTimerStatement = LogStatement::tRelationSaveTime(
toString(relation->getQualifiedName()), relation->getSrcLoc());
statement = mk<ram::LogRelationTimer>(
std::move(statement), logTimerStatement, getConcreteRelationName(relation));
}
appendStmt(curStmts, std::move(statement));

appendStmt(storeStmts, std::move(statement));
}
return mk<ram::Sequence>(std::move(storeStmts));
}

void AstToRamTranslator::createRamRelations(size_t scc) {
Expand All @@ -703,19 +711,21 @@ void AstToRamTranslator::createRamRelations(size_t scc) {
getTypeQualifier(typeEnv->getType(attributes[i]->getTypeName())));
}
}

// Add main relation
auto ramRelation = mk<ram::Relation>(
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<ram::Relation>(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<ram::Relation>(
newName, arity, auxiliaryArity, attributeNames, attributeTypeQualifiers, representation);
Expand Down
13 changes: 5 additions & 8 deletions src/ast2ram/AstToRamTranslator.h
Expand Up @@ -122,18 +122,12 @@ class AstToRamTranslator {
const std::set<const ast::Relation*>& 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<ram::Statement> 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<ram::Statement> translateRecursiveRelation(const std::set<const ast::Relation*>& scc) const;

/** add a statement to drop a relation */
void makeRamStore(VecOwn<ram::Statement>& curStmts, const ast::Relation* relation) const;

/** add a statement to load a relation */
void makeRamLoad(VecOwn<ram::Statement>& curStmts, const ast::Relation* relation) const;

void addRamSubroutine(std::string subroutineID, Own<ram::Statement> subroutine);
void addRamRelation(std::string relationName, Own<ram::Relation> ramRelation);

Expand Down Expand Up @@ -167,6 +161,9 @@ class AstToRamTranslator {
Own<ram::Statement> generateStratumTableUpdates(const std::set<const ast::Relation*>& scc) const;
Own<ram::Statement> generateStratumMainLoop(const std::set<const ast::Relation*>& scc) const;
Own<ram::Statement> generateStratumExitSequence(const std::set<const ast::Relation*>& scc) const;

Own<ram::Statement> generateStoreRelation(const ast::Relation* relation) const;
Own<ram::Statement> generateLoadRelation(const ast::Relation* relation) const;
};

} // namespace souffle::ast2ram

0 comments on commit 2cec9d5

Please sign in to comment.