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

Function generate_names_and_flags

Tools/cases_generator/uop_metadata_generator.py:65–136  ·  view source on GitHub ↗
(analysis: Analysis, out: CWriter)

Source from the content-addressed store, hash-verified

63
64
65def generate_names_and_flags(analysis: Analysis, out: CWriter) -> None:
66 out.emit(f"#define MAX_CACHED_REGISTER {MAX_CACHED_REGISTER}\n")
67 out.emit("extern const uint32_t _PyUop_Flags[MAX_UOP_ID+1];\n")
68 out.emit("typedef struct _rep_range { uint8_t start; uint8_t stop; } ReplicationRange;\n")
69 out.emit("extern const ReplicationRange _PyUop_Replication[MAX_UOP_ID+1];\n")
70 out.emit("extern const char * const _PyOpcode_uop_name[MAX_UOP_REGS_ID+1];\n\n")
71 out.emit("extern int _PyUop_num_popped(int opcode, int oparg);\n")
72 out.emit(CACHING_INFO_DECL)
73 out.emit(f"extern const uint16_t _PyUop_SpillsAndReloads[{MAX_CACHED_REGISTER+1}][{MAX_CACHED_REGISTER+1}];\n")
74 out.emit("extern const uint16_t _PyUop_Uncached[MAX_UOP_REGS_ID+1];\n\n")
75 out.emit("#ifdef NEED_OPCODE_METADATA\n")
76 out.emit("const uint32_t _PyUop_Flags[MAX_UOP_ID+1] = {\n")
77 for uop in analysis.uops.values():
78 if uop.is_viable() and uop.properties.tier != 1 and not uop.is_super():
79 out.emit(f"[{uop.name}] = {cflags(uop.properties)},\n")
80
81 out.emit("};\n\n")
82 out.emit("const ReplicationRange _PyUop_Replication[MAX_UOP_ID+1] = {\n")
83 for uop in analysis.uops.values():
84 if uop.replicated:
85 assert(uop.replicated.step == 1)
86 out.emit(f"[{uop.name}] = {{ {uop.replicated.start}, {uop.replicated.stop} }},\n")
87
88 out.emit("};\n\n")
89 out.emit("const _PyUopCachingInfo _PyUop_Caching[MAX_UOP_ID+1] = {\n")
90 for uop in analysis.uops.values():
91 if uop.is_viable() and uop.properties.tier != 1 and not uop.is_super():
92 info = uop_cache_info(uop)
93 if info is not None:
94 out.emit(f"[{uop.name}] = {{\n")
95 for line in info:
96 out.emit(line)
97 out.emit("},\n")
98 out.emit("};\n\n")
99 out.emit("const uint16_t _PyUop_Uncached[MAX_UOP_REGS_ID+1] = {\n");
100 for uop in analysis.uops.values():
101 if uop.is_viable() and uop.properties.tier != 1 and not uop.is_super() and not uop.properties.records_value:
102 for inputs, outputs, _ in get_uop_cache_depths(uop):
103 out.emit(f"[{uop.name}_r{inputs}{outputs}] = {uop.name},\n")
104 out.emit("};\n\n")
105 out.emit(f"const uint16_t _PyUop_SpillsAndReloads[{MAX_CACHED_REGISTER+1}][{MAX_CACHED_REGISTER+1}] = {{\n")
106 for i in range(MAX_CACHED_REGISTER+1):
107 for j in range(MAX_CACHED_REGISTER+1):
108 if i != j:
109 out.emit(f"[{i}][{j}] = _SPILL_OR_RELOAD_r{i}{j},\n")
110 out.emit("};\n\n")
111 out.emit("const char *const _PyOpcode_uop_name[MAX_UOP_REGS_ID+1] = {\n")
112 for uop in sorted(analysis.uops.values(), key=lambda t: t.name):
113 if uop.is_viable() and uop.properties.tier != 1 and not uop.is_super():
114 out.emit(f'[{uop.name}] = "{uop.name}",\n')
115 if not uop.properties.records_value:
116 for inputs, outputs, _ in get_uop_cache_depths(uop):
117 out.emit(f'[{uop.name}_r{inputs}{outputs}] = "{uop.name}_r{inputs}{outputs}",\n')
118 out.emit("};\n")
119 out.emit("int _PyUop_num_popped(int opcode, int oparg)\n{\n")
120 out.emit("switch(opcode) {\n")
121 null = CWriter.null()
122 for uop in analysis.uops.values():

Callers 1

generate_uop_metadataFunction · 0.85

Calls 11

popMethod · 0.95
cflagsFunction · 0.90
get_uop_cache_depthsFunction · 0.90
StackClass · 0.90
uop_cache_infoFunction · 0.85
is_viableMethod · 0.80
to_cMethod · 0.80
emitMethod · 0.45
valuesMethod · 0.45
is_superMethod · 0.45
nullMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…