Skip to content

Commit

Permalink
Standardise Analysis naming
Browse files Browse the repository at this point in the history
  • Loading branch information
mmcgr authored and XiaowenHu96 committed Jul 31, 2020
1 parent c658212 commit f271c45
Show file tree
Hide file tree
Showing 63 changed files with 148 additions and 144 deletions.
18 changes: 10 additions & 8 deletions src/AstToRamTranslator.cpp
Expand Up @@ -98,7 +98,8 @@ size_t AstToRamTranslator::getEvaluationArity(const AstAtom* atom) const {
}
}

std::vector<std::map<std::string, std::string>> AstToRamTranslator::getInputDirectives(const AstRelation* rel) {
std::vector<std::map<std::string, std::string>> AstToRamTranslator::getInputDirectives(
const AstRelation* rel) {
std::vector<std::map<std::string, std::string>> inputDirectives;

for (const auto* load : program->getIOs()) {
Expand All @@ -120,7 +121,8 @@ std::vector<std::map<std::string, std::string>> AstToRamTranslator::getInputDire
return inputDirectives;
}

std::vector<std::map<std::string, std::string>> AstToRamTranslator::getOutputDirectives(const AstRelation* rel) {
std::vector<std::map<std::string, std::string>> AstToRamTranslator::getOutputDirectives(
const AstRelation* rel) {
std::vector<std::map<std::string, std::string>> outputDirectives;

for (const auto* store : program->getIOs()) {
Expand Down Expand Up @@ -835,7 +837,7 @@ std::unique_ptr<RamExpression> AstToRamTranslator::translateConstant(AstConstant

/** generate RAM code for a non-recursive relation */
std::unique_ptr<RamStatement> AstToRamTranslator::translateNonRecursiveRelation(
const AstRelation& rel, const RecursiveClauses* recursiveClauses) {
const AstRelation& rel, const RecursiveClausesAnalysis* recursiveClauses) {
/* start with an empty sequence */
std::vector<std::unique_ptr<RamStatement>> res;

Expand Down Expand Up @@ -934,7 +936,7 @@ void AstToRamTranslator::nameUnnamedVariables(AstClause* clause) {

/** generate RAM code for recursive relations in a strongly-connected component */
std::unique_ptr<RamStatement> AstToRamTranslator::translateRecursiveRelation(
const std::set<const AstRelation*>& scc, const RecursiveClauses* recursiveClauses) {
const std::set<const AstRelation*>& scc, const RecursiveClausesAnalysis* recursiveClauses) {
// initialize sections
std::vector<std::unique_ptr<RamStatement>> preamble;
std::vector<std::unique_ptr<RamStatement>> updateTable;
Expand Down Expand Up @@ -1434,16 +1436,16 @@ void AstToRamTranslator::translateProgram(const AstTranslationUnit& translationU
typeEnv = &translationUnit.getAnalysis<TypeEnvironmentAnalysis>()->getTypeEnvironment();

// obtain recursive clauses from analysis
const auto* recursiveClauses = translationUnit.getAnalysis<RecursiveClauses>();
const auto* recursiveClauses = translationUnit.getAnalysis<RecursiveClausesAnalysis>();

// obtain strongly connected component (SCC) graph from analysis
const auto& sccGraph = *translationUnit.getAnalysis<SCCGraph>();
const auto& sccGraph = *translationUnit.getAnalysis<SCCGraphAnalysis>();

// obtain some topological order over the nodes of the SCC graph
const auto& sccOrder = *translationUnit.getAnalysis<TopologicallySortedSCCGraph>();
const auto& sccOrder = *translationUnit.getAnalysis<TopologicallySortedSCCGraphAnalysis>();

// obtain the schedule of relations expired at each index of the topological order
const auto& expirySchedule = translationUnit.getAnalysis<RelationSchedule>()->schedule();
const auto& expirySchedule = translationUnit.getAnalysis<RelationScheduleAnalysis>()->schedule();

// get auxiliary arity analysis
auxArityAnalysis = translationUnit.getAnalysis<AuxiliaryArity>();
Expand Down
6 changes: 3 additions & 3 deletions src/AstToRamTranslator.h
Expand Up @@ -56,7 +56,7 @@ class RamTupleElement;
class RamOperation;
class RamTranslationUnit;
class RamExpression;
class RecursiveClauses;
class RecursiveClausesAnalysis;
class TypeEnvironment;

/**
Expand Down Expand Up @@ -423,11 +423,11 @@ class AstToRamTranslator {
* @return a corresponding statement or null if there are no non-recursive clauses.
*/
std::unique_ptr<RamStatement> translateNonRecursiveRelation(
const AstRelation& rel, const RecursiveClauses* recursiveClauses);
const AstRelation& rel, const RecursiveClausesAnalysis* recursiveClauses);

/** translate RAM code for recursive relations in a strongly-connected component */
std::unique_ptr<RamStatement> translateRecursiveRelation(
const std::set<const AstRelation*>& scc, const RecursiveClauses* recursiveClauses);
const std::set<const AstRelation*>& scc, const RecursiveClausesAnalysis* recursiveClauses);

/** translate RAM code for subroutine to get subproofs */
std::unique_ptr<RamStatement> makeSubproofSubroutine(const AstClause& clause);
Expand Down
4 changes: 2 additions & 2 deletions src/ast/AstTranslationUnit.h
Expand Up @@ -56,8 +56,8 @@ class AstTranslationUnit {
if (debug) {
std::stringstream ss;
analyses[name]->print(ss);
if (nullptr == dynamic_cast<PrecedenceGraph*>(analyses[name].get()) &&
nullptr == dynamic_cast<SCCGraph*>(analyses[name].get())) {
if (nullptr == dynamic_cast<PrecedenceGraphAnalysis*>(analyses[name].get()) &&
nullptr == dynamic_cast<SCCGraphAnalysis*>(analyses[name].get())) {
debugReport.addSection(name, "Ast Analysis [" + name + "]", ss.str());
} else {
debugReport.addSection(
Expand Down
4 changes: 2 additions & 2 deletions src/ast/analysis/AstGroundAnalysis.cpp
Expand Up @@ -153,10 +153,10 @@ BoolDisjunctConstraint imply(const std::vector<BoolDisjunctVar>& vars, const Boo

std::map<const AstArgument*, bool> getGroundedTerms(const AstTranslationUnit& tu, const AstClause& clause) {
struct Analysis : public AstConstraintAnalysis<BoolDisjunctVar> {
const RelationDetailCache& relCache;
const RelationDetailCacheAnalysis& relCache;
std::set<const AstAtom*> ignore;

Analysis(const AstTranslationUnit& tu) : relCache(*tu.getAnalysis<RelationDetailCache>()) {}
Analysis(const AstTranslationUnit& tu) : relCache(*tu.getAnalysis<RelationDetailCacheAnalysis>()) {}

// atoms are producing grounded variables
void visitAtom(const AstAtom& cur) override {
Expand Down
2 changes: 1 addition & 1 deletion src/ast/analysis/AstIOTypeAnalysis.cpp
Expand Up @@ -8,7 +8,7 @@

/************************************************************************
*
* @file AstIOTypeAnalysis.h
* @file AstIOTypeAnalysis.cpp
*
* Implements methods to identify a relation as input, output, or printsize.
*
Expand Down
8 changes: 4 additions & 4 deletions src/ast/analysis/AstProfileUse.cpp
Expand Up @@ -31,7 +31,7 @@ class AstTranslationUnit;
/**
* Run analysis, i.e., retrieve profile information
*/
void AstProfileUse::run(const AstTranslationUnit&) {
void AstProfileUseAnalysis::run(const AstTranslationUnit&) {
if (Global::config().has("profile-use")) {
std::string filename = Global::config().get("profile-use");
profile::Reader(filename, programRun).processFile();
Expand All @@ -41,19 +41,19 @@ void AstProfileUse::run(const AstTranslationUnit&) {
/**
* Print analysis
*/
void AstProfileUse::print(std::ostream&) const {}
void AstProfileUseAnalysis::print(std::ostream&) const {}

/**
* Check whether relation size is defined in profile
*/
bool AstProfileUse::hasRelationSize(const AstQualifiedName& rel) {
bool AstProfileUseAnalysis::hasRelationSize(const AstQualifiedName& rel) {
return programRun->getRelation(rel.toString()) != nullptr;
}

/**
* Get relation size from profile
*/
size_t AstProfileUse::getRelationSize(const AstQualifiedName& rel) {
size_t AstProfileUseAnalysis::getRelationSize(const AstQualifiedName& rel) {
if (const auto* profRel = programRun->getRelation(rel.toString())) {
return profRel->size();
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/ast/analysis/AstProfileUse.h
Expand Up @@ -31,12 +31,12 @@ class AstTranslationUnit;
/**
* AstAnalysis that loads profile data and has a profile query interface.
*/
class AstProfileUse : public AstAnalysis {
class AstProfileUseAnalysis : public AstAnalysis {
public:
/** Name of analysis */
static constexpr const char* name = "profile-use";

AstProfileUse()
AstProfileUseAnalysis()
: AstAnalysis(name), programRun(std::make_shared<profile::ProgramRun>(profile::ProgramRun())) {}

/** Run analysis */
Expand Down
72 changes: 37 additions & 35 deletions src/ast/analysis/PrecedenceGraph.cpp
Expand Up @@ -106,7 +106,7 @@ void printHTMLGraph(std::ostream& out, const std::string& dotSpec, const std::st

} // namespace

void PrecedenceGraph::run(const AstTranslationUnit& translationUnit) {
void PrecedenceGraphAnalysis::run(const AstTranslationUnit& translationUnit) {
/* Get relations */
const AstProgram& program = *translationUnit.getProgram();
std::vector<AstRelation*> relations = program.getRelations();
Expand All @@ -123,7 +123,7 @@ void PrecedenceGraph::run(const AstTranslationUnit& translationUnit) {
}
}

void PrecedenceGraph::print(std::ostream& os) const {
void PrecedenceGraphAnalysis::print(std::ostream& os) const {
/* Print dependency graph */
std::stringstream ss;
ss << "digraph {\n";
Expand All @@ -148,8 +148,8 @@ void PrecedenceGraph::print(std::ostream& os) const {
printHTMLGraph(os, ss.str(), getName());
}

void RedundantRelations::run(const AstTranslationUnit& translationUnit) {
precedenceGraph = translationUnit.getAnalysis<PrecedenceGraph>();
void RedundantRelationsAnalysis::run(const AstTranslationUnit& translationUnit) {
precedenceGraph = translationUnit.getAnalysis<PrecedenceGraphAnalysis>();

std::set<const AstRelation*> work;
std::set<const AstRelation*> notRedundant;
Expand Down Expand Up @@ -189,11 +189,11 @@ void RedundantRelations::run(const AstTranslationUnit& translationUnit) {
}
}

void RedundantRelations::print(std::ostream& os) const {
void RedundantRelationsAnalysis::print(std::ostream& os) const {
os << redundantRelations << std::endl;
}

void RelationDetailCache::run(const AstTranslationUnit& translationUnit) {
void RelationDetailCacheAnalysis::run(const AstTranslationUnit& translationUnit) {
const auto& program = *translationUnit.getProgram();
for (auto* rel : program.getRelations()) {
nameToRelation[rel->getQualifiedName()] = rel;
Expand All @@ -208,7 +208,7 @@ void RelationDetailCache::run(const AstTranslationUnit& translationUnit) {
}
}

void RelationDetailCache::print(std::ostream& os) const {
void RelationDetailCacheAnalysis::print(std::ostream& os) const {
for (const auto& pair : nameToClauses) {
os << "--" << pair.first << "--";
os << std::endl;
Expand All @@ -219,21 +219,21 @@ void RelationDetailCache::print(std::ostream& os) const {
}
}

void RecursiveClauses::run(const AstTranslationUnit& translationUnit) {
void RecursiveClausesAnalysis::run(const AstTranslationUnit& translationUnit) {
visitDepthFirst(*translationUnit.getProgram(), [&](const AstClause& clause) {
if (computeIsRecursive(clause, translationUnit)) {
recursiveClauses.insert(&clause);
}
});
}

void RecursiveClauses::print(std::ostream& os) const {
void RecursiveClausesAnalysis::print(std::ostream& os) const {
os << recursiveClauses << std::endl;
}

bool RecursiveClauses::computeIsRecursive(
bool RecursiveClausesAnalysis::computeIsRecursive(
const AstClause& clause, const AstTranslationUnit& translationUnit) const {
const auto& relationDetail = *translationUnit.getAnalysis<RelationDetailCache>();
const auto& relationDetail = *translationUnit.getAnalysis<RelationDetailCacheAnalysis>();
const AstProgram& program = *translationUnit.getProgram();

// we want to reach the atom of the head through the body
Expand Down Expand Up @@ -283,8 +283,8 @@ bool RecursiveClauses::computeIsRecursive(
return false;
}

void SCCGraph::run(const AstTranslationUnit& translationUnit) {
precedenceGraph = translationUnit.getAnalysis<PrecedenceGraph>();
void SCCGraphAnalysis::run(const AstTranslationUnit& translationUnit) {
precedenceGraph = translationUnit.getAnalysis<PrecedenceGraphAnalysis>();
ioType = translationUnit.getAnalysis<IOType>();
sccToRelation.clear();
relationToScc.clear();
Expand Down Expand Up @@ -333,8 +333,9 @@ void SCCGraph::run(const AstTranslationUnit& translationUnit) {
/* Compute strongly connected components using Gabow's algorithm (cf. Algorithms in
* Java by Robert Sedgewick / Part 5 / Graph * algorithms). The algorithm has linear
* runtime. */
void SCCGraph::scR(const AstRelation* w, std::map<const AstRelation*, size_t>& preOrder, size_t& counter,
std::stack<const AstRelation*>& S, std::stack<const AstRelation*>& P, size_t& numSCCs) {
void SCCGraphAnalysis::scR(const AstRelation* w, std::map<const AstRelation*, size_t>& preOrder,
size_t& counter, std::stack<const AstRelation*>& S, std::stack<const AstRelation*>& P,
size_t& numSCCs) {
preOrder[w] = counter++;
S.push(w);
P.push(w);
Expand Down Expand Up @@ -362,7 +363,7 @@ void SCCGraph::scR(const AstRelation* w, std::map<const AstRelation*, size_t>& p
numSCCs++;
}

void SCCGraph::print(std::ostream& os) const {
void SCCGraphAnalysis::print(std::ostream& os) const {
const std::string& name = Global::config().get("name");
std::stringstream ss;
/* Print SCC graph */
Expand All @@ -383,7 +384,8 @@ void SCCGraph::print(std::ostream& os) const {
printHTMLGraph(os, ss.str(), getName());
}

int TopologicallySortedSCCGraph::topologicalOrderingCost(const std::vector<size_t>& permutationOfSCCs) const {
int TopologicallySortedSCCGraphAnalysis::topologicalOrderingCost(
const std::vector<size_t>& permutationOfSCCs) const {
// create variables to hold the cost of the current SCC and the permutation as a whole
int costOfSCC = 0;
int costOfPermutation = -1;
Expand Down Expand Up @@ -420,7 +422,7 @@ int TopologicallySortedSCCGraph::topologicalOrderingCost(const std::vector<size_
return costOfPermutation;
}

void TopologicallySortedSCCGraph::computeTopologicalOrdering(size_t scc, std::vector<bool>& visited) {
void TopologicallySortedSCCGraphAnalysis::computeTopologicalOrdering(size_t scc, std::vector<bool>& visited) {
// create a flag to indicate that a successor was visited (by default it hasn't been)
bool found = false;
bool hasUnvisitedSuccessor = false;
Expand Down Expand Up @@ -478,9 +480,9 @@ void TopologicallySortedSCCGraph::computeTopologicalOrdering(size_t scc, std::ve
}
}

void TopologicallySortedSCCGraph::run(const AstTranslationUnit& translationUnit) {
void TopologicallySortedSCCGraphAnalysis::run(const AstTranslationUnit& translationUnit) {
// obtain the scc graph
sccGraph = translationUnit.getAnalysis<SCCGraph>();
sccGraph = translationUnit.getAnalysis<SCCGraphAnalysis>();
// clear the list of ordered sccs
sccOrder.clear();
std::vector<bool> visited;
Expand All @@ -502,7 +504,7 @@ void TopologicallySortedSCCGraph::run(const AstTranslationUnit& translationUnit)
}
}

void TopologicallySortedSCCGraph::print(std::ostream& os) const {
void TopologicallySortedSCCGraphAnalysis::print(std::ostream& os) const {
os << "--- partial order of strata as list of pairs ---" << std::endl;
for (size_t sccIndex = 0; sccIndex < sccOrder.size(); sccIndex++) {
const auto& successorSccs = sccGraph->getSuccessorSCCs(sccOrder.at(sccIndex));
Expand All @@ -528,7 +530,7 @@ void TopologicallySortedSCCGraph::print(std::ostream& os) const {
os << "cost: " << topologicalOrderingCost(sccOrder) << std::endl;
}

void RelationScheduleStep::print(std::ostream& os) const {
void RelationScheduleAnalysisStep::print(std::ostream& os) const {
os << "computed: ";
for (const AstRelation* compRel : computed()) {
os << compRel->getQualifiedName() << ", ";
Expand All @@ -546,36 +548,36 @@ void RelationScheduleStep::print(std::ostream& os) const {
os << "\n";
}

void RelationSchedule::run(const AstTranslationUnit& translationUnit) {
topsortSCCGraph = translationUnit.getAnalysis<TopologicallySortedSCCGraph>();
precedenceGraph = translationUnit.getAnalysis<PrecedenceGraph>();
void RelationScheduleAnalysis::run(const AstTranslationUnit& translationUnit) {
topsortSCCGraphAnalysis = translationUnit.getAnalysis<TopologicallySortedSCCGraphAnalysis>();
precedenceGraph = translationUnit.getAnalysis<PrecedenceGraphAnalysis>();

size_t numSCCs = translationUnit.getAnalysis<SCCGraph>()->getNumberOfSCCs();
size_t numSCCs = translationUnit.getAnalysis<SCCGraphAnalysis>()->getNumberOfSCCs();
std::vector<std::set<const AstRelation*>> relationExpirySchedule =
computeRelationExpirySchedule(translationUnit);

relationSchedule.clear();
for (size_t i = 0; i < numSCCs; i++) {
auto scc = topsortSCCGraph->order()[i];
auto scc = topsortSCCGraphAnalysis->order()[i];
const std::set<const AstRelation*> computedRelations =
translationUnit.getAnalysis<SCCGraph>()->getInternalRelations(scc);
translationUnit.getAnalysis<SCCGraphAnalysis>()->getInternalRelations(scc);
relationSchedule.emplace_back(computedRelations, relationExpirySchedule[i],
translationUnit.getAnalysis<SCCGraph>()->isRecursive(scc));
translationUnit.getAnalysis<SCCGraphAnalysis>()->isRecursive(scc));
}
}

std::vector<std::set<const AstRelation*>> RelationSchedule::computeRelationExpirySchedule(
std::vector<std::set<const AstRelation*>> RelationScheduleAnalysis::computeRelationExpirySchedule(
const AstTranslationUnit& translationUnit) {
std::vector<std::set<const AstRelation*>> relationExpirySchedule;
/* Compute for each step in the reverse topological order
of evaluating the SCC the set of alive relations. */
size_t numSCCs = topsortSCCGraph->order().size();
size_t numSCCs = topsortSCCGraphAnalysis->order().size();

/* Alive set for each step */
std::vector<std::set<const AstRelation*>> alive(numSCCs);
/* Resize expired relations sets */
relationExpirySchedule.resize(numSCCs);
const auto& sccGraph = translationUnit.getAnalysis<SCCGraph>();
const auto& sccGraph = translationUnit.getAnalysis<SCCGraphAnalysis>();

/* Compute all alive relations by iterating over all steps in reverse order
determine the dependencies */
Expand All @@ -584,7 +586,7 @@ std::vector<std::set<const AstRelation*>> RelationSchedule::computeRelationExpir
alive[orderedSCC].insert(alive[orderedSCC - 1].begin(), alive[orderedSCC - 1].end());

/* Add predecessors of relations computed in this step */
auto scc = topsortSCCGraph->order()[numSCCs - orderedSCC];
auto scc = topsortSCCGraphAnalysis->order()[numSCCs - orderedSCC];
for (const AstRelation* r : sccGraph->getInternalRelations(scc)) {
for (const AstRelation* predecessor : precedenceGraph->graph().predecessors(r)) {
alive[orderedSCC].insert(predecessor);
Expand All @@ -602,9 +604,9 @@ std::vector<std::set<const AstRelation*>> RelationSchedule::computeRelationExpir
return relationExpirySchedule;
}

void RelationSchedule::print(std::ostream& os) const {
void RelationScheduleAnalysis::print(std::ostream& os) const {
os << "begin schedule\n";
for (const RelationScheduleStep& step : relationSchedule) {
for (const RelationScheduleAnalysisStep& step : relationSchedule) {
os << step;
os << "computed: ";
for (const AstRelation* compRel : step.computed()) {
Expand Down

0 comments on commit f271c45

Please sign in to comment.