MCPcopy Index your code
hub / github.com/python/cpython / write_uop

Function write_uop

Tools/cases_generator/optimizer_generator.py:382–425  ·  view source on GitHub ↗
(
    override: Uop | None,
    uop: Uop,
    out: CWriter,
    stack: Stack,
    debug: bool,
    skip_inputs: bool,
)

Source from the content-addressed store, hash-verified

380
381
382def write_uop(
383 override: Uop | None,
384 uop: Uop,
385 out: CWriter,
386 stack: Stack,
387 debug: bool,
388 skip_inputs: bool,
389) -> None:
390 locals: dict[str, Local] = {}
391 prototype = override if override else uop
392 try:
393 out.start_line()
394 if override:
395 storage = Storage.for_uop(stack, prototype, out, check_liveness=False)
396 if debug:
397 args = []
398 for input in prototype.stack.inputs:
399 if not input.peek or override:
400 args.append(input.name)
401 out.emit(f'DEBUG_PRINTF({", ".join(args)});\n')
402 if override:
403 for cache in uop.caches:
404 if cache.name != "unused":
405 if cache.size == 4:
406 type = cast = "PyObject *"
407 else:
408 type = f"uint{cache.size*16}_t "
409 cast = f"uint{cache.size*16}_t"
410 out.emit(f"{type}{cache.name} = ({cast})this_instr->operand0;\n")
411 if override:
412 emitter = OptimizerEmitter(out, {}, uop, stack.copy())
413 # No reference management of inputs needed.
414 for var in storage.inputs: # type: ignore[possibly-undefined]
415 var.in_local = False
416 _, storage = emitter.emit_tokens(override, storage, None, False)
417 out.start_line()
418 storage.flush(out)
419 out.start_line()
420 else:
421 emit_default(out, uop, stack)
422 out.start_line()
423 stack.flush(out)
424 except StackError as ex:
425 raise analysis_error(ex.args[0], prototype.body.open) # from None
426
427
428SKIPS = ("_EXTENDED_ARG",)

Callers 1

Calls 11

analysis_errorFunction · 0.90
OptimizerEmitterClass · 0.85
emit_defaultFunction · 0.85
start_lineMethod · 0.80
for_uopMethod · 0.80
emit_tokensMethod · 0.80
appendMethod · 0.45
emitMethod · 0.45
joinMethod · 0.45
copyMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…