Skip to content

Commit

Permalink
Merge pull request #83 from nanocoh/main
Browse files Browse the repository at this point in the history
Stats + Constant api
  • Loading branch information
nanocoh authored Jun 6, 2024
2 parents 5c1910d + c854201 commit 7bc84ab
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/apps/naja_edit/NajaEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "SNLCapnP.h"
#include "SNLUniverse.h"
#include "Reduction.h"
#include "Utils.h"

using namespace naja::DNL;
using namespace naja::SNL;
Expand Down Expand Up @@ -282,6 +283,8 @@ int main(int argc, char* argv[]) {
}
}



if (optimizationType == OptimizationType::DLE) {
const auto start{std::chrono::steady_clock::now()};
SPDLOG_INFO("Starting removal of loadless logic");
Expand All @@ -294,6 +297,9 @@ int main(int argc, char* argv[]) {
oss << "Removal of loadless logic done in: " << elapsed_seconds.count() << "s";
SPDLOG_INFO(oss.str());
}
NetlistStatistics stats(*get());
stats.process();
spdlog::info(stats.getReport());
} else if (optimizationType == OptimizationType::ALL) {
const auto start{std::chrono::steady_clock::now()};
spdlog::info("Starting full optimization(constant propagation and removal of loadless logic)");
Expand All @@ -312,8 +318,13 @@ int main(int argc, char* argv[]) {
<< "s";
spdlog::info(oss.str());
}
NetlistStatistics stats(*get());
stats.process();
spdlog::info(stats.getReport());
}



if (program.is_used("-z")) {
const auto start{std::chrono::steady_clock::now()};
auto editPath = std::filesystem::path(program.get<std::string>("-z"));
Expand Down
5 changes: 2 additions & 3 deletions src/optimization/ConstantPropagation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1025,8 +1025,7 @@ void ConstantPropagation::propagateConstants() {
term->setNet(assign0);
SNLTruthTable tt(0, 0);
auto logic0 = SNLLibraryTruthTables::getDesignForTruthTable(
term->getDB()->getLibrary(
SNLName("nangate45")),
*(term->getDB()->getPrimitiveLibraries().begin()),
tt)
.first;
SNLInstance* logic0Inst = term->getDesign()->getInstance(SNLName(name));
Expand Down Expand Up @@ -1058,7 +1057,7 @@ void ConstantPropagation::propagateConstants() {
term->setNet(assign1);
SNLTruthTable tt(0, 1);
auto logic1 = SNLLibraryTruthTables::getDesignForTruthTable(
term->getDB()->getLibrary(SNLName("nangate45")),
*(term->getDB()->getPrimitiveLibraries().begin()),
tt)
.first;
SNLInstance* logic1Inst = term->getDesign()->getInstance(SNLName(name));
Expand Down
13 changes: 13 additions & 0 deletions src/optimization/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "SNLBusNetBit.h"
#include "SNLDB0.h"
#include "SNLUniverse.h"
#include <sstream>

using namespace naja::DNL;
using namespace naja::SNL;
Expand Down Expand Up @@ -72,4 +73,16 @@ std::string Uniquifier::getFullPath() {
return fullPath;
}

void NetlistStatistics::process() {
std::map<std::string, size_t> pritmitveCount;
std::stringstream ss;
for (auto leaf : dnl_.getLeaves()) {
pritmitveCount[dnl_.getDNLInstanceFromID(leaf).getSNLModel()->getName().getString()]++;
}
for (const auto& entry : pritmitveCount) {
ss << entry.first << " : " << entry.second << std::endl;
}
report_ = ss.str();
}

} // namespace naja::NAJA_OPT
12 changes: 12 additions & 0 deletions src/optimization/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,16 @@ class Uniquifier {
std::vector<SNLInstance*> pathUniq_;
DNLID id_ = DNLID_MAX;
};

class NetlistStatistics {
public:
NetlistStatistics(DNLFull& dnl) : dnl_(dnl) {}
void process();
const std::string& getReport() const { return report_; }

private:
DNLFull& dnl_;
std::string report_;
};

} // namespace naja::NAJA_OPT
5 changes: 4 additions & 1 deletion test/logic_opt/ReductionOptTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using ::testing::ElementsAre;
#include "SNLScalarTerm.h"
#include "SNLUniverse.h"
using namespace naja::SNL;

#include "Utils.h"
#include "ConstantPropagation.h"
#include "DNL.h"
#include "NetlistGraph.h"
Expand Down Expand Up @@ -314,4 +314,7 @@ TEST_F(ReductionOptTests, testTruthTablesMap) {
ReductionOptimization reductionOpt(cp.getPartialConstantReaders());
reductionOpt.run();
}
NetlistStatistics netlistStats(*get());
netlistStats.process();
printf("Netlist statistics: %s\n", netlistStats.getReport().c_str());
}

0 comments on commit 7bc84ab

Please sign in to comment.