Skip to content

Commit

Permalink
Use constexpr for constants in Jit/util.h
Browse files Browse the repository at this point in the history
Summary:
It's more appropriate than const when used for literals in a header file.

Also renames py_debug to kPyDebug to keep with code style guidelines.

Reviewed By: swtaarrs

Differential Revision: D46899105

fbshipit-source-id: 29e8774b952e60bbd341bc68644b8ff274c64978
  • Loading branch information
Alex Malyshev authored and facebook-github-bot committed Jun 28, 2023
1 parent 9fee3f9 commit 14b7914
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Jit/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ void doShadowStackWalk(PyThreadState* tstate, FrameHandler handler) {
// Invoke handler for each frame on the shadow stack
void walkShadowStack(PyThreadState* tstate, FrameHandler handler) {
doShadowStackWalk(tstate, handler);
if (py_debug) {
if (kPyDebug) {
assertShadowCallStackConsistent(tstate);
}
}
Expand Down
8 changes: 4 additions & 4 deletions Jit/lir/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,7 @@ LIRGenerator::TranslatedBlock LIRGenerator::TranslateOneBasicBlock(
// TODO(emacs): If we manage to optimize leaf calls to a series of
// non-deopting instructions, remove BeginInlinedFunction and
// EndInlinedFunction completely.
if (py_debug) {
if (kPyDebug) {
bbb.AppendInvoke(assertShadowCallStackConsistent, "__asm_tstate");
}
auto instr = static_cast<const BeginInlinedFunction*>(&i);
Expand Down Expand Up @@ -2627,15 +2627,15 @@ LIRGenerator::TranslatedBlock LIRGenerator::TranslateOneBasicBlock(
"Store {}, __asm_tstate, {}",
callee_shadow_frame,
offsetof(PyThreadState, shadow_frame));
if (py_debug) {
if (kPyDebug) {
bbb.AppendInvoke(assertShadowCallStackConsistent, "__asm_tstate");
}
break;
}
case Opcode::kEndInlinedFunction: {
// TODO(T109706798): Support calling from generators and inlining
// generators.
if (py_debug) {
if (kPyDebug) {
bbb.AppendInvoke(assertShadowCallStackConsistent, "__asm_tstate");
}
// callee_shadow_frame <- tstate.shadow_frame
Expand Down Expand Up @@ -2679,7 +2679,7 @@ LIRGenerator::TranslatedBlock LIRGenerator::TranslateOneBasicBlock(
bbb.AppendLabel(GetSafeLabelName());
bbb.AppendInvoke(JITRT_UnlinkFrame, "__asm_tstate");
bbb.AppendLabel(done);
if (py_debug) {
if (kPyDebug) {
bbb.AppendInvoke(assertShadowCallStackConsistent, "__asm_tstate");
}
break;
Expand Down
14 changes: 7 additions & 7 deletions Jit/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct jit_string_t* ss_sprintf_alloc(const char* format, ...);
#ifdef __cplusplus
}

const bool py_debug =
constexpr bool kPyDebug =
#ifdef Py_DEBUG
true;
#else
Expand All @@ -61,14 +61,14 @@ const char* ss_get_string(const auto_jit_string_t& ss);

namespace jit {

const int kPointerSize = sizeof(void*);
constexpr int kPointerSize = sizeof(void*);

const int kKiB = 1024;
const int kMiB = kKiB * kKiB;
const int kGiB = kKiB * kKiB * kKiB;
constexpr int kKiB = 1024;
constexpr int kMiB = kKiB * kKiB;
constexpr int kGiB = kKiB * kKiB * kKiB;

#if defined(__x86_64__) || defined(__aarch64__)
const int kPageSize = 4 * kKiB;
constexpr int kPageSize = 4 * kKiB;
#else
#error Please define kPageSize for the current architecture
#endif
Expand All @@ -89,7 +89,7 @@ constexpr T roundUp(T x, size_t n) {
return roundDown(x + n - 1, n);
}

const int kCoFlagsAnyGenerator =
constexpr int kCoFlagsAnyGenerator =
CO_ASYNC_GENERATOR | CO_COROUTINE | CO_GENERATOR | CO_ITERABLE_COROUTINE;

// If stable pointers are enabled (with a call to setUseStablePointers(true))
Expand Down

0 comments on commit 14b7914

Please sign in to comment.