jit logging: fix for codegen v1

This commit is contained in:
Jake Hillion 2023-09-26 18:14:23 -07:00 committed by Jake Hillion
parent bd826f9794
commit 7a7a9b347a
4 changed files with 46 additions and 66 deletions

View File

@ -105,48 +105,6 @@ struct OIArray {
)";
}
void defineJitLog(FeatureSet features, std::string& code) {
if (features[Feature::JitLogging]) {
code += R"(
extern int logFile;
void __jlogptr(uintptr_t ptr) {
static constexpr char hexdigits[] = "0123456789abcdef";
static constexpr size_t ptrlen = 2 * sizeof(ptr);
static char hexstr[ptrlen + 1] = {};
size_t i = ptrlen;
while (i--) {
hexstr[i] = hexdigits[ptr & 0xf];
ptr = ptr >> 4;
}
hexstr[ptrlen] = '\n';
write(logFile, hexstr, sizeof(hexstr));
}
#define JLOG(str) \
do { \
if (__builtin_expect(logFile, 0)) { \
write(logFile, str, sizeof(str) - 1); \
} \
} while (false)
#define JLOGPTR(ptr) \
do { \
if (__builtin_expect(logFile, 0)) { \
__jlogptr((uintptr_t)ptr); \
} \
} while (false)
)";
} else {
code += R"(
#define JLOG(str)
#define JLOGPTR(ptr)
)";
}
}
void addIncludes(const TypeGraph& typeGraph,
FeatureSet features,
std::string& code) {
@ -1137,7 +1095,7 @@ void CodeGen::generate(
}
addIncludes(typeGraph, config_.features, code);
defineArray(code);
defineJitLog(config_.features, code);
FuncGen::DefineJitLog(code, config_.features);
if (config_.features[Feature::TypedDataSegment]) {
if (config_.features[Feature::Library]) {

View File

@ -157,6 +157,48 @@ extern uintptr_t cookieValue;
code.append(vars);
}
void FuncGen::DefineJitLog(std::string& code, FeatureSet features) {
if (features[Feature::JitLogging]) {
code += R"(
extern int logFile;
void __jlogptr(uintptr_t ptr) {
static constexpr char hexdigits[] = "0123456789abcdef";
static constexpr size_t ptrlen = 2 * sizeof(ptr);
static char hexstr[ptrlen + 1] = {};
size_t i = ptrlen;
while (i--) {
hexstr[i] = hexdigits[ptr & 0xf];
ptr = ptr >> 4;
}
hexstr[ptrlen] = '\n';
write(logFile, hexstr, sizeof(hexstr));
}
#define JLOG(str) \
do { \
if (__builtin_expect(logFile, 0)) { \
write(logFile, str, sizeof(str) - 1); \
} \
} while (false)
#define JLOGPTR(ptr) \
do { \
if (__builtin_expect(logFile, 0)) { \
__jlogptr((uintptr_t)ptr); \
} \
} while (false)
)";
} else {
code += R"(
#define JLOG(str)
#define JLOGPTR(ptr)
)";
}
}
void FuncGen::DeclareStoreData(std::string& testCode) {
testCode.append("void StoreData(uintptr_t data, size_t& dataSegOffset);\n");
}

View File

@ -30,6 +30,7 @@ namespace oi::detail {
class FuncGen {
public:
static void DeclareExterns(std::string& code);
static void DefineJitLog(std::string& code, FeatureSet features);
static void DeclareStoreData(std::string& testCode);
static void DefineStoreData(std::string& testCode);

View File

@ -3031,29 +3031,6 @@ bool OICodeGen::generateJitCode(std::string& code) {
#define SAVE_SIZE(val)
#define SAVE_DATA(val) StoreData(val, returnArg)
)");
if (config.features[Feature::JitLogging]) {
code.append(R"(
#define JLOG(str) \
do { \
if (__builtin_expect(logFile, 0)) { \
write(logFile, str, sizeof(str) - 1); \
} \
} while (false)
#define JLOGPTR(ptr) \
do { \
if (__builtin_expect(logFile, 0)) { \
__jlogptr((uintptr_t)ptr); \
} \
} while (false)
)");
} else {
code.append(R"(
#define JLOG(str)
#define JLOGPTR(ptr)
)");
}
} else {
code.append(R"(
#define SAVE_SIZE(val) AddData(val, returnArg)
@ -3063,6 +3040,8 @@ bool OICodeGen::generateJitCode(std::string& code) {
)");
}
FuncGen::DefineJitLog(code, config.features);
// The purpose of the anonymous namespace within `OIInternal` is that
// anything defined within an anonymous namespace has internal-linkage,
// and therefore won't appear in the symbol table of the resulting object