Skip to content

Commit

Permalink
remove tracer for ir and func address
Browse files Browse the repository at this point in the history
  • Loading branch information
mo-xiaoming committed Mar 22, 2023
1 parent c62659d commit 47c80a0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 112 deletions.
6 changes: 0 additions & 6 deletions include/hobbes/eval/jitcc.H
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <hobbes/util/llvm.H>
#include <hobbes/eval/func.H>
#include <hobbes/eval/ctype.H>
#include <memory>

#if LLVM_VERSION_MAJOR >= 11
#include <llvm/IR/ValueHandle.h>
Expand Down Expand Up @@ -261,11 +260,6 @@ private:
#if LLVM_VERSION_MAJOR >= 11
std::unique_ptr<ORCJIT> orcjit;
#endif

struct IrTracer;
std::unique_ptr<IrTracer> irTracer;
struct JitFuncTracer;
std::unique_ptr<JitFuncTracer> jitFuncTracer;
};

// shorthand for compilation over a sequence of expressions
Expand Down
108 changes: 2 additions & 106 deletions lib/hobbes/eval/jitcc.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
#include <llvm/Support/Compiler.h>
#include <llvm/Support/Error.h>
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/raw_ostream.h>
#include <llvm/Target/TargetMachine.h>

#include <algorithm>
#include <cstdint>
#include <fstream>
#include <ostream>
#include <sstream>
#include <stdexcept>
#include <system_error>
#include <utility>
Expand Down Expand Up @@ -557,104 +553,11 @@ private:
};
#endif

struct jitcc::IrTracer {
IrTracer() {
std::error_code ec;
const char* name = std::getenv("HOBBES_IR_TRACE_FILE");
if (name == nullptr) {
return;
}
out = std::make_unique<llvm::raw_fd_ostream>(name, ec, llvm::sys::fs::F_None);
if (ec != std::errc()) {
out = nullptr;
return;
}
}

void log(const llvm::Module& m) {
if (isEnabled()) {
m.print(*out, nullptr, false, true);
}
}

private:
[[nodiscard]] bool isEnabled() const noexcept {
return !!out;
}

std::unique_ptr<llvm::raw_fd_ostream> out;
};

struct jitcc::JitFuncTracer {
JitFuncTracer() {
std::error_code ec;
const char* name = std::getenv("HOBBES_JIT_FUNC_TRACE_FILE");
if (name == nullptr) {
return;
}
out = std::make_unique<llvm::raw_fd_ostream>(name, ec, llvm::sys::fs::F_None);
if (ec != std::errc()) {
out = nullptr;
return;
}
}

private:
struct ModuleFunctions {
ModuleFunctions() = default;
explicit ModuleFunctions(const llvm::Module& m) {
funcs.reserve(m.getFunctionList().size());
for (const auto& f : m) {
if (!f.isDeclaration()) {
funcs.push_back(f.getName());
}
}
}

const std::vector<llvm::StringRef>& get() const noexcept {
return funcs;
}

private:
std::vector<llvm::StringRef> funcs;
};

public:
ModuleFunctions getCollector(const llvm::Module& m) {
if (isEnabled()) {
return ModuleFunctions(m);
}
return {};
}

void log(const ModuleFunctions& mf, llvm::ExecutionEngine& ee) {
if (isEnabled()) {
for (const auto name : mf.get()) {
if (const auto a = ee.getFunctionAddress(name.str())) {
*out << name << ":0x";
out->write_hex(a);
*out << '\n';
}
}
out->flush();
}
}

private:
[[nodiscard]] bool isEnabled() const noexcept {
return !!out;
}

std::unique_ptr<llvm::raw_fd_ostream> out;
};

#if LLVM_VERSION_MAJOR >= 11
jitcc::jitcc(const TEnvPtr& tenv)
: tenv(tenv), vtenv(std::make_unique<VTEnv>()), ignoreLocalScope(false),
globals(std::make_unique<Globals>()), globalData(32768 /* min global page size = 32K */),
constants(std::make_unique<ConstantList>()),
irTracer(std::make_unique<IrTracer>()),
jitFuncTracer(std::make_unique<JitFuncTracer>())
constants(std::make_unique<ConstantList>())
{
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmParser();
Expand Down Expand Up @@ -684,9 +587,7 @@ jitcc::~jitcc() {
jitcc::jitcc(const TEnvPtr& tenv) :
tenv(tenv),
ignoreLocalScope(false),
globalData(32768 /* min global page size = 32K */),
irTracer(std::make_unique<IrTracer>()),
jitFuncTracer(std::make_unique<JitFuncTracer>())
globalData(32768 /* min global page size = 32K */)
{
llvm::InitializeNativeTarget();
llvm::InitializeNativeTargetAsmParser();
Expand Down Expand Up @@ -850,9 +751,6 @@ void* jitcc::getMachineCode(llvm::Function* f, llvm::JITEventListener* listener)
if (!this->currentModule) {
throw std::runtime_error("Internal compiler error, can't derive machine code for unknown function");
}
irTracer->log(*this->currentModule);

const auto moduleFunctions = jitFuncTracer->getCollector(*this->currentModule);

// make a new execution engine out of this module (finalizing the module)
std::string err;
Expand Down Expand Up @@ -907,8 +805,6 @@ void* jitcc::getMachineCode(llvm::Function* f, llvm::JITEventListener* listener)
// and _now_ we must be able to get machine code for this function
void* pf = ee->getPointerToFunction(f);

jitFuncTracer->log(moduleFunctions, *ee);

if (listener) {
ee->UnregisterJITEventListener(listener);
}
Expand Down

0 comments on commit 47c80a0

Please sign in to comment.