Skip to content

Commit

Permalink
minor change to make old compiler happy
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-xiaoming committed Mar 19, 2023
1 parent b93b46b commit 5ba5fbb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
38 changes: 21 additions & 17 deletions lib/hobbes/eval/cc.C
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,25 @@
#include <csignal>
#include <cstdlib>

#include <algorithm>
#include <chrono>
#include <fstream>
#include <memory>
#include <mutex>
#include <numeric>
#include <stdexcept>
#include <unordered_map>

namespace hobbes {

struct cc::PerfTracer {
PerfTracer() : ofs(std::getenv("HOBBES_PERF_TRACE_FILE")) {
PerfTracer() {
const char* name = std::getenv("HOBBES_PERF_TRACE_FILE");
if (name == nullptr) {
return;
}

ofs.open(name);
if (!ofs) {
ofs.close();
return;
Expand All @@ -49,24 +57,20 @@ struct cc::PerfTracer {
threshold = std::chrono::seconds(atoi(th));
}

template <typename T, typename F>
[[nodiscard]] std::size_t nonHiddenSz(const T& t, F f) {
const auto& ms = t.members();
return std::accumulate(ms.cbegin(), ms.cend(), 0UL, [f](auto a, const auto& m) {
return a + (f(m).substr(0, 2) != ".p" ? 1UL : 0UL);
});
}

template <typename TT>
void log(const std::string& name, const ExprPtr& e, const Definitions& defs, TT delta) {
if (!isEnabled() || delta <= threshold || name.empty() || name.substr(0, 5) == ".rfn.") {
return;
}

const auto normal = [](const std::string& n) { return (n.substr(0, 2) != ".p") ? 1 : 0; };
const auto nonHiddenVar = [normal](const Variant& c) {
const auto& ms = c.members();
return std::accumulate(ms.cbegin(), ms.cend(), 0,
[normal](int a, const auto& m) { return a + normal(m.selector); });
};
const auto nonHiddenRec = [normal](const Record& c) {
const auto& ms = c.members();
return std::accumulate(ms.cbegin(), ms.cend(), 0,
[normal](int a, const auto& m) { return a + normal(m.field); });
};

constexpr const char* MARK = "HOBBES_PERF";
ofs << MARK << ':' << name
<< ":BEGIN:" << std::chrono::duration_cast<std::chrono::seconds>(delta).count() << ":";
Expand All @@ -87,14 +91,14 @@ struct cc::PerfTracer {
if (cs->name() == VariantDeconstructor::constraintName()) {
const auto& var = cs->arguments()[1];
var->show(oss);
const auto sz = nonHiddenVar(*is<Variant>(var));
i -= sz - 1U;
const int sz = nonHiddenSz(*is<Variant>(var), [](const auto& m) { return m.selector; });
i -= static_cast<std::size_t>(sz - 1);
ofs << MARK << ':' << name << ':' << sz << ':' << std::move(oss).str() << '\n';
} else if (cs->name() == RecordDeconstructor::constraintName()) {
const auto& rec = cs->arguments()[2];
rec->show(oss);
const auto sz = nonHiddenRec(*is<Record>(rec));
i -= sz - 1U;
const int sz = nonHiddenSz(*is<Record>(rec), [](const auto& m) { return m.field; });
i -= static_cast<std::size_t>(sz - 1);
ofs << MARK << ':' << name << ':' << sz << ':' << std::move(oss).str() << '\n';
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/hobbes/eval/jitcc.C
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <llvm/Support/Casting.h>
#include <llvm/Support/Compiler.h>
#include <llvm/Support/Error.h>
#include <llvm/Support/raw_os_ostream.h>
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Target/TargetMachine.h>

Expand Down Expand Up @@ -561,7 +561,7 @@ struct jitcc::IrTracer {
if (name == nullptr) {
return;
}
out = std::make_unique<llvm::raw_fd_ostream>(name, ec);
out = std::make_unique<llvm::raw_fd_ostream>(name, ec, llvm::sys::fs::F_None);
if (ec != std::errc()) {
out = nullptr;
return;
Expand Down

0 comments on commit 5ba5fbb

Please sign in to comment.