Skip to content

Commit f5f8743

Browse files
alexmalyshevmeta-codesync[bot]
authored andcommitted
Move capture_compilation_times_for and s_use_stable_pointers into Config
Summary: Move two process-lifetime configuration globals into the `jit::Config` struct: - `capture_compilation_times_for` from `Jit/jit_time_log.cpp` — list of function name patterns for compilation time capture. - `s_use_stable_pointers` from `Common/util.cpp` — testing flag for deterministic pointer output. Both are configuration-like values with process lifetime that naturally belong in Config rather than as file-scope globals. Reviewed By: yoney Differential Revision: D96480903 fbshipit-source-id: 1487afa84bde791a6a585161f175aaa261ee6ad5
1 parent d9f6c1d commit f5f8743

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

cinderx/Common/util.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "cinderx/Common/log.h"
1010
#include "cinderx/Common/ref.h"
11+
#include "cinderx/Jit/config.h"
1112

1213
#include <cstdarg>
1314
#include <cstdio>
@@ -103,15 +104,14 @@ jit_string_t* ss_sprintf_alloc(const char* format, ...) {
103104

104105
namespace jit {
105106

106-
static bool s_use_stable_pointers{false};
107-
108107
const void* getStablePointer(const void* ptr) {
109-
return s_use_stable_pointers ? reinterpret_cast<const void*>(0xdeadbeef)
110-
: ptr;
108+
return getConfig().use_stable_pointers
109+
? reinterpret_cast<const void*>(0xdeadbeef)
110+
: ptr;
111111
}
112112

113113
void setUseStablePointers(bool enable) {
114-
s_use_stable_pointers = enable;
114+
getMutableConfig().use_stable_pointers = enable;
115115
}
116116

117117
std::string unicodeAsString(PyObject* str) {

cinderx/Jit/config.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <cstdint>
77
#include <optional>
88
#include <string>
9+
#include <vector>
910

1011
namespace jit {
1112

@@ -203,6 +204,12 @@ struct Config {
203204

204205
// The ASM syntax the JIT should use when disassembling.
205206
AsmSyntax asm_syntax{AsmSyntax::ATT};
207+
208+
// List of function name patterns for which to capture compilation times.
209+
std::vector<std::string> capture_compilation_times_for;
210+
211+
// Use stable sentinel pointers in output (for deterministic test output).
212+
bool use_stable_pointers{false};
206213
};
207214

208215
// Get the JIT's current config object.

cinderx/Jit/jit_time_log.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "cinderx/Jit/jit_time_log.h"
44

55
#include "cinderx/Common/log.h"
6+
#include "cinderx/Jit/config.h"
67
#include "cinderx/Jit/containers.h"
78

89
#include <fmt/core.h>
@@ -14,18 +15,17 @@
1415

1516
namespace jit {
1617

17-
static std::vector<std::string> capture_compilation_times_for;
18-
1918
void parseAndSetFuncList(const std::string& flag_value) {
20-
capture_compilation_times_for.clear();
19+
auto& func_list = getMutableConfig().capture_compilation_times_for;
20+
func_list.clear();
2121

2222
std::stringstream ss(flag_value);
2323

2424
while (ss.good()) {
2525
std::string substr;
2626
getline(ss, substr, ',');
2727
if (!substr.empty()) {
28-
capture_compilation_times_for.emplace_back(substr);
28+
func_list.emplace_back(substr);
2929
}
3030
}
3131
}
@@ -63,7 +63,7 @@ bool isMatch(const std::string& word, const std::string& pattern) {
6363
}
6464

6565
bool captureCompilationTimeFor(const std::string& function_name) {
66-
for (const std::string& pattern : capture_compilation_times_for) {
66+
for (const std::string& pattern : getConfig().capture_compilation_times_for) {
6767
if (isMatch(function_name, pattern)) {
6868
return true;
6969
}

cinderx/Jit/pyjit.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3513,13 +3513,15 @@ int initialize() {
35133513
return 0;
35143514
}
35153515

3516-
// Save the force_init field as it might have be set by test code before
3517-
// jit::initialize() is called.
3516+
// Save fields that might have been set by test code before jit::initialize()
3517+
// is called.
35183518
auto force_init = getConfig().force_init;
3519+
auto use_stable_pointers = getConfig().use_stable_pointers;
35193520
getMutableConfig() = Config{};
35203521
if (force_init.has_value()) {
35213522
getMutableConfig().force_init = force_init;
35223523
}
3524+
getMutableConfig().use_stable_pointers = use_stable_pointers;
35233525

35243526
FlagProcessor flag_processor = initFlagProcessor();
35253527
if (flag_processor.hasHandled("jit-help")) {

0 commit comments

Comments
 (0)