8000 Merge Parser and Target · python/cpython@af7606d · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit af7606d

Browse files
committed
Merge Parser and Target
1 parent 44a024a commit af7606d

File tree

4 files changed

+375
-454
lines changed

4 files changed

+375
-454
lines changed

Python/jit.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,8 @@ copy_and_patch(char *base, const Stencil *stencil, uint64_t *patches)
288288
static void
289289
emit(const StencilGroup *group, uint64_t patches[])
290290
{
291-
char *data = (char *)patches[HoleValue_DATA];
292-
copy_and_patch(data, &group->data, patches);
293-
char *text = (char *)patches[HoleValue_TEXT];
294-
copy_and_patch(text, &group->text, patches);
291+
copy_and_patch((char *)patches[HoleValue_CODE], &group->code, patches);
292+
copy_and_patch((char *)patches[HoleValue_DATA], &group->data, patches);
295293
}
296294

297295
// This becomes the executor's execute member, and handles some setup/teardown:
@@ -312,53 +310,53 @@ int
312310
_PyJIT_Compile(_PyUOpExecutorObject *executor)
313311
{
314312
// Loop once to find the total compiled size:
315-
size_t text_size = 0;
313+
size_t code_size = 0;
316314
size_t data_size = 0;
317315
for (Py_ssize_t i = 0; i < Py_SIZE(executor); i++) {
318316
_PyUOpInstruction *instruction = &executor->trace[i];
319317
const StencilGroup *group = &stencil_groups[instruction->opcode];
320-
text_size += group->text.body_size;
318+
code_size += group->code.body_size;
321319
data_size += group->data.body_size;
322320
}
323-
// Round up to the nearest page (text and data need separate pages):
321+
// Round up to the nearest page (code and data need separate pages):
324322
size_t page_size = get_page_size();
325323
assert((page_size & (page_size - 1)) == 0);
326-
text_size += page_size - (text_size & (page_size - 1));
324+
code_size += page_size - (code_size & (page_size - 1));
327325
data_size += page_size - (data_size & (page_size - 1));
328-
char *memory = jit_alloc(text_size + data_size);
326+
char *memory = jit_alloc(code_size + data_size);
329327
if (memory == NU 8000 LL) {
330328
goto fail;
331329
}
332330
// Loop again to emit the code:
333-
char *text = memory;
334-
char *data = memory + text_size;
331+
char *code = memory;
332+
char *data = memory + code_size;
335333
for (Py_ssize_t i = 0; i < Py_SIZE(executor); i++) {
336334
_PyUOpInstruction *instruction = &executor->trace[i];
337335
const StencilGroup *group = &stencil_groups[instruction->opcode];
338336
// Think of patches as a dictionary mapping HoleValue to uint64_t:
339337
uint64_t patches[] = GET_PATCHES();
340-
patches[HoleValue_CONTINUE] = (uint64_t)text + group->text.body_size;
341-
patches[HoleValue_CURRENT_EXECUTOR] = (uint64_t)executor;
338+
patches[HoleValue_CODE] = (uint64_t)code;
339+
patches[HoleValue_CONTINUE] = (uint64_t)code + group->code.body_size;
340+
patches[HoleValue_DATA] = (uint64_t)data;
341+
patches[HoleValue_EXECUTOR] = (uint64_t)executor;
342342
patches[HoleValue_OPARG] = instruction->oparg;
343343
patches[HoleValue_OPERAND] = instruction->operand;
344344
patches[HoleValue_TARGET] = instruction->target;
345-
patches[HoleValue_DATA] = (uint64_t)data;
346-
patches[HoleValue_TEXT] = (uint64_t)text;
347345
patches[HoleValue_TOP] = (uint64_t)memory;
348346
patches[HoleValue_ZERO] = 0;
349347
emit(group, patches);
350-
text += group->text.body_size;
348+
code += group->code.body_size;
351349
data += group->data.body_size;
352350
}
353-
if (mark_executable(memory, text_size) ||
354-
mark_readable(memory + text_size, data_size))
351+
if (mark_executable(memory, code_size) ||
352+
mark_readable(memory + code_size, data_size))
355353
{
356-
jit_free(memory, text_size + data_size);
354+
jit_free(memory, code_size + data_size);
357355
goto fail;
358356
}
359357
executor->base.execute = execute;
360358
executor->jit_code = memory;
361-
executor->jit_size = text_size + data_size;
359+
executor->jit_size = code_size + data_size;
362360
return 1;
363361
fail:
364362
return PyErr_Occurred() ? -1 : 0;

Tools/jit/README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
<div align=center>
2-
31
The JIT Compiler
42
================
53

6-
</div>
7-
84
This version of CPython can be built with an experimental just-in-time compiler. While most everything you already know about building and using CPython is unchanged, you will probably need to install a compatible version of LLVM first.
95

106
### Installing LLVM
117

12-
While the JIT compiler does not require end users to install any third-party dependencies, part of it must be *built* using LLVM. It is *not* required for you to build the rest of CPython using LLVM, or the even the same version of LLVM (in fact, this is uncommon).
8+
The JIT compiler does not require end users to install any third-party dependencies, but part of it must be *built* using LLVM. You are *not* required to build the rest of CPython using LLVM, or the even the same version of LLVM (in fact, this is uncommon).
139

1410
LLVM version 16 is required. Both `clang` and `llvm-readobj` need to be installed and discoverable (version suffixes, like `clang-16`, are okay). It's highly recommended that you also have `llvm-objdump` available, since this allows the build script to dump human-readable assembly for the generated code.
1511

@@ -47,4 +43,4 @@ For `PCbuild`-based builds, pass the new `--experimental-jit` option to `build.b
4743

4844
For all other builds, pass the new `--enable-experimental-jit` option to `configure`.
4945

50-
Otherwise, just configure and build as you normally would. Even cross-compiling "just works", since the JIT is built for the host platform.
46+
Otherwise, just configure and build as you normally would. Cross-compiling "just works", since the JIT is built for the host platform.

0 commit comments

Comments
 (0)
0