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

Function generate_tier2

Tools/cases_generator/tier2_generator.py:250–297  ·  view source on GitHub ↗
(
    filenames: list[str], analysis: Analysis, outfile: TextIO, lines: bool
)

Source from the content-addressed store, hash-verified

248 )
249
250def generate_tier2(
251 filenames: list[str], analysis: Analysis, outfile: TextIO, lines: bool
252) -> None:
253 write_header(__file__, filenames, outfile)
254 outfile.write(
255 """
256#ifdef TIER_ONE
257 #error "This file is for Tier 2 only"
258#endif
259#define TIER_TWO 2
260"""
261 )
262 out = CWriter(outfile, 2, lines)
263 out.emit("\n")
264
265 for name, uop in analysis.uops.items():
266 if uop.properties.tier == 1:
267 continue
268 if uop.is_super():
269 continue
270 if uop.properties.records_value:
271 continue
272 why_not_viable = uop.why_not_viable()
273 if why_not_viable is not None:
274 out.emit(
275 f"/* {uop.name} is not a viable micro-op for tier 2 because it {why_not_viable} */\n\n"
276 )
277 continue
278 for inputs, outputs, exit_depth in get_uop_cache_depths(uop):
279 emitter = Tier2Emitter(out, analysis.labels, exit_depth)
280 out.emit(f"case {uop.name}_r{inputs}{outputs}: {{\n")
281 out.emit(f"CHECK_CURRENT_CACHED_VALUES({inputs});\n")
282 out.emit("assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());\n")
283 declare_variables(uop, out)
284 stack = Stack()
285 stack.push_cache([f"_tos_cache{i}" for i in range(inputs)], out)
286 stack._print(out)
287 reachable, stack = write_uop(uop, emitter, stack, outputs)
288 out.start_line()
289 if reachable:
290 out.emit("assert(WITHIN_STACK_BOUNDS_IGNORING_CACHE());\n")
291 if not uop.properties.always_exits:
292 out.emit("break;\n")
293 out.start_line()
294 out.emit("}")
295 out.emit("\n\n")
296 out.emit("\n")
297 outfile.write("#undef TIER_TWO\n")
298
299
300arg_parser = argparse.ArgumentParser(

Callers 1

tier2_generator.pyFile · 0.85

Calls 15

emitMethod · 0.95
push_cacheMethod · 0.95
_printMethod · 0.95
start_lineMethod · 0.95
write_headerFunction · 0.90
CWriterClass · 0.90
get_uop_cache_depthsFunction · 0.90
StackClass · 0.90
Tier2EmitterClass · 0.85
why_not_viableMethod · 0.80
declare_variablesFunction · 0.70
write_uopFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…