Skip to content

Commit 7a7a9b3

Browse files
committed
jit logging: fix for codegen v1
1 parent bd826f9 commit 7a7a9b3

File tree

4 files changed

+46
-66
lines changed

4 files changed

+46
-66
lines changed

oi/CodeGen.cpp

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -105,48 +105,6 @@ struct OIArray {
105105
)";
106106
}
107107

108-
void defineJitLog(FeatureSet features, std::string& code) {
109-
if (features[Feature::JitLogging]) {
110-
code += R"(
111-
extern int logFile;
112-
113-
void __jlogptr(uintptr_t ptr) {
114-
static constexpr char hexdigits[] = "0123456789abcdef";
115-
static constexpr size_t ptrlen = 2 * sizeof(ptr);
116-
117-
static char hexstr[ptrlen + 1] = {};
118-
119-
size_t i = ptrlen;
120-
while (i--) {
121-
hexstr[i] = hexdigits[ptr & 0xf];
122-
ptr = ptr >> 4;
123-
}
124-
hexstr[ptrlen] = '\n';
125-
write(logFile, hexstr, sizeof(hexstr));
126-
}
127-
128-
#define JLOG(str) \
129-
do { \
130-
if (__builtin_expect(logFile, 0)) { \
131-
write(logFile, str, sizeof(str) - 1); \
132-
} \
133-
} while (false)
134-
135-
#define JLOGPTR(ptr) \
136-
do { \
137-
if (__builtin_expect(logFile, 0)) { \
138-
__jlogptr((uintptr_t)ptr); \
139-
} \
140-
} while (false)
141-
)";
142-
} else {
143-
code += R"(
144-
#define JLOG(str)
145-
#define JLOGPTR(ptr)
146-
)";
147-
}
148-
}
149-
150108
void addIncludes(const TypeGraph& typeGraph,
151109
FeatureSet features,
152110
std::string& code) {
@@ -1137,7 +1095,7 @@ void CodeGen::generate(
11371095
}
11381096
addIncludes(typeGraph, config_.features, code);
11391097
defineArray(code);
1140-
defineJitLog(config_.features, code);
1098+
FuncGen::DefineJitLog(code, config_.features);
11411099

11421100
if (config_.features[Feature::TypedDataSegment]) {
11431101
if (config_.features[Feature::Library]) {

oi/FuncGen.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,48 @@ extern uintptr_t cookieValue;
157157
code.append(vars);
158158
}
159159

160+
void FuncGen::DefineJitLog(std::string& code, FeatureSet features) {
161+
if (features[Feature::JitLogging]) {
162+
code += R"(
163+
extern int logFile;
164+
165+
void __jlogptr(uintptr_t ptr) {
166+
static constexpr char hexdigits[] = "0123456789abcdef";
167+
static constexpr size_t ptrlen = 2 * sizeof(ptr);
168+
169+
static char hexstr[ptrlen + 1] = {};
170+
171+
size_t i = ptrlen;
172+
while (i--) {
173+
hexstr[i] = hexdigits[ptr & 0xf];
174+
ptr = ptr >> 4;
175+
}
176+
hexstr[ptrlen] = '\n';
177+
write(logFile, hexstr, sizeof(hexstr));
178+
}
179+
180+
#define JLOG(str) \
181+
do { \
182+
if (__builtin_expect(logFile, 0)) { \
183+
write(logFile, str, sizeof(str) - 1); \
184+
} \
185+
} while (false)
186+
187+
#define JLOGPTR(ptr) \
188+
do { \
189+
if (__builtin_expect(logFile, 0)) { \
190+
__jlogptr((uintptr_t)ptr); \
191+
} \
192+
} while (false)
193+
)";
194+
} else {
195+
code += R"(
196+
#define JLOG(str)
197+
#define JLOGPTR(ptr)
198+
)";
199+
}
200+
}
201+
160202
void FuncGen::DeclareStoreData(std::string& testCode) {
161203
testCode.append("void StoreData(uintptr_t data, size_t& dataSegOffset);\n");
162204
}

oi/FuncGen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace oi::detail {
3030
class FuncGen {
3131
public:
3232
static void DeclareExterns(std::string& code);
33+
static void DefineJitLog(std::string& code, FeatureSet features);
3334

3435
static void DeclareStoreData(std::string& testCode);
3536
static void DefineStoreData(std::string& testCode);

oi/OICodeGen.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,29 +3031,6 @@ bool OICodeGen::generateJitCode(std::string& code) {
30313031
#define SAVE_SIZE(val)
30323032
#define SAVE_DATA(val) StoreData(val, returnArg)
30333033
)");
3034-
3035-
if (config.features[Feature::JitLogging]) {
3036-
code.append(R"(
3037-
#define JLOG(str) \
3038-
do { \
3039-
if (__builtin_expect(logFile, 0)) { \
3040-
write(logFile, str, sizeof(str) - 1); \
3041-
} \
3042-
} while (false)
3043-
3044-
#define JLOGPTR(ptr) \
3045-
do { \
3046-
if (__builtin_expect(logFile, 0)) { \
3047-
__jlogptr((uintptr_t)ptr); \
3048-
} \
3049-
} while (false)
3050-
)");
3051-
} else {
3052-
code.append(R"(
3053-
#define JLOG(str)
3054-
#define JLOGPTR(ptr)
3055-
)");
3056-
}
30573034
} else {
30583035
code.append(R"(
30593036
#define SAVE_SIZE(val) AddData(val, returnArg)
@@ -3063,6 +3040,8 @@ bool OICodeGen::generateJitCode(std::string& code) {
30633040
)");
30643041
}
30653042

3043+
FuncGen::DefineJitLog(code, config.features);
3044+
30663045
// The purpose of the anonymous namespace within `OIInternal` is that
30673046
// anything defined within an anonymous namespace has internal-linkage,
30683047
// and therefore won't appear in the symbol table of the resulting object

0 commit comments

Comments
 (0)