Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Factor out tier-2 code generator
  • Loading branch information
markshannon committed Dec 11, 2023
commit 3f01a7af763675d730048338696a92194ac3a324
3 changes: 3 additions & 0 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -3967,6 +3967,7 @@ dummy_func(
}

inst(EXTENDED_ARG, ( -- )) {
TIER_ONE_ONLY
assert(oparg);
opcode = next_instr->op.code;
oparg = oparg << 8 | next_instr->op.arg;
Expand All @@ -3975,11 +3976,13 @@ dummy_func(
}

inst(CACHE, (--)) {
TIER_ONE_ONLY
assert(0 && "Executing a cache.");
Py_UNREACHABLE();
}

inst(RESERVED, (--)) {
TIER_ONE_ONLY
assert(0 && "Executing RESERVED instruction.");
Py_UNREACHABLE();
}
Expand Down
23 changes: 2 additions & 21 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Tools/cases_generator/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ def pop(self, var: StackItem) -> str:
return ""
else:
self.defined.add(var.name)
assign = f"{var.name} = {indirect}stack_pointer[{self.base_offset.to_c()}];"
cast = f"({var.type})" if (not indirect and var.type) else ""
assign = f"{var.name} = {cast}{indirect}stack_pointer[{self.base_offset.to_c()}];"
if var.condition:
return f"if ({var.condition}) {{ {assign} }}\n"
return f"{assign}\n"
Expand All @@ -142,11 +143,12 @@ def push(self, var: StackItem) -> str:
def flush(self, out: CWriter) -> None:
for var in self.variables:
if not var.peek:
cast = "(PyObject *)" if var.type else ""
if var.name != "unused" and not var.is_array():
if var.condition:
out.emit(f" if ({var.condition}) ")
out.emit(
f"stack_pointer[{self.base_offset.to_c()}] = {var.name};\n"
f"stack_pointer[{self.base_offset.to_c()}] = {cast}{var.name};\n"
)
self.base_offset.push(var)
if self.base_offset.to_c() != self.top_offset.to_c():
Expand Down
3 changes: 3 additions & 0 deletions Tools/cases_generator/tier2_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ def write_uop(uop: Uop, out: CWriter, stack: Stack) -> None:
raise analysis_error(ex.args[0], uop.body[0])


SKIPS = (
"_EXTENDED_ARG",)

def generate_tier2(
filenames: str, analysis: Analysis, outfile: TextIO, lines: bool
) -> None:
Expand Down
8 changes: 7 additions & 1 deletion Tools/cases_generator/uop_id_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
DEFAULT_OUTPUT = ROOT / "Include/internal/pycore_uop_ids.h"


OMIT = { "_CACHE", "_RESERVED", "_EXTENDED_ARG" }
Comment thread
markshannon marked this conversation as resolved.
Outdated

def generate_uop_ids(
filenames: str, analysis: Analysis, outfile: TextIO, distinct_namespace: bool
) -> None:
Expand All @@ -45,11 +47,15 @@ def generate_uop_ids(
next_id += 1
out.emit(f"#define _SET_IP {next_id}\n")
next_id += 1
PRE_DEFINED = {"_EXIT_TRACE", "_SET_IP", "_CACHE", "_RESERVED", "_EXTENDED_ARG"}
PRE_DEFINED = {"_EXIT_TRACE", "_SET_IP"}

for uop in analysis.uops.values():
if uop.name in PRE_DEFINED:
continue
# We should omit all tier-1 only uops, but
Comment thread
markshannon marked this conversation as resolved.
Outdated
# generate_cases.py still generates code for those.
if uop.name in OMIT:
continue
if uop.implicitly_created and not distinct_namespace:
out.emit(f"#define {uop.name} {uop.name[1:]}\n")
else:
Expand Down