8000 gh-104909: Split some more insts into ops by gvanrossum · Pull Request #109943 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-104909: Split some more insts into ops #109943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 27, 2023
Merged
Prev Previous commit
Next Next commit
Sort non-viable opcodes by execution count
  • Loading branch information
gvanrossum committed Sep 27, 2023
commit e19517c7f6cbd7d588fb3aea8654bca07ec7f440
42 changes: 34 additions & 8 deletions Tools/cases_generator/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,34 +415,60 @@ def check_macro_components(
assert_never(uop)
return components

def report_non_viable_uops(self):
def report_non_viable_uops(self, jsonfile: str) -> None:
print("The following ops are not viable uops:")
skips = {
"CACHE",
"RESERVED",
"ENTER_EXECUTOR",
"INTERPRETER_EXIT",
"JUMP_BACKWARD",
"LOAD_FAST_LOAD_FAST",
"LOAD_FAST_LOAD_CONST",
"LOAD_CONST_LOAD_FAST",
"STORE_FAST_STORE_FAST",
"_BINARY_OP_INPLACE_ADD_UNICODE",
"POP_JUMP_IF_TRUE",
"POP_JUMP_IF_FALSE",
"_ITER_JUMP_LIST",
"_ITER_JUMP_TUPLE",
"_ITER_JUMP_SET",
"_ITER_JUMP_RANGE",
}
try:
# Secret feature: if bmraw.json exists, print and sort by execution count
counts = load_execution_counts(jsonfile)
except FileNotFoundError as err:
counts = {}
non_viable = [
instr
for instr in self.instrs.values()
if not instr.is_viable_uop()
and instr.name not in skips
if instr.name not in skips
and not instr.name.startswith("INSTRUMENTED_")
and not instr.is_viable_uop()
]
non_viable.sort(key=lambda instr: instr.name)
non_viable.sort(key=lambda instr: (-counts.get(instr.name, 0), instr.name))
for instr in non_viable:
print(f" {instr.name:<35}", end="")
if instr.name in counts:
scount = f"{counts[instr.name]:,}"
else:
scount = ""
print(f" {scount:>15} {instr.name:<35}", end="")
if instr.name in self.families:
print(" (unspecialized)", end="")
elif instr.family is not None:
print(f" (specialization of {instr.family.name})", end="")
print()


def load_execution_counts(jsonfile: str) -> dict[str, int]:
import json

with open(jsonfile) as f:
jsondata = json.load(f)

# Look for keys like "opcode[LOAD_FAST].execution_count"
prefix = "opcode["
suffix = "].execution_count"
res: dict[str, int] = {}
for key, value in jsondata.items():
if key.startswith(prefix) and key.endswith(suffix):
res[key[len(prefix) : -len(suffix)]] = value
return res
3 changes: 2 additions & 1 deletion Tools/cases_generator/generate_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,8 @@ def main() -> None:
if a.errors:
sys.exit(f"Found {a.errors} errors")
if args.verbose:
a.report_non_viable_uops()
# Load execution counts from bmraw.json, if it exists
a.report_non_viable_uops("bmraw.json")
return

# These raise OSError if output can't be written
Expand Down
0